LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
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 >
 
using provider_type = detinfo::DetectorProperties
 

Public Member Functions

 DetectorPropertiesServiceStandard (fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
 
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:

  • InheritNumberTimeSamples (boolean; default: false): if true, the configuration database in the ROOT input file is queried and if a configuration for this service is found, it's used instead of the one from the current FHiCL configuration

Definition at line 40 of file DetectorPropertiesServiceStandard.h.

Member Typedef Documentation

Constructor & Destructor Documentation

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

Definition at line 26 of file DetectorPropertiesServiceStandard.cc.

References fInheritNumberTimeSamples, fPS, and postOpenFile().

29  : fProp{pset,
30  lar::providerFrom<geo::Geometry>(),
32  lar::providerFrom<detinfo::LArPropertiesService>(),
33  std::set<std::string>({"InheritNumberTimeSamples"})}
34  , fPS{pset}
35  , fInheritNumberTimeSamples{pset.get<bool>("InheritNumberTimeSamples", false)}
36  {
38  }
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::DetectorPropertiesService::DataFor ( art::Event const &  e) const
inlineinherited

Definition at line 41 of file DetectorPropertiesService.h.

42  {
44  return DataFor(e, clockData);
45  }
DetectorPropertiesData DataFor(art::Event const &e) const
Float_t e
Definition: plot.C:35
DetectorPropertiesData detinfo::DetectorPropertiesService::DataFor ( art::Event const &  e,
detinfo::DetectorClocksData const &  clockData 
) const
inlineinherited

Definition at line 46 of file DetectorPropertiesService.h.

References DECLARE_ART_SERVICE_INTERFACE, e, and art::SHARED.

48  {
49  return getDataFor(e, clockData);
50  }
virtual DetectorPropertiesData getDataFor(art::Event const &e, detinfo::DetectorClocksData const &clockData) const =0
Float_t e
Definition: plot.C:35
DetectorPropertiesData detinfo::DetectorPropertiesService::DataForJob ( ) const
inlineinherited

Definition at line 31 of file DetectorPropertiesService.h.

32  {
33  auto const clockData =
35  return DataForJob(clockData);
36  }
DetectorPropertiesData DataForJob() const
DetectorPropertiesData detinfo::DetectorPropertiesService::DataForJob ( detinfo::DetectorClocksData const &  clockData) const
inlineinherited

Definition at line 37 of file DetectorPropertiesService.h.

38  {
39  return getDataForJob(clockData);
40  }
virtual DetectorPropertiesData getDataForJob(detinfo::DetectorClocksData const &clockData) const =0
DetectorPropertiesData detinfo::DetectorPropertiesServiceStandard::getDataFor ( art::Event const &  ,
DetectorClocksData const &  clockData 
) const
inlineoverrideprivatevirtual

Implements detinfo::DetectorPropertiesService.

Definition at line 70 of file DetectorPropertiesServiceStandard.h.

References detinfo::DetectorPropertiesStandard::DataFor(), fProp, and postOpenFile().

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

Implements detinfo::DetectorPropertiesService.

Definition at line 65 of file DetectorPropertiesServiceStandard.h.

References detinfo::DetectorPropertiesStandard::DataFor(), and fProp.

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

Definition at line 128 of file DetectorPropertiesServiceStandard.cc.

References fhicl::ParameterSet::get().

Referenced by postOpenFile().

130  {
131  // This method uses heuristics to determine whether the parameter
132  // set passed as argument is a DetectorPropertiesService configuration
133  // parameter set.
134 
135  return (ps.get<std::string>("service_type", "") == "DetectorPropertiesService") &&
136  (ps.get<std::string>("service_provider", "") == "DetectorPropertiesServiceStandard");
137  }
T get(std::string const &key) const
Definition: ParameterSet.h:314
void detinfo::DetectorPropertiesServiceStandard::postOpenFile ( const std::string &  filename)
private

Definition at line 43 of file DetectorPropertiesServiceStandard.cc.

References file, fInheritNumberTimeSamples, fProp, fPS, fhicl::ParameterSet::get(), isDetectorPropertiesServiceStandard(), fhicl::ParameterSet::make(), detinfo::DetectorPropertiesStandard::NumberTimeSamples(), and detinfo::DetectorPropertiesStandard::SetNumberTimeSamples().

Referenced by DetectorPropertiesServiceStandard(), and getDataFor().

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) {
93  auto ps =
94  fhicl::ParameterSet::make(reinterpret_cast<char const*>(sqlite3_column_text(stmt, 0)));
95  if (!isDetectorPropertiesServiceStandard(ps)) { continue; }
96 
97  auto const newNumberTimeSamples = ps.get<unsigned int>("NumberTimeSamples");
98  if (newNumberTimeSamples == fPS.get<unsigned int>("NumberTimeSamples")) { continue; }
99 
100  if (nNumberTimeSamples != 0 and newNumberTimeSamples != iNumberTimeSamples) {
101  sqlite3_finalize(stmt);
102  throw cet::exception(__FUNCTION__)
103  << "Historical values of NumberTimeSamples do not agree: " << iNumberTimeSamples << " "
104  << newNumberTimeSamples << "\n";
105  }
106 
107  iNumberTimeSamples = newNumberTimeSamples;
108  ++nNumberTimeSamples;
109  }
110  sqlite3_finalize(stmt);
111 
112  // Done looping over parameter sets.
113  // Now decide which parameters we will actually override.
114 
115  if (nNumberTimeSamples != 0 && iNumberTimeSamples != fProp.NumberTimeSamples()) {
116  mf::LogInfo("DetectorPropertiesServiceStandard")
117  << "Overriding configuration parameter NumberTimeSamples using "
118  "historical value.\n"
119  << " Configured value: " << fProp.NumberTimeSamples() << "\n"
120  << " Historical (used) value: " << iNumberTimeSamples << "\n";
121  fProp.SetNumberTimeSamples(iNumberTimeSamples);
122  }
123  }
unsigned int NumberTimeSamples() const override
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
T get(std::string const &key) const
Definition: ParameterSet.h:314
fhicl::ParameterSet fPS
Original parameter set.
bool isDetectorPropertiesServiceStandard(const fhicl::ParameterSet &ps) const
bool fInheritNumberTimeSamples
Flag saying whether to inherit NumberTimeSamples.
TFile * file
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 81 of file DetectorPropertiesServiceStandard.h.

Referenced by DetectorPropertiesServiceStandard(), and postOpenFile().

DetectorPropertiesStandard detinfo::DetectorPropertiesServiceStandard::fProp
private

Definition at line 78 of file DetectorPropertiesServiceStandard.h.

Referenced by getDataFor(), getDataForJob(), and postOpenFile().

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

Original parameter set.

Definition at line 79 of file DetectorPropertiesServiceStandard.h.

Referenced by DetectorPropertiesServiceStandard(), and postOpenFile().


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