LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
AuxDetGeometry.cc
Go to the documentation of this file.
1 
8 // class header
11 
12 // lar includes
14 
15 // Framework includes
19 #include "cetlib/search_path.h"
20 #include "cetlib_except/exception.h"
21 #include "fhiclcpp/ParameterSet.h"
23 
24 // C/C++ standard libraries
25 #include <string>
26 
27 namespace geo {
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", {}))
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 
58  {
59  // FIXME this seems utterly wrong: constructor loads geometry based on an
60  // explicit parameter, whereas here we load it by detector name
61 
62  // if we are requested to stick to the configured geometry, do nothing
63  if (fForceUseFCLOnly) return;
64 
65  // check here to see if we need to load a new geometry.
66  // get the detector id from the run object
67  //std::vector< art::Handle<sumdata::RunData> > rdcol;
68  //run.getManyByType(rdcol);
69  auto rdcol = run.getMany<sumdata::RunData>();
70  if (rdcol.empty()) {
71  mf::LogWarning("LoadNewGeometry")
72  << "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 (GetProvider().DetectorName() == newDetectorName) return;
81 
82  // else {
83  // // the detector name is specified in the RunData object
84  // SetDetectorName(newDetectorName);
85  // }
86 
87  LoadNewGeometry(GetProvider().DetectorName() + ".gdml", GetProvider().DetectorName() + ".gdml");
88  } // Geometry::preBeginRun()
89 
90  //......................................................................
92  {
93  // the channel map is responsible of calling the channel map configuration
94  // of the geometry
95  auto channelMap =
96  art::ServiceHandle<geo::AuxDetExptGeoHelperInterface>()->ConfigureAuxDetChannelMapAlg(
98  if (!channelMap) {
99  throw cet::exception("ChannelMapLoadFail") << " failed to load new channel map";
100  }
101  fProvider.ApplyChannelMap(move(channelMap));
102  } // Geometry::InitializeChannelMap()
103 
104  //......................................................................
105  void AuxDetGeometry::LoadNewGeometry(std::string gdmlfile, std::string /* rootfile */)
106  {
107  // start with the relative path
108  std::string GDMLFileName(fRelPath), ROOTFileName(fRelPath);
109 
110  // add the base file names
111  ROOTFileName.append(gdmlfile); // not rootfile (why?)
112  GDMLFileName.append(gdmlfile);
113 
114  // Search all reasonable locations for the GDML file that contains
115  // the detector geometry.
116  // cet::search_path constructor decides if initialized value is a path
117  // or an environment variable
118  cet::search_path sp("FW_SEARCH_PATH");
119 
120  std::string GDMLfile;
121  if (!sp.find_file(GDMLFileName, GDMLfile)) {
122  throw cet::exception("AuxDetGeometry") << "cannot find the gdml geometry file:"
123  << "\n"
124  << GDMLFileName << "\nbail ungracefully.\n";
125  }
126 
127  std::string ROOTfile;
128  if (!sp.find_file(ROOTFileName, ROOTfile)) {
129  throw cet::exception("AuxDetGeometry") << "cannot find the root geometry file:\n"
130  << "\n"
131  << ROOTFileName << "\nbail ungracefully.\n";
132  }
133 
134  // initialize the geometry with the files we have found
135  GetProvider().LoadGeometryFile(GDMLfile, ROOTfile);
136 
137  // now update the channel map
139 
140  } // Geometry::LoadNewGeometry()
141 
142 } // namespace geo
void LoadGeometryFile(std::string gdmlfile, std::string rootfile)
Loads the geometry information from the specified files.
void ApplyChannelMap(std::unique_ptr< geo::AuxDetChannelMapAlg > pChannelMap)
Initializes the geometry to work with this channel map.
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.
Definition: Run.h:37
void LoadNewGeometry(std::string gdmlfile, std::string rootfile)
Expands the provided paths and loads the geometry description(s)
parameter set interface
Interface to a service that handles any experiment-specific knowledge that is needed by the AuxDetGeo...
art framework interface to geometry description for auxiliary detectors
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.
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
AuxDetGeometryCore fProvider
the actual service provider
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Namespace collecting geometry-related classes utilities.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const