LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
DetectorPropertiesServiceStandard_service.cc
Go to the documentation of this file.
1 //
3 // \file DetectorProperties_service.cc
4 //
6 // Framework includes
7 
8 // LArSoft includes
16 #include "lardata/DetectorInfoServices/ServicePack.h" // lar::extractProviders()
19 
20 // Art includes
23 
24 namespace detinfo{
25 
26  //--------------------------------------------------------------------
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  }
61 
62  //--------------------------------------------------------------------
64  {
65  fProp->ValidateAndConfigure(p, { "InheritNumberTimeSamples" });
66 
67  // Save the parameter set.
68  fPS = p;
69 
70  return;
71  }
72 
73  //-------------------------------------------------------------
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  }
79 
80  //--------------------------------------------------------------------
81  // Callback called after input file is opened.
82 
83  void DetectorPropertiesServiceStandard::postOpenFile(const std::string& filename)
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  }
182 
183  //--------------------------------------------------------------------
184  // Determine whether a parameter set is a DetectorPropertiesService configuration.
185 
187  (const fhicl::ParameterSet& ps) const
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  }
213 
214 } // namespace detinfo
215 
217 
Utilities to manage ProviderPack objects with art.
Float_t s
Definition: plot.C:23
ProviderPackFromServices< Services... > extractProviders()
Returns a provider pack with providers from specified services.
Definition: ServicePack.h:54
Encapsulate the construction of a single cyostat.
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
void make_ParameterSet(intermediate_table const &tbl, ParameterSet &ps)
DetectorPropertiesServiceStandard(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
std::unique_ptr< detinfo::DetectorPropertiesStandard > fProp
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
fhicl::ParameterSet fPS
Original parameter set.
General LArSoft Utilities.
The geometry of one entire detector, as served by art.
Definition: Geometry.h:110
bool isDetectorPropertiesServiceStandard(const fhicl::ParameterSet &ps) const
"Standard" implementation of DetectorProperties service
Encapsulate the construction of a single detector plane.
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
TFile * file
virtual void reconfigure(fhicl::ParameterSet const &pset) override
TCEvent evt
Definition: DataStructs.cxx:5
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Encapsulate the construction of a single detector plane.