LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 ElectronicsCalib & ElectronicsCalibObject (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 IOVTimeStamp & Begin () const
 Get Timestamp information. More...
 
const IOVTimeStamp & End () 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< ElectronicsCalib > fData
 

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 17 of file SIOVElectronicsCalibProvider.cxx.

References Reconfigure().

17  :
18  DatabaseRetrievalAlg(p.get<fhicl::ParameterSet>("DatabaseRetrievalAlg")),
19  fEventTimeStamp(0),
21 
22  this->Reconfigure(p);
23  }
void Reconfigure(fhicl::ParameterSet const &p) override
Reconfigure function called by fhicl constructor.
DatabaseRetrievalAlg(const std::string &foldername, const std::string &url, const std::string &tag="")
Constructors.

Member Function Documentation

const IOVTimeStamp& lariov::DatabaseRetrievalAlg::Begin ( ) const
inlineinherited
bool lariov::SIOVElectronicsCalibProvider::DBUpdate ( ) const
private

Do actual database updates.

Definition at line 126 of file SIOVElectronicsCalibProvider.cxx.

References fEventTimeStamp.

Referenced by ElectronicsCalibObject(), and Update().

126  {
127  return DBUpdate(fEventTimeStamp);
128  }
bool DBUpdate() const
Do actual database updates.
bool lariov::SIOVElectronicsCalibProvider::DBUpdate ( DBTimeStamp_t  ts) const
private

Definition at line 133 of file SIOVElectronicsCalibProvider.cxx.

References lariov::DatabaseRetrievalAlg::Begin(), lariov::DatabaseRetrievalAlg::End(), fCurrentTimeStamp, fData, fDataSource, lariov::DatabaseRetrievalAlg::fFolder, and lariov::DatabaseRetrievalAlg::UpdateFolder().

133  {
134 
135  bool result = false;
136  if (fDataSource == DataSource::Database && ts != fCurrentTimeStamp) {
137 
138  mf::LogInfo("SIOVElectronicsCalibProvider") << "SIOVElectronicsCalibProvider::DBUpdate called with new timestamp.";
139 
140  fCurrentTimeStamp = ts;
141 
142  // Call non-const base class method.
143 
144  result = const_cast<SIOVElectronicsCalibProvider*>(this)->UpdateFolder(ts);
145  if(result) {
146  //DBFolder was updated, so now update the Snapshot
147  fData.Clear();
148  fData.SetIoV(this->Begin(), this->End());
149 
150  std::vector<DBChannelID_t> channels;
151  fFolder->GetChannelList(channels);
152  for (auto it = channels.begin(); it != channels.end(); ++it) {
153 
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);
159 
160 
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"));
167 
168  fData.AddOrReplaceRow(pg);
169  }
170  }
171  }
172 
173  return result;
174  }
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 176 of file SIOVElectronicsCalibProvider.cxx.

References DBUpdate(), and fData.

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

176  {
177  DBUpdate();
178  return fData.GetRow(ch);
179  }
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 197 of file SIOVElectronicsCalibProvider.cxx.

References ElectronicsCalibObject().

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

Definition at line 55 of file DatabaseRetrievalAlg.h.

References lariov::DatabaseRetrievalAlg::fFolder.

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

Definition at line 181 of file SIOVElectronicsCalibProvider.cxx.

References ElectronicsCalibObject().

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

Definition at line 185 of file SIOVElectronicsCalibProvider.cxx.

References ElectronicsCalibObject().

185  {
186  return this->ElectronicsCalibObject(ch).GainErr();
187  }
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 25 of file SIOVElectronicsCalibProvider.cxx.

References geo::GeometryCore::begin_wire_id(), geo::GeometryCore::end_wire_id(), fData, fDataSource, file, fhicl::ParameterSet::get(), geo::GeometryCore::PlaneWireToChannel(), lariov::DatabaseRetrievalAlg::Reconfigure(), and tmp.

Referenced by SIOVElectronicsCalibProvider().

25  {
26 
27  this->DatabaseRetrievalAlg::Reconfigure(p.get<fhicl::ParameterSet>("DatabaseRetrievalAlg"));
28  fData.Clear();
29  IOVTimeStamp tmp = IOVTimeStamp::MaxTimeStamp();
30  tmp.SetStamp(tmp.Stamp()-1, tmp.SubStamp());
31  fData.SetIoV(tmp, IOVTimeStamp::MaxTimeStamp());
32 
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", "");
36 
37  //priority: (1) use db, (2) use table, (3) use defaults
38  //If none are specified, use defaults
39  if ( UseDB ) fDataSource = DataSource::Database;
40  else if (UseFile) fDataSource = DataSource::File;
41  else fDataSource = DataSource::Default;
42 
43  if (fDataSource == DataSource::Default) {
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");
48 
49  ElectronicsCalib defaultCalib(0);
50 
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"));
56 
59  for (; itW != geo->end_wire_id(); ++itW) {
60  DBChannelID_t ch = geo->PlaneWireToChannel(*itW);
61  defaultCalib.SetChannel(ch);
62  fData.AddOrReplaceRow(defaultCalib);
63  }
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( line.substr(current_comma+1, line.find(',',current_comma+1)-(current_comma+1)) );
82 
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)) );
85 
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)) );
88 
89  current_comma = line.find(',',current_comma+1);
90  float shaping_time_err = std::stof( line.substr(current_comma+1) );
91 
92  CalibrationExtraInfo info("ElectronicsCalib");
93 
94  dp.SetChannel(ch);
95  dp.SetGain(gain);
96  dp.SetGainErr(gain_err);
97  dp.SetShapingTime(shaping_time);
98  dp.SetShapingTimeErr(shaping_time_err);
99  dp.SetExtraInfo(info);
100 
101  fData.AddOrReplaceRow(dp);
102  }
103  }
104  else {
105  std::cout << "Using electronics calibrations from conditions database"<<std::endl;
106  }
107  }
virtual void Reconfigure(fhicl::ParameterSet const &p)
Configure using fhicl::ParameterSet.
Base forward iterator browsing all wire IDs in the detector.
Definition: GeometryCore.h:567
Float_t tmp
Definition: plot.C:37
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.
TFile * file
wire_id_iterator begin_wire_id() const
Returns an iterator pointing to the first wire ID in the detector.
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 189 of file SIOVElectronicsCalibProvider.cxx.

References ElectronicsCalibObject().

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

Definition at line 193 of file SIOVElectronicsCalibProvider.cxx.

References ElectronicsCalibObject().

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

Definition at line 56 of file DatabaseRetrievalAlg.h.

References lariov::DatabaseRetrievalAlg::fFolder.

56 {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 118 of file SIOVElectronicsCalibProvider.cxx.

References DBUpdate(), and fEventTimeStamp.

118  {
119 
120  fEventTimeStamp = ts;
121  return DBUpdate(ts);
122  }
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 49 of file DatabaseRetrievalAlg.h.

References lariov::DatabaseRetrievalAlg::fFolder.

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

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

Update event time stamp.

Definition at line 111 of file SIOVElectronicsCalibProvider.cxx.

References fEventTimeStamp.

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

111  {
112  mf::LogInfo("SIOVElectronicsCalibProvider") << "SIOVElectronicsCalibProvider::UpdateTimeStamp called.";
113  fEventTimeStamp = ts;
114  }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
const std::string& lariov::DatabaseRetrievalAlg::URL ( ) const
inlineinherited

Get connection information.

Definition at line 54 of file DatabaseRetrievalAlg.h.

References lariov::DatabaseRetrievalAlg::fFolder.

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

Member Data Documentation

DBTimeStamp_t lariov::SIOVElectronicsCalibProvider::fCurrentTimeStamp
mutableprivate

Definition at line 76 of file SIOVElectronicsCalibProvider.h.

Referenced by DBUpdate().

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

Definition at line 80 of file SIOVElectronicsCalibProvider.h.

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

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

Definition at line 78 of file SIOVElectronicsCalibProvider.h.

Referenced by DBUpdate(), and Reconfigure().

DBTimeStamp_t lariov::SIOVElectronicsCalibProvider::fEventTimeStamp
private

Definition at line 75 of file SIOVElectronicsCalibProvider.h.

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


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