GEMC  2.3
Geant4 Monte-Carlo Framework
clara_det_factory.cc
Go to the documentation of this file.
1 
2 // gemc headers
3 #include "clara_det_factory.h"
4 #include "utils.h"
5 
6 #include <dlfcn.h>
7 
8 typedef map<string, map<string,string> > volmap_t;
9 
10 map<string, detector> clara_det_factory::loadDetectors()
11 {
12  string hd_msg = gemcOpt.optMap["LOG_MSG"].args + " CLARA Factory: >> ";
13  // double verbosity = gemcOpt.optMap["GEO_VERBOSITY"].arg;
14 
15  map<string, detector> dets;
16  // first check if there's at least one detector with CLARA factory
18  return dets;
19 
20  // checking if the plugin directory exist
21  if(getenv ("GEMC_PLUGINS") == NULL)
22  {
23  cout << " !!! Warning: the GEMC_PLUGINS env variable, needed for the CLARA plugin, is not set. " << endl;
24  cout << " !!! Warning: for CLAS12, this is typically /group/clas12/lib " << endl;
25  cout << " !!! Warning: CLARA detectors won't be loaded. " << endl << endl;
26  return dets;
27  }
28 
29  string clasraPlugin = (string) getenv("GEMC_PLUGINS") + "/libclas12_geometry_gemc.so";
30 
31  cout << " > Opening geometry plugin..." << endl;
32  void* handle = dlopen(clasraPlugin.c_str(), RTLD_NOW);
33 
34  if (!handle)
35  {
36  cerr << " !!! Error: Cannot open library: " << dlerror() << '\n';
37  exit(0);
38  }
39 
40  // reset errors
41  dlerror();
42 
43  // extract function symbol from library
44  typedef volmap_t (*get_volume_maps_t)(const map<string,string>&);
45  get_volume_maps_t get_volume_maps = (get_volume_maps_t) dlsym(handle, "get_volume_maps");
46 
47  const char *dlsym_error = dlerror();
48  if (dlsym_error)
49  {
50  cerr << " !!! Error: Cannot load symbol 'get_volume_maps': " << dlerror() << endl;
51  dlclose(handle);
52  exit(0);
53  }
54 
55 
56  // building detectors that are tagged with CLARA factory
57  for(map<string, detectorCondition>::iterator it=RC.detectorConditionsMap.begin(); it != RC.detectorConditionsMap.end(); it++)
58  {
59  if(it->second.get_factory() != factoryType )
60  continue;
61 
62 
63  // send request with a string with the detector name in it + "/volumes"
64  // e.g. dc/volumes.
65  map<string,string> request;
66  request["request"] = it->first + "/volumes";
67 
68  map<string, map<string,string> > volumes = get_volume_maps(request);
69 
70  cout << " >>>> Loading: " << it->first << endl;
71 
72  for(map<string, map<string,string> >::iterator idet = volumes.begin(); idet != volumes.end(); idet++)
73  {
74  gtable gt;
75 
76  gt.add_data(idet->first); // 1 name
77  gt.add_data(idet->second["mother"]); // 2 mother volume
78  gt.add_data(idet->second["description"]); // 3 description
79  gt.add_data(idet->second["pos"]); // 4 position
80  gt.add_data(idet->second["rotation"]); // 5 rotation
81  gt.add_data(idet->second["color"]); // 6 color
82  gt.add_data(idet->second["type"]); // 7 type
83  gt.add_data(idet->second["dimensions"]); // 8 dimensions
84  gt.add_data(idet->second["material"]); // 9 material
85  gt.add_data(idet->second["mfield"]); // 10 magnetic field
86  gt.add_data(idet->second["ncopy"]); // 11 copy number
87  gt.add_data(idet->second["pMany"]); // 12 pmany
88  gt.add_data(idet->second["exist"]); // 13 activation flag
89  gt.add_data(idet->second["visible"]); // 14 visibility
90  gt.add_data(idet->second["style"]); // 15 style
91  gt.add_data(idet->second["sensitivity"]); // 16 sensitivity
92  gt.add_data(idet->second["hit_type"]); // 17 hit_type
93  gt.add_data(idet->second["identifiers"]); // 18 identifiers
94  gt.add_data(it->first); // 19 system
95  gt.add_data((string) "CLARA"); // 20 factory
96  gt.add_data(idet->second["variation"]); // 21 variation
97  gt.add_data(idet->second["run"]); // 22 run number
98 
99  dets[gt.data[0]] = get_detector(gt, gemcOpt, RC);
100 
101 
102  }
103  }
104 
105  // close the library
106  dlclose(handle);
107 
108 
109  return dets;
110 }
111 
112 
113 
114 
115 
int check_if_factory_is_needed(map< string, detectorCondition > dcon, string factory)
map< string, detector > loadDetectors()
vector< string > data
Definition: utils.h:76
Definition: utils.h:65
void add_data(QVariant input)
Definition: utils.h:78
map< string, detectorCondition > detectorConditionsMap
runConditions RC
map< string, map< string, string > > volmap_t
map< string, aopt > optMap
Options map.
Definition: options.h:75
detector get_detector(gtable gt, goptions go, runConditions RC)