DetectorPropertiesServiceProtoDUNEsp_service.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //Adapted for ProtoDUNE by Owen Goodwin (ogoodwin@fnal.gov) from
3 // \file DetectorProperties_service.cc
4 //
5 ////////////////////////////////////////////////////////////////////////
6 // Framework includes
7 // LArSoft includes
16 #include "lardata/DetectorInfoServices/ServicePack.h" // lar::extractProviders()
19 // Art includes
20 #include "art_root_io/RootDB/SQLite3Wrapper.h"
22 
23 
24 #include "ifdh_art/IFDHService/IFDH_service.h"
25 
26 #include "TFile.h"
27 
28 namespace spdp{
29  //--------------------------------------------------------------------
32  : fInheritNumberTimeSamples(pset.get<bool>("InheritNumberTimeSamples", false))
33  {
34  // Dummy handle to ensure that the DetectorClocksService callbacks are invoked first
36 
37  // Register for callbacks.
40 
41 
42  isNewRun=true;
43 /*
44  // obtain the required dependency service providers and create our own
45  const geo::GeometryCore* geo = lar::providerFrom<geo::Geometry>();
46 
47  const detinfo::LArProperties* lp = lar::providerFrom<detinfo::LArPropertiesService>();
48 
49  const detinfo::DetectorClocks* clks = art::ServiceHandle<detinfo::DetectorClocksService const>()->;
50 
51  fProp = std::make_unique<detinfo::DetectorPropertiesStandard>(pset,geo,lp,clks);
52  */
53  fProp = std::make_unique<spdp::DetectorPropertiesProtoDUNEsp>(pset,
57  >(),
58  std::set<std::string>({ "InheritNumberTimeSamples" })
59  );
60 
61  // at this point we need and expect the provider to be fully configured
62  fProp->CheckIfConfigured();
63 
64  // Save the parameter set.
65  fPS = pset;
66 
67 
68  }
69  //--------------------------------------------------------------------
71  {
72  fProp->ValidateAndConfigure(p, { "InheritNumberTimeSamples" });
73 
74  // Save the parameter set.
75  fPS = p;
76  return;
77  }
78 
80  {
81  isNewRun=true;
82  std::cout<<"New run, Num is: "<<run.run()<<" Updating DetectorProperties."<<std::endl;
83  // make it into a TTimeStamp
84 
85  //Get run dependent temperature correction
86 
87  // Before 11/17/18, temperature = 87.68 and is stable
88  // Between 11/17/18 and 3/1/19, temperature = 87.36 and has a rather large fluctuation. first run in this period 5903
89  // After 3/1/19, temperature = 87.65 and is stable. first run 6930
90  fProp->UpdateTemp(run.run());
91  }
92 
93 
94  //--------------------------------------------------------------------
95  // Callback called after input file is opened.
97  {
98 
99 
100 
101 
102 
103 
104 
105 
106  // std::cout<<"new run?"<<isNewRun<<std::endl;
107  if(isNewRun){
108 
109  auto start = filename.rfind("/"); //finds the final "/"
110  if (start == std::string::npos)
111  {
112  start = 0;
113  }
114  else
115  {
116  start += 1;
117  }
118 
119  int end = filename.length(); //last postion
120  std::string filename_s=(filename.substr(start, end-start)); //creates string of just file name, not path
121  // std::cout<<"filename:"<<filename_s<<std::endl;
123  fProp->UpdateHV(filename_s); //pass file name to be able update HV value from MetaData (if requested)
125  fProp->UpdateReadoutWindowSize(clockData, filename_s); //update Readout window value from filename
126  isNewRun=false;
127 
128  }
129 
130 
131  // Use this method to figure out whether to inherit configuration
132  // parameters from previous jobs.
133  // There is no way currently to correlate parameter sets saved in
134  // sqlite RootFileDB with process history (from MetaData tree).
135  // Therefore, we use the approach of scanning every historical
136  // parameter set in RootFileDB, and finding all parameter sets
137  // that appear to be DetectorPropertiesService configurations. If all
138  // historical parameter sets are in agreement about the value of
139  // an inherited parameter, then we accept the historical value,
140  // print a message, and override the configuration parameter. In
141  // cases where the historical configurations are not in agreement
142  // about the value of an inherited parameter, we ignore any
143  // historical parameter values that are the same as the current
144  // configured value of the parameter (that is, we resolve the
145  // conflict in favor of parameters values that are different than
146  // the current configuration). If two or more historical values
147  // differ from the current configuration, throw an exception.
148  // Note that it is possible to give precendence to the current
149  // configuration by disabling inheritance for that configuration
150  // parameter.
151  // Don't do anything if no parameters are supposed to be inherited.
152  if(!fInheritNumberTimeSamples) return;
153  // The only way to access art service metadata from the input file
154  // is to open it as a separate TFile object. Do that now.
155  if(filename.size() != 0) {
156  TFile* file = TFile::Open(filename.c_str(), "READ");
157  if(file != 0 && !file->IsZombie() && file->IsOpen()) {
158  // Open the sqlite datatabase.
159  art::SQLite3Wrapper sqliteDB(file, "RootFileDB");
160  // Loop over all stored ParameterSets.
161  unsigned int iNumberTimeSamples = 0; // Combined value of NumberTimeSamples.
162  unsigned int nNumberTimeSamples = 0; // Number of NumberTimeSamples parameters seen.
163  sqlite3_stmt * stmt = 0;
164  sqlite3_prepare_v2(sqliteDB, "SELECT PSetBlob from ParameterSets;", -1, &stmt, NULL);
165  while (sqlite3_step(stmt) == SQLITE_ROW) {
166  auto ps = fhicl::ParameterSet::make(reinterpret_cast<char const *>(sqlite3_column_text(stmt, 0)));
167  // Is this a DetectorPropertiesService parameter set?
169  if(psok) {
170  // Check NumberTimeSamples
171  // if(fInheritNumberTimeSamples) {
172  unsigned int newNumberTimeSamples = ps.get<unsigned int>("NumberTimeSamples");
173 
174  // Ignore parameter values that match the current configuration.
175 
176  if(newNumberTimeSamples != fPS.get<unsigned int>("NumberTimeSamples")) {
177  if(nNumberTimeSamples == 0)
178  iNumberTimeSamples = newNumberTimeSamples;
179  else if(newNumberTimeSamples != iNumberTimeSamples) {
180  throw cet::exception(__FUNCTION__)
181  << "Historical values of NumberTimeSamples do not agree: "
182  << iNumberTimeSamples << " " << newNumberTimeSamples << "\n" ;
183  }
184  ++nNumberTimeSamples;
185  // }
186  }
187  }
188  }
189  // Done looping over parameter sets.
190  // Now decide which parameters we will actually override.
191  if(// fInheritNumberTimeSamples &&
192  nNumberTimeSamples != 0 &&
193  iNumberTimeSamples != fProp->NumberTimeSamples()) {
194  mf::LogInfo("DetectorPropertiesServiceProtoDUNEsp")
195  << "Overriding configuration parameter NumberTimeSamples using historical value.\n"
196  << " Configured value: " << fProp->NumberTimeSamples() << "\n"
197  << " Historical (used) value: " << iNumberTimeSamples << "\n";
198  fProp->SetNumberTimeSamples(iNumberTimeSamples);
199  }
200  }
201  // Close file.
202  if(file != 0) {
203  if(file->IsOpen())
204  file->Close();
205  delete file;
206  }
207  }
208 
209  }
210  //--------------------------------------------------------------------
211  // Determine whether a parameter set is a DetectorPropertiesService configuration.
212 
214  (const fhicl::ParameterSet& ps) const
215  {
216  // This method uses heuristics to determine whether the parameter
217  // set passed as argument is a DetectorPropertiesService configuration
218  // parameter set.
219 
220  return
221  (ps.get<std::string>("service_type", "") == "DetectorPropertiesService")
222  && (ps.get<std::string>("service_provider", "") == "DetectorPropertiesServiceProtoDUNEsp")
223  ;
224 #if 0
225  // old heuristics here:
226  std::string s;
227  double d;
228  int i;
229  unsigned int u;
230 
231  bool result = !ps.get_if_present("module_label", s);
232  result = result && ps.get_if_present("TriggerOffset", i);
233  result = result && ps.get_if_present("SamplingRate", d);
234  result = result && ps.get_if_present("NumberTimeSamples", u);
235  result = result && ps.get_if_present("ReadOutWindowSize", u);
236 
237  return result;
238 #endif // 0
239  }
240 } // namespace spdf
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
ProviderPackFromServices< Services... > extractProviders()
Returns a provider pack with providers from specified services.
Definition: ServicePack.h:54
static QCString result
Encapsulate the construction of a single cyostat.
std::string string
Definition: nybbler.cc:12
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
struct sqlite3_stmt sqlite3_stmt
string filename
Definition: train.py:213
art framework interface to geometry description
Definition: Run.h:17
bool fInheritNumberTimeSamples
Flag saying whether to inherit NumberTimeSamples.
fhicl::ParameterSet fPS
Original parameter set.
DetectorPropertiesServiceProtoDUNEsp(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
T get(std::string const &key) const
Definition: ParameterSet.h:271
DetectorPropertiesData DataForJob() const
General LArSoft Utilities.
p
Definition: test.py:223
RunNumber_t run() const
Definition: DataViewImpl.cc:71
The geometry of one entire detector, as served by art.
Definition: Geometry.h:196
static constexpr double ps
Definition: Units.h:99
GlobalSignal< detail::SignalResponseType::FIFO, void(Run const &)> sPreBeginRun
Encapsulate the construction of a single detector plane.
GlobalSignal< detail::SignalResponseType::LIFO, void(std::string const &)> sPostOpenFile
std::optional< T > get_if_present(std::string const &key) const
Definition: ParameterSet.h:224
bool isDetectorPropertiesServiceProtoDUNEsp(const fhicl::ParameterSet &ps) const
static QCString * s
Definition: config.cpp:1042
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
Encapsulate the construction of a single detector plane.
std::unique_ptr< spdp::DetectorPropertiesProtoDUNEsp > fProp
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)