LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lariov::SIOVElectronicsCalibProvider Class Reference

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

#include "SIOVElectronicsCalibProvider.h"

Inheritance diagram for lariov::SIOVElectronicsCalibProvider:
lariov::DatabaseRetrievalAlg

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
 
bool UpdateFolder (DBTimeStamp_t ts)
 Return true if fFolder is successfully updated. More...
 
const std::string & URL () const
 Get connection information. More...
 
const std::string & FolderName () const
 
const std::string & Tag () const
 
const IOVTimeStampBegin () const
 Get Timestamp information. More...
 
const IOVTimeStampEnd () const
 

Protected Attributes

std::unique_ptr< DBFolderfFolder
 

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
 

Detailed Description

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

Configuration parameters

  • DatabaseRetrievalAlg (parameter set, mandatory): configuration for the database; see lariov::DatabaseRetrievalAlg
  • UseDB (boolean, default: false): retrieve information from the database
  • UseFile (boolean, default: false): retrieve information from a file; not implemented yet
  • DefaultGain (real, default: ): Gain returned when /UseDB/ and /UseFile/ parameters are false
  • DefaultGainErr (real, default: ): Gain uncertainty returned when /UseDB/ and /UseFile/ parameters are false
  • DefaultShapingTime (real, default: ): Shaping Time returned when /UseDB/ and /UseFile/ parameters are false
  • DefaultShapingTimeErr (real, default: ): Shaping Time uncertainty returned when /UseDB/ and /UseFile/ parameters are false

Definition at line 42 of file SIOVElectronicsCalibProvider.h.

Constructor & Destructor Documentation

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

Constructors.

Definition at line 14 of file SIOVElectronicsCalibProvider.cxx.

References Reconfigure().

15  : DatabaseRetrievalAlg(p.get<fhicl::ParameterSet>("DatabaseRetrievalAlg"))
16  , fEventTimeStamp(0)
18  {
19 
20  this->Reconfigure(p);
21  }
DatabaseRetrievalAlg(const std::string &foldername, const std::string &url, const std::string &url2="", const std::string &tag="", bool usesqlite=false, bool testmode=false)
Constructors.
void Reconfigure(fhicl::ParameterSet const &p) override
Reconfigure function called by fhicl constructor.

Member Function Documentation

const IOVTimeStamp& lariov::DatabaseRetrievalAlg::Begin ( ) const
inlineinherited

Get Timestamp information.

Definition at line 63 of file DatabaseRetrievalAlg.h.

Referenced by lariov::SIOVPmtGainProvider::DBUpdate(), DBUpdate(), lariov::DetPedestalRetrievalAlg::DBUpdate(), and lariov::SIOVChannelStatusProvider::DBUpdate().

63 { return fFolder->CachedStart(); }
std::unique_ptr< DBFolder > fFolder
bool lariov::SIOVElectronicsCalibProvider::DBUpdate ( ) const
private

Do actual database updates.

Definition at line 132 of file SIOVElectronicsCalibProvider.cxx.

References fEventTimeStamp.

Referenced by ElectronicsCalibObject(), and Update().

133  {
134  return DBUpdate(fEventTimeStamp);
135  }
bool DBUpdate() const
Do actual database updates.
bool lariov::SIOVElectronicsCalibProvider::DBUpdate ( DBTimeStamp_t  ts) const
private

Definition at line 140 of file SIOVElectronicsCalibProvider.cxx.

References lariov::DatabaseRetrievalAlg::Begin(), lariov::DataSource::Database, lariov::DatabaseRetrievalAlg::End(), fCurrentTimeStamp, fData, fDataSource, lariov::DatabaseRetrievalAlg::fFolder, lariov::ElectronicsCalib::SetExtraInfo(), lariov::ElectronicsCalib::SetGain(), lariov::ElectronicsCalib::SetGainErr(), lariov::ElectronicsCalib::SetShapingTime(), lariov::ElectronicsCalib::SetShapingTimeErr(), and lariov::DatabaseRetrievalAlg::UpdateFolder().

141  {
142 
143  bool result = false;
145 
146  mf::LogInfo("SIOVElectronicsCalibProvider")
147  << "SIOVElectronicsCalibProvider::DBUpdate called with new timestamp.";
148 
149  fCurrentTimeStamp = ts;
150 
151  // Call non-const base class method.
152 
153  result = const_cast<SIOVElectronicsCalibProvider*>(this)->UpdateFolder(ts);
154  if (result) {
155  //DBFolder was updated, so now update the Snapshot
156  fData.Clear();
157  fData.SetIoV(this->Begin(), this->End());
158 
159  std::vector<DBChannelID_t> channels;
160  fFolder->GetChannelList(channels);
161  for (auto it = channels.begin(); it != channels.end(); ++it) {
162 
163  double gain, gain_err, shaping_time, shaping_time_err;
164  fFolder->GetNamedChannelData(*it, "gain", gain);
165  fFolder->GetNamedChannelData(*it, "gain_err", gain_err);
166  fFolder->GetNamedChannelData(*it, "shaping_time", shaping_time);
167  fFolder->GetNamedChannelData(*it, "shaping_time_err", shaping_time_err);
168 
169  ElectronicsCalib pg(*it);
170  pg.SetGain((float)gain);
171  pg.SetGainErr((float)gain_err);
172  pg.SetShapingTime((float)shaping_time);
173  pg.SetShapingTimeErr((float)shaping_time_err);
174  pg.SetExtraInfo(CalibrationExtraInfo("ElectronicsCalib"));
175 
176  fData.AddOrReplaceRow(pg);
177  }
178  }
179  }
180 
181  return result;
182  }
std::unique_ptr< DBFolder > fFolder
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 184 of file SIOVElectronicsCalibProvider.cxx.

References DBUpdate(), and fData.

Referenced by ExtraInfo(), Gain(), GainErr(), ShapingTime(), and ShapingTimeErr().

186  {
187  DBUpdate();
188  return fData.GetRow(ch);
189  }
bool DBUpdate() const
Do actual database updates.
const IOVTimeStamp& lariov::DatabaseRetrievalAlg::End ( ) const
inlineinherited
CalibrationExtraInfo const & lariov::SIOVElectronicsCalibProvider::ExtraInfo ( DBChannelID_t  ch) const
override

Definition at line 211 of file SIOVElectronicsCalibProvider.cxx.

References ElectronicsCalibObject(), and lariov::ElectronicsCalib::ExtraInfo().

212  {
213  return this->ElectronicsCalibObject(ch).ExtraInfo();
214  }
const ElectronicsCalib & ElectronicsCalibObject(DBChannelID_t ch) const
Retrieve electronics calibration information.
CalibrationExtraInfo const & ExtraInfo() const
const std::string& lariov::DatabaseRetrievalAlg::FolderName ( ) const
inlineinherited

Definition at line 59 of file DatabaseRetrievalAlg.h.

59 { return fFolder->FolderName(); }
std::unique_ptr< DBFolder > fFolder
float lariov::SIOVElectronicsCalibProvider::Gain ( DBChannelID_t  ch) const
override

Definition at line 191 of file SIOVElectronicsCalibProvider.cxx.

References ElectronicsCalibObject(), and lariov::ElectronicsCalib::Gain().

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

Definition at line 196 of file SIOVElectronicsCalibProvider.cxx.

References ElectronicsCalibObject(), and lariov::ElectronicsCalib::GainErr().

197  {
198  return this->ElectronicsCalibObject(ch).GainErr();
199  }
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 23 of file SIOVElectronicsCalibProvider.cxx.

References lariov::DataSource::Database, lariov::DataSource::Default, fData, fDataSource, file, lariov::DataSource::File, fhicl::ParameterSet::get(), geo::GeometryCore::Iterate(), lariov::IOVTimeStamp::MaxTimeStamp(), geo::GeometryCore::PlaneWireToChannel(), lariov::DatabaseRetrievalAlg::Reconfigure(), lariov::ChData::SetChannel(), lariov::ElectronicsCalib::SetExtraInfo(), lariov::ElectronicsCalib::SetGain(), lariov::ElectronicsCalib::SetGainErr(), lariov::ElectronicsCalib::SetShapingTime(), lariov::ElectronicsCalib::SetShapingTimeErr(), lariov::IOVTimeStamp::SetStamp(), lariov::IOVTimeStamp::Stamp(), lariov::IOVTimeStamp::SubStamp(), and tmp.

Referenced by SIOVElectronicsCalibProvider().

24  {
25 
26  this->DatabaseRetrievalAlg::Reconfigure(p.get<fhicl::ParameterSet>("DatabaseRetrievalAlg"));
27  fData.Clear();
28  IOVTimeStamp tmp = IOVTimeStamp::MaxTimeStamp();
29  tmp.SetStamp(tmp.Stamp() - 1, tmp.SubStamp());
30  fData.SetIoV(tmp, IOVTimeStamp::MaxTimeStamp());
31 
32  bool UseDB = p.get<bool>("UseDB", false);
33  bool UseFile = p.get<bool>("UseFile", false);
34  std::string fileName = p.get<std::string>("FileName", "");
35 
36  //priority: (1) use db, (2) use table, (3) use defaults
37  //If none are specified, use defaults
38  if (UseDB)
40  else if (UseFile)
42  else
44 
46  float default_gain = p.get<float>("DefaultGain");
47  float default_gain_err = p.get<float>("DefaultGainErr");
48  float default_st = p.get<float>("DefaultShapingTime");
49  float default_st_err = p.get<float>("DefaultShapingTimeErr");
50 
51  ElectronicsCalib defaultCalib(0);
52 
53  defaultCalib.SetGain(default_gain);
54  defaultCalib.SetGainErr(default_gain_err);
55  defaultCalib.SetShapingTime(default_st);
56  defaultCalib.SetShapingTimeErr(default_st_err);
57  defaultCalib.SetExtraInfo(CalibrationExtraInfo("ElectronicsCalib"));
58 
60  for (auto const& wid : geo->Iterate<geo::WireID>()) {
61  DBChannelID_t ch = geo->PlaneWireToChannel(wid);
62  defaultCalib.SetChannel(ch);
63  fData.AddOrReplaceRow(defaultCalib);
64  }
65  }
66  else if (fDataSource == DataSource::File) {
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);
71  if (!file) {
72  throw cet::exception("SIOVElectronicsCalibProvider")
73  << "File " << abs_fp << " is not found.";
74  }
75 
76  std::string line;
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(
82  line.substr(current_comma + 1, line.find(',', current_comma + 1) - (current_comma + 1)));
83 
84  current_comma = line.find(',', current_comma + 1);
85  float gain_err = std::stof(
86  line.substr(current_comma + 1, line.find(',', current_comma + 1) - (current_comma + 1)));
87 
88  current_comma = line.find(',', current_comma + 1);
89  float shaping_time = std::stof(
90  line.substr(current_comma + 1, line.find(',', current_comma + 1) - (current_comma + 1)));
91 
92  current_comma = line.find(',', current_comma + 1);
93  float shaping_time_err = std::stof(line.substr(current_comma + 1));
94 
95  CalibrationExtraInfo info("ElectronicsCalib");
96 
97  dp.SetChannel(ch);
98  dp.SetGain(gain);
99  dp.SetGainErr(gain_err);
100  dp.SetShapingTime(shaping_time);
101  dp.SetShapingTimeErr(shaping_time_err);
102  dp.SetExtraInfo(info);
103 
104  fData.AddOrReplaceRow(dp);
105  }
106  }
107  else {
108  std::cout << "Using electronics calibrations from conditions database" << std::endl;
109  }
110  }
details::range_type< T > Iterate() const
Initializes the specified ID with the ID of the first cryostat.
Definition: GeometryCore.h:541
virtual void Reconfigure(fhicl::ParameterSet const &p)
Configure using fhicl::ParameterSet.
Float_t tmp
Definition: plot.C:35
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
TFile * file
static IOVTimeStamp MaxTimeStamp()
Namespace collecting geometry-related classes utilities.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
float lariov::SIOVElectronicsCalibProvider::ShapingTime ( DBChannelID_t  ch) const
override

Definition at line 201 of file SIOVElectronicsCalibProvider.cxx.

References ElectronicsCalibObject(), and lariov::ElectronicsCalib::ShapingTime().

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

Definition at line 206 of file SIOVElectronicsCalibProvider.cxx.

References ElectronicsCalibObject(), and lariov::ElectronicsCalib::ShapingTimeErr().

207  {
208  return this->ElectronicsCalibObject(ch).ShapingTimeErr();
209  }
const ElectronicsCalib & ElectronicsCalibObject(DBChannelID_t ch) const
Retrieve electronics calibration information.
float ShapingTimeErr() const
const std::string& lariov::DatabaseRetrievalAlg::Tag ( ) const
inlineinherited

Definition at line 60 of file DatabaseRetrievalAlg.h.

60 { return fFolder->Tag(); }
std::unique_ptr< DBFolder > fFolder
bool lariov::SIOVElectronicsCalibProvider::Update ( DBTimeStamp_t  ts)

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

Definition at line 123 of file SIOVElectronicsCalibProvider.cxx.

References DBUpdate(), and fEventTimeStamp.

124  {
125 
126  fEventTimeStamp = ts;
127  return DBUpdate(ts);
128  }
bool DBUpdate() const
Do actual database updates.
bool lariov::DatabaseRetrievalAlg::UpdateFolder ( DBTimeStamp_t  ts)
inlineinherited

Return true if fFolder is successfully updated.

Definition at line 55 of file DatabaseRetrievalAlg.h.

Referenced by lariov::SIOVPmtGainProvider::DBUpdate(), DBUpdate(), lariov::DetPedestalRetrievalAlg::DBUpdate(), and lariov::SIOVChannelStatusProvider::DBUpdate().

55 { return fFolder->UpdateData(ts); }
std::unique_ptr< DBFolder > fFolder
void lariov::SIOVElectronicsCalibProvider::UpdateTimeStamp ( DBTimeStamp_t  ts)

Update event time stamp.

Definition at line 114 of file SIOVElectronicsCalibProvider.cxx.

References fEventTimeStamp.

Referenced by lariov::SIOVElectronicsCalibService::PreProcessEvent().

115  {
116  mf::LogInfo("SIOVElectronicsCalibProvider")
117  << "SIOVElectronicsCalibProvider::UpdateTimeStamp called.";
118  fEventTimeStamp = ts;
119  }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
const std::string& lariov::DatabaseRetrievalAlg::URL ( ) const
inlineinherited

Get connection information.

Definition at line 58 of file DatabaseRetrievalAlg.h.

58 { return fFolder->URL(); }
std::unique_ptr< DBFolder > fFolder

Member Data Documentation

DBTimeStamp_t lariov::SIOVElectronicsCalibProvider::fCurrentTimeStamp
mutableprivate

Definition at line 75 of file SIOVElectronicsCalibProvider.h.

Referenced by DBUpdate().

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

Definition at line 79 of file SIOVElectronicsCalibProvider.h.

Referenced by DBUpdate(), ElectronicsCalibObject(), and Reconfigure().

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

Definition at line 77 of file SIOVElectronicsCalibProvider.h.

Referenced by DBUpdate(), and Reconfigure().

DBTimeStamp_t lariov::SIOVElectronicsCalibProvider::fEventTimeStamp
private

Definition at line 74 of file SIOVElectronicsCalibProvider.h.

Referenced by DBUpdate(), Update(), and UpdateTimeStamp().


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