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

Retrieves channel information: pedestal and RMS. More...

#include "DetPedestalRetrievalAlg.h"

Inheritance diagram for lariov::DetPedestalRetrievalAlg:
lariov::DatabaseRetrievalAlg

Public Member Functions

 DetPedestalRetrievalAlg (const std::string &foldername, const std::string &url, const std::string &tag="")
 Constructors. More...
 
 DetPedestalRetrievalAlg (fhicl::ParameterSet const &p)
 
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 DetPedestalPedestal (DBChannelID_t ch) const
 Retrieve pedestal information. More...
 
float PedMean (DBChannelID_t ch) const override
 
float PedRms (DBChannelID_t ch) const override
 
float PedMeanErr (DBChannelID_t ch) const override
 
float PedRmsErr (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
 

Static Public Attributes

static constexpr unsigned int NCOLUMNS = 5
 
static constexpr const char * FIELD_NAMES [NCOLUMNS]
 
static constexpr const char * FIELD_TYPES [NCOLUMNS]
 

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< DetPedestalfData
 

Detailed Description

Retrieves channel information: pedestal and RMS.

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
  • DefaultCollMean (real, default: 400.0): pedestal value returned for collection plane channels when /UseDB/ and /UseFile/ parameters are false
  • DefaultIndMean (real, default: 2048.0): pedestal value returned for induction plane channels when /UseDB/ and /UseFile/ parameters are false
  • DefaultCollRms (real, default: 0.3): pedestal RMS value returned for collection plane channels when /UseDB/ and /UseFile/ parameters are false
  • DefaultIndRms (real, default: 0.3): pedestal RMS value returned for induction plane channels when /UseDB/ and /UseFile/ parameters are false
  • DefaultMeanErr (real, default: 0.0): error on the pedestal value for all channels returned when /UseDB/ and /UseFile/ parameters are false
  • DefaultRmsErr (real, default: 0.0): error on the RMS value for all channels returned when /UseDB/ and /UseFile/ parameters are false

Definition at line 58 of file DetPedestalRetrievalAlg.h.

Constructor & Destructor Documentation

lariov::DetPedestalRetrievalAlg::DetPedestalRetrievalAlg ( const std::string &  foldername,
const std::string &  url,
const std::string &  tag = "" 
)

Constructors.

Definition at line 22 of file DetPedestalRetrievalAlg.cxx.

References fData, lariov::IOVTimeStamp::MaxTimeStamp(), lariov::IOVTimeStamp::SetStamp(), lariov::IOVTimeStamp::Stamp(), lariov::IOVTimeStamp::SubStamp(), and tmp.

25  : DatabaseRetrievalAlg(foldername, url, tag)
26  , fEventTimeStamp(0)
29  {
30 
31  fData.Clear();
32  IOVTimeStamp tmp = IOVTimeStamp::MaxTimeStamp();
33  tmp.SetStamp(tmp.Stamp() - 1, tmp.SubStamp());
34  fData.SetIoV(tmp, IOVTimeStamp::MaxTimeStamp());
35  }
Float_t tmp
Definition: plot.C:35
DatabaseRetrievalAlg(const std::string &foldername, const std::string &url, const std::string &url2="", const std::string &tag="", bool usesqlite=false, bool testmode=false)
Constructors.
static IOVTimeStamp MaxTimeStamp()
lariov::DetPedestalRetrievalAlg::DetPedestalRetrievalAlg ( fhicl::ParameterSet const &  p)

Definition at line 37 of file DetPedestalRetrievalAlg.cxx.

References Reconfigure().

38  : DatabaseRetrievalAlg(p.get<fhicl::ParameterSet>("DatabaseRetrievalAlg"))
39  {
40 
41  this->Reconfigure(p);
42  }
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 lariov::SIOVPmtGainProvider::DBUpdate(), lariov::SIOVElectronicsCalibProvider::DBUpdate(), DBUpdate(), and lariov::SIOVChannelStatusProvider::DBUpdate().

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

Do actual database updates.

Definition at line 164 of file DetPedestalRetrievalAlg.cxx.

References fEventTimeStamp.

Referenced by Pedestal(), and Update().

165  {
166  return DBUpdate(fEventTimeStamp);
167  }
bool DBUpdate() const
Do actual database updates.
bool lariov::DetPedestalRetrievalAlg::DBUpdate ( DBTimeStamp_t  ts) const
private

Definition at line 172 of file DetPedestalRetrievalAlg.cxx.

References lariov::DatabaseRetrievalAlg::Begin(), lariov::DataSource::Database, lariov::DatabaseRetrievalAlg::End(), fCurrentTimeStamp, fData, fDataSource, lariov::DatabaseRetrievalAlg::fFolder, pmtana::mean(), lariov::DetPedestal::SetPedMean(), lariov::DetPedestal::SetPedMeanErr(), lariov::DetPedestal::SetPedRms(), lariov::DetPedestal::SetPedRmsErr(), and lariov::DatabaseRetrievalAlg::UpdateFolder().

173  {
174 
175  // A static mutex that is shared across all invocations of the function.
176  static std::mutex mutex;
177  std::lock_guard<std::mutex> lock(mutex);
178 
179  bool result = false;
181 
182  mf::LogInfo("DetPedestalRetrievalAlg")
183  << "DetPedestalRetrievalAlg::DBUpdate called with new timestamp.";
184  fCurrentTimeStamp = ts;
185 
186  // Call non-const base class method.
187 
188  result = const_cast<DetPedestalRetrievalAlg*>(this)->UpdateFolder(ts);
189  if (result) {
190 
191  //DBFolder was updated, so now update the Snapshot
192  fData.Clear();
193  fData.SetIoV(this->Begin(), this->End());
194 
195  std::vector<DBChannelID_t> channels;
196  fFolder->GetChannelList(channels);
197  for (auto it = channels.begin(); it != channels.end(); ++it) {
198 
199  double mean, mean_err, rms, rms_err;
200  fFolder->GetNamedChannelData(*it, "mean", mean);
201  fFolder->GetNamedChannelData(*it, "mean_err", mean_err);
202  fFolder->GetNamedChannelData(*it, "rms", rms);
203  fFolder->GetNamedChannelData(*it, "rms_err", rms_err);
204 
205  DetPedestal pd(*it);
206  pd.SetPedMean((float)mean);
207  pd.SetPedMeanErr((float)mean_err);
208  pd.SetPedRms((float)rms);
209  pd.SetPedRmsErr((float)rms_err);
210 
211  fData.AddOrReplaceRow(pd);
212  }
213  }
214  }
215 
216  return result;
217  }
std::unique_ptr< DBFolder > fFolder
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
bool UpdateFolder(DBTimeStamp_t ts)
Return true if fFolder is successfully updated.
DetPedestalRetrievalAlg(const std::string &foldername, const std::string &url, const std::string &tag="")
Constructors.
const IOVTimeStamp & End() const
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:13
const IOVTimeStamp & Begin() const
Get Timestamp information.
const IOVTimeStamp& lariov::DatabaseRetrievalAlg::End ( ) const
inlineinherited
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
const DetPedestal & lariov::DetPedestalRetrievalAlg::Pedestal ( DBChannelID_t  ch) const

Retrieve pedestal information.

Definition at line 219 of file DetPedestalRetrievalAlg.cxx.

References DBUpdate(), and fData.

Referenced by PedMean(), PedMeanErr(), PedRms(), and PedRmsErr().

220  {
221  DBUpdate();
222  return fData.GetRow(ch);
223  }
bool DBUpdate() const
Do actual database updates.
float lariov::DetPedestalRetrievalAlg::PedMean ( DBChannelID_t  ch) const
override

Definition at line 225 of file DetPedestalRetrievalAlg.cxx.

References Pedestal(), and lariov::DetPedestal::PedMean().

226  {
227  return this->Pedestal(ch).PedMean();
228  }
float PedMean() const
Definition: DetPedestal.h:32
const DetPedestal & Pedestal(DBChannelID_t ch) const
Retrieve pedestal information.
float lariov::DetPedestalRetrievalAlg::PedMeanErr ( DBChannelID_t  ch) const
override

Definition at line 235 of file DetPedestalRetrievalAlg.cxx.

References Pedestal(), and lariov::DetPedestal::PedMeanErr().

236  {
237  return this->Pedestal(ch).PedMeanErr();
238  }
float PedMeanErr() const
Definition: DetPedestal.h:34
const DetPedestal & Pedestal(DBChannelID_t ch) const
Retrieve pedestal information.
float lariov::DetPedestalRetrievalAlg::PedRms ( DBChannelID_t  ch) const
override

Definition at line 230 of file DetPedestalRetrievalAlg.cxx.

References Pedestal(), and lariov::DetPedestal::PedRms().

231  {
232  return this->Pedestal(ch).PedRms();
233  }
const DetPedestal & Pedestal(DBChannelID_t ch) const
Retrieve pedestal information.
float PedRms() const
Definition: DetPedestal.h:33
float lariov::DetPedestalRetrievalAlg::PedRmsErr ( DBChannelID_t  ch) const
override

Definition at line 240 of file DetPedestalRetrievalAlg.cxx.

References Pedestal(), and lariov::DetPedestal::PedRmsErr().

241  {
242  return this->Pedestal(ch).PedRmsErr();
243  }
const DetPedestal & Pedestal(DBChannelID_t ch) const
Retrieve pedestal information.
float PedRmsErr() const
Definition: DetPedestal.h:35
void lariov::DetPedestalRetrievalAlg::Reconfigure ( fhicl::ParameterSet const &  p)
overridevirtual

Reconfigure function called by fhicl constructor.

Reimplemented from lariov::DatabaseRetrievalAlg.

Definition at line 44 of file DetPedestalRetrievalAlg.cxx.

References lariov::DataSource::Database, lariov::DataSource::Default, fData, fDataSource, file, lariov::DataSource::File, fhicl::ParameterSet::get(), geo::GeometryCore::Iterate(), geo::kCollection, geo::kInduction, lariov::IOVTimeStamp::MaxTimeStamp(), geo::GeometryCore::PlaneWireToChannel(), lariov::DatabaseRetrievalAlg::Reconfigure(), lariov::ChData::SetChannel(), lariov::DetPedestal::SetPedMean(), lariov::DetPedestal::SetPedMeanErr(), lariov::DetPedestal::SetPedRms(), lariov::DetPedestal::SetPedRmsErr(), lariov::IOVTimeStamp::SetStamp(), geo::GeometryCore::SignalType(), lariov::IOVTimeStamp::Stamp(), lariov::IOVTimeStamp::SubStamp(), and tmp.

Referenced by DetPedestalRetrievalAlg().

45  {
46 
47  this->DatabaseRetrievalAlg::Reconfigure(p.get<fhicl::ParameterSet>("DatabaseRetrievalAlg"));
48  fData.Clear();
49  IOVTimeStamp tmp = IOVTimeStamp::MaxTimeStamp();
50  tmp.SetStamp(tmp.Stamp() - 1, tmp.SubStamp());
51  fData.SetIoV(tmp, IOVTimeStamp::MaxTimeStamp());
52 
53  bool UseDB = p.get<bool>("UseDB", false);
54  bool UseFile = p.get<bool>("UseFile", false);
55  std::string fileName = p.get<std::string>("FileName", "");
56 
57  //priority: (1) use db, (2) use table, (3) use defaults
58  //If none are specified, use defaults
59  if (UseDB)
61  else if (UseFile)
63  else
65 
67  std::cout << "Using default pedestal values\n";
68  float default_collmean = p.get<float>("DefaultCollMean", 400.0);
69  float default_collrms = p.get<float>("DefaultCollRms", 0.3);
70  float default_mean_err = p.get<float>("DefaultMeanErr", 0.0);
71  float default_rms_err = p.get<float>("DefaultRmsErr", 0.0);
72  float default_indmean = p.get<float>("DefaultIndMean", 2048.0);
73  float default_indrms = p.get<float>("DefaultIndRms", 0.3);
74 
75  DetPedestal DefaultColl(0);
76  DetPedestal DefaultInd(0);
77 
78  DefaultColl.SetPedMean(default_collmean);
79  DefaultColl.SetPedMeanErr(default_mean_err);
80  DefaultColl.SetPedRms(default_collrms);
81  DefaultColl.SetPedRmsErr(default_rms_err);
82 
83  DefaultInd.SetPedMean(default_indmean);
84  DefaultInd.SetPedMeanErr(default_mean_err);
85  DefaultInd.SetPedRms(default_indrms);
86  DefaultInd.SetPedRmsErr(default_rms_err);
87 
89  for (auto const& wid : geo->Iterate<geo::WireID>()) {
90  DBChannelID_t ch = geo->PlaneWireToChannel(wid);
91 
92  if (geo->SignalType(ch) == geo::kCollection) {
93  DefaultColl.SetChannel(ch);
94  fData.AddOrReplaceRow(DefaultColl);
95  }
96  else if (geo->SignalType(ch) == geo::kInduction) {
97  DefaultInd.SetChannel(ch);
98  fData.AddOrReplaceRow(DefaultInd);
99  }
100  else
101  throw IOVDataError("Wire type is not collection or induction!");
102  }
103  }
104  else if (fDataSource == DataSource::File) {
105  cet::search_path sp("FW_SEARCH_PATH");
106  std::string abs_fp = sp.find_file(fileName);
107  std::cout << "Using pedestals from local file: " << abs_fp << "\n";
108  std::ifstream file(abs_fp);
109  if (!file) {
110  throw cet::exception("DetPedestalRetrievalAlg") << "File " << abs_fp << " is not found.";
111  }
112 
113  std::string line;
114  DetPedestal dp(0);
115  while (std::getline(file, line)) {
116  size_t current_comma = line.find(',');
117  DBChannelID_t ch = (DBChannelID_t)std::stoi(line.substr(0, current_comma));
118  float ped = std::stof(
119  line.substr(current_comma + 1, line.find(',', current_comma + 1) - (current_comma + 1)));
120 
121  current_comma = line.find(',', current_comma + 1);
122  float rms = std::stof(
123  line.substr(current_comma + 1, line.find(',', current_comma + 1) - (current_comma + 1)));
124 
125  current_comma = line.find(',', current_comma + 1);
126  float ped_err = std::stof(
127  line.substr(current_comma + 1, line.find(',', current_comma + 1) - (current_comma + 1)));
128 
129  current_comma = line.find(',', current_comma + 1);
130  float rms_err = std::stof(line.substr(current_comma + 1));
131 
132  dp.SetChannel(ch);
133  dp.SetPedMean(ped);
134  dp.SetPedMeanErr(ped_err);
135  dp.SetPedRms(rms);
136  dp.SetPedRmsErr(rms_err);
137  fData.AddOrReplaceRow(dp);
138  }
139  } // if source from file
140  else {
141  std::cout << "Using pedestals from conditions database\n";
142  }
143  }
details::range_type< T > Iterate() const
Initializes the specified ID with the ID of the first cryostat.
Definition: GeometryCore.h:541
virtual void Reconfigure(fhicl::ParameterSet const &p)
Configure using fhicl::ParameterSet.
Float_t tmp
Definition: plot.C:35
Signal from induction planes.
Definition: geo_types.h:151
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
SigType_t SignalType(PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
TFile * file
static IOVTimeStamp MaxTimeStamp()
Namespace collecting geometry-related classes utilities.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Signal from collection planes.
Definition: geo_types.h:152
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::DetPedestalRetrievalAlg::Update ( DBTimeStamp_t  ts)

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

Definition at line 155 of file DetPedestalRetrievalAlg.cxx.

References DBUpdate(), and fEventTimeStamp.

156  {
157 
158  fEventTimeStamp = ts;
159  return DBUpdate(ts);
160  }
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 lariov::SIOVPmtGainProvider::DBUpdate(), lariov::SIOVElectronicsCalibProvider::DBUpdate(), DBUpdate(), and lariov::SIOVChannelStatusProvider::DBUpdate().

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

Update event time stamp.

Definition at line 147 of file DetPedestalRetrievalAlg.cxx.

References fEventTimeStamp.

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

148  {
149  mf::LogInfo("DetPedestalRetrievalAlg") << "DetPedestalRetrievalAlg::UpdateTimeStamp called.";
150  fEventTimeStamp = ts;
151  }
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::DetPedestalRetrievalAlg::fCurrentTimeStamp
mutableprivate

Definition at line 106 of file DetPedestalRetrievalAlg.h.

Referenced by DBUpdate().

Snapshot<DetPedestal> lariov::DetPedestalRetrievalAlg::fData
mutableprivate
DataSource::ds lariov::DetPedestalRetrievalAlg::fDataSource
private

Definition at line 108 of file DetPedestalRetrievalAlg.h.

Referenced by DBUpdate(), and Reconfigure().

DBTimeStamp_t lariov::DetPedestalRetrievalAlg::fEventTimeStamp
private

Definition at line 105 of file DetPedestalRetrievalAlg.h.

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

constexpr const char* lariov::DetPedestalRetrievalAlg::FIELD_NAMES[NCOLUMNS]
static
Initial value:
= {"channel",
"mean",
"mean_err",
"rms",
"rms_err"}

Definition at line 86 of file DetPedestalRetrievalAlg.h.

constexpr const char* lariov::DetPedestalRetrievalAlg::FIELD_TYPES[NCOLUMNS]
static
Initial value:
= {"unsigned int",
"float",
"float",
"float",
"float"}

Definition at line 91 of file DetPedestalRetrievalAlg.h.

constexpr unsigned int lariov::DetPedestalRetrievalAlg::NCOLUMNS = 5
static

Definition at line 85 of file DetPedestalRetrievalAlg.h.


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