All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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::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
 
- 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 14 of file SIOVElectronicsCalibProvider.cxx.

14  :
15  DatabaseRetrievalAlg(p.get<fhicl::ParameterSet>("DatabaseRetrievalAlg")),
16  fEventTimeStamp(0),
18 
19  this->Reconfigure(p);
20  }
pdgs p
Definition: selectors.fcl:22
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

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

Do actual database updates.

Definition at line 123 of file SIOVElectronicsCalibProvider.cxx.

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

Definition at line 130 of file SIOVElectronicsCalibProvider.cxx.

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

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

Definition at line 194 of file SIOVElectronicsCalibProvider.cxx.

194  {
195  return this->ElectronicsCalibObject(ch).ExtraInfo();
196  }
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 178 of file SIOVElectronicsCalibProvider.cxx.

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

Definition at line 182 of file SIOVElectronicsCalibProvider.cxx.

182  {
183  return this->ElectronicsCalibObject(ch).GainErr();
184  }
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 22 of file SIOVElectronicsCalibProvider.cxx.

22  {
23 
24  this->DatabaseRetrievalAlg::Reconfigure(p.get<fhicl::ParameterSet>("DatabaseRetrievalAlg"));
25  fData.Clear();
26  IOVTimeStamp tmp = IOVTimeStamp::MaxTimeStamp();
27  tmp.SetStamp(tmp.Stamp()-1, tmp.SubStamp());
28  fData.SetIoV(tmp, IOVTimeStamp::MaxTimeStamp());
29 
30  bool UseDB = p.get<bool>("UseDB", false);
31  bool UseFile = p.get<bool>("UseFile", false);
32  std::string fileName = p.get<std::string>("FileName", "");
33 
34  //priority: (1) use db, (2) use table, (3) use defaults
35  //If none are specified, use defaults
36  if ( UseDB ) fDataSource = DataSource::Database;
37  else if (UseFile) fDataSource = DataSource::File;
39 
41  float default_gain = p.get<float>("DefaultGain");
42  float default_gain_err = p.get<float>("DefaultGainErr");
43  float default_st = p.get<float>("DefaultShapingTime");
44  float default_st_err = p.get<float>("DefaultShapingTimeErr");
45 
46  ElectronicsCalib defaultCalib(0);
47 
48  defaultCalib.SetGain(default_gain);
49  defaultCalib.SetGainErr(default_gain_err);
50  defaultCalib.SetShapingTime(default_st);
51  defaultCalib.SetShapingTimeErr(default_st_err);
52  defaultCalib.SetExtraInfo(CalibrationExtraInfo("ElectronicsCalib"));
53 
54  art::ServiceHandle<geo::Geometry const> geo;
55  geo::wire_id_iterator itW = geo->begin_wire_id();
56  for (; itW != geo->end_wire_id(); ++itW) {
57  DBChannelID_t ch = geo->PlaneWireToChannel(*itW);
58  defaultCalib.SetChannel(ch);
59  fData.AddOrReplaceRow(defaultCalib);
60  }
61 
62  }
63  else if (fDataSource == DataSource::File) {
64  cet::search_path sp("FW_SEARCH_PATH");
65  std::string abs_fp = sp.find_file(fileName);
66  std::cout << "Using electronics calibrations from local file: "<<abs_fp<<"\n";
67  std::ifstream file(abs_fp);
68  if (!file) {
69  throw cet::exception("SIOVElectronicsCalibProvider")
70  << "File "<<abs_fp<<" is not found.";
71  }
72 
73  std::string line;
74  ElectronicsCalib dp(0);
75  while (std::getline(file, line)) {
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)) );
79 
80  current_comma = line.find(',',current_comma+1);
81  float gain_err = 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 shaping_time = 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_err = std::stof( line.substr(current_comma+1) );
88 
89  CalibrationExtraInfo info("ElectronicsCalib");
90 
91  dp.SetChannel(ch);
92  dp.SetGain(gain);
93  dp.SetGainErr(gain_err);
94  dp.SetShapingTime(shaping_time);
95  dp.SetShapingTimeErr(shaping_time_err);
96  dp.SetExtraInfo(info);
97 
98  fData.AddOrReplaceRow(dp);
99  }
100  }
101  else {
102  std::cout << "Using electronics calibrations from conditions database"<<std::endl;
103  }
104  }
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::uint32_t DBChannelID_t
* file
Definition: file_to_url.sh:69
pdgs p
Definition: selectors.fcl:22
static IOVTimeStamp MaxTimeStamp()
BEGIN_PROLOG could also be cout
float lariov::SIOVElectronicsCalibProvider::ShapingTime ( DBChannelID_t  ch) const
override

Definition at line 186 of file SIOVElectronicsCalibProvider.cxx.

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

Definition at line 190 of file SIOVElectronicsCalibProvider.cxx.

190  {
191  return this->ElectronicsCalibObject(ch).ShapingTimeErr();
192  }
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 115 of file SIOVElectronicsCalibProvider.cxx.

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

Update event time stamp.

Definition at line 108 of file SIOVElectronicsCalibProvider.cxx.

108  {
109  mf::LogInfo("SIOVElectronicsCalibProvider") << "SIOVElectronicsCalibProvider::UpdateTimeStamp called.";
110  fEventTimeStamp = ts;
111  }

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: