LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 PmtGain & PmtGainObject (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 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< PmtGain > fData
 

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 17 of file SIOVPmtGainProvider.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::SIOVPmtGainProvider::DBUpdate ( ) const
private

Do actual database updates.

Definition at line 115 of file SIOVPmtGainProvider.cxx.

References fEventTimeStamp.

Referenced by PmtGainObject(), and Update().

115  {
116  return DBUpdate(fEventTimeStamp);
117  }
bool DBUpdate() const
Do actual database updates.
bool lariov::SIOVPmtGainProvider::DBUpdate ( DBTimeStamp_t  ts) const
private

Definition at line 122 of file SIOVPmtGainProvider.cxx.

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

122  {
123 
124  bool result = false;
125  if (fDataSource == DataSource::Database && ts != fCurrentTimeStamp) {
126 
127  mf::LogInfo("SIOVPmtGainProvider") << "SIOVPmtGainProvider::DBUpdate called with new timestamp.";
128 
129  fCurrentTimeStamp = ts;
130 
131  // Call non-const base class method.
132 
133  result = const_cast<SIOVPmtGainProvider*>(this)->UpdateFolder(ts);
134  if(result) {
135  //DBFolder was updated, so now update the Snapshot
136  fData.Clear();
137  fData.SetIoV(this->Begin(), this->End());
138 
139  std::vector<DBChannelID_t> channels;
140  fFolder->GetChannelList(channels);
141  for (auto it = channels.begin(); it != channels.end(); ++it) {
142 
143  double gain, gain_err;
144  fFolder->GetNamedChannelData(*it, "gain", gain);
145  fFolder->GetNamedChannelData(*it, "gain_sigma", gain_err);
146 
147  PmtGain pg(*it);
148  pg.SetGain( (float)gain );
149  pg.SetGainErr( (float)gain_err );
150  pg.SetExtraInfo(CalibrationExtraInfo("PmtGain"));
151 
152  fData.AddOrReplaceRow(pg);
153  }
154  }
155  }
156 
157  return result;
158  }
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 173 of file SIOVPmtGainProvider.cxx.

References PmtGainObject().

173  {
174  return this->PmtGainObject(ch).ExtraInfo();
175  }
const PmtGain & PmtGainObject(DBChannelID_t ch) const
Retrieve gain 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::SIOVPmtGainProvider::Gain ( DBChannelID_t  ch) const
override

Definition at line 165 of file SIOVPmtGainProvider.cxx.

References PmtGainObject().

165  {
166  return this->PmtGainObject(ch).Gain();
167  }
const PmtGain & PmtGainObject(DBChannelID_t ch) const
Retrieve gain information.
float lariov::SIOVPmtGainProvider::GainErr ( DBChannelID_t  ch) const
override

Definition at line 169 of file SIOVPmtGainProvider.cxx.

References PmtGainObject().

169  {
170  return this->PmtGainObject(ch).GainErr();
171  }
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 160 of file SIOVPmtGainProvider.cxx.

References DBUpdate(), and fData.

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

160  {
161  DBUpdate();
162  return fData.GetRow(ch);
163  }
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 25 of file SIOVPmtGainProvider.cxx.

References fData, fDataSource, file, fhicl::ParameterSet::get(), geo::GeometryCore::IsValidOpChannel(), geo::GeometryCore::NOpDets(), lariov::DatabaseRetrievalAlg::Reconfigure(), and tmp.

Referenced by SIOVPmtGainProvider().

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 
47  PmtGain defaultGain(0);
48 
49  defaultGain.SetGain(default_gain);
50  defaultGain.SetGainErr(default_gain_err);
51  defaultGain.SetExtraInfo(CalibrationExtraInfo("PmtGain"));
52 
54  for (unsigned int od=0; od!=geo->NOpDets(); ++od) {
55  if (geo->IsValidOpChannel(od)) {
56  defaultGain.SetChannel(od);
57  fData.AddOrReplaceRow(defaultGain);
58  }
59  }
60 
61  }
62  else if (fDataSource == DataSource::File) {
63  cet::search_path sp("FW_SEARCH_PATH");
64  std::string abs_fp = sp.find_file(fileName);
65  std::cout << "Using pmt gains from local file: "<<abs_fp<<"\n";
66  std::ifstream file(abs_fp);
67  if (!file) {
68  throw cet::exception("SIOVPmtGainProvider")
69  << "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( 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) );
82 
83  CalibrationExtraInfo info("PmtGain");
84 
85  dp.SetChannel(ch);
86  dp.SetGain(gain);
87  dp.SetGainErr(gain_err);
88  dp.SetExtraInfo(info);
89 
90  fData.AddOrReplaceRow(dp);
91  }
92  }
93  else {
94  std::cout << "Using pmt gains from conditions database"<<std::endl;
95  }
96  }
virtual void Reconfigure(fhicl::ParameterSet const &p)
Configure using fhicl::ParameterSet.
Float_t tmp
Definition: plot.C:37
unsigned int NOpDets() const
Number of OpDets in the whole detector.
TFile * file
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 56 of file DatabaseRetrievalAlg.h.

References lariov::DatabaseRetrievalAlg::fFolder.

56 {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 107 of file SIOVPmtGainProvider.cxx.

References DBUpdate(), and fEventTimeStamp.

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

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

Update event time stamp.

Definition at line 100 of file SIOVPmtGainProvider.cxx.

References fEventTimeStamp.

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

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

Definition at line 70 of file SIOVPmtGainProvider.h.

Referenced by DBUpdate().

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

Definition at line 74 of file SIOVPmtGainProvider.h.

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

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

Definition at line 72 of file SIOVPmtGainProvider.h.

Referenced by DBUpdate(), and Reconfigure().

DBTimeStamp_t lariov::SIOVPmtGainProvider::fEventTimeStamp
private

Definition at line 69 of file SIOVPmtGainProvider.h.

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


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