AuxDetGeometry_service.cc
Go to the documentation of this file.
1 /**
2  * @file Geometry_service.cc
3  * @brief art framework interface to geometry description - implementation file
4  * @author brebel@fnal.gov
5  * @see GeometryGAr.h
6  */
7 
8 // class header
9 #include "Geometry/AuxDetGeometry.h"
10 #include "Geometry/AuxDetExptGeoHelperInterface.h"
11 
13 
14 // Framework includes
15 #include "cetlib_except/exception.h"
16 #include "cetlib/search_path.h"
18 
19 // C/C++ standard libraries
20 #include <vector>
21 #include <string>
22 
23 
24 namespace gar {
25  namespace geo {
26 
27 
28  //......................................................................
29  // Constructor.
31  : fProvider (pset)
32  , fRelPath (pset.get< std::string >("RelativePath", "" ))
33  , fForceUseFCLOnly (pset.get< bool >("ForceUseFCLOnly" , false))
34  , fSortingParameters(pset.get<fhicl::ParameterSet>("SortingParameters", fhicl::ParameterSet() ))
35  {
36  // add a final directory separator ("/") to fRelPath if not already there
37  if (!fRelPath.empty() && (fRelPath.back() != '/')) fRelPath += '/';
38 
39  // register a callback to be executed when a new run starts
40  reg.sPreBeginRun.watch(this, &AuxDetGeometry::preBeginRun);
41 
42  //......................................................................
43  // 5.15.12 BJR: use the gdml file for both the fGDMLFile and fROOTFile
44  // variables as ROOT v5.30.06 is once again able to read in gdml files
45  // during batch operation, in this case think of fROOTFile meaning the
46  // file used to make the ROOT TGeoManager. I don't want to remove
47  // the separate variables in case ROOT breaks again
48  std::string GDMLFileName = pset.get<std::string>("GDML");
49  std::string ROOTFileName = pset.get<std::string>("GDML");
50 
51  // load the geometry
52  LoadNewGeometry(GDMLFileName, ROOTFileName);
53 
54  } // Geometry::Geometry()
55 
56 
57  //--------------------------------------------------------------------------
59  {
60  // if we are requested to stick to the configured geometry, do nothing
61  if (fForceUseFCLOnly) return;
62 
63  // check here to see if we need to load a new geometry.
64  // get the detector id from the run object
65  auto rdcol = run.getMany<sumdata::RunData>();
66  if (rdcol.empty()) {
67  MF_LOG_WARNING("LoadNewGeometry")
68  << "cannot find sumdata::RunData object to grab detector name\n"
69  << "this is expected if generating MC files\n"
70  << "using default geometry from configuration file\n";
71  return;
72  }
73 
74  // if the detector name is still the same, everything is fine
75  std::string newDetectorName = rdcol.front()->DetName();
76  if (GetProvider().DetectorName() == newDetectorName) return;
77 
78  LoadNewGeometry(GetProvider().DetectorName() + ".gdml",
79  GetProvider().DetectorName() + ".gdml");
80 
81  } // Geometry::preBeginRun()
82 
83 
84  //......................................................................
86  {
87  // the channel map is responsible of calling the channel map configuration
88  // of the geometry
90  GetProviderPtr());
91  if ( !GetProvider().hasAuxDetChannelMap() ) {
92  throw cet::exception("ChannelMapLoadFail") << " failed to load new channel map";
93  }
94 
95  } // Geometry::InitializeChannelMap()
96 
97  //......................................................................
99  {
100  // start with the relative path
101  std::string GDMLFileName(fRelPath), ROOTFileName(fRelPath);
102 
103  // add the base file names
104  ROOTFileName.append(gdmlfile); // not rootfile (why?)
105  GDMLFileName.append(gdmlfile);
106 
107  // Search all reasonable locations for the GDML file that contains
108  // the detector geometry.
109  // cet::search_path constructor decides if initialized value is a path
110  // or an environment variable
111  cet::search_path sp("FW_SEARCH_PATH");
112 
113  std::string GDMLfile;
114  if( !sp.find_file(GDMLFileName, GDMLfile) ) {
115  throw cet::exception("AuxDetGeometry")
116  << "cannot find the gdml geometry file:"
117  << "\n" << GDMLFileName
118  << "\nbail ungracefully.\n";
119  }
120 
121  std::string ROOTfile;
122  if( !sp.find_file(ROOTFileName, ROOTfile) ) {
123  throw cet::exception("AuxDetGeometry")
124  << "cannot find the root geometry file:\n"
125  << "\n" << ROOTFileName
126  << "\nbail ungracefully.\n";
127  }
128 
129  // initialize the geometry with the files we have found
130  GetProvider().LoadGeometryFile(GDMLfile, ROOTfile);
131 
132  // now update the channel map
134 
135  } // Geometry::LoadNewGeometry()
136 
138  } // namespace geo
139 } // gar
std::string string
Definition: nybbler.cc:12
STL namespace.
Definition: Run.h:17
AuxDetGeometry(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
fhicl::ParameterSet fSortingParameters
Parameter set to define the channel map sorting.
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
Definition: DataViewImpl.h:479
T get(std::string const &key) const
Definition: ParameterSet.h:271
AuxDetGeometryCore const & GetProvider() const
Returns a constant reference to the service provider.
AuxDetGeometryCore const * GetProviderPtr() const
Returns a constant pointer to the service provider.
General GArSoft Utilities.
#define DEFINE_ART_SERVICE(svc)
GlobalSignal< detail::SignalResponseType::FIFO, void(Run const &)> sPreBeginRun
void preBeginRun(art::Run const &run)
Updates the geometry if needed at the beginning of each new run.
void LoadGeometryFile(std::string gdmlfile, std::string rootfile)
Loads the geometry information from the specified files.
std::string find_file(std::string const &filename) const
Definition: search_path.cc:96
bool hasAuxDetChannelMap() const
Returns whether we have a channel map.
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
#define MF_LOG_WARNING(category)
The geometry of one entire detector, as served by art.
LArSoft geometry interface.
Definition: ChannelGeo.h:16
int bool
Definition: qglobal.h:345
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void LoadNewGeometry(std::string gdmlfile, std::string rootfile)
Expands the provided paths and loads the geometry description(s)