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::SIOVPmtGainProvider Class Reference

Retrieves information: pmt gain. More...

#include <SIOVPmtGainProvider.h>

Inheritance diagram for lariov::SIOVPmtGainProvider:
lariov::DatabaseRetrievalAlg lariov::PmtGainProvider lar::UncopiableAndUnmovableClass

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
 
- 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::PmtGainProvider
virtual ~PmtGainProvider ()=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 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< PmtGainfData
 

Additional Inherited Members

- Protected Attributes inherited from lariov::DatabaseRetrievalAlg
std::unique_ptr< DBFolderfFolder
 

Detailed Description

Retrieves information: pmt gain.

Configuration parameters

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.

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::SIOVPmtGainProvider::DBUpdate ( ) const
private

Do actual database updates.

Definition at line 112 of file SIOVPmtGainProvider.cxx.

112  {
113  return DBUpdate(fEventTimeStamp);
114  }
bool DBUpdate() const
Do actual database updates.
bool lariov::SIOVPmtGainProvider::DBUpdate ( DBTimeStamp_t  ts) const
private

Definition at line 119 of file SIOVPmtGainProvider.cxx.

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

Definition at line 170 of file SIOVPmtGainProvider.cxx.

170  {
171  return this->PmtGainObject(ch).ExtraInfo();
172  }
const PmtGain & PmtGainObject(DBChannelID_t ch) const
Retrieve gain information.
CalibrationExtraInfo const & ExtraInfo() const
Definition: PmtGain.h:38
float lariov::SIOVPmtGainProvider::Gain ( DBChannelID_t  ch) const
override

Definition at line 162 of file SIOVPmtGainProvider.cxx.

162  {
163  return this->PmtGainObject(ch).Gain();
164  }
const PmtGain & PmtGainObject(DBChannelID_t ch) const
Retrieve gain information.
float Gain() const
Definition: PmtGain.h:36
float lariov::SIOVPmtGainProvider::GainErr ( DBChannelID_t  ch) const
override

Definition at line 166 of file SIOVPmtGainProvider.cxx.

166  {
167  return this->PmtGainObject(ch).GainErr();
168  }
float GainErr() const
Definition: PmtGain.h:37
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 157 of file SIOVPmtGainProvider.cxx.

157  {
158  DBUpdate();
159  return fData.GetRow(ch);
160  }
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 22 of file SIOVPmtGainProvider.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 
44  PmtGain defaultGain(0);
45 
46  defaultGain.SetGain(default_gain);
47  defaultGain.SetGainErr(default_gain_err);
48  defaultGain.SetExtraInfo(CalibrationExtraInfo("PmtGain"));
49 
50  art::ServiceHandle<geo::Geometry const> geo;
51  for (unsigned int od=0; od!=geo->NOpDets(); ++od) {
52  if (geo->IsValidOpChannel(od)) {
53  defaultGain.SetChannel(od);
54  fData.AddOrReplaceRow(defaultGain);
55  }
56  }
57 
58  }
59  else if (fDataSource == DataSource::File) {
60  cet::search_path sp("FW_SEARCH_PATH");
61  std::string abs_fp = sp.find_file(fileName);
62  std::cout << "Using pmt gains from local file: "<<abs_fp<<"\n";
63  std::ifstream file(abs_fp);
64  if (!file) {
65  throw cet::exception("SIOVPmtGainProvider")
66  << "File "<<abs_fp<<" is not found.";
67  }
68 
69  std::string line;
70  PmtGain dp(0);
71  while (std::getline(file, line)) {
72  if (line[0] == '#') continue;
73  size_t current_comma = line.find(',');
74  DBChannelID_t ch = (DBChannelID_t)std::stoi(line.substr(0, current_comma));
75  float gain = std::stof( line.substr(current_comma+1, line.find(',',current_comma+1)-(current_comma+1)) );
76 
77  current_comma = line.find(',',current_comma+1);
78  float gain_err = std::stof( line.substr(current_comma+1) );
79 
80  CalibrationExtraInfo info("PmtGain");
81 
82  dp.SetChannel(ch);
83  dp.SetGain(gain);
84  dp.SetGainErr(gain_err);
85  dp.SetExtraInfo(info);
86 
87  fData.AddOrReplaceRow(dp);
88  }
89  }
90  else {
91  std::cout << "Using pmt gains from conditions database"<<std::endl;
92  }
93  }
virtual void Reconfigure(fhicl::ParameterSet const &p)
Configure using fhicl::ParameterSet.
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
bool lariov::SIOVPmtGainProvider::Update ( DBTimeStamp_t  ts)

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

Definition at line 104 of file SIOVPmtGainProvider.cxx.

104  {
105 
106  fEventTimeStamp = ts;
107  return DBUpdate(ts);
108  }
bool DBUpdate() const
Do actual database updates.
void lariov::SIOVPmtGainProvider::UpdateTimeStamp ( DBTimeStamp_t  ts)

Update event time stamp.

Definition at line 97 of file SIOVPmtGainProvider.cxx.

97  {
98  mf::LogInfo("SIOVPmtGainProvider") << "SIOVPmtGainProvider::UpdateTimeStamp called.";
99  fEventTimeStamp = ts;
100  }

Member Data Documentation

DBTimeStamp_t lariov::SIOVPmtGainProvider::fCurrentTimeStamp
mutableprivate

Definition at line 70 of file SIOVPmtGainProvider.h.

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

Definition at line 74 of file SIOVPmtGainProvider.h.

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

Definition at line 72 of file SIOVPmtGainProvider.h.

DBTimeStamp_t lariov::SIOVPmtGainProvider::fEventTimeStamp
private

Definition at line 69 of file SIOVPmtGainProvider.h.


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