DetectorClocksServiceStandardGAr_service.cc
Go to the documentation of this file.
2 
3 #include "TFile.h"
4 #include "art_root_io/RootDB/SQLite3Wrapper.h"
8 
9 //-----------------------------------------------------------------------------------------
12 : fClocks(std::make_unique<detinfo::DetectorClocksStandardGAr>(pset))
13 {
14 
18 
19 }
20 
21 //------------------------------------------------------------------
23 //------------------------------------------------------------------
24 {
25  fClocks->Configure(pset);
26 
27 }
28 
29 //------------------------------------------------------------
31 //------------------------------------------------------------
32 {
33  auto trig_handle = evt.getHandle<std::vector<raw::Trigger> >(fClocks->TrigModuleName());
34 
35  std::vector<std::string> cfgNames = fClocks->ConfigNames();
36  std::vector<double> cfgValues = fClocks->ConfigValues();
37 
38  fClocks->SetSpillLength( cfgValues.at(detinfo::kDefaultSpillLength) );
39 
40  if(!trig_handle.isValid() || trig_handle->empty()) {
41  // Trigger simulation has not run yet!
42  fClocks->SetTriggerTime(cfgValues.at(detinfo::kDefaultTrigTime),
43  cfgValues.at(detinfo::kDefaultBeamTime) );
44  return;
45  }
46 
47  if(trig_handle->size()>1)
48 
49  throw cet::exception("DetectorClocksServiceStandardGAr::preProcessEvent")
50  << "Found "
51  << trig_handle->size()
52  << " triggers (only 1 trigger/event supported)\n";
53 
54  const ::art::Ptr<raw::Trigger> trig_ptr(trig_handle,0);
55 
56  fClocks->SetTriggerTime(trig_ptr->TriggerTime(),
57  trig_ptr->BeamGateTime() );
58 
59  return;
60 }
61 
62 //------------------------------------------------------
64 //------------------------------------------------------
65 {
66  // run number is unsigned so clang says this statement cannot happen
67  //if (run.id().run() < 0) return;
68 
69  fClocks->ApplyParams();
70 }
71 
72 
73 //---------------------------------------------------------------
75 //---------------------------------------------------------------
76 {
77 
78  // Method inheriting from DetectorProperties
79 
80  if(!fClocks->InheritClockConfig()) return;
81 
82  // The only way to access art service metadata from the input file
83  // is to open it as a separate TFile object. Do that now.
84 
85  if(!filename.empty()) {
86 
87  TFile* file = TFile::Open(filename.c_str(), "READ");
88  if(file != 0 && !file->IsZombie() && file->IsOpen()) {
89 
90  std::vector<std::string> cfgName = fClocks->ConfigNames();
91  std::vector<double> cfgValue = fClocks->ConfigValues();
92 
93  // Open the sqlite datatabase.
94 
95  ::art::SQLite3Wrapper sqliteDB(file, "RootFileDB");
96 
97  // Loop over all stored ParameterSets.
98 
99  std::vector<size_t> config_count(detinfo::kInheritConfigTypeMax,0);
100  std::vector<double> config_value(detinfo::kInheritConfigTypeMax,0);
101 
102  sqlite3_stmt * stmt = 0;
103  sqlite3_prepare_v2(sqliteDB, "SELECT PSetBlob from ParameterSets;", -1, &stmt, NULL);
104 
105  while (sqlite3_step(stmt) == SQLITE_ROW) {
106 
107  //fhicl::ParameterSet ps;
108  //fhicl::make_ParameterSet(reinterpret_cast<char const *>(sqlite3_column_text(stmt, 0)), ps);
109  auto ps = fhicl::ParameterSet::make(reinterpret_cast<char const *>(sqlite3_column_text(stmt, 0)));
110 
111  if(!fClocks->IsRightConfig(ps)) continue;
112 
113  for(size_t i=0; i<detinfo::kInheritConfigTypeMax; ++i) {
114 
115  double value_from_file = ps.get<double>(cfgName.at(i).c_str());
116 
117  if(!(config_count.at(i)))
118 
119  config_value.at(i) = value_from_file;
120 
121  else if(config_value.at(i) != value_from_file)
122 
123  throw cet::exception(__FUNCTION__)
124  << Form("\033[95mFound historical value disagreement for %s ... %g != %g",
125  cfgName.at(i).c_str(),
126  config_value.at(i),
127  value_from_file)
128  << "\033[00m";
129  config_count.at(i) +=1;
130 
131  }
132 
133  }
134 
135  // Override parameters
136 
137  for(size_t i=0; i<detinfo::kInheritConfigTypeMax; ++i)
138 
139  if(config_count.at(i) && cfgValue.at(i) != config_value.at(i)) {
140 
141  MF_LOG_INFO("DetectorClocksServiceStandardGAr")
142  << Form("\033[93mOverriding configuration parameter %s ... %g (fcl) => %g (data file)\033[00m",
143  cfgName.at(i).c_str(),
144  cfgValue.at(i),
145  config_value.at(i));
146 
147  fClocks->SetConfigValue(i,config_value.at(i));
148 
149  }
150  }
151 
152  // Close file.
153  if(file != 0) {
154  if(file->IsOpen())
155  file->Close();
156  delete file;
157  }
158  }
159 
160  // Reset parameters
161  fClocks->ApplyParams();
162 
163 }
164 
166 
virtual void reconfigure(fhicl::ParameterSet const &pset) override
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
STL namespace.
struct sqlite3_stmt sqlite3_stmt
DetectorClocksServiceStandardGAr(fhicl::ParameterSet const &pset,::art::ActivityRegistry &reg)
string filename
Definition: train.py:213
Definition: Run.h:17
void preProcessEvent(::art::Event const &evt, art::ScheduleContext)
std::unique_ptr< detinfo::DetectorClocksStandardGAr > fClocks
General LArSoft Utilities.
static constexpr double ps
Definition: Units.h:99
#define MF_LOG_INFO(category)
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &, ScheduleContext)> sPreProcessEvent
GlobalSignal< detail::SignalResponseType::FIFO, void(Run const &)> sPreBeginRun
GlobalSignal< detail::SignalResponseType::LIFO, void(std::string const &)> sPostOpenFile
TCEvent evt
Definition: DataStructs.cxx:7
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)