GEMC  2.3
Geant4 Monte-Carlo Framework
text_det_factory.cc
Go to the documentation of this file.
1 // Qt headers
2 #include <QtSql>
3 
4 // gemc headers
5 #include "text_det_factory.h"
6 #include "utils.h"
7 
8 map<string, detector> text_det_factory::loadDetectors()
9 {
10  string hd_msg = gemcOpt.optMap["LOG_MSG"].args + " TEXT Factory: >> ";
11  double verbosity = gemcOpt.optMap["GEO_VERBOSITY"].arg;
12 
13  map<string, detector> dets;
14  // first check if there's at least one detector with TEXT factory
16  return dets;
17 
18  // building detectors that are tagged with TEXT factory
19  for(map<string, detectorCondition>::iterator it=RC.detectorConditionsMap.begin(); it != RC.detectorConditionsMap.end(); it++)
20  {
21  if(it->second.get_factory() != factoryType )
22  continue;
23 
24  string dname = it->first;
25  string fname = dname + "__geometry";
26  string variation = get_variation(it->second.get_variation());
27 
28  if(verbosity)
29  cout << hd_msg << " Importing Detector: " << dname << " with " << factoryType << " factory, variation " << variation << endl;
30 
31  fname += "_" + variation + ".txt";
32  ifstream IN(fname.c_str());
33  if(!IN)
34  {
35 
36  // if file is not found, maybe it's in the GEMC_DATA_DIR directory
37  if(getenv("GEMC_DATA_DIR") != NULL)
38  {
39  string maybeHere = (string) getenv("GEMC_DATA_DIR") + "/" + fname;
40 
41  IN.open(maybeHere.c_str());
42  if(!IN)
43  {
44 
45  cout << hd_msg << " Failed to open geometry file " << maybeHere << " for system: " << dname
46  << ". Maybe the filename doesn't exist? Exiting." << endl;
47  exit(0);
48  }
49  }
50 
51  if(!IN)
52  {
53 
54  cout << hd_msg << " Failed to open geometry file " << fname << " for system: " << dname
55  << ". Maybe the filename doesn't exist? Exiting." << endl;
56  exit(0);
57  }
58  }
59 
60 
61 
62  // else loading parameters from file
63  while(!IN.eof())
64  {
65  string dbline;
66  getline(IN, dbline);
67 
68  if(!dbline.size())
69  continue;
70 
71  gtable gt(get_strings(dbline, "|"));
72  if( gt.data.size() != 18)
73  cout << "ERROR: Incorrect number of geometry items (" << gt.data.size() << ") for " << gt.data[0] << endl;
74 
75  gt.add_data(dname);
76  gt.add_data((string)"TEXT");
77  gt.add_data(variation);
78 
79  // big warning if detector already exist
80  // detector is NOT loaded if already existing
81  if(dets.find(gt.data[0]) != dets.end())
82  {
83  cout << endl << " *** WARNING! A detector >" << gt.data[0]
84  << " exists already. Keeping original, not loading this instance. " << endl << endl;
85  }
86  else
87  {
88  dets[gt.data[0]] = get_detector(gt, gemcOpt, RC);
89  }
90 
91  }
92  IN.close();
93  }
94 
95  return dets;
96 }
97 
98 
99 
100 
101 
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
void add_data(QVariant input)
Definition: utils.h:78
map< string, detectorCondition > detectorConditionsMap
runConditions RC
map< string, aopt > optMap
Options map.
Definition: options.h:75
detector get_detector(gtable gt, goptions go, runConditions RC)
map< string, detector > loadDetectors()