9
9
10
10
// mlibrary
11
11
#include " gstring.h"
12
+
12
13
using namespace gstring ;
13
14
14
15
// G4 headers
@@ -17,99 +18,95 @@ using namespace gstring;
17
18
#include " G4OpBoundaryProcess.hh"
18
19
19
20
20
- map<string, G4Material*> mysql_materials::initMaterials (runConditions rc, goptions opts)
21
- {
22
-
23
- string hd_msg = opts.optMap [" LOG_MSG" ].args + " MYSQL Materials Factory: >> " ;
24
- double verbosity = opts.optMap [" MATERIAL_VERBOSITY" ].arg ;
25
-
26
- map<string, material> mymats; // material map
27
-
28
- // first check if there's at least one detector with MYSQL factory
29
- if (!check_if_factory_is_needed (rc.detectorConditionsMap , " MYSQL" ))
30
- return materialsFromMap (mymats);
31
-
32
- // connection to the DB
33
- QSqlDatabase db = openGdb (opts);
34
-
35
- // Looping over detectorConditionsMap for detector names
36
- // To each detector is associated a material and (optional) opt properties
37
- for (map<string, detectorCondition>::iterator it=rc.detectorConditionsMap .begin (); it != rc.detectorConditionsMap .end (); it++)
38
- {
39
- // building materials belonging to detectors that are tagged with MYSQL factory
40
- if (it->second .get_factory () != " MYSQL" )
41
- continue ;
42
-
43
- if (verbosity)
44
- cout << hd_msg << " Initializing " << it->second .get_factory () << " for detector " << it->first << endl;
45
-
46
- // only add "main" if it's the main variation
47
- string dname = it->first ;
48
- string tname = dname + " __materials" ;
49
- string variation = get_variation (it->second .get_variation ());
50
- if (is_main_variation (it->second .get_variation ()))
51
- tname += " _main" ;
52
-
53
- string dbexecute = " select name, description, density, ncomponents, components, photonEnergy, indexOfRefraction, " ;
54
- dbexecute += " absorptionLength, reflectivity, efficiency, fastcomponent, slowcomponent, " ;
55
- dbexecute += " scintillationyield, resolutionscale, fasttimeconstant, slowtimeconstant, yieldratio, rayleigh, birkConstant, " ;
56
- dbexecute += " mie, mieforward, miebackward, mieratio from " + tname;
57
- dbexecute += " where variation ='" + variation + " '" ;
58
-
59
- // executing query - will exit if not successfull.
60
- QSqlQuery q;
61
- if (!q.exec (dbexecute.c_str ())) {
62
- cout << hd_msg << " Failed to execute MYSQL query " << dbexecute << " . This is a fatal error. Exiting." << endl;
63
- qDebug () << q.lastError ();
64
- exit (1 );
65
- }
66
- // Warning if nothing is found
67
- if (q.size () == 0 && verbosity)
68
- {
69
- cout << " ** WARNING: material for system \" " << dname << " \" not found with variation \" " << variation << endl << endl;
70
- }
71
-
72
- while (q.next ())
73
- {
74
- material thisMat (trimSpacesFromString (qv_tostring ( q.value (0 )))); // name
75
- thisMat.desc = qv_tostring (q.value (1 )); // description
76
- thisMat.density = q.value (2 ).toDouble (); // density
77
- thisMat.ncomponents = q.value (3 ).toInt (); // number of components
78
- thisMat.componentsFromString (qv_tostring (q.value (4 ))); // component + quantity list
79
- thisMat.opticalsFromString (qv_tostring ( q.value (5 )), " photonEnergy" );
80
- thisMat.opticalsFromString (qv_tostring ( q.value (6 )), " indexOfRefraction" );
81
- thisMat.opticalsFromString (qv_tostring ( q.value (7 )), " absorptionLength" );
82
- thisMat.opticalsFromString (qv_tostring ( q.value (8 )), " reflectivity" );
83
- thisMat.opticalsFromString (qv_tostring ( q.value (9 )), " efficiency" );
84
-
85
- // scintillation
86
- thisMat.opticalsFromString (qv_tostring ( q.value (10 )), " fastcomponent" );
87
- thisMat.opticalsFromString (qv_tostring ( q.value (11 )), " slowcomponent" );
88
- thisMat.scintillationyield = q.value (12 ).toDouble (); // scintillationyield
89
- thisMat.resolutionscale = q.value (13 ).toDouble (); // resolutionscale
90
- thisMat.fasttimeconstant = q.value (14 ).toDouble (); // fasttimeconstant
91
- thisMat.slowtimeconstant = q.value (15 ).toDouble (); // slowtimeconstant
92
- thisMat.yieldratio = q.value (16 ).toDouble (); // yieldratio
93
- thisMat.opticalsFromString (qv_tostring ( q.value (17 )), " rayleigh" );
94
-
95
- // Birk Constant
96
- thisMat.birkConstant = q.value (18 ).toDouble (); // yieldratio
97
-
98
- // Mie scattering
99
- thisMat.opticalsFromString (qv_tostring ( q.value (19 )), " mie" );
100
- thisMat.mieforward = q.value (20 ).toDouble (); // mie forward scattering
101
- thisMat.miebackward = q.value (21 ).toDouble (); // mie backward scattering
102
- thisMat.mieratio = q.value (22 ).toDouble (); // mie forward/backward scattering ratio
103
-
104
- mymats[thisMat.name ] = thisMat;
105
-
106
- }
107
- }
108
-
109
- cout << endl;
110
-
111
- map<string, G4Material*> returnMap = materialsFromMap (mymats);
112
- if (verbosity>0 ) printMaterials (returnMap);
113
-
114
- return returnMap;
21
+ map<string, G4Material *> mysql_materials::initMaterials (runConditions rc, goptions opts) {
22
+
23
+ string hd_msg = opts.optMap [" LOG_MSG" ].args + " MYSQL Materials Factory: >> " ;
24
+ double verbosity = opts.optMap [" MATERIAL_VERBOSITY" ].arg ;
25
+
26
+ map <string, material> mymats; // material map
27
+
28
+ // first check if there's at least one detector with MYSQL factory
29
+ if (!check_if_factory_is_needed (rc.detectorConditionsMap , " MYSQL" ))
30
+ return materialsFromMap (mymats);
31
+
32
+ // connection to the DB
33
+ QSqlDatabase db = openGdb (opts);
34
+
35
+ // Looping over detectorConditionsMap for detector names
36
+ // To each detector is associated a material and (optional) opt properties
37
+ for (map<string, detectorCondition>::iterator it = rc.detectorConditionsMap .begin (); it != rc.detectorConditionsMap .end (); it++) {
38
+ // building materials belonging to detectors that are tagged with MYSQL factory
39
+ if (it->second .get_factory () != " MYSQL" )
40
+ continue ;
41
+
42
+ if (verbosity)
43
+ cout << hd_msg << " Initializing " << it->second .get_factory () << " for detector " << it->first << endl;
44
+
45
+ // only add "main" if it's the main variation
46
+ string dname = it->first ;
47
+ string tname = dname + " __materials" ;
48
+ string variation = get_variation (it->second .get_variation ());
49
+ if (is_main_variation (it->second .get_variation ()))
50
+ tname += " _main" ;
51
+
52
+ string dbexecute = " select name, description, density, ncomponents, components, photonEnergy, indexOfRefraction, " ;
53
+ dbexecute += " absorptionLength, reflectivity, efficiency, fastcomponent, slowcomponent, " ;
54
+ dbexecute += " scintillationyield, resolutionscale, fasttimeconstant, slowtimeconstant, yieldratio, rayleigh, birkConstant, " ;
55
+ dbexecute += " mie, mieforward, miebackward, mieratio from " + tname;
56
+ dbexecute += " where variation ='" + variation + " '" ;
57
+
58
+ // executing query - will exit if not successfull.
59
+ QSqlQuery q;
60
+ if (!q.exec (dbexecute.c_str ())) {
61
+ cout << hd_msg << " Failed to execute MYSQL query " << dbexecute << " . This is a fatal error. Exiting." << endl;
62
+ qDebug () << q.lastError ();
63
+ exit (1 );
64
+ }
65
+ // Warning if nothing is found
66
+ if (q.size () == 0 && verbosity) {
67
+ cout << " ** WARNING: material for system \" " << dname << " \" not found with variation \" " << variation << endl << endl;
68
+ }
69
+
70
+ while (q.next ()) {
71
+ material thisMat (trimSpacesFromString (qv_tostring ( q.value (0 )))); // name
72
+ thisMat.desc = qv_tostring (q.value (1 )); // description
73
+ thisMat.density = q.value (2 ).toDouble (); // density
74
+ thisMat.ncomponents = q.value (3 ).toInt (); // number of components
75
+ thisMat.componentsFromString (qv_tostring (q.value (4 ))); // component + quantity list
76
+ thisMat.opticalsFromString (qv_tostring (q.value (5 )), " photonEnergy" );
77
+ thisMat.opticalsFromString (qv_tostring (q.value (6 )), " indexOfRefraction" );
78
+ thisMat.opticalsFromString (qv_tostring (q.value (7 )), " absorptionLength" );
79
+ thisMat.opticalsFromString (qv_tostring (q.value (8 )), " reflectivity" );
80
+ thisMat.opticalsFromString (qv_tostring (q.value (9 )), " efficiency" );
81
+
82
+ // scintillation
83
+ thisMat.opticalsFromString (qv_tostring (q.value (10 )), " fastcomponent" );
84
+ thisMat.opticalsFromString (qv_tostring (q.value (11 )), " slowcomponent" );
85
+ thisMat.scintillationyield = q.value (12 ).toDouble (); // scintillationyield
86
+ thisMat.resolutionscale = q.value (13 ).toDouble (); // resolutionscale
87
+ thisMat.fasttimeconstant = q.value (14 ).toDouble (); // fasttimeconstant
88
+ thisMat.slowtimeconstant = q.value (15 ).toDouble (); // slowtimeconstant
89
+ thisMat.yieldratio = q.value (16 ).toDouble (); // yieldratio
90
+ thisMat.opticalsFromString (qv_tostring (q.value (17 )), " rayleigh" );
91
+
92
+ // Birk Constant
93
+ thisMat.birkConstant = q.value (18 ).toDouble (); // yieldratio
94
+
95
+ // Mie scattering
96
+ thisMat.opticalsFromString (qv_tostring (q.value (19 )), " mie" );
97
+ thisMat.mieforward = q.value (20 ).toDouble (); // mie forward scattering
98
+ thisMat.miebackward = q.value (21 ).toDouble (); // mie backward scattering
99
+ thisMat.mieratio = q.value (22 ).toDouble (); // mie forward/backward scattering ratio
100
+
101
+ mymats[thisMat.name ] = thisMat;
102
+
103
+ }
104
+ }
105
+
106
+ cout << endl;
107
+
108
+ map < string, G4Material * > returnMap = materialsFromMap (mymats);
109
+ if (verbosity > 0 ) printMaterials (returnMap);
110
+
111
+ return returnMap;
115
112
}
0 commit comments