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

art service managing detinfo::DetectorClocksStandard. More...

#include <DetectorClocksServiceStandard.h>

Inheritance diagram for detinfo::DetectorClocksServiceStandard:
detinfo::DetectorClocksService

Public Member Functions

 DetectorClocksServiceStandard (fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
 
- Public Member Functions inherited from detinfo::DetectorClocksService
virtual ~DetectorClocksService ()=default
 

Private Member Functions

void preBeginRun (art::Run const &run)
 
void postOpenFile (std::string const &filename)
 
DetectorClocksData DataForJob () const override
 
DetectorClocksData DataFor (art::Event const &e) const override
 

Private Attributes

DetectorClocksStandard fClocks
 
bool fInheritClockConfig
 

Additional Inherited Members

- Public Types inherited from detinfo::DetectorClocksService
using provider_type = detinfo::DetectorClocks
 

Detailed Description

art service managing detinfo::DetectorClocksStandard.

See also
detinfo::DetectorClocksStandard, detinfo::DetectorClocks

This art service manages LArSoft's service provider detinfo::DetectorClocksStandard, which implements detinfo::DetectorClocks interface.

For information about functionality of the service, see the documentation of its interface, detinfo::DetectorClocks. For information of the configuration, see also detinfo::DetectorClocksStandard.

Configuration

The configuration parameters are documented in the service provider implementation: detinfo::DetectorClocksStandard.

Consistency check

This service manager honors the InheritClockConfig configuration option in the following way:

  1. if the past jobs (explicitly excluding the current job) had inconsistent configuration, an exception is thrown claiming an "historical disagreement"
  2. after the verification that the past configuration is consistent, the values from that configurations override the ones in the configuration of the current job; a value from the configuration of the current job is retained only if it was not present in the past (i.e. it is a new configuration parameter added since the input file was produced).

The "past jobs" are the jobs that have produced the input file, and whose configuration is stored by art in the input file itself. The check and reconfiguration is performed on each new input file.

Timing specifics

The trigger and beam gate times are set by this service before each event is processed. The logic is the following:

  1. if the event contains a raw trigger (raw::Trigger) data product with input tag TriggerName() (from the configuration), that data product is read and the trigger and beam gate times stored in it are imported in the current service provider configuration; if there are more than one raw::Trigger objects in the data product, an exception is thrown
  2. if no raw trigger is found with the specified label, the configuration of the service provider is updated using the default values of trigger and beam times specified in the service configuration

The first set up happens on opening the first run in the first input file. Accessing this service before (e.g. during beginJob() phase) yields undefined behaviour.

Definition at line 84 of file DetectorClocksServiceStandard.h.

Constructor & Destructor Documentation

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

Definition at line 34 of file DetectorClocksServiceStandard_service.cc.

36  : fClocks{pset}, fInheritClockConfig{pset.get<bool>("InheritClockConfig")}
37  {
40  }
GlobalSignal< detail::SignalResponseType::FIFO, void(Run const &)> sPreBeginRun
GlobalSignal< detail::SignalResponseType::LIFO, void(std::string const &)> sPostOpenFile

Member Function Documentation

DetectorClocksData detinfo::DetectorClocksServiceStandard::DataFor ( art::Event const &  e) const
overrideprivatevirtual

Implements detinfo::DetectorClocksService.

Definition at line 128 of file DetectorClocksServiceStandard_service.cc.

const double e
detinfo::DetectorClocksData detectorClocksStandardDataFor(detinfo::DetectorClocksStandard const &detClocks, Event const &event)
Returns DetectorClocksData tuned on the specified event.
DetectorClocksData detinfo::DetectorClocksServiceStandard::DataForJob ( ) const
inlineoverrideprivatevirtual

Implements detinfo::DetectorClocksService.

Definition at line 93 of file DetectorClocksServiceStandard.h.

94  {
95  return fClocks.DataForJob();
96  }
DetectorClocksData DataForJob() const override
Returns a complete detinfo::DetectorClocksData object.
void detinfo::DetectorClocksServiceStandard::postOpenFile ( std::string const &  filename)
private

Definition at line 50 of file DetectorClocksServiceStandard_service.cc.

51  {
52  if (!fInheritClockConfig) { return; }
53  if (filename.empty()) { return; }
54  std::unique_ptr<TFile> file{TFile::Open(filename.c_str(), "READ")};
55  if (!file || file->IsZombie() || !file->IsOpen()) { return; }
56  std::unique_ptr<TTree> metaDataTree{
57  file->Get<TTree>(art::rootNames::metaDataTreeName().c_str())};
58  if (metaDataTree == nullptr) {
59  throw cet::exception("DetectorClocksServiceStandard",
60  "Input file does not contain a metadata tree!");
61  }
62  auto const fileFormatVersion =
63  art::detail::readMetadata<art::FileFormatVersion>(metaDataTree.get());
65  vector<string> const cfgName(fClocks.ConfigNames());
66  vector<double> const cfgValue(fClocks.ConfigValues());
67  bitset<kConfigTypeMax> config_set;
68  vector<double> config_value(kConfigTypeMax, 0);
69 
70  auto count_configuration_changes =
71  [&cfgName, &config_set, &config_value](fhicl::ParameterSet const& ps) {
72  for (size_t i = 0; i < kConfigTypeMax; ++i) {
73  auto const value_from_file = ps.get<double>(cfgName[i]);
74  if (not config_set[i]) {
75  config_value[i] = value_from_file;
76  config_set[i] = true;
77  }
78  else if (config_value[i] != value_from_file) {
79  throw cet::exception("DetectorClocksServiceStandard")
80  << "Found historical value disagreement for " << cfgName[i] << " ... "
81  << config_value[i] << " != " << value_from_file;
82  }
83  }
84  };
85 
86  if (fileFormatVersion.value_ < 5) {
87  art::ParameterSetMap psetMap;
88  if (!art::detail::readMetadata(metaDataTree.get(), psetMap)) {
89  throw cet::exception("DetectorClocksServiceStandard",
90  "Could not read ParameterSetMap from metadata tree!");
91  }
92 
93  for (auto const& psEntry : psetMap) {
95  ps = fhicl::ParameterSet::make(psEntry.second.pset_);
96  if (!fClocks.IsRightConfig(ps)) { continue; }
97 
98  count_configuration_changes(ps);
99  }
100  }
101  else {
102  art::SQLite3Wrapper sqliteDB(file.get(), "RootFileDB");
103  sqlite3_stmt* stmt{nullptr};
104  sqlite3_prepare_v2(sqliteDB, "SELECT PSetBlob from ParameterSets;", -1, &stmt, nullptr);
105  while (sqlite3_step(stmt) == SQLITE_ROW) {
107  ps = fhicl::ParameterSet::make(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0)));
108  if (!fClocks.IsRightConfig(ps)) { continue; }
109 
110  count_configuration_changes(ps);
111  }
112  sqlite3_finalize(stmt);
113  }
114 
115  for (size_t i = 0; i < kConfigTypeMax; ++i) {
116  if (not config_set[i]) continue;
117  if (cfgValue[i] == config_value[i]) continue;
118 
119  cout << "Overriding configuration parameter " << cfgName[i] << " ... " << cfgValue[i]
120  << " (fcl) => " << config_value[i] << " (data file)" << endl;
121  fClocks.SetConfigValue(i, config_value[i]);
122  }
124  } // DetectorClocksServiceStandard::postOpenFile()
bool IsRightConfig(const fhicl::ParameterSet &ps) const
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
std::vector< std::string > const & ConfigNames() const override
struct sqlite3_stmt sqlite3_stmt
string filename
Definition: train.py:213
std::vector< double > const & ConfigValues() const override
std::string const & metaDataTreeName()
Definition: rootNames.cc:42
void ApplyParams()
Internal function to apply loaded parameters to member attributes.
static constexpr double ps
Definition: Units.h:99
void SetConfigValue(size_t i, double val)
std::map< fhicl::ParameterSetID, ParameterSetBlob > ParameterSetMap
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
void detinfo::DetectorClocksServiceStandard::preBeginRun ( art::Run const &  run)
private

Definition at line 43 of file DetectorClocksServiceStandard_service.cc.

44  {
45  // This callback probably is not necessary.
47  }
void ApplyParams()
Internal function to apply loaded parameters to member attributes.

Member Data Documentation

DetectorClocksStandard detinfo::DetectorClocksServiceStandard::fClocks
private

Definition at line 101 of file DetectorClocksServiceStandard.h.

bool detinfo::DetectorClocksServiceStandard::fInheritClockConfig
private

Definition at line 102 of file DetectorClocksServiceStandard.h.


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