LArSoft  v06_85_00
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...
 
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 Attributes

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 
20  this->Reconfigure(p);
21  }
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

Get Timestamp information.

Definition at line 59 of file DatabaseRetrievalAlg.h.

References lariov::DatabaseRetrievalAlg::fFolder.

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

59 {return fFolder->CachedStart();}
std::unique_ptr< DBFolder > fFolder
const ElectronicsCalib & lariov::SIOVElectronicsCalibProvider::ElectronicsCalibObject ( DBChannelID_t  ch) const

Retrieve electronics calibration information.

Definition at line 141 of file SIOVElectronicsCalibProvider.cxx.

References fData.

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

141  {
142  return fData.GetRow(ch);
143  }
const IOVTimeStamp& lariov::DatabaseRetrievalAlg::End ( ) const
inlineinherited
CalibrationExtraInfo const & lariov::SIOVElectronicsCalibProvider::ExtraInfo ( DBChannelID_t  ch) const
override

Definition at line 161 of file SIOVElectronicsCalibProvider.cxx.

References ElectronicsCalibObject().

161  {
162  return this->ElectronicsCalibObject(ch).ExtraInfo();
163  }
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 145 of file SIOVElectronicsCalibProvider.cxx.

References ElectronicsCalibObject().

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

Definition at line 149 of file SIOVElectronicsCalibProvider.cxx.

References ElectronicsCalibObject().

149  {
150  return this->ElectronicsCalibObject(ch).GainErr();
151  }
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 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().

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

References ElectronicsCalibObject().

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

Definition at line 157 of file SIOVElectronicsCalibProvider.cxx.

References ElectronicsCalibObject().

157  {
158  return this->ElectronicsCalibObject(ch).ShapingTimeErr();
159  }
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 107 of file SIOVElectronicsCalibProvider.cxx.

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

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

107  {
108 
109  if (fDataSource != DataSource::Database) return false;
110 
111  if (!this->UpdateFolder(ts)) return false;
112 
113  //DBFolder was updated, so now update the Snapshot
114  fData.Clear();
115  fData.SetIoV(this->Begin(), this->End());
116 
117  std::vector<DBChannelID_t> channels;
118  fFolder->GetChannelList(channels);
119  for (auto it = channels.begin(); it != channels.end(); ++it) {
120 
121  double gain, gain_err, shaping_time, shaping_time_err;
122  fFolder->GetNamedChannelData(*it, "gain", gain);
123  fFolder->GetNamedChannelData(*it, "gain_err", gain_err);
124  fFolder->GetNamedChannelData(*it, "shaping_time", shaping_time);
125  fFolder->GetNamedChannelData(*it, "shaping_time_err", shaping_time_err);
126 
127 
128  ElectronicsCalib pg(*it);
129  pg.SetGain( (float)gain );
130  pg.SetGainErr( (float)gain_err );
131  pg.SetShapingTime( (float)shaping_time );
132  pg.SetShapingTimeErr( (float)shaping_time_err );
133  pg.SetExtraInfo(CalibrationExtraInfo("ElectronicsCalib"));
134 
135  fData.AddOrReplaceRow(pg);
136  }
137 
138  return true;
139  }
std::unique_ptr< DBFolder > fFolder
bool UpdateFolder(DBTimeStamp_t ts)
Return true if fFolder is successfully updated.
const IOVTimeStamp & End() const
const IOVTimeStamp & Begin() const
Get Timestamp information.
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::Update(), Update(), lariov::DetPedestalRetrievalAlg::Update(), and lariov::SIOVChannelStatusProvider::Update().

49  {
50  return fFolder->UpdateData(ts);
51  }
std::unique_ptr< DBFolder > fFolder
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

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

Definition at line 67 of file SIOVElectronicsCalibProvider.h.

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

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

Definition at line 65 of file SIOVElectronicsCalibProvider.h.

Referenced by Reconfigure(), and Update().


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