LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
Geometry_service.cc
Go to the documentation of this file.
1 
8 // class header
10 
11 // lar includes
15 
16 // Framework includes
17 #include "cetlib_except/exception.h"
18 #include "cetlib/search_path.h"
20 
21 // C/C++ standard libraries
22 #include <vector>
23 #include <string>
24 
25 
26 namespace geo {
27 
28 
29  //......................................................................
30  // Constructor.
32  : GeometryCore(pset)
33  , fRelPath (pset.get< std::string >("RelativePath", "" ))
34  , fDisableWiresInG4 (pset.get< bool >("DisableWiresInG4", false))
35  , fForceUseFCLOnly (pset.get< bool >("ForceUseFCLOnly" , false))
36  , fSortingParameters(pset.get<fhicl::ParameterSet>("SortingParameters", fhicl::ParameterSet() ))
37  {
38  // add a final directory separator ("/") to fRelPath if not already there
39  if (!fRelPath.empty() && (fRelPath.back() != '/')) fRelPath += '/';
40 
41  // register a callback to be executed when a new run starts
42  reg.sPreBeginRun.watch(this, &Geometry::preBeginRun);
43 
44  //......................................................................
45  // 5.15.12 BJR: use the gdml file for both the fGDMLFile and fROOTFile
46  // variables as ROOT v5.30.06 is once again able to read in gdml files
47  // during batch operation, in this case think of fROOTFile meaning the
48  // file used to make the ROOT TGeoManager. I don't want to remove
49  // the separate variables in case ROOT breaks again
50  std::string GDMLFileName = pset.get<std::string>("GDML");
51  std::string ROOTFileName = pset.get<std::string>("GDML");
52 
53  // load the geometry
54  LoadNewGeometry(GDMLFileName, ROOTFileName);
55 
56  } // Geometry::Geometry()
57 
58 
60  {
61  // FIXME this seems utterly wrong: constructor loads geometry based on an
62  // explicit parameter, whereas here we load it by detector name
63 
64  // if we are requested to stick to the configured geometry, do nothing
65  if (fForceUseFCLOnly) return;
66 
67  // check here to see if we need to load a new geometry.
68  // get the detector id from the run object
69  std::vector< art::Handle<sumdata::RunData> > rdcol;
70  run.getManyByType(rdcol);
71  if (rdcol.empty()) {
72  mf::LogWarning("Geometry") << "cannot find sumdata::RunData object to grab detector name\n"
73  << "this is expected if generating MC files\n"
74  << "using default geometry from configuration file\n";
75  return;
76  }
77 
78  // if the detector name is still the same, everything is fine
79  std::string newDetectorName = rdcol.front()->DetName();
80  if (DetectorName() == newDetectorName) return;
81 
82  // check to see if the detector name in the RunData
83  // object has not been set.
84  std::string const nodetname("nodetectorname");
85  if (newDetectorName == nodetname) {
86  LOG_WARNING("Geometry") << "Detector name not set: " << newDetectorName;
87  } // if no detector name stored
88  else {
89  // the detector name is specified in the RunData object
90  SetDetectorName(newDetectorName);
91  }
92 
93  LoadNewGeometry(DetectorName() + ".gdml", DetectorName() + ".gdml", true);
94  } // Geometry::preBeginRun()
95 
96 
97  //......................................................................
99  {
100  // the channel map is responsible of calling the channel map configuration
101  // of the geometry
103  ->ConfigureChannelMapAlg(fSortingParameters, this);
104 
105  if ( ! ChannelMap() ) {
106  throw cet::exception("ChannelMapLoadFail")
107  << " failed to load new channel map";
108  }
109 
110  } // Geometry::InitializeChannelMap()
111 
112  //......................................................................
114  std::string gdmlfile, std::string /* rootfile */,
115  bool bForceReload /* = false */
116  ) {
117  // start with the relative path
118  std::string GDMLFileName(fRelPath), ROOTFileName(fRelPath);
119 
120  // add the base file names
121  ROOTFileName.append(gdmlfile); // not rootfile (why?)
122  GDMLFileName.append(gdmlfile);
123 
124  // special for GDML if geometry with no wires is used for Geant4 simulation
126  GDMLFileName.insert(GDMLFileName.find(".gdml"), "_nowires");
127 
128  // Search all reasonable locations for the GDML file that contains
129  // the detector geometry.
130  // cet::search_path constructor decides if initialized value is a path
131  // or an environment variable
132  cet::search_path sp("FW_SEARCH_PATH");
133 
134  std::string GDMLfile;
135  if( !sp.find_file(GDMLFileName, GDMLfile) ) {
136  throw cet::exception("Geometry")
137  << "cannot find the gdml geometry file:"
138  << "\n" << GDMLFileName
139  << "\nbail ungracefully.\n";
140  }
141 
142  std::string ROOTfile;
143  if( !sp.find_file(ROOTFileName, ROOTfile) ) {
144  throw cet::exception("Geometry")
145  << "cannot find the root geometry file:\n"
146  << "\n" << ROOTFileName
147  << "\nbail ungracefully.\n";
148  }
149 
150  // initialize the geometry with the files we have found
151  LoadGeometryFile(GDMLfile, ROOTfile, bForceReload);
152 
153  // now update the channel map
155 
156  } // Geometry::LoadNewGeometry()
157 
159 } // namespace geo
void LoadGeometryFile(std::string gdmlfile, std::string rootfile, bool bForceReload=false)
Loads the geometry information from the specified files.
fhicl::ParameterSet fSortingParameters
Parameter set to define the channel map sorting.
Definition: Geometry.h:141
#define DEFINE_ART_SERVICE(svc)
Definition: ServiceMacros.h:93
STL namespace.
bool fDisableWiresInG4
Definition: Geometry.h:137
Geometry(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
void preBeginRun(art::Run const &run)
Updates the geometry if needed at the beginning of each new run.
Definition: Run.h:30
bool fForceUseFCLOnly
Definition: Geometry.h:139
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
parameter set interface
T get(std::string const &key) const
Definition: ParameterSet.h:231
std::string fRelPath
Definition: Geometry.h:135
void LoadNewGeometry(std::string gdmlfile, std::string rootfile, bool bForceReload=false)
Expands the provided paths and loads the geometry description(s)
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: DataViewImpl.h:446
Interface to a service that handles any experiment-specific knowledge that is needed by the Geometry ...
The geometry of one entire detector, as served by art.
Definition: Geometry.h:110
Description of geometry of one entire detector.
Definition of data types for geometry description.
#define LOG_WARNING(category)
GlobalSignal< detail::SignalResponseType::FIFO, void(Run const &)> sPreBeginRun
geo::ChannelMapAlg const * ChannelMap() const
Returns the object handling the channel map.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Namespace collecting geometry-related classes utilities.
void SetDetectorName(std::string new_name)
Sets the detector name.
void InitializeChannelMap()
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33