LArSoft  v09_90_00
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 25 of file DetectorPropertiesServiceStandard.cc.

References fInheritNumberTimeSamples, fPS, and postOpenFile().

28  : fProp{pset,
29  lar::providerFrom<geo::Geometry>(),
30  lar::providerFrom<detinfo::LArPropertiesService>(),
31  std::set<std::string>({"InheritNumberTimeSamples"})}
32  , fPS{pset}
33  , fInheritNumberTimeSamples{pset.get<bool>("InheritNumberTimeSamples", false)}
34  {
36  }
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 132 of file DetectorPropertiesServiceStandard.cc.

References fhicl::ParameterSet::get().

Referenced by postOpenFile().

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

Definition at line 41 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().

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