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

Retrieves information: pmt gain. More...

#include "SIOVPmtGainProvider.h"

Inheritance diagram for lariov::SIOVPmtGainProvider:
lariov::DatabaseRetrievalAlg

Public Member Functions

 SIOVPmtGainProvider (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 PmtGainPmtGainObject (DBChannelID_t ch) const
 Retrieve gain information. More...
 
float Gain (DBChannelID_t ch) const override
 
float GainErr (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< PmtGainfData
 

Detailed Description

Retrieves information: pmt gain.

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

Definition at line 38 of file SIOVPmtGainProvider.h.

Constructor & Destructor Documentation

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

Constructors.

Definition at line 14 of file SIOVPmtGainProvider.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 DBUpdate(), lariov::SIOVElectronicsCalibProvider::DBUpdate(), lariov::DetPedestalRetrievalAlg::DBUpdate(), and lariov::SIOVChannelStatusProvider::DBUpdate().

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

Do actual database updates.

Definition at line 118 of file SIOVPmtGainProvider.cxx.

References fEventTimeStamp.

Referenced by PmtGainObject(), and Update().

119  {
120  return DBUpdate(fEventTimeStamp);
121  }
bool DBUpdate() const
Do actual database updates.
bool lariov::SIOVPmtGainProvider::DBUpdate ( DBTimeStamp_t  ts) const
private

Definition at line 126 of file SIOVPmtGainProvider.cxx.

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

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

Definition at line 182 of file SIOVPmtGainProvider.cxx.

References lariov::PmtGain::ExtraInfo(), and PmtGainObject().

183  {
184  return this->PmtGainObject(ch).ExtraInfo();
185  }
const PmtGain & PmtGainObject(DBChannelID_t ch) const
Retrieve gain information.
CalibrationExtraInfo const & ExtraInfo() const
Definition: PmtGain.h:35
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::SIOVPmtGainProvider::Gain ( DBChannelID_t  ch) const
override

Definition at line 172 of file SIOVPmtGainProvider.cxx.

References lariov::PmtGain::Gain(), and PmtGainObject().

173  {
174  return this->PmtGainObject(ch).Gain();
175  }
const PmtGain & PmtGainObject(DBChannelID_t ch) const
Retrieve gain information.
float Gain() const
Definition: PmtGain.h:33
float lariov::SIOVPmtGainProvider::GainErr ( DBChannelID_t  ch) const
override

Definition at line 177 of file SIOVPmtGainProvider.cxx.

References lariov::PmtGain::GainErr(), and PmtGainObject().

178  {
179  return this->PmtGainObject(ch).GainErr();
180  }
float GainErr() const
Definition: PmtGain.h:34
const PmtGain & PmtGainObject(DBChannelID_t ch) const
Retrieve gain information.
const PmtGain & lariov::SIOVPmtGainProvider::PmtGainObject ( DBChannelID_t  ch) const

Retrieve gain information.

Definition at line 166 of file SIOVPmtGainProvider.cxx.

References DBUpdate(), and fData.

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

167  {
168  DBUpdate();
169  return fData.GetRow(ch);
170  }
bool DBUpdate() const
Do actual database updates.
void lariov::SIOVPmtGainProvider::Reconfigure ( fhicl::ParameterSet const &  p)
overridevirtual

Reconfigure function called by fhicl constructor.

Reimplemented from lariov::DatabaseRetrievalAlg.

Definition at line 23 of file SIOVPmtGainProvider.cxx.

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

Referenced by SIOVPmtGainProvider().

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 
49  PmtGain defaultGain(0);
50 
51  defaultGain.SetGain(default_gain);
52  defaultGain.SetGainErr(default_gain_err);
53  defaultGain.SetExtraInfo(CalibrationExtraInfo("PmtGain"));
54 
56  for (unsigned int od = 0; od != geo->NOpDets(); ++od) {
57  if (geo->IsValidOpChannel(od)) {
58  defaultGain.SetChannel(od);
59  fData.AddOrReplaceRow(defaultGain);
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 pmt gains from local file: " << abs_fp << "\n";
67  std::ifstream file(abs_fp);
68  if (!file) {
69  throw cet::exception("SIOVPmtGainProvider") << "File " << abs_fp << " is not found.";
70  }
71 
72  std::string line;
73  PmtGain dp(0);
74  while (std::getline(file, line)) {
75  if (line[0] == '#') continue;
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(
79  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));
83 
84  CalibrationExtraInfo info("PmtGain");
85 
86  dp.SetChannel(ch);
87  dp.SetGain(gain);
88  dp.SetGainErr(gain_err);
89  dp.SetExtraInfo(info);
90 
91  fData.AddOrReplaceRow(dp);
92  }
93  }
94  else {
95  std::cout << "Using pmt gains from conditions database" << std::endl;
96  }
97  }
virtual void Reconfigure(fhicl::ParameterSet const &p)
Configure using fhicl::ParameterSet.
Float_t tmp
Definition: plot.C:35
unsigned int NOpDets() const
Number of OpDets in the whole detector.
TFile * file
static IOVTimeStamp MaxTimeStamp()
Namespace collecting geometry-related classes utilities.
bool IsValidOpChannel(int opChannel) const
Is this a valid OpChannel number?
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
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::SIOVPmtGainProvider::Update ( DBTimeStamp_t  ts)

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

Definition at line 109 of file SIOVPmtGainProvider.cxx.

References DBUpdate(), and fEventTimeStamp.

110  {
111 
112  fEventTimeStamp = ts;
113  return DBUpdate(ts);
114  }
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 DBUpdate(), lariov::SIOVElectronicsCalibProvider::DBUpdate(), lariov::DetPedestalRetrievalAlg::DBUpdate(), and lariov::SIOVChannelStatusProvider::DBUpdate().

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

Update event time stamp.

Definition at line 101 of file SIOVPmtGainProvider.cxx.

References fEventTimeStamp.

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

102  {
103  mf::LogInfo("SIOVPmtGainProvider") << "SIOVPmtGainProvider::UpdateTimeStamp called.";
104  fEventTimeStamp = ts;
105  }
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::SIOVPmtGainProvider::fCurrentTimeStamp
mutableprivate

Definition at line 68 of file SIOVPmtGainProvider.h.

Referenced by DBUpdate().

Snapshot<PmtGain> lariov::SIOVPmtGainProvider::fData
mutableprivate

Definition at line 72 of file SIOVPmtGainProvider.h.

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

DataSource::ds lariov::SIOVPmtGainProvider::fDataSource
private

Definition at line 70 of file SIOVPmtGainProvider.h.

Referenced by DBUpdate(), and Reconfigure().

DBTimeStamp_t lariov::SIOVPmtGainProvider::fEventTimeStamp
private

Definition at line 67 of file SIOVPmtGainProvider.h.

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


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