1 #ifndef SIOVELECTRONICSCALIBPROVIDER_CXX 2 #define SIOVELECTRONICSCALIBPROVIDER_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");
46 float default_st = p.
get<
float>(
"DefaultShapingTime");
47 float default_st_err = p.
get<
float>(
"DefaultShapingTimeErr");
49 ElectronicsCalib defaultCalib(0);
51 defaultCalib.SetGain(default_gain);
52 defaultCalib.SetGainErr(default_gain_err);
53 defaultCalib.SetShapingTime(default_st);
54 defaultCalib.SetShapingTimeErr(default_st_err);
55 defaultCalib.SetExtraInfo(CalibrationExtraInfo(
"ElectronicsCalib"));
61 defaultCalib.SetChannel(ch);
62 fData.AddOrReplaceRow(defaultCalib);
67 cet::search_path sp(
"FW_SEARCH_PATH");
68 std::string abs_fp = sp.find_file(fileName);
69 std::cout <<
"Using electronics calibrations from local file: "<<abs_fp<<
"\n";
70 std::ifstream
file(abs_fp);
73 <<
"File "<<abs_fp<<
" is not found.";
77 ElectronicsCalib dp(0);
78 while (std::getline(file, line)) {
79 size_t current_comma = line.find(
',');
80 DBChannelID_t ch = (DBChannelID_t)std::stoi(line.substr(0, current_comma));
81 float gain = std::stof( line.substr(current_comma+1, line.find(
',',current_comma+1)-(current_comma+1)) );
83 current_comma = line.find(
',',current_comma+1);
84 float gain_err = std::stof( line.substr(current_comma+1, line.find(
',',current_comma+1)-(current_comma+1)) );
86 current_comma = line.find(
',',current_comma+1);
87 float shaping_time = std::stof( line.substr(current_comma+1, line.find(
',',current_comma+1)-(current_comma+1)) );
89 current_comma = line.find(
',',current_comma+1);
90 float shaping_time_err = std::stof( line.substr(current_comma+1) );
92 CalibrationExtraInfo info(
"ElectronicsCalib");
96 dp.SetGainErr(gain_err);
97 dp.SetShapingTime(shaping_time);
98 dp.SetShapingTimeErr(shaping_time_err);
99 dp.SetExtraInfo(info);
101 fData.AddOrReplaceRow(dp);
105 std::cout <<
"Using electronics calibrations from conditions database"<<std::endl;
112 mf::LogInfo(
"SIOVElectronicsCalibProvider") <<
"SIOVElectronicsCalibProvider::UpdateTimeStamp called.";
138 mf::LogInfo(
"SIOVElectronicsCalibProvider") <<
"SIOVElectronicsCalibProvider::DBUpdate called with new timestamp.";
150 std::vector<DBChannelID_t> channels;
151 fFolder->GetChannelList(channels);
152 for (
auto it = channels.begin(); it != channels.end(); ++it) {
154 double gain, gain_err, shaping_time, shaping_time_err;
155 fFolder->GetNamedChannelData(*it,
"gain", gain);
156 fFolder->GetNamedChannelData(*it,
"gain_err", gain_err);
157 fFolder->GetNamedChannelData(*it,
"shaping_time", shaping_time);
158 fFolder->GetNamedChannelData(*it,
"shaping_time_err", shaping_time_err);
161 ElectronicsCalib pg(*it);
162 pg.SetGain( (
float)gain );
163 pg.SetGainErr( (
float)gain_err );
164 pg.SetShapingTime( (
float)shaping_time );
165 pg.SetShapingTimeErr( (
float)shaping_time_err );
166 pg.SetExtraInfo(CalibrationExtraInfo(
"ElectronicsCalib"));
168 fData.AddOrReplaceRow(pg);
178 return fData.GetRow(ch);
float ShapingTimeErr(DBChannelID_t ch) const override
Class def header for a class SIOVElectronicsCalibProvider.
std::unique_ptr< DBFolder > fFolder
virtual void Reconfigure(fhicl::ParameterSet const &p)
Configure using fhicl::ParameterSet.
Base forward iterator browsing all wire IDs in the detector.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
DBTimeStamp_t fCurrentTimeStamp
Retrieves information: electronics calibrations, specifically gain and shaping time.
CalibrationExtraInfo const & ExtraInfo(DBChannelID_t ch) const override
DataSource::ds fDataSource
float GainErr(DBChannelID_t ch) const override
const ElectronicsCalib & ElectronicsCalibObject(DBChannelID_t ch) const
Retrieve electronics calibration information.
bool UpdateFolder(DBTimeStamp_t ts)
Return true if fFolder is successfully updated.
T get(std::string const &key) const
float ShapingTime(DBChannelID_t ch) const override
DBTimeStamp_t fEventTimeStamp
wire_id_iterator end_wire_id() const
Returns an iterator pointing after the last wire ID in the detector.
const IOVTimeStamp & End() const
void UpdateTimeStamp(DBTimeStamp_t ts)
Update event time stamp.
Filters for channels, events, etc.
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
float Gain(DBChannelID_t ch) const override
bool Update(DBTimeStamp_t ts)
Update Snapshot and inherited DBFolder if using database. Return true if updated. ...
SIOVElectronicsCalibProvider(fhicl::ParameterSet const &p)
Constructors.
const IOVTimeStamp & Begin() const
Get Timestamp information.
void Reconfigure(fhicl::ParameterSet const &p) override
Reconfigure function called by fhicl constructor.
wire_id_iterator begin_wire_id() const
Returns an iterator pointing to the first wire ID in the detector.
Snapshot< ElectronicsCalib > fData
Namespace collecting geometry-related classes utilities.
Collection of exception classes for WebDBI.
bool DBUpdate() const
Do actual database updates.
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception