12 #include "art_root_io/Inputfwd.h"
13 #include "art_root_io/RootDB/SQLite3Wrapper.h"
14 #include "art_root_io/detail/readMetadata.h"
15 #include "art/Framework/Principal/Event.h"
16 #include "art/Framework/Principal/Run.h"
17 #include "art/Framework/Services/Registry/ActivityRegistry.h"
18 #include "art/Framework/Services/Registry/ServiceHandle.h"
19 #include "art/Persistency/Provenance/ScheduleContext.h"
20 #include "canvas/Persistency/Provenance/FileFormatVersion.h"
21 #include "canvas/Persistency/Provenance/ParameterSetMap.h"
22 #include "canvas/Persistency/Provenance/rootNames.h"
23 #include "fhiclcpp/ParameterSet.h"
24 #include "cetlib_except/exception.h"
35 DetectorClocksServiceStandard::DetectorClocksServiceStandard(fhicl::ParameterSet
const& pset,
36 art::ActivityRegistry& reg)
37 : fClocks{pset}, fInheritClockConfig{pset.get<
bool>(
"InheritClockConfig")}
54 if (filename.empty()) {
return; }
55 std::unique_ptr<TFile>
file{TFile::Open(filename.c_str(),
"READ")};
56 if (!
file ||
file->IsZombie() || !
file->IsOpen()) {
return; }
57 std::unique_ptr<TTree> metaDataTree{
58 file->Get<TTree>(art::rootNames::metaDataTreeName().c_str())};
59 if (metaDataTree ==
nullptr) {
60 throw cet::exception(
"DetectorClocksServiceStandard",
61 "Input file does not contain a metadata tree!");
63 auto const fileFormatVersion =
64 art::detail::readMetadata<art::FileFormatVersion>(metaDataTree.get());
65 fhicl::ParameterSet ps;
68 bitset<kConfigTypeMax> config_set;
71 auto count_configuration_changes =
72 [&cfgName, &config_set, &config_value](fhicl::ParameterSet
const& ps) {
74 auto const value_from_file = ps.get<
double>(cfgName[i]);
75 if (not config_set[i]) {
76 config_value[i] = value_from_file;
79 else if (config_value[i] != value_from_file) {
80 throw cet::exception(
"DetectorClocksServiceStandard")
81 <<
"Found historical value disagreement for " << cfgName[i] <<
" ... "
82 << config_value[i] <<
" != " << value_from_file;
87 if (fileFormatVersion.value_ < 5) {
88 art::ParameterSetMap psetMap;
89 if (!art::detail::readMetadata(metaDataTree.get(), psetMap)) {
90 throw cet::exception(
"DetectorClocksServiceStandard",
91 "Could not read ParameterSetMap from metadata tree!");
94 for (
auto const& psEntry : psetMap) {
95 fhicl::ParameterSet ps;
96 ps = fhicl::ParameterSet::make(psEntry.second.pset_);
99 count_configuration_changes(ps);
104 sqlite3_stmt* stmt{
nullptr};
105 sqlite3_prepare_v2(
sqliteDB,
"SELECT PSetBlob from ParameterSets;", -1, &stmt,
nullptr);
106 while (sqlite3_step(stmt) == SQLITE_ROW) {
107 fhicl::ParameterSet ps;
108 ps = fhicl::ParameterSet::make(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0)));
111 count_configuration_changes(ps);
113 sqlite3_finalize(stmt);
117 if (not config_set[i])
continue;
118 if (cfgValue[i] == config_value[i])
continue;
120 cout <<
"Overriding configuration parameter " << cfgName[i] <<
" ... " << cfgValue[i]
121 <<
" (fcl) => " << config_value[i] <<
" (data file)" << endl;
129 (art::Event
const&
e)
const
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
bool IsRightConfig(const fhicl::ParameterSet &ps) const
BEGIN_PROLOG could also be dds filename
std::vector< std::string > const & ConfigNames() const override
void ApplyParams()
Internal function to apply loaded parameters to member attributes.
void preBeginRun(art::Run const &run)
std::vector< double > const & ConfigValues() const override
void postOpenFile(std::string const &filename)
detinfo::DetectorClocksData detectorClocksStandardDataFor(detinfo::DetectorClocksStandard const &detClocks, Event const &event)
Returns DetectorClocksData tuned on the specified event.
void SetConfigValue(size_t i, double val)
DetectorClocksData DataFor(art::Event const &e) const override
Contains all timing reference information for the detector.
DetectorClocksStandard fClocks
Helper to get clocks data from detinfo::DetectorClocksStandard.
BEGIN_PROLOG could also be cout