GeometryGAr_service.cc
Go to the documentation of this file.
1 /**
2 * @file GeometryGAr_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/GeometryGAr.h"
10 
11 // gar includes
13 #include "Geometry/ExptGeoHelperInterface.h"
14 
15 // Framework includes
16 #include "cetlib_except/exception.h"
17 #include "cetlib/search_path.h"
19 
20 // C/C++ standard libraries
21 #include <vector>
22 #include <string>
23 #include <algorithm> // std::min()
24 
25 namespace gar {
26  namespace geo {
27 
28 
29  //......................................................................
30  // Constructor.
32  : GeometryCore(pset)
33  , fRelPath (pset.get< std::string >("RelativePath", "" ))
34  , fNonFatalConfCheck(pset.get< bool >("SkipConfigurationCheck", false))
35  , fSortingParameters(pset.get<fhicl::ParameterSet>("SortingParameters", fhicl::ParameterSet() ))
36  , fSegParameters(pset.get<fhicl::ParameterSet>("SegmentationAlgPars", fhicl::ParameterSet() ))
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, &GeometryGAr::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 
57 
58  } // GeometryGAr::Geometry()
59 
60 
61  //------------------------------------------------------------------------
63  {
65  if (!CheckConfigurationInfo(inputGeomInfo)) {
66  if (fNonFatalConfCheck) {
67  // disable the non-fatal option if you need the details
68  MF_LOG_WARNING("Geometry") << "Geometry used for " << run.id()
69  << " is incompatible with the one configured in the job.";
70  }
71  else
72  {
73  throw cet::exception("Geometry")
74  << "Geometry used for run " << run.id()
75  << " is incompatible with the one configured in the job!"
76  << "\n=== job configuration " << std::string(50, '=')
77  << "\n" << fConfInfo
78  << "\n=== run configuration " << std::string(50, '=')
79  << "\n" << inputGeomInfo
80  << "\n======================" << std::string(50, '=')
81  << "\n";
82  }
83  }
84  } // GeometryGAr::preBeginRun()
85 
86  //......................................................................
88  {
89  // the channel map is responsible of calling the channel map configuration
90  // of the TPC geometry
92 
93  if ( ! ChannelMap() ) {
94  throw cet::exception("ChannelMapLoadFail")
95  << " failed to load new channel map";
96  }
97 
98  // the channel map is responsible of calling the channel map configuration
99  // of the ECAL geometry
101  if(not fECALSegParameters.is_empty()) {
102  ::art::ServiceHandle<geo::ExptGeoHelperInterface>()->ConfigureECALSegmentationAlg(fECALSegParameters, this);
103 
104  if ( ! ECALSegmentationAlg() ) {
105  throw cet::exception("ECALSegmentationAlgLoadFailed")
106  << " failed to load the ECAL segmentation";
107  }
108  }
109 
110  // the channel map is responsible of calling the channel map configuration
111  // of the Tracker Sc geometry
113  if(not fMinervaSegParameters.is_empty()) {
114  ::art::ServiceHandle<geo::ExptGeoHelperInterface>()->ConfigureMinervaSegmentationAlg(fMinervaSegParameters, this);
115 
116  if ( ! MinervaSegmentationAlg() ) {
117  throw cet::exception("MinervaSegmentationAlgLoadFailed")
118  << " failed to load the Minerva segmentation";
119  }
120  }
121 
122  // the channel map is responsible of calling the channel map configuration
123  // of the MuID geometry
125  if(not fMuIDSegParameters.is_empty()) {
126  ::art::ServiceHandle<geo::ExptGeoHelperInterface>()->ConfigureMuIDSegmentationAlg(fMuIDSegParameters, this);
127 
128  if ( ! MuIDSegmentationAlg() ) {
129  throw cet::exception("MuIDSegmentationAlgLoadFailed")
130  << " failed to load the MuID segmentation";
131  }
132  }
133 
134  } // GeometryGAr::InitializeSegmentation()
135 
136  //......................................................................
138  std::string const& /* rootfile */,
139  bool bForceReload /* = false */)
140  {
141  // start with the relative path
142  std::string GDMLFileName(fRelPath), ROOTFileName(fRelPath);
143 
144  // add the base file names
145  ROOTFileName.append(gdmlfile);
146  GDMLFileName.append(gdmlfile);
147 
148  // Search all reasonable locations for the GDML file that contains
149  // the detector geometry.
150  // cet::search_path constructor decides if initialized value is a path
151  // or an environment variable
152  std::string GDMLfile("");
153  std::string ROOTfile("");
154 
155  if(fRelPath.empty()){
156  cet::search_path sp("FW_SEARCH_PATH");
157 
158  ;
159  if( !sp.find_file(GDMLFileName, GDMLfile) ) {
160  throw cet::exception("Geometry")
161  << "cannot find the gdml geometry file:"
162  << "\n" << GDMLFileName
163  << "\nbail ungracefully.\n";
164  }
165 
166  if( !sp.find_file(ROOTFileName, ROOTfile) ) {
167  throw cet::exception("Geometry")
168  << "cannot find the root geometry file:\n"
169  << "\n" << ROOTFileName
170  << "\nbail ungracefully.\n";
171  }
172  }
173  else{
174  GDMLfile = GDMLFileName;
175  ROOTfile = GDMLFileName;
176  }
177 
178  // initialize the geometry with the files we have found
179  LoadGeometryFile(GDMLfile, ROOTfile, bForceReload);
180 
181  //Get detector parameters
183 
184  // now init the detector Segmentations (Channel Map, ECAL etc...)
186 
187  // Finish the geometry when it uses the segmentation
189 
190  //Print the geometry parameters
191  PrintGeometry();
192  } // GeometryGAr::LoadNewGeometry()
193 
194  //......................................................................
196  {
197 
200 
201  // version 1+:
202  confInfo.detectorName = DetectorName();
203 
204  // version 2+:
206  fConfInfo = std::move(confInfo);
207 
208  MF_LOG_DEBUG("Geometry") << "Geometry configuration information:\n" << fConfInfo;
209 
210  } // Geometry::FillGeometryConfigurationInfo()
211 
212  //......................................................................
214  {
215  MF_LOG_DEBUG("Geometry") << "New geometry information:\n"
216  << other;
217  return CompareConfigurationInfo(fConfInfo, other);
218  } // Geometry::CheckConfigurationInfo()
219 
220  //......................................................................
222  {
223 
224  try {
225  return run.getProduct<gar::sumdata::GeometryConfigurationInfo>(art::InputTag{"GeometryGArConfigurationWriter"});
226  }
227  catch (art::Exception const& e) {
228  throw art::Exception{
229  e.categoryCode(),
230  "Can't read geometry configuration information.\n"
231  "Is `GeometryGArConfigurationWriter` service configured?\n",
232  e};
233  }
234 
235  } // Geometry::ReadConfigurationInfo()
236 
237  //......................................................................
239  {
240  /*
241  * Implemented criteria:
242  *
243  * * both informations must be valid
244  * * the detector names must exactly match
245  *
246  */
247 
248  if (!A.isDataValid()) {
249  MF_LOG_WARNING("Geometry") << "Geometry::CompareConfigurationInfo(): "
250  "invalid version for configuration A:\n" << A;
251  return false;
252  }
253  if (!B.isDataValid()) {
254  MF_LOG_WARNING("Geometry") << "Geometry::CompareConfigurationInfo(): "
255  "invalid version for configuration B:\n" << B;
256  return false;
257  }
258 
259  return true;
260  } // CompareConfigurationInfo()
261 
263  } // namespace geo
264 } // namespace gar
fhicl::ParameterSet fSortingParameters
Parameter set to define the channel map sorting.
Definition: GeometryGAr.h:140
bool CheckConfigurationInfo(gar::sumdata::GeometryConfigurationInfo const &other) const
GeometryGAr(fhicl::ParameterSet const &pset,::art::ActivityRegistry &reg)
RunID id() const
Definition: Run.cc:17
fhicl::ParameterSet fMuIDSegParameters
Parameters for the MuID Segmentation.
Definition: GeometryGAr.h:145
std::string string
Definition: nybbler.cc:12
DataVersion_t dataVersion
Version of the data in this object (0 is invalid version).
void LoadNewGeometry(std::string const &gdmlfile, std::string const &rootfile, bool bForceReload=false)
Expands the provided paths and loads the geometry description(s)
fhicl::ParameterSet fMinervaSegParameters
Parameters for the Tracker Sc Segmentation.
Definition: GeometryGAr.h:144
STL namespace.
Description of geometry of one entire detector.
Definition: GeometryCore.h:436
std::string fRelPath
Definition: GeometryGAr.h:137
void LoadGeometryFile(std::string const &gdmlfile, std::string const &rootfile, bool bForceReload=false)
Loads the geometry information from the specified files.
Definition: Run.h:17
gar::geo::seg::ChannelMapAlg const * ChannelMap() const
Returns the object handling the channel map.
Definition: GeometryCore.h:930
Description of the current configuration of detector geometry.
std::string geometryServiceConfiguration
geo::Geometry service configuration, as FHiCL table.
const double e
fhicl::ParameterSet fECALSegParameters
Parameters for the ECAL Segmentation.
Definition: GeometryGAr.h:143
static Config * config
Definition: config.cpp:1054
def move(depos, offset)
Definition: depos.py:107
unsigned int DataVersion_t
Type used for the version of data.
T get(std::string const &key) const
Definition: ParameterSet.h:271
std::string to_indented_string() const
void preBeginRun(::art::Run const &run)
Updates the geometry if needed at the beginning of each new run.
void PrintGeometry() const
static gar::sumdata::GeometryConfigurationInfo const & ReadConfigurationInfo(art::Run const &run)
gar::geo::seg::SegmentationAlg const * ECALSegmentationAlg() const
Returns the object handling the ECAL segmentation.
Definition: GeometryCore.h:933
gar::geo::seg::SegmentationAlg const * MinervaSegmentationAlg() const
Returns the object handling the Sc Tracker segmentation.
Definition: GeometryCore.h:936
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
General GArSoft Utilities.
#define DEFINE_ART_SERVICE(svc)
bool is_empty() const
GlobalSignal< detail::SignalResponseType::FIFO, void(Run const &)> sPreBeginRun
gar::sumdata::GeometryConfigurationInfo fConfInfo
Definition: GeometryGAr.h:147
fhicl::ParameterSet fSegParameters
Parameter set to define the segmentation algorithms.
Definition: GeometryGAr.h:142
The geometry of one entire detector, as served by art.
Definition: GeometryGAr.h:104
static bool CompareConfigurationInfo(gar::sumdata::GeometryConfigurationInfo const &A, gar::sumdata::GeometryConfigurationInfo const &B)
#define MF_LOG_DEBUG(id)
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
Definition: GeometryCore.h:495
std::string find_file(std::string const &filename) const
Definition: search_path.cc:96
#define A
Definition: memgrp.cpp:38
bool isDataValid() const noexcept
Protocol: whether the data content is valid.
void FillGeometryConfigurationInfo(fhicl::ParameterSet const &config)
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
#define MF_LOG_WARNING(category)
PROD const & getProduct(InputTag const &tag) const
Definition: DataViewImpl.h:367
LArSoft geometry interface.
Definition: ChannelGeo.h:16
art framework interface to geometry description
gar::geo::seg::SegmentationAlg const * MuIDSegmentationAlg() const
Returns the object handling the MuID segmentation.
Definition: GeometryCore.h:939
int bool
Definition: qglobal.h:345
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33