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

"Standard" implementation of DetectorProperties service More...

#include <DetectorPropertiesServiceStandardGAr.h>

Inheritance diagram for gar::detinfo::DetectorPropertiesServiceStandardGAr:
gar::detinfo::DetectorPropertiesService

Classes

struct  ServiceConfiguration_t
 

Public Types

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

Public Member Functions

 DetectorPropertiesServiceStandardGAr (fhicl::ParameterSet const &pset,::art::ActivityRegistry &reg)
 
virtual void reconfigure (fhicl::ParameterSet const &pset) override
 
void preProcessEvent (::art::Event const &evt, art::ScheduleContext)
 
void postOpenFile (std::string const &filename)
 
virtual const provider_typeprovider () const override
 
- Public Member Functions inherited from gar::detinfo::DetectorPropertiesService
virtual ~DetectorPropertiesService ()=default
 

Private Member Functions

bool isDetectorPropertiesServiceStandardGAr (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
  = gar::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:

Definition at line 60 of file DetectorPropertiesServiceStandardGAr.h.

Member Typedef Documentation

Definition at line 82 of file DetectorPropertiesServiceStandardGAr.h.

Constructor & Destructor Documentation

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

Definition at line 29 of file DetectorPropertiesServiceStandardGAr_service.cc.

31  : fInheritNumberTimeSamples(pset.get<bool>("InheritNumberTimeSamples", false))
32  {
33  // Register for callbacks.
34 
37  fProp = std::make_unique<detinfo::DetectorPropertiesStandard>(pset,
38  gar::extractProviders<geo::GeometryGAr,
39  detinfo::GArPropertiesService,
40  detinfo::ECALPropertiesService,
41  detinfo::DetectorClocksServiceGAr>(),
42  std::set<std::string>({ "InheritNumberTimeSamples" })
43  );
44 
45  // at this point we need and expect the provider to be fully configured
46  fProp->CheckIfConfigured();
47 
48  // Save the parameter set.
49  fPS = pset;
50 
51  }
bool fInheritNumberTimeSamples
Flag saying whether to inherit NumberTimeSamples.
std::unique_ptr< detinfo::DetectorPropertiesStandard > fProp
ProviderPackFromServices< Services... > extractProviders()
Returns a provider pack with providers from specified services.
Definition: ServicePack.h:53
void preProcessEvent(::art::Event const &evt, art::ScheduleContext)
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &, ScheduleContext)> sPreProcessEvent
GlobalSignal< detail::SignalResponseType::LIFO, void(std::string const &)> sPostOpenFile

Member Function Documentation

bool gar::detinfo::DetectorPropertiesServiceStandardGAr::isDetectorPropertiesServiceStandardGAr ( const fhicl::ParameterSet ps) const
private

Definition at line 180 of file DetectorPropertiesServiceStandardGAr_service.cc.

181  {
182  // This method uses heuristics to determine whether the parameter
183  // set passed as argument is a DetectorPropertiesService configuration
184  // parameter set.
185 
186  return
187  (ps.get<std::string>("service_type", "") == "DetectorPropertiesService")
188  && (ps.get<std::string>("service_provider", "") == "DetectorPropertiesServiceStandardGAr")
189  ;
190 #if 0
191  // old heuristics here:
192  std::string s;
193  double d;
194  int i;
195  unsigned int u;
196 
197  bool result = !ps.get_if_present("module_label", s);
198  result = result && ps.get_if_present("TriggerOffset", i);
199  result = result && ps.get_if_present("SamplingRate", d);
200  result = result && ps.get_if_present("NumberTimeSamples", u);
201 
202  return result;
203 #endif // 0
204  }
static QCString result
std::string string
Definition: nybbler.cc:12
T get(std::string const &key) const
Definition: ParameterSet.h:271
std::optional< T > get_if_present(std::string const &key) const
Definition: ParameterSet.h:224
static QCString * s
Definition: config.cpp:1042
void gar::detinfo::DetectorPropertiesServiceStandardGAr::postOpenFile ( std::string const &  filename)

Definition at line 74 of file DetectorPropertiesServiceStandardGAr_service.cc.

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

Definition at line 65 of file DetectorPropertiesServiceStandardGAr_service.cc.

66  {
67  // Make sure TPC Clock is updated with TimeService (though in principle it shouldn't change
68  fProp->UpdateClocks(gar::providerFrom<detinfo::DetectorClocksServiceGAr>());
69  }
std::unique_ptr< detinfo::DetectorPropertiesStandard > fProp
virtual const provider_type* gar::detinfo::DetectorPropertiesServiceStandardGAr::provider ( ) const
inlineoverridevirtual

Implements gar::detinfo::DetectorPropertiesService.

Definition at line 91 of file DetectorPropertiesServiceStandardGAr.h.

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

Implements gar::detinfo::DetectorPropertiesService.

Definition at line 54 of file DetectorPropertiesServiceStandardGAr_service.cc.

55  {
56  fProp->ValidateAndConfigure(p, { "InheritNumberTimeSamples" });
57 
58  // Save the parameter set.
59  fPS = p;
60 
61  return;
62  }
std::unique_ptr< detinfo::DetectorPropertiesStandard > fProp
p
Definition: test.py:223

Member Data Documentation

bool gar::detinfo::DetectorPropertiesServiceStandardGAr::fInheritNumberTimeSamples
private

Flag saying whether to inherit NumberTimeSamples.

Definition at line 98 of file DetectorPropertiesServiceStandardGAr.h.

std::unique_ptr<detinfo::DetectorPropertiesStandard> gar::detinfo::DetectorPropertiesServiceStandardGAr::fProp
private

Definition at line 95 of file DetectorPropertiesServiceStandardGAr.h.

fhicl::ParameterSet gar::detinfo::DetectorPropertiesServiceStandardGAr::fPS
private

Original parameter set.

Definition at line 96 of file DetectorPropertiesServiceStandardGAr.h.


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