All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AuxDetGeometry.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
16 #include "art/Framework/Principal/Run.h"
17 #include "art/Framework/Services/Registry/ActivityRegistry.h"
18 #include "art/Framework/Services/Registry/ServiceHandle.h"
19 #include "messagefacility/MessageLogger/MessageLogger.h"
20 #include "fhiclcpp/ParameterSet.h"
21 #include "cetlib_except/exception.h"
22 #include "cetlib/search_path.h"
23 
24 // C/C++ standard libraries
25 #include <string>
26 
27 namespace geo {
28 
29 
30  //......................................................................
31  // Constructor.
32  AuxDetGeometry::AuxDetGeometry(fhicl::ParameterSet const& pset, art::ActivityRegistry &reg)
33  : fProvider (pset)
34  , fRelPath (pset.get< std::string >("RelativePath", "" ))
35  , fForceUseFCLOnly (pset.get< bool >("ForceUseFCLOnly" , false))
36  , fSortingParameters(pset.get<fhicl::ParameterSet>("SortingParameters", {}))
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, &AuxDetGeometry::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 
59  void AuxDetGeometry::preBeginRun(art::Run const& run)
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  auto rdcol = run.getMany<sumdata::RunData>();
72  if (rdcol.empty()) {
73  mf::LogWarning("LoadNewGeometry") << "cannot find sumdata::RunData object to grab detector name\n"
74  << "this is expected if generating MC files\n"
75  << "using default geometry from configuration file\n";
76  return;
77  }
78 
79  // if the detector name is still the same, everything is fine
80  std::string newDetectorName = rdcol.front()->DetName();
81  if (GetProvider().DetectorName() == newDetectorName) return;
82 
83  // else {
84  // // the detector name is specified in the RunData object
85  // SetDetectorName(newDetectorName);
86  // }
87 
89  GetProvider().DetectorName() + ".gdml",
90  GetProvider().DetectorName() + ".gdml"
91  );
92  } // Geometry::preBeginRun()
93 
94 
95  //......................................................................
97  {
98  // the channel map is responsible of calling the channel map configuration
99  // of the geometry
100  auto channelMap = art::ServiceHandle<geo::AuxDetExptGeoHelperInterface>()->ConfigureAuxDetChannelMapAlg(fSortingParameters);
101  if (!channelMap) {
102  throw cet::exception("ChannelMapLoadFail") << " failed to load new channel map";
103  }
104  fProvider.ApplyChannelMap(move(channelMap));
105  } // Geometry::InitializeChannelMap()
106 
107  //......................................................................
108  void AuxDetGeometry::LoadNewGeometry(std::string gdmlfile, std::string /* rootfile */)
109  {
110  // start with the relative path
112 
113  // add the base file names
114  ROOTFileName.append(gdmlfile); // not rootfile (why?)
115  GDMLFileName.append(gdmlfile);
116 
117  // Search all reasonable locations for the GDML file that contains
118  // the detector geometry.
119  // cet::search_path constructor decides if initialized value is a path
120  // or an environment variable
121  cet::search_path sp("FW_SEARCH_PATH");
122 
123  std::string GDMLfile;
124  if( !sp.find_file(GDMLFileName, GDMLfile) ) {
125  throw cet::exception("AuxDetGeometry") << "cannot find the gdml geometry file:"
126  << "\n" << GDMLFileName
127  << "\nbail ungracefully.\n";
128  }
129 
130  std::string ROOTfile;
131  if( !sp.find_file(ROOTFileName, ROOTfile) ) {
132  throw cet::exception("AuxDetGeometry") << "cannot find the root geometry file:\n"
133  << "\n" << ROOTFileName
134  << "\nbail ungracefully.\n";
135  }
136 
137  // initialize the geometry with the files we have found
138  GetProvider().LoadGeometryFile(GDMLfile, ROOTfile);
139 
140  // now update the channel map
142 
143  } // Geometry::LoadNewGeometry()
144 
145 } // namespace geo
void LoadGeometryFile(std::string gdmlfile, std::string rootfile)
Loads the geometry information from the specified files.
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
void ApplyChannelMap(std::unique_ptr< geo::AuxDetChannelMapAlg > pChannelMap)
Initializes the geometry to work with this channel map.
std::string const & DetName() const
Definition: RunData.h:39
fhicl::ParameterSet fSortingParameters
Parameter set to define the channel map sorting.
AuxDetGeometryCore const & GetProvider() const
Returns a constant reference to the service provider.
static constexpr bool
std::string ROOTFileName
void LoadNewGeometry(std::string gdmlfile, std::string rootfile)
Expands the provided paths and loads the geometry description(s)
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.
std::string GDMLFileName
AuxDetGeometryCore fProvider
the actual service provider