LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
detinfo::DetectorPropertiesServiceStandard Class Reference

"Standard" implementation of DetectorProperties service More...

#include "DetectorPropertiesServiceStandard.h"

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

Classes

struct  ServiceConfiguration_t
 

Public Types

using Parameters = art::ServiceTable< ServiceConfiguration_t >
 
typedef detinfo::DetectorProperties provider_type
 

Public Member Functions

 DetectorPropertiesServiceStandard (fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
 
virtual void reconfigure (fhicl::ParameterSet const &pset) override
 
void preProcessEvent (const art::Event &evt)
 
void postOpenFile (const std::string &filename)
 
virtual const provider_typeprovider () const override
 

Private Member Functions

bool isDetectorPropertiesServiceStandard (const fhicl::ParameterSet &ps) const
 

Private Attributes

std::unique_ptr< detinfo::DetectorPropertiesStandardfProp
 
fhicl::ParameterSet fPS
 Original parameter set. More...
 
bool fInheritNumberTimeSamples
 Flag saying whether to inherit NumberTimeSamples. More...
 

Detailed Description

"Standard" implementation of DetectorProperties service

This class wraps DetectorPropertiesStandard provider into a art service. It delivers the provider via the standard interface:

detinfo::DetectorProperties const* detprop
  = art::ServiceHandle<detinfo::DetectorPropertiesStandard>()
  ->provider();

or, using the standard interface in "CoreUtils/ServiceUtil.h":

auto const* detprop
  = lar::providerFrom<detinfo::DetectorPropertiesStandard>();

In addition to the functionality of the provider, this service allows to read the configuration from the input file, inherited from a previous run.

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 55 of file DetectorPropertiesServiceStandard.h.

Member Typedef Documentation

Constructor & Destructor Documentation

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

Definition at line 28 of file DetectorPropertiesServiceStandard_service.cc.

References lar::extractProviders(), postOpenFile(), preProcessEvent(), art::ActivityRegistry::sPostOpenFile, and art::ActivityRegistry::sPreProcessEvent.

29  : fInheritNumberTimeSamples(pset.get<bool>("InheritNumberTimeSamples", false))
30  {
31  // Register for callbacks.
32 
35 /*
36  // obtain the required dependency service providers and create our own
37  const geo::GeometryCore* geo = lar::providerFrom<geo::Geometry>();
38 
39  const detinfo::LArProperties* lp = lar::providerFrom<detinfo::LArPropertiesService>();
40 
41  const detinfo::DetectorClocks* clks = lar::providerFrom<detinfo::DetectorClocksService>();
42 
43  fProp = std::make_unique<detinfo::DetectorPropertiesStandard>(pset,geo,lp,clks);
44  */
45  fProp = std::make_unique<detinfo::DetectorPropertiesStandard>(pset,
50  >(),
51  std::set<std::string>({ "InheritNumberTimeSamples" })
52  );
53 
54  // at this point we need and expect the provider to be fully configured
55  fProp->CheckIfConfigured();
56 
57  // Save the parameter set.
58  fPS = pset;
59 
60  }
ProviderPackFromServices< Services... > extractProviders()
Returns a provider pack with providers from specified services.
Definition: ServicePack.h:54
std::unique_ptr< detinfo::DetectorPropertiesStandard > fProp
fhicl::ParameterSet fPS
Original parameter set.
The geometry of one entire detector, as served by art.
Definition: Geometry.h:110
bool fInheritNumberTimeSamples
Flag saying whether to inherit NumberTimeSamples.
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &)> sPreProcessEvent
GlobalSignal< detail::SignalResponseType::LIFO, void(std::string const &)> sPostOpenFile

Member Function Documentation

bool detinfo::DetectorPropertiesServiceStandard::isDetectorPropertiesServiceStandard ( const fhicl::ParameterSet ps) const
private

Definition at line 187 of file DetectorPropertiesServiceStandard_service.cc.

References d, DEFINE_ART_SERVICE_INTERFACE_IMPL, fhicl::ParameterSet::get(), fhicl::ParameterSet::get_if_present(), and s.

Referenced by postOpenFile().

188  {
189  // This method uses heuristics to determine whether the parameter
190  // set passed as argument is a DetectorPropertiesService configuration
191  // parameter set.
192 
193  return
194  (ps.get<std::string>("service_type", "") == "DetectorPropertiesService")
195  && (ps.get<std::string>("service_provider", "") == "DetectorPropertiesServiceStandard")
196  ;
197 #if 0
198  // old heuristics here:
199  std::string s;
200  double d;
201  int i;
202  unsigned int u;
203 
204  bool result = !ps.get_if_present("module_label", s);
205  result = result && ps.get_if_present("TriggerOffset", i);
206  result = result && ps.get_if_present("SamplingRate", d);
207  result = result && ps.get_if_present("NumberTimeSamples", u);
208  result = result && ps.get_if_present("ReadOutWindowSize", u);
209 
210  return result;
211 #endif // 0
212  }
Float_t s
Definition: plot.C:23
T get(std::string const &key) const
Definition: ParameterSet.h:231
Float_t d
Definition: plot.C:237
bool get_if_present(std::string const &key, T &value) const
Definition: ParameterSet.h:208
void detinfo::DetectorPropertiesServiceStandard::postOpenFile ( const std::string &  filename)

Definition at line 83 of file DetectorPropertiesServiceStandard_service.cc.

References file, fInheritNumberTimeSamples, fProp, fPS, fhicl::ParameterSet::get(), isDetectorPropertiesServiceStandard(), and fhicl::make_ParameterSet().

Referenced by DetectorPropertiesServiceStandard().

84  {
85  // Use this method to figure out whether to inherit configuration
86  // parameters from previous jobs.
87 
88  // There is no way currently to correlate parameter sets saved in
89  // sqlite RootFileDB with process history (from MetaData tree).
90  // Therefore, we use the approach of scanning every historical
91  // parameter set in RootFileDB, and finding all parameter sets
92  // that appear to be DetectorPropertiesService configurations. If all
93  // historical parameter sets are in agreement about the value of
94  // an inherited parameter, then we accept the historical value,
95  // print a message, and override the configuration parameter. In
96  // cases where the historical configurations are not in agreement
97  // about the value of an inherited parameter, we ignore any
98  // historical parameter values that are the same as the current
99  // configured value of the parameter (that is, we resolve the
100  // conflict in favor of parameters values that are different than
101  // the current configuration). If two or more historical values
102  // differ from the current configuration, throw an exception.
103  // Note that it is possible to give precendence to the current
104  // configuration by disabling inheritance for that configuration
105  // parameter.
106 
107  // Don't do anything if no parameters are supposed to be inherited.
108 
109  if(!fInheritNumberTimeSamples) return;
110 
111  // The only way to access art service metadata from the input file
112  // is to open it as a separate TFile object. Do that now.
113 
114  if(filename.size() != 0) {
115 
116  TFile* file = TFile::Open(filename.c_str(), "READ");
117  if(file != 0 && !file->IsZombie() && file->IsOpen()) {
118 
119  // Open the sqlite datatabase.
120 
121  art::SQLite3Wrapper sqliteDB(file, "RootFileDB");
122 
123  // Loop over all stored ParameterSets.
124 
125  unsigned int iNumberTimeSamples = 0; // Combined value of NumberTimeSamples.
126  unsigned int nNumberTimeSamples = 0; // Number of NumberTimeSamples parameters seen.
127 
128  sqlite3_stmt * stmt = 0;
129  sqlite3_prepare_v2(sqliteDB, "SELECT PSetBlob from ParameterSets;", -1, &stmt, NULL);
130  while (sqlite3_step(stmt) == SQLITE_ROW) {
132  fhicl::make_ParameterSet(reinterpret_cast<char const *>(sqlite3_column_text(stmt, 0)), ps);
133  // Is this a DetectorPropertiesService parameter set?
134 
135  bool psok = isDetectorPropertiesServiceStandard(ps);
136  if(psok) {
137 
138  // Check NumberTimeSamples
139 
140  // if(fInheritNumberTimeSamples) {
141  unsigned int newNumberTimeSamples = ps.get<unsigned int>("NumberTimeSamples");
142 
143  // Ignore parameter values that match the current configuration.
144 
145  if(newNumberTimeSamples != fPS.get<unsigned int>("NumberTimeSamples")) {
146  if(nNumberTimeSamples == 0)
147  iNumberTimeSamples = newNumberTimeSamples;
148  else if(newNumberTimeSamples != iNumberTimeSamples) {
149  throw cet::exception(__FUNCTION__)
150  << "Historical values of NumberTimeSamples do not agree: "
151  << iNumberTimeSamples << " " << newNumberTimeSamples << "\n" ;
152  }
153  ++nNumberTimeSamples;
154  // }
155  }
156  }
157  }
158 
159  // Done looping over parameter sets.
160  // Now decide which parameters we will actually override.
161 
162  if(// fInheritNumberTimeSamples &&
163  nNumberTimeSamples != 0 &&
164  iNumberTimeSamples != fProp->NumberTimeSamples()) {
165  mf::LogInfo("DetectorPropertiesServiceStandard")
166  << "Overriding configuration parameter NumberTimeSamples using historical value.\n"
167  << " Configured value: " << fProp->NumberTimeSamples() << "\n"
168  << " Historical (used) value: " << iNumberTimeSamples << "\n";
169  fProp->SetNumberTimeSamples(iNumberTimeSamples);
170  }
171  }
172 
173  // Close file.
174  if(file != 0) {
175  if(file->IsOpen())
176  file->Close();
177  delete file;
178  }
179  }
180 
181  }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
void make_ParameterSet(intermediate_table const &tbl, ParameterSet &ps)
std::unique_ptr< detinfo::DetectorPropertiesStandard > fProp
T get(std::string const &key) const
Definition: ParameterSet.h:231
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
void detinfo::DetectorPropertiesServiceStandard::preProcessEvent ( const art::Event evt)

Definition at line 74 of file DetectorPropertiesServiceStandard_service.cc.

References fProp.

Referenced by DetectorPropertiesServiceStandard().

75  {
76  // Make sure TPC Clock is updated with TimeService (though in principle it shouldn't change
77  fProp->UpdateClocks(lar::providerFrom<detinfo::DetectorClocksService>());
78  }
std::unique_ptr< detinfo::DetectorPropertiesStandard > fProp
virtual const provider_type* detinfo::DetectorPropertiesServiceStandard::provider ( ) const
inlineoverridevirtual

Implements detinfo::DetectorPropertiesService.

Definition at line 86 of file DetectorPropertiesServiceStandard.h.

References fProp.

86 { return fProp.get();}
std::unique_ptr< detinfo::DetectorPropertiesStandard > fProp
void detinfo::DetectorPropertiesServiceStandard::reconfigure ( fhicl::ParameterSet const &  pset)
overridevirtual

Implements detinfo::DetectorPropertiesService.

Definition at line 63 of file DetectorPropertiesServiceStandard_service.cc.

References fProp, and fPS.

64  {
65  fProp->ValidateAndConfigure(p, { "InheritNumberTimeSamples" });
66 
67  // Save the parameter set.
68  fPS = p;
69 
70  return;
71  }
std::unique_ptr< detinfo::DetectorPropertiesStandard > fProp
fhicl::ParameterSet fPS
Original parameter set.

Member Data Documentation

bool detinfo::DetectorPropertiesServiceStandard::fInheritNumberTimeSamples
private

Flag saying whether to inherit NumberTimeSamples.

Definition at line 93 of file DetectorPropertiesServiceStandard.h.

Referenced by postOpenFile().

std::unique_ptr<detinfo::DetectorPropertiesStandard> detinfo::DetectorPropertiesServiceStandard::fProp
private
fhicl::ParameterSet detinfo::DetectorPropertiesServiceStandard::fPS
private

Original parameter set.

Definition at line 91 of file DetectorPropertiesServiceStandard.h.

Referenced by postOpenFile(), and reconfigure().


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