Public Member Functions | Private Member Functions | Private Attributes | List of all members
lariov::SIOVElectronicsCalibProvider Class Reference

Retrieves information: electronics calibrations, specifically gain and shaping time. More...

#include <SIOVElectronicsCalibProvider.h>

Inheritance diagram for lariov::SIOVElectronicsCalibProvider:
lariov::DatabaseRetrievalAlg lariov::ElectronicsCalibProvider lar::UncopiableAndUnmovableClass

Public Member Functions

 SIOVElectronicsCalibProvider (fhicl::ParameterSet const &p)
 Constructors. More...
 
void Reconfigure (fhicl::ParameterSet const &p) override
 Reconfigure function called by fhicl constructor. More...
 
void UpdateTimeStamp (DBTimeStamp_t ts)
 Update event time stamp. More...
 
bool Update (DBTimeStamp_t ts)
 Update Snapshot and inherited DBFolder if using database. Return true if updated. More...
 
const ElectronicsCalibElectronicsCalibObject (DBChannelID_t ch) const
 Retrieve electronics calibration information. More...
 
float Gain (DBChannelID_t ch) const override
 
float GainErr (DBChannelID_t ch) const override
 
float ShapingTime (DBChannelID_t ch) const override
 
float ShapingTimeErr (DBChannelID_t ch) const override
 
CalibrationExtraInfo const & ExtraInfo (DBChannelID_t ch) const override
 
- Public Member Functions inherited from lariov::DatabaseRetrievalAlg
 DatabaseRetrievalAlg (const std::string &foldername, const std::string &url, const std::string &url2="", const std::string &tag="", bool usesqlite=false, bool testmode=false)
 Constructors. More...
 
 DatabaseRetrievalAlg (fhicl::ParameterSet const &p)
 
virtual ~DatabaseRetrievalAlg ()
 Default destructor. More...
 
bool UpdateFolder (DBTimeStamp_t ts)
 Return true if fFolder is successfully updated. More...
 
const std::stringURL () const
 Get connection information. More...
 
const std::stringFolderName () const
 
const std::stringTag () const
 
const IOVTimeStampBegin () const
 Get Timestamp information. More...
 
const IOVTimeStampEnd () const
 
- Public Member Functions inherited from lariov::ElectronicsCalibProvider
virtual ~ElectronicsCalibProvider ()=default
 
virtual float Gain (raw::ChannelID_t ch) const =0
 Retrieve pmt gain information. More...
 
virtual float GainErr (raw::ChannelID_t ch) const =0
 
virtual float ShapingTime (raw::ChannelID_t ch) const =0
 
virtual float ShapingTimeErr (raw::ChannelID_t ch) const =0
 
virtual CalibrationExtraInfo const & ExtraInfo (raw::ChannelID_t ch) const =0
 

Private Member Functions

bool DBUpdate () const
 Do actual database updates. More...
 
bool DBUpdate (DBTimeStamp_t ts) const
 

Private Attributes

DBTimeStamp_t fEventTimeStamp
 
DBTimeStamp_t fCurrentTimeStamp
 
DataSource::ds fDataSource
 
Snapshot< ElectronicsCalibfData
 

Additional Inherited Members

- Protected Attributes inherited from lariov::DatabaseRetrievalAlg
std::unique_ptr< DBFolderfFolder
 

Detailed Description

Retrieves information: electronics calibrations, specifically gain and shaping time.

Configuration parameters

Definition at line 42 of file SIOVElectronicsCalibProvider.h.

Constructor & Destructor Documentation

lariov::SIOVElectronicsCalibProvider::SIOVElectronicsCalibProvider ( fhicl::ParameterSet const &  p)

Constructors.

Definition at line 13 of file SIOVElectronicsCalibProvider.cxx.

13  :
14  DatabaseRetrievalAlg(p.get<fhicl::ParameterSet>("DatabaseRetrievalAlg")),
15  fEventTimeStamp(0),
17 
18  this->Reconfigure(p);
19  }
DatabaseRetrievalAlg(const std::string &foldername, const std::string &url, const std::string &url2="", const std::string &tag="", bool usesqlite=false, bool testmode=false)
Constructors.
p
Definition: test.py:223
void Reconfigure(fhicl::ParameterSet const &p) override
Reconfigure function called by fhicl constructor.

Member Function Documentation

bool lariov::SIOVElectronicsCalibProvider::DBUpdate ( ) const
private

Do actual database updates.

Definition at line 122 of file SIOVElectronicsCalibProvider.cxx.

122  {
123  return DBUpdate(fEventTimeStamp);
124  }
bool DBUpdate() const
Do actual database updates.
bool lariov::SIOVElectronicsCalibProvider::DBUpdate ( DBTimeStamp_t  ts) const
private

Definition at line 129 of file SIOVElectronicsCalibProvider.cxx.

129  {
130 
131  bool result = false;
133 
134  mf::LogInfo("SIOVElectronicsCalibProvider") << "SIOVElectronicsCalibProvider::DBUpdate called with new timestamp.";
135 
136  fCurrentTimeStamp = ts;
137 
138  // Call non-const base class method.
139 
140  result = const_cast<SIOVElectronicsCalibProvider*>(this)->UpdateFolder(ts);
141  if(result) {
142  //DBFolder was updated, so now update the Snapshot
143  fData.Clear();
144  fData.SetIoV(this->Begin(), this->End());
145 
146  std::vector<DBChannelID_t> channels;
147  fFolder->GetChannelList(channels);
148  for (auto it = channels.begin(); it != channels.end(); ++it) {
149 
150  double gain, gain_err, shaping_time, shaping_time_err;
151  fFolder->GetNamedChannelData(*it, "gain", gain);
152  fFolder->GetNamedChannelData(*it, "gain_err", gain_err);
153  fFolder->GetNamedChannelData(*it, "shaping_time", shaping_time);
154  fFolder->GetNamedChannelData(*it, "shaping_time_err", shaping_time_err);
155 
156 
157  ElectronicsCalib pg(*it);
158  pg.SetGain( (float)gain );
159  pg.SetGainErr( (float)gain_err );
160  pg.SetShapingTime( (float)shaping_time );
161  pg.SetShapingTimeErr( (float)shaping_time_err );
162  pg.SetExtraInfo(CalibrationExtraInfo("ElectronicsCalib"));
163 
164  fData.AddOrReplaceRow(pg);
165  }
166  }
167  }
168 
169  return result;
170  }
std::unique_ptr< DBFolder > fFolder
static QCString result
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
bool UpdateFolder(DBTimeStamp_t ts)
Return true if fFolder is successfully updated.
const IOVTimeStamp & End() const
SIOVElectronicsCalibProvider(fhicl::ParameterSet const &p)
Constructors.
const IOVTimeStamp & Begin() const
Get Timestamp information.
const ElectronicsCalib & lariov::SIOVElectronicsCalibProvider::ElectronicsCalibObject ( DBChannelID_t  ch) const

Retrieve electronics calibration information.

Definition at line 172 of file SIOVElectronicsCalibProvider.cxx.

172  {
173  DBUpdate();
174  return fData.GetRow(ch);
175  }
bool DBUpdate() const
Do actual database updates.
CalibrationExtraInfo const & lariov::SIOVElectronicsCalibProvider::ExtraInfo ( DBChannelID_t  ch) const
override

Definition at line 193 of file SIOVElectronicsCalibProvider.cxx.

193  {
194  return this->ElectronicsCalibObject(ch).ExtraInfo();
195  }
const ElectronicsCalib & ElectronicsCalibObject(DBChannelID_t ch) const
Retrieve electronics calibration information.
CalibrationExtraInfo const & ExtraInfo() const
float lariov::SIOVElectronicsCalibProvider::Gain ( DBChannelID_t  ch) const
override

Definition at line 177 of file SIOVElectronicsCalibProvider.cxx.

177  {
178  return this->ElectronicsCalibObject(ch).Gain();
179  }
const ElectronicsCalib & ElectronicsCalibObject(DBChannelID_t ch) const
Retrieve electronics calibration information.
float lariov::SIOVElectronicsCalibProvider::GainErr ( DBChannelID_t  ch) const
override

Definition at line 181 of file SIOVElectronicsCalibProvider.cxx.

181  {
182  return this->ElectronicsCalibObject(ch).GainErr();
183  }
const ElectronicsCalib & ElectronicsCalibObject(DBChannelID_t ch) const
Retrieve electronics calibration information.
void lariov::SIOVElectronicsCalibProvider::Reconfigure ( fhicl::ParameterSet const &  p)
overridevirtual

Reconfigure function called by fhicl constructor.

Reimplemented from lariov::DatabaseRetrievalAlg.

Definition at line 21 of file SIOVElectronicsCalibProvider.cxx.

21  {
22 
23  this->DatabaseRetrievalAlg::Reconfigure(p.get<fhicl::ParameterSet>("DatabaseRetrievalAlg"));
24  fData.Clear();
25  IOVTimeStamp tmp = IOVTimeStamp::MaxTimeStamp();
26  tmp.SetStamp(tmp.Stamp()-1, tmp.SubStamp());
27  fData.SetIoV(tmp, IOVTimeStamp::MaxTimeStamp());
28 
29  bool UseDB = p.get<bool>("UseDB", false);
30  bool UseFile = p.get<bool>("UseFile", false);
31  std::string fileName = p.get<std::string>("FileName", "");
32 
33  //priority: (1) use db, (2) use table, (3) use defaults
34  //If none are specified, use defaults
35  if ( UseDB ) fDataSource = DataSource::Database;
36  else if (UseFile) fDataSource = DataSource::File;
38 
40  float default_gain = p.get<float>("DefaultGain");
41  float default_gain_err = p.get<float>("DefaultGainErr");
42  float default_st = p.get<float>("DefaultShapingTime");
43  float default_st_err = p.get<float>("DefaultShapingTimeErr");
44 
45  ElectronicsCalib defaultCalib(0);
46 
47  defaultCalib.SetGain(default_gain);
48  defaultCalib.SetGainErr(default_gain_err);
49  defaultCalib.SetShapingTime(default_st);
50  defaultCalib.SetShapingTimeErr(default_st_err);
51  defaultCalib.SetExtraInfo(CalibrationExtraInfo("ElectronicsCalib"));
52 
55  for (; itW != geo->end_wire_id(); ++itW) {
56  DBChannelID_t ch = geo->PlaneWireToChannel(*itW);
57  defaultCalib.SetChannel(ch);
58  fData.AddOrReplaceRow(defaultCalib);
59  }
60 
61  }
62  else if (fDataSource == DataSource::File) {
63  cet::search_path sp("FW_SEARCH_PATH");
64  std::string abs_fp = sp.find_file(fileName);
65  std::cout << "Using electronics calibrations from local file: "<<abs_fp<<"\n";
66  std::ifstream file(abs_fp);
67  if (!file) {
68  throw cet::exception("SIOVElectronicsCalibProvider")
69  << "File "<<abs_fp<<" is not found.";
70  }
71 
73  ElectronicsCalib dp(0);
74  while (std::getline(file, line)) {
75  size_t current_comma = line.find(',');
76  DBChannelID_t ch = (DBChannelID_t)std::stoi(line.substr(0, current_comma));
77  float gain = std::stof( line.substr(current_comma+1, line.find(',',current_comma+1)-(current_comma+1)) );
78 
79  current_comma = line.find(',',current_comma+1);
80  float gain_err = std::stof( line.substr(current_comma+1, line.find(',',current_comma+1)-(current_comma+1)) );
81 
82  current_comma = line.find(',',current_comma+1);
83  float shaping_time = std::stof( line.substr(current_comma+1, line.find(',',current_comma+1)-(current_comma+1)) );
84 
85  current_comma = line.find(',',current_comma+1);
86  float shaping_time_err = std::stof( line.substr(current_comma+1) );
87 
88  CalibrationExtraInfo info("ElectronicsCalib");
89 
90  dp.SetChannel(ch);
91  dp.SetGain(gain);
92  dp.SetGainErr(gain_err);
93  dp.SetShapingTime(shaping_time);
94  dp.SetShapingTimeErr(shaping_time_err);
95  dp.SetExtraInfo(info);
96 
97  fData.AddOrReplaceRow(dp);
98  }
99  }
100  else {
101  std::cout << "Using electronics calibrations from conditions database"<<std::endl;
102  }
103  }
virtual void Reconfigure(fhicl::ParameterSet const &p)
Configure using fhicl::ParameterSet.
Base forward iterator browsing all wire IDs in the detector.
Definition: GeometryCore.h:587
std::string string
Definition: nybbler.cc:12
std::uint32_t DBChannelID_t
fileName
Definition: dumpTree.py:9
p
Definition: test.py:223
string tmp
Definition: languages.py:63
wire_id_iterator end_wire_id() const
Returns an iterator pointing after the last wire ID in the detector.
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
void line(double t, double *p, double &x, double &y, double &z)
wire_id_iterator begin_wire_id() const
Returns an iterator pointing to the first wire ID in the detector.
static IOVTimeStamp MaxTimeStamp()
LArSoft geometry interface.
Definition: ChannelGeo.h:16
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
float lariov::SIOVElectronicsCalibProvider::ShapingTime ( DBChannelID_t  ch) const
override

Definition at line 185 of file SIOVElectronicsCalibProvider.cxx.

185  {
186  return this->ElectronicsCalibObject(ch).ShapingTime();
187  }
const ElectronicsCalib & ElectronicsCalibObject(DBChannelID_t ch) const
Retrieve electronics calibration information.
float lariov::SIOVElectronicsCalibProvider::ShapingTimeErr ( DBChannelID_t  ch) const
override

Definition at line 189 of file SIOVElectronicsCalibProvider.cxx.

189  {
190  return this->ElectronicsCalibObject(ch).ShapingTimeErr();
191  }
const ElectronicsCalib & ElectronicsCalibObject(DBChannelID_t ch) const
Retrieve electronics calibration information.
float ShapingTimeErr() const
bool lariov::SIOVElectronicsCalibProvider::Update ( DBTimeStamp_t  ts)

Update Snapshot and inherited DBFolder if using database. Return true if updated.

Definition at line 114 of file SIOVElectronicsCalibProvider.cxx.

114  {
115 
116  fEventTimeStamp = ts;
117  return DBUpdate(ts);
118  }
bool DBUpdate() const
Do actual database updates.
void lariov::SIOVElectronicsCalibProvider::UpdateTimeStamp ( DBTimeStamp_t  ts)

Update event time stamp.

Definition at line 107 of file SIOVElectronicsCalibProvider.cxx.

107  {
108  mf::LogInfo("SIOVElectronicsCalibProvider") << "SIOVElectronicsCalibProvider::UpdateTimeStamp called.";
109  fEventTimeStamp = ts;
110  }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo

Member Data Documentation

DBTimeStamp_t lariov::SIOVElectronicsCalibProvider::fCurrentTimeStamp
mutableprivate

Definition at line 76 of file SIOVElectronicsCalibProvider.h.

Snapshot<ElectronicsCalib> lariov::SIOVElectronicsCalibProvider::fData
mutableprivate

Definition at line 80 of file SIOVElectronicsCalibProvider.h.

DataSource::ds lariov::SIOVElectronicsCalibProvider::fDataSource
private

Definition at line 78 of file SIOVElectronicsCalibProvider.h.

DBTimeStamp_t lariov::SIOVElectronicsCalibProvider::fEventTimeStamp
private

Definition at line 75 of file SIOVElectronicsCalibProvider.h.


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