LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
DetectorClocksServiceStandard_service.cc
Go to the documentation of this file.
3 #include "TFile.h"
6 
7 //-----------------------------------------------------------------------------------------
10  : fClocks(std::make_unique<detinfo::DetectorClocksStandard>(pset))
11 {
12 
13  reg.sPreProcessEvent.watch (this, &DetectorClocksServiceStandard::preProcessEvent);
14  reg.sPostOpenFile.watch (this, &DetectorClocksServiceStandard::postOpenFile);
15  reg.sPreBeginRun.watch (this, &DetectorClocksServiceStandard::preBeginRun);
16 
17 }
18 
19 //------------------------------------------------------------------
21 //------------------------------------------------------------------
22 {
23  fClocks->Configure(pset);
24 
25 }
26 
27 //------------------------------------------------------------
29 //------------------------------------------------------------
30 {
32 }
33 
34 //------------------------------------------------------
36 //------------------------------------------------------
37 {
38 
39  fClocks->ApplyParams();
40 
41 }
42 
43 
44 //---------------------------------------------------------------
46 //---------------------------------------------------------------
47 {
48 
49  // Method inheriting from DetectorProperties
50 
51  if(!fClocks->InheritClockConfig()) return;
52 
53  // The only way to access art service metadata from the input file
54  // is to open it as a separate TFile object. Do that now.
55 
56  if(!filename.empty()) {
57 
58  TFile* file = TFile::Open(filename.c_str(), "READ");
59  if(file != 0 && !file->IsZombie() && file->IsOpen()) {
60 
61  std::vector<std::string> cfgName = fClocks->ConfigNames();
62  std::vector<double> cfgValue = fClocks->ConfigValues();
63 
64  // Open the sqlite datatabase.
65 
66  art::SQLite3Wrapper sqliteDB(file, "RootFileDB");
67 
68  // Loop over all stored ParameterSets.
69 
70  std::vector<size_t> config_count(detinfo::kInheritConfigTypeMax,0);
71  std::vector<double> config_value(detinfo::kInheritConfigTypeMax,0);
72 
73  sqlite3_stmt * stmt = 0;
74  sqlite3_prepare_v2(sqliteDB, "SELECT PSetBlob from ParameterSets;", -1, &stmt, NULL);
75 
76  while (sqlite3_step(stmt) == SQLITE_ROW) {
77 
79  fhicl::make_ParameterSet(reinterpret_cast<char const *>(sqlite3_column_text(stmt, 0)), ps);
80 
81  if(!fClocks->IsRightConfig(ps)) continue;
82 
83  for(size_t i=0; i<detinfo::kInheritConfigTypeMax; ++i) {
84 
85  double value_from_file = ps.get<double>(cfgName.at(i).c_str());
86 
87  if(!(config_count.at(i)))
88 
89  config_value.at(i) = value_from_file;
90 
91  else if(config_value.at(i) != value_from_file)
92 
93  throw cet::exception(__FUNCTION__) << Form("\033[95mFound historical value disagreement for %s ... %g != %g",
94  cfgName.at(i).c_str(),
95  config_value.at(i),
96  value_from_file)
97  << "\033[00m" << std::endl;
98  config_count.at(i) +=1;
99 
100  }
101 
102  }
103 
104  // Override parameters
105 
106  for(size_t i=0; i<detinfo::kInheritConfigTypeMax; ++i)
107 
108  if(config_count.at(i) && cfgValue.at(i) != config_value.at(i)) {
109 
110  std::cout << Form("\033[93mOverriding configuration parameter %s ... %g (fcl) => %g (data file)\033[00m",
111  cfgName.at(i).c_str(),
112  cfgValue.at(i),
113  config_value.at(i))
114  << std::endl;
115 
116  fClocks->SetConfigValue(i,config_value.at(i));
117 
118  }
119  }
120 
121  // Close file.
122  if(file != 0) {
123  if(file->IsOpen())
124  file->Close();
125  delete file;
126  }
127  }
128 
129  // Reset parameters
130  fClocks->ApplyParams();
131 
132 }
133 
135 
bool setDetectorClocksStandardTrigger(detinfo::DetectorClocksStandard &detClocks, Event const &event)
Loads DetectorClocksStandard trigger times.
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)
void make_ParameterSet(intermediate_table const &tbl, ParameterSet &ps)
Definition: Run.h:30
virtual void reconfigure(fhicl::ParameterSet const &pset) override
T get(std::string const &key) const
Definition: ParameterSet.h:231
art service managing detinfo::DetectorClocksStandard.
GlobalSignal< detail::SignalResponseType::FIFO, void(Run const &)> sPreBeginRun
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &)> sPreProcessEvent
GlobalSignal< detail::SignalResponseType::LIFO, void(std::string const &)> sPostOpenFile
TFile * file
TCEvent evt
Definition: DataStructs.cxx:5
std::unique_ptr< detinfo::DetectorClocksStandard > fClocks
Functions to load trigger time in detinfo::DetectorClocksStandard.
DetectorClocksServiceStandard(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33