LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
AuxDetGeometry_service.cc
Go to the documentation of this file.
1 
8 // class header
11 
12 // 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  : fProvider (pset)
33  , fRelPath (pset.get< std::string >("RelativePath", "" ))
34  , fForceUseFCLOnly (pset.get< bool >("ForceUseFCLOnly" , false))
35  , fSortingParameters(pset.get<fhicl::ParameterSet>("SortingParameters", fhicl::ParameterSet() ))
36  {
37  // add a final directory separator ("/") to fRelPath if not already there
38  if (!fRelPath.empty() && (fRelPath.back() != '/')) fRelPath += '/';
39 
40  // register a callback to be executed when a new run starts
41  reg.sPreBeginRun.watch(this, &AuxDetGeometry::preBeginRun);
42 
43  //......................................................................
44  // 5.15.12 BJR: use the gdml file for both the fGDMLFile and fROOTFile
45  // variables as ROOT v5.30.06 is once again able to read in gdml files
46  // during batch operation, in this case think of fROOTFile meaning the
47  // file used to make the ROOT TGeoManager. I don't want to remove
48  // the separate variables in case ROOT breaks again
49  std::string GDMLFileName = pset.get<std::string>("GDML");
50  std::string ROOTFileName = pset.get<std::string>("GDML");
51 
52  // load the geometry
53  LoadNewGeometry(GDMLFileName, ROOTFileName);
54 
55  } // Geometry::Geometry()
56 
57 
59  {
60  // FIXME this seems utterly wrong: constructor loads geometry based on an
61  // explicit parameter, whereas here we load it by detector name
62 
63  // if we are requested to stick to the configured geometry, do nothing
64  if (fForceUseFCLOnly) return;
65 
66  // check here to see if we need to load a new geometry.
67  // get the detector id from the run object
68  std::vector< art::Handle<sumdata::RunData> > rdcol;
69  run.getManyByType(rdcol);
70  if (rdcol.empty()) {
71  mf::LogWarning("LoadNewGeometry") << "cannot find sumdata::RunData object to grab detector name\n"
72  << "this is expected if generating MC files\n"
73  << "using default geometry from configuration file\n";
74  return;
75  }
76 
77  // if the detector name is still the same, everything is fine
78  std::string newDetectorName = rdcol.front()->DetName();
79  if (GetProvider().DetectorName() == newDetectorName) return;
80 
81  // else {
82  // // the detector name is specified in the RunData object
83  // SetDetectorName(newDetectorName);
84  // }
85 
87  GetProvider().DetectorName() + ".gdml",
88  GetProvider().DetectorName() + ".gdml"
89  );
90  } // Geometry::preBeginRun()
91 
92 
93  //......................................................................
95  {
96  // the channel map is responsible of calling the channel map configuration
97  // of the geometry
99 
100  if ( ! GetProvider().hasAuxDetChannelMap() ) {
101  throw cet::exception("ChannelMapLoadFail") << " failed to load new channel map";
102  }
103 
104  } // Geometry::InitializeChannelMap()
105 
106  //......................................................................
107  void AuxDetGeometry::LoadNewGeometry(std::string gdmlfile, std::string /* rootfile */)
108  {
109  // start with the relative path
110  std::string GDMLFileName(fRelPath), ROOTFileName(fRelPath);
111 
112  // add the base file names
113  ROOTFileName.append(gdmlfile); // not rootfile (why?)
114  GDMLFileName.append(gdmlfile);
115 
116  // Search all reasonable locations for the GDML file that contains
117  // the detector geometry.
118  // cet::search_path constructor decides if initialized value is a path
119  // or an environment variable
120  cet::search_path sp("FW_SEARCH_PATH");
121 
122  std::string GDMLfile;
123  if( !sp.find_file(GDMLFileName, GDMLfile) ) {
124  throw cet::exception("AuxDetGeometry") << "cannot find the gdml geometry file:"
125  << "\n" << GDMLFileName
126  << "\nbail ungracefully.\n";
127  }
128 
129  std::string ROOTfile;
130  if( !sp.find_file(ROOTFileName, ROOTfile) ) {
131  throw cet::exception("AuxDetGeometry") << "cannot find the root geometry file:\n"
132  << "\n" << ROOTFileName
133  << "\nbail ungracefully.\n";
134  }
135 
136  // initialize the geometry with the files we have found
137  GetProvider().LoadGeometryFile(GDMLfile, ROOTfile);
138 
139  // now update the channel map
141 
142  } // Geometry::LoadNewGeometry()
143 
145 } // namespace geo
void LoadGeometryFile(std::string gdmlfile, std::string rootfile)
Loads the geometry information from the specified files.
#define DEFINE_ART_SERVICE(svc)
Definition: ServiceMacros.h:93
AuxDetGeometryCore const * GetProviderPtr() const
Returns a constant pointer to the service provider.
fhicl::ParameterSet fSortingParameters
Parameter set to define the channel map sorting.
AuxDetGeometryCore const & GetProvider() const
Returns a constant reference to the service provider.
STL namespace.
The geometry of one entire detector, as served by art.
Definition: Run.h:30
void LoadNewGeometry(std::string gdmlfile, std::string rootfile)
Expands the provided paths and loads the geometry description(s)
bool hasAuxDetChannelMap() const
Returns whether we have a channel map.
parameter set interface
Interface to a service that handles any experiment-specific knowledge that is needed by the AuxDetGeo...
T get(std::string const &key) const
Definition: ParameterSet.h:231
art framework interface to geometry description for auxiliary detectors
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: DataViewImpl.h:446
Definition of data types for geometry description.
AuxDetGeometry(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.
GlobalSignal< detail::SignalResponseType::FIFO, void(Run const &)> sPreBeginRun
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Namespace collecting geometry-related classes utilities.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33