Public Member Functions | Private Attributes | List of all members
gar::detinfo::DetectorClocksServiceStandardGAr Class Reference

#include <DetectorClocksServiceStandardGAr.h>

Inheritance diagram for gar::detinfo::DetectorClocksServiceStandardGAr:
gar::detinfo::DetectorClocksServiceGAr

Public Member Functions

 DetectorClocksServiceStandardGAr (fhicl::ParameterSet const &pset,::art::ActivityRegistry &reg)
 
virtual void reconfigure (fhicl::ParameterSet const &pset) override
 
void preBeginRun (::art::Run const &run)
 
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::DetectorClocksServiceGAr
virtual ~DetectorClocksServiceGAr ()=default
 

Private Attributes

std::unique_ptr< detinfo::DetectorClocksStandardGArfClocks
 

Additional Inherited Members

- Public Types inherited from gar::detinfo::DetectorClocksServiceGAr
typedef detinfo::DetectorClocks provider_type
 

Detailed Description

Definition at line 27 of file DetectorClocksServiceStandardGAr.h.

Constructor & Destructor Documentation

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

Definition at line 10 of file DetectorClocksServiceStandardGAr_service.cc.

12 : fClocks(std::make_unique<detinfo::DetectorClocksStandardGAr>(pset))
13 {
14 
18 
19 }
void preProcessEvent(::art::Event const &evt, art::ScheduleContext)
std::unique_ptr< detinfo::DetectorClocksStandardGAr > fClocks
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

Member Function Documentation

void gar::detinfo::DetectorClocksServiceStandardGAr::postOpenFile ( std::string const &  filename)

Definition at line 74 of file DetectorClocksServiceStandardGAr_service.cc.

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 }
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::DetectorClocksStandardGAr > fClocks
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::DetectorClocksServiceStandardGAr::preBeginRun ( ::art::Run const &  run)

Definition at line 63 of file DetectorClocksServiceStandardGAr_service.cc.

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 }
std::unique_ptr< detinfo::DetectorClocksStandardGAr > fClocks
void gar::detinfo::DetectorClocksServiceStandardGAr::preProcessEvent ( ::art::Event const &  evt,
art::ScheduleContext   
)

Definition at line 30 of file DetectorClocksServiceStandardGAr_service.cc.

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 }
std::unique_ptr< detinfo::DetectorClocksStandardGAr > fClocks
TCEvent evt
Definition: DataStructs.cxx:7
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
virtual const provider_type* gar::detinfo::DetectorClocksServiceStandardGAr::provider ( ) const
inlineoverridevirtual

Implements gar::detinfo::DetectorClocksServiceGAr.

Definition at line 37 of file DetectorClocksServiceStandardGAr.h.

37 { return fClocks.get();}
std::unique_ptr< detinfo::DetectorClocksStandardGAr > fClocks
void gar::detinfo::DetectorClocksServiceStandardGAr::reconfigure ( fhicl::ParameterSet const &  pset)
overridevirtual

Implements gar::detinfo::DetectorClocksServiceGAr.

Definition at line 22 of file DetectorClocksServiceStandardGAr_service.cc.

24 {
25  fClocks->Configure(pset);
26 
27 }
std::unique_ptr< detinfo::DetectorClocksStandardGAr > fClocks

Member Data Documentation

std::unique_ptr<detinfo::DetectorClocksStandardGAr> gar::detinfo::DetectorClocksServiceStandardGAr::fClocks
private

Definition at line 41 of file DetectorClocksServiceStandardGAr.h.


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