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 Geometry.h
6  */
7 
8 // class header
11 
12 // lar includes
14 
15 // Framework includes
17 #include "cetlib_except/exception.h"
18 #include "cetlib/search_path.h"
20 
21 // C/C++ standard libraries
22 #include <string>
23 
24 
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", {}))
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 
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") << "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
98  auto channelMap = art::ServiceHandle<geo::AuxDetExptGeoHelperInterface>()->ConfigureAuxDetChannelMapAlg(fSortingParameters);
99  if (!channelMap) {
100  throw cet::exception("ChannelMapLoadFail") << " failed to load new channel map";
101  }
102  fProvider.ApplyChannelMap(move(channelMap));
103  } // Geometry::InitializeChannelMap()
104 
105  //......................................................................
107  {
108  // start with the relative path
109  std::string GDMLFileName(fRelPath), ROOTFileName(fRelPath);
110 
111  // add the base file names
112  ROOTFileName.append(gdmlfile); // not rootfile (why?)
113  GDMLFileName.append(gdmlfile);
114 
115  // Search all reasonable locations for the GDML file that contains
116  // the detector geometry.
117  // cet::search_path constructor decides if initialized value is a path
118  // or an environment variable
119  cet::search_path sp("FW_SEARCH_PATH");
120 
121  std::string GDMLfile;
122  if( !sp.find_file(GDMLFileName, GDMLfile) ) {
123  throw cet::exception("AuxDetGeometry") << "cannot find the gdml geometry file:"
124  << "\n" << GDMLFileName
125  << "\nbail ungracefully.\n";
126  }
127 
128  std::string ROOTfile;
129  if( !sp.find_file(ROOTFileName, ROOTfile) ) {
130  throw cet::exception("AuxDetGeometry") << "cannot find the root geometry file:\n"
131  << "\n" << ROOTFileName
132  << "\nbail ungracefully.\n";
133  }
134 
135  // initialize the geometry with the files we have found
136  GetProvider().LoadGeometryFile(GDMLfile, ROOTfile);
137 
138  // now update the channel map
140 
141  } // Geometry::LoadNewGeometry()
142 
144 } // 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.
std::string string
Definition: nybbler.cc:12
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:17
void LoadNewGeometry(std::string gdmlfile, std::string rootfile)
Expands the provided paths and loads the geometry description(s)
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
Definition: DataViewImpl.h:479
def move(depos, offset)
Definition: depos.py:107
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.
#define DEFINE_ART_SERVICE(svc)
AuxDetGeometryCore fProvider
the actual service provider
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::string find_file(std::string const &filename) const
Definition: search_path.cc:96
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
LArSoft geometry interface.
Definition: ChannelGeo.h:16
int bool
Definition: qglobal.h:345
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33