Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
detinfo::DetectorPropertiesServiceStandard Class Reference

#include <DetectorPropertiesServiceStandard.h>

Inheritance diagram for detinfo::DetectorPropertiesServiceStandard:
detinfo::DetectorPropertiesService

Classes

struct  ServiceConfiguration_t
 

Public Types

using Parameters = art::ServiceTable< ServiceConfiguration_t >
 
- Public Types inherited from detinfo::DetectorPropertiesService
using provider_type = detinfo::DetectorProperties
 

Public Member Functions

 DetectorPropertiesServiceStandard (fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
 
- Public Member Functions inherited from detinfo::DetectorPropertiesService
virtual ~DetectorPropertiesService ()=default
 
DetectorPropertiesData DataForJob () const
 
DetectorPropertiesData DataForJob (detinfo::DetectorClocksData const &clockData) const
 
DetectorPropertiesData DataFor (art::Event const &e) const
 
DetectorPropertiesData DataFor (art::Event const &e, detinfo::DetectorClocksData const &clockData) const
 

Private Member Functions

DetectorPropertiesData getDataForJob (DetectorClocksData const &clockData) const override
 
DetectorPropertiesData getDataFor (art::Event const &, DetectorClocksData const &clockData) const override
 
void postOpenFile (const std::string &filename)
 
bool isDetectorPropertiesServiceStandard (const fhicl::ParameterSet &ps) const
 

Private Attributes

DetectorPropertiesStandard fProp
 
fhicl::ParameterSet fPS
 Original parameter set. More...
 
bool fInheritNumberTimeSamples
 Flag saying whether to inherit NumberTimeSamples. More...
 

Detailed Description

Configuration parameters

This service passes the whole configuration down to its service provider, but it also reacts to:

Definition at line 37 of file DetectorPropertiesServiceStandard.h.

Member Typedef Documentation

Definition at line 57 of file DetectorPropertiesServiceStandard.h.

Constructor & Destructor Documentation

detinfo::DetectorPropertiesServiceStandard::DetectorPropertiesServiceStandard ( fhicl::ParameterSet const &  pset,
art::ActivityRegistry reg 
)

Definition at line 26 of file DetectorPropertiesServiceStandard_service.cc.

29  : fProp{pset,
30  lar::providerFrom<geo::Geometry>(),
31  lar::providerFrom<detinfo::LArPropertiesService>(),
32  std::set<std::string>({"InheritNumberTimeSamples"})}
33  , fPS{pset}
34  , fInheritNumberTimeSamples{pset.get<bool>("InheritNumberTimeSamples", false)}
35  {
37  }
fhicl::ParameterSet fPS
Original parameter set.
bool fInheritNumberTimeSamples
Flag saying whether to inherit NumberTimeSamples.
GlobalSignal< detail::SignalResponseType::LIFO, void(std::string const &)> sPostOpenFile

Member Function Documentation

DetectorPropertiesData detinfo::DetectorPropertiesServiceStandard::getDataFor ( art::Event const &  ,
DetectorClocksData const &  clockData 
) const
inlineoverrideprivatevirtual

Implements detinfo::DetectorPropertiesService.

Definition at line 69 of file DetectorPropertiesServiceStandard.h.

70  {
71  return fProp.DataFor(clockData);
72  }
DetectorPropertiesData DataFor(detinfo::DetectorClocksData const &clock_data) const override
DetectorPropertiesData detinfo::DetectorPropertiesServiceStandard::getDataForJob ( DetectorClocksData const &  clockData) const
inlineoverrideprivatevirtual

Implements detinfo::DetectorPropertiesService.

Definition at line 63 of file DetectorPropertiesServiceStandard.h.

64  {
65  return fProp.DataFor(clockData);
66  }
DetectorPropertiesData DataFor(detinfo::DetectorClocksData const &clock_data) const override
bool detinfo::DetectorPropertiesServiceStandard::isDetectorPropertiesServiceStandard ( const fhicl::ParameterSet ps) const
private

Definition at line 135 of file DetectorPropertiesServiceStandard_service.cc.

137  {
138  // This method uses heuristics to determine whether the parameter
139  // set passed as argument is a DetectorPropertiesService configuration
140  // parameter set.
141 
142  return (ps.get<std::string>("service_type", "") == "DetectorPropertiesService") &&
143  (ps.get<std::string>("service_provider", "") == "DetectorPropertiesServiceStandard");
144  }
std::string string
Definition: nybbler.cc:12
T get(std::string const &key) const
Definition: ParameterSet.h:271
void detinfo::DetectorPropertiesServiceStandard::postOpenFile ( const std::string filename)
private

Definition at line 43 of file DetectorPropertiesServiceStandard_service.cc.

44  {
45  // Use this method to figure out whether to inherit configuration
46  // parameters from previous jobs.
47 
48  // There is no way currently to correlate parameter sets saved in
49  // sqlite RootFileDB with process history (from MetaData tree).
50  // Therefore, we use the approach of scanning every historical
51  // parameter set in RootFileDB, and finding all parameter sets
52  // that appear to be DetectorPropertiesService configurations. If all
53  // historical parameter sets are in agreement about the value of
54  // an inherited parameter, then we accept the historical value,
55  // print a message, and override the configuration parameter. In
56  // cases where the historical configurations are not in agreement
57  // about the value of an inherited parameter, we ignore any
58  // historical parameter values that are the same as the current
59  // configured value of the parameter (that is, we resolve the
60  // conflict in favor of parameters values that are different than
61  // the current configuration). If two or more historical values
62  // differ from the current configuration, throw an exception.
63  // Note that it is possible to give precendence to the current
64  // configuration by disabling inheritance for that configuration
65  // parameter.
66 
67  // Don't do anything if no parameters are supposed to be inherited.
68 
69  if (!fInheritNumberTimeSamples) return;
70 
71  // The only way to access art service metadata from the input file
72  // is to open it as a separate TFile object. Do that now.
73 
74  if (filename.empty()) { return; }
75 
76  std::unique_ptr<TFile> file{TFile::Open(filename.c_str(), "READ")};
77  if (!file) { return; }
78 
79  if (file->IsZombie() || !file->IsOpen()) { return; }
80 
81  // Open the sqlite datatabase.
82 
83  art::SQLite3Wrapper sqliteDB(file.get(), "RootFileDB");
84 
85  // Loop over all stored ParameterSets.
86 
87  unsigned int iNumberTimeSamples = 0; // Combined value of NumberTimeSamples.
88  unsigned int nNumberTimeSamples = 0; // Number of NumberTimeSamples parameters seen.
89 
90  sqlite3_stmt* stmt = nullptr;
91  sqlite3_prepare_v2(sqliteDB, "SELECT PSetBlob from ParameterSets;", -1, &stmt, nullptr);
92  while (sqlite3_step(stmt) == SQLITE_ROW) {
94  ps = fhicl::ParameterSet::make(reinterpret_cast<char const*>(sqlite3_column_text(stmt, 0)));
95  // Is this a DetectorPropertiesService parameter set?
96 
98 
99  // Check NumberTimeSamples
100 
101  auto const newNumberTimeSamples = ps.get<unsigned int>("NumberTimeSamples");
102 
103  // Ignore parameter values that match the current configuration.
104 
105  if (newNumberTimeSamples != fPS.get<unsigned int>("NumberTimeSamples")) {
106  if (nNumberTimeSamples == 0)
107  iNumberTimeSamples = newNumberTimeSamples;
108  else if (newNumberTimeSamples != iNumberTimeSamples) {
109  throw cet::exception(__FUNCTION__)
110  << "Historical values of NumberTimeSamples do not agree: " << iNumberTimeSamples
111  << " " << newNumberTimeSamples << "\n";
112  }
113  ++nNumberTimeSamples;
114  }
115  }
116  }
117 
118  // Done looping over parameter sets.
119  // Now decide which parameters we will actually override.
120 
121  if (nNumberTimeSamples != 0 && iNumberTimeSamples != fProp.NumberTimeSamples()) {
122  mf::LogInfo("DetectorPropertiesServiceStandard")
123  << "Overriding configuration parameter NumberTimeSamples using "
124  "historical value.\n"
125  << " Configured value: " << fProp.NumberTimeSamples() << "\n"
126  << " Historical (used) value: " << iNumberTimeSamples << "\n";
127  fProp.SetNumberTimeSamples(iNumberTimeSamples);
128  }
129  }
unsigned int NumberTimeSamples() const override
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
struct sqlite3_stmt sqlite3_stmt
string filename
Definition: train.py:213
T get(std::string const &key) const
Definition: ParameterSet.h:271
fhicl::ParameterSet fPS
Original parameter set.
static constexpr double ps
Definition: Units.h:99
bool isDetectorPropertiesServiceStandard(const fhicl::ParameterSet &ps) const
bool fInheritNumberTimeSamples
Flag saying whether to inherit NumberTimeSamples.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33

Member Data Documentation

bool detinfo::DetectorPropertiesServiceStandard::fInheritNumberTimeSamples
private

Flag saying whether to inherit NumberTimeSamples.

Definition at line 79 of file DetectorPropertiesServiceStandard.h.

DetectorPropertiesStandard detinfo::DetectorPropertiesServiceStandard::fProp
private

Definition at line 76 of file DetectorPropertiesServiceStandard.h.

fhicl::ParameterSet detinfo::DetectorPropertiesServiceStandard::fPS
private

Original parameter set.

Definition at line 77 of file DetectorPropertiesServiceStandard.h.


The documentation for this class was generated from the following files: