GEMC  2.3
Geant4 Monte-Carlo Framework
text_mirrors.cc
Go to the documentation of this file.
1 // gemc headers
2 #include "mirrors_factory.h"
3 #include "text_mirrors.h"
4 #include "string_utilities.h"
5 #include "utils.h"
6 
7 
8 map<string, mirror*> text_mirrors::initMirrors(runConditions rc, goptions opts)
9 {
10 
11  string hd_msg = opts.optMap["LOG_MSG"].args + " TEXT Mirrors Factory: >> ";
12  double verbosity = opts.optMap["MIRROR_VERBOSITY"].arg;
13 
14  map<string, mirror*> mymirs; // mirror map
15 
16  // first check if there's at least one detector with TEXT factory
18  return mymirs;
19 
20  // Looping over detectorConditionsMap for detector names
21  // To each detector maybe associated a mirror
22  for(map<string, detectorCondition>::iterator it=rc.detectorConditionsMap.begin(); it != rc.detectorConditionsMap.end(); it++)
23  {
24  // building mirror belonging to detectors that are tagged with MYSQL factory
25  if(it->second.get_factory() != "TEXT")
26  continue;
27 
28  if(verbosity)
29  cout << hd_msg << " Initializing " << it->second.get_factory() << " for detector " << it->first << endl;
30 
31  // only add "main" if it's the main variation
32  string dname = it->first ;
33  string variation = get_variation(it->second.get_variation());
34  string filename = dname + "__mirrors_" + variation + ".txt";
35 
36  ifstream IN(filename.c_str());
37  if(!IN)
38  {
39  // if file is not found, maybe it's in the GEMC_DATA_DIR directory
40  if(getenv("GEMC_DATA_DIR") != NULL)
41  {
42 
43  string maybeHere = (string) getenv("GEMC_DATA_DIR") + "/" + filename;
44 
45  IN.open(maybeHere.c_str());
46  if(!IN)
47  {
48  if(verbosity>1)
49  cout << hd_msg << "Warning: The system >" << dname
50  << "< does not have a mirror file associated with it. " << endl;
51  continue;
52  }
53  }
54 
55  if(!IN)
56  {
57  if(verbosity>1)
58  cout << hd_msg << "Warning: The system >" << dname
59  << "< does not have a mirror file associated with it. " << endl;
60  continue;
61  }
62  }
63 
64  // else loading parameters from file
65  while(!IN.eof())
66  {
67  string dbline;
68  getline(IN, dbline);
69 
70  if(!dbline.size())
71  continue;
72 
73  gtable gt(get_strings(dbline, "|"));
74  if( gt.data.size() != 14)
75  cout << "ERROR: Incorrect number of mirror items (" << gt.data.size() << ") for " << gt.data[0]
76  << ". We should have 14 but we have " << gt.data.size() << " instead." << endl;
77 
78 
79  mirror *thisMir = new mirror(TrimSpaces( gt.data[0])); // name
80  thisMir->desc = gt.data[1]; // description
81  thisMir->type = TrimSpaces(gt.data[2]); // type
82  thisMir->finish = TrimSpaces(gt.data[3]); // finish
83  thisMir->model = TrimSpaces(gt.data[4]); // model
84  thisMir->border = TrimSpaces(gt.data[5]); // border
85  thisMir->maptOptProps = TrimSpaces(gt.data[6]); // material with optical properties
86  thisMir->opticalsFromString( gt.data[7], "photonEnergy");
87  thisMir->opticalsFromString( gt.data[8], "indexOfRefraction");
88  thisMir->opticalsFromString( gt.data[9], "reflectivity");
89  thisMir->opticalsFromString( gt.data[10], "efficiency");
90  thisMir->opticalsFromString( gt.data[11], "specularlobe");
91  thisMir->opticalsFromString( gt.data[12], "specularspike");
92  thisMir->opticalsFromString( gt.data[13], "backscatter");
93 
94  mymirs[thisMir->name] = thisMir;
95 
96  }
97  }
98  cout << endl;
99 
100  if(verbosity>0) printMirrors(mymirs);
101 
102  return mymirs;
103 }
104 
105 
106 
107 
vector< string > get_strings(string input)
returns a vector of strings from a stringstream, space is delimiter
int check_if_factory_is_needed(map< string, detectorCondition > dcon, string factory)
vector< string > data
Definition: utils.h:76
Definition: utils.h:65
double verbosity
string get_variation(string var)
parse variation name from string
string desc
void opticalsFromString(string, string)
Overloaded "<<" for mirror class. Dumps infos on screen.
map< string, detectorCondition > detectorConditionsMap
string model
string finish
map< string, aopt > optMap
Options map.
Definition: options.h:75
map< string, mirror * > initMirrors(runConditions, goptions)
Definition: text_mirrors.cc:8
string type
void printMirrors(map< string, mirror * > mirMap)
string TrimSpaces(string in)
Removes leading and trailing spaces.
string name
string border
string maptOptProps