1 #ifndef SIOVPMTGAINPROVIDER_CXX 2 #define SIOVPMTGAINPROVIDER_CXX 8 #include "cetlib_except/exception.h" 20 fCurrentTimeStamp(0) {
29 IOVTimeStamp
tmp = IOVTimeStamp::MaxTimeStamp();
30 tmp.SetStamp(tmp.Stamp()-1, tmp.SubStamp());
31 fData.SetIoV(tmp, IOVTimeStamp::MaxTimeStamp());
33 bool UseDB = p.
get<
bool>(
"UseDB",
false);
34 bool UseFile = p.
get<
bool>(
"UseFile",
false);
35 std::string fileName = p.
get<std::string>(
"FileName",
"");
44 float default_gain = p.
get<
float>(
"DefaultGain");
45 float default_gain_err = p.
get<
float>(
"DefaultGainErr");
47 PmtGain defaultGain(0);
49 defaultGain.SetGain(default_gain);
50 defaultGain.SetGainErr(default_gain_err);
51 defaultGain.SetExtraInfo(CalibrationExtraInfo(
"PmtGain"));
54 for (
unsigned int od=0; od!=geo->
NOpDets(); ++od) {
56 defaultGain.SetChannel(od);
57 fData.AddOrReplaceRow(defaultGain);
63 cet::search_path sp(
"FW_SEARCH_PATH");
64 std::string abs_fp = sp.find_file(fileName);
65 std::cout <<
"Using pmt gains from local file: "<<abs_fp<<
"\n";
66 std::ifstream
file(abs_fp);
69 <<
"File "<<abs_fp<<
" is not found.";
74 while (std::getline(file, line)) {
75 if (line[0] ==
'#')
continue;
76 size_t current_comma = line.find(
',');
77 DBChannelID_t ch = (DBChannelID_t)std::stoi(line.substr(0, current_comma));
78 float gain = std::stof( line.substr(current_comma+1, line.find(
',',current_comma+1)-(current_comma+1)) );
80 current_comma = line.find(
',',current_comma+1);
81 float gain_err = std::stof( line.substr(current_comma+1) );
83 CalibrationExtraInfo info(
"PmtGain");
87 dp.SetGainErr(gain_err);
88 dp.SetExtraInfo(info);
90 fData.AddOrReplaceRow(dp);
94 std::cout <<
"Using pmt gains from conditions database"<<std::endl;
101 mf::LogInfo(
"SIOVPmtGainProvider") <<
"SIOVPmtGainProvider::UpdateTimeStamp called.";
127 mf::LogInfo(
"SIOVPmtGainProvider") <<
"SIOVPmtGainProvider::DBUpdate called with new timestamp.";
139 std::vector<DBChannelID_t> channels;
140 fFolder->GetChannelList(channels);
141 for (
auto it = channels.begin(); it != channels.end(); ++it) {
143 double gain, gain_err;
144 fFolder->GetNamedChannelData(*it,
"gain", gain);
145 fFolder->GetNamedChannelData(*it,
"gain_sigma", gain_err);
148 pg.SetGain( (
float)gain );
149 pg.SetGainErr( (
float)gain_err );
150 pg.SetExtraInfo(CalibrationExtraInfo(
"PmtGain"));
152 fData.AddOrReplaceRow(pg);
162 return fData.GetRow(ch);
std::unique_ptr< DBFolder > fFolder
bool DBUpdate() const
Do actual database updates.
const PmtGain & PmtGainObject(DBChannelID_t ch) const
Retrieve gain information.
bool Update(DBTimeStamp_t ts)
Update Snapshot and inherited DBFolder if using database. Return true if updated. ...
virtual void Reconfigure(fhicl::ParameterSet const &p)
Configure using fhicl::ParameterSet.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Snapshot< PmtGain > fData
SIOVPmtGainProvider(fhicl::ParameterSet const &p)
Constructors.
CalibrationExtraInfo const & ExtraInfo(DBChannelID_t ch) const override
bool UpdateFolder(DBTimeStamp_t ts)
Return true if fFolder is successfully updated.
T get(std::string const &key) const
Retrieves information: pmt gain.
DataSource::ds fDataSource
const IOVTimeStamp & End() const
DBTimeStamp_t fCurrentTimeStamp
unsigned int NOpDets() const
Number of OpDets in the whole detector.
void UpdateTimeStamp(DBTimeStamp_t ts)
Update event time stamp.
Filters for channels, events, etc.
DBTimeStamp_t fEventTimeStamp
Class def header for a class SIOVPmtGainProvider.
const IOVTimeStamp & Begin() const
Get Timestamp information.
void Reconfigure(fhicl::ParameterSet const &p) override
Reconfigure function called by fhicl constructor.
float Gain(DBChannelID_t ch) const override
Namespace collecting geometry-related classes utilities.
Collection of exception classes for WebDBI.
float GainErr(DBChannelID_t ch) const override
bool IsValidOpChannel(int opChannel) const
Is this a valid OpChannel number?
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception