All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
lariov::DetPedestalRetrievalAlg Class Reference

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

#include <DetPedestalRetrievalAlg.h>

Inheritance diagram for lariov::DetPedestalRetrievalAlg:
lariov::DatabaseRetrievalAlg lariov::DetPedestalProvider lar::UncopiableAndUnmovableClass

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
 
- 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::DetPedestalProvider
virtual ~DetPedestalProvider ()=default
 
virtual float PedMean (raw::ChannelID_t ch) const =0
 Retrieve pedestal information. More...
 
virtual float PedRms (raw::ChannelID_t ch) const =0
 
virtual float PedMeanErr (raw::ChannelID_t ch) const =0
 
virtual float PedRmsErr (raw::ChannelID_t ch) const =0
 

Static Public Attributes

static constexpr unsigned int NCOLUMNS = 5
 
static constexpr const char * FIELD_NAMES [NCOLUMNS] = {"channel", "mean", "mean_err", "rms", "rms_err"}
 
static constexpr const char * FIELD_TYPES [NCOLUMNS] = {"unsigned int", "float", "float", "float", "float"}
 

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
 

Additional Inherited Members

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

Detailed Description

Retrieves channel information: pedestal and RMS.

Configuration parameters

Definition at line 56 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.

24  :
25  DatabaseRetrievalAlg(foldername, url, tag),
26  fEventTimeStamp(0),
29 
30  fData.Clear();
31  IOVTimeStamp tmp = IOVTimeStamp::MaxTimeStamp();
32  tmp.SetStamp(tmp.Stamp()-1, tmp.SubStamp());
33  fData.SetIoV(tmp, IOVTimeStamp::MaxTimeStamp());
34  }
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.

37  :
38  DatabaseRetrievalAlg(p.get<fhicl::ParameterSet>("DatabaseRetrievalAlg")) {
39 
40  this->Reconfigure(p);
41  }
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::DetPedestalRetrievalAlg::DBUpdate ( ) const
private

Do actual database updates.

Definition at line 156 of file DetPedestalRetrievalAlg.cxx.

156  {
157  return DBUpdate(fEventTimeStamp);
158  }
bool DBUpdate() const
Do actual database updates.
bool lariov::DetPedestalRetrievalAlg::DBUpdate ( DBTimeStamp_t  ts) const
private

Definition at line 163 of file DetPedestalRetrievalAlg.cxx.

163  {
164 
165  bool result = false;
167 
168  mf::LogInfo("DetPedestalRetrievalAlg") << "DetPedestalRetrievalAlg::DBUpdate called with new timestamp.";
169  fCurrentTimeStamp = ts;
170 
171  // Call non-const base class method.
172 
173  result = const_cast<DetPedestalRetrievalAlg*>(this)->UpdateFolder(ts);
174  if(result) {
175 
176  //DBFolder was updated, so now update the Snapshot
177  fData.Clear();
178  fData.SetIoV(this->Begin(), this->End());
179 
180  std::vector<DBChannelID_t> channels;
181  fFolder->GetChannelList(channels);
182  for (auto it = channels.begin(); it != channels.end(); ++it) {
183 
184  double mean, mean_err, rms, rms_err;
185  fFolder->GetNamedChannelData(*it, "mean", mean);
186  fFolder->GetNamedChannelData(*it, "mean_err", mean_err);
187  fFolder->GetNamedChannelData(*it, "rms", rms);
188  fFolder->GetNamedChannelData(*it, "rms_err", rms_err);
189 
190  DetPedestal pd(*it);
191  pd.SetPedMean( (float)mean );
192  pd.SetPedMeanErr( (float)mean_err );
193  pd.SetPedRms( (float)rms );
194  pd.SetPedRmsErr( (float)rms_err );
195 
196  fData.AddOrReplaceRow(pd);
197  }
198  }
199  }
200 
201  return result;
202 
203  }
std::unique_ptr< DBFolder > fFolder
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 DetPedestal & lariov::DetPedestalRetrievalAlg::Pedestal ( DBChannelID_t  ch) const

Retrieve pedestal information.

Definition at line 205 of file DetPedestalRetrievalAlg.cxx.

205  {
206  DBUpdate();
207  return fData.GetRow(ch);
208  }
bool DBUpdate() const
Do actual database updates.
float lariov::DetPedestalRetrievalAlg::PedMean ( DBChannelID_t  ch) const
override

Definition at line 210 of file DetPedestalRetrievalAlg.cxx.

210  {
211  return this->Pedestal(ch).PedMean();
212  }
float PedMean() const
Definition: DetPedestal.h:33
const DetPedestal & Pedestal(DBChannelID_t ch) const
Retrieve pedestal information.
float lariov::DetPedestalRetrievalAlg::PedMeanErr ( DBChannelID_t  ch) const
override

Definition at line 218 of file DetPedestalRetrievalAlg.cxx.

218  {
219  return this->Pedestal(ch).PedMeanErr();
220  }
float PedMeanErr() const
Definition: DetPedestal.h:35
const DetPedestal & Pedestal(DBChannelID_t ch) const
Retrieve pedestal information.
float lariov::DetPedestalRetrievalAlg::PedRms ( DBChannelID_t  ch) const
override

Definition at line 214 of file DetPedestalRetrievalAlg.cxx.

214  {
215  return this->Pedestal(ch).PedRms();
216  }
const DetPedestal & Pedestal(DBChannelID_t ch) const
Retrieve pedestal information.
float PedRms() const
Definition: DetPedestal.h:34
float lariov::DetPedestalRetrievalAlg::PedRmsErr ( DBChannelID_t  ch) const
override

Definition at line 222 of file DetPedestalRetrievalAlg.cxx.

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

Reconfigure function called by fhicl constructor.

Reimplemented from lariov::DatabaseRetrievalAlg.

Definition at line 43 of file DetPedestalRetrievalAlg.cxx.

43  {
44 
45  this->DatabaseRetrievalAlg::Reconfigure(p.get<fhicl::ParameterSet>("DatabaseRetrievalAlg"));
46  fData.Clear();
47  IOVTimeStamp tmp = IOVTimeStamp::MaxTimeStamp();
48  tmp.SetStamp(tmp.Stamp()-1, tmp.SubStamp());
49  fData.SetIoV(tmp, IOVTimeStamp::MaxTimeStamp());
50 
51  bool UseDB = p.get<bool>("UseDB", false);
52  bool UseFile = p.get<bool>("UseFile", false);
53  std::string fileName = p.get<std::string>("FileName", "");
54 
55  //priority: (1) use db, (2) use table, (3) use defaults
56  //If none are specified, use defaults
57  if ( UseDB ) fDataSource = DataSource::Database;
58  else if (UseFile) fDataSource = DataSource::File;
60 
62  std::cout << "Using default pedestal values\n";
63  float default_collmean = p.get<float>("DefaultCollMean", 400.0);
64  float default_collrms = p.get<float>("DefaultCollRms", 0.3);
65  float default_mean_err = p.get<float>("DefaultMeanErr", 0.0);
66  float default_rms_err = p.get<float>("DefaultRmsErr", 0.0);
67  float default_indmean = p.get<float>("DefaultIndMean", 2048.0);
68  float default_indrms = p.get<float>("DefaultIndRms", 0.3);
69 
70  DetPedestal DefaultColl(0);
71  DetPedestal DefaultInd(0);
72 
73  DefaultColl.SetPedMean(default_collmean);
74  DefaultColl.SetPedMeanErr(default_mean_err);
75  DefaultColl.SetPedRms(default_collrms);
76  DefaultColl.SetPedRmsErr(default_rms_err);
77 
78  DefaultInd.SetPedMean(default_indmean);
79  DefaultInd.SetPedMeanErr(default_mean_err);
80  DefaultInd.SetPedRms(default_indrms);
81  DefaultInd.SetPedRmsErr(default_rms_err);
82 
83  art::ServiceHandle<geo::Geometry const> geo;
84  geo::wire_id_iterator itW = geo->begin_wire_id();
85  for ( ; itW != geo->end_wire_id(); ++itW) {
86  DBChannelID_t ch = geo->PlaneWireToChannel(*itW);
87 
88  if (geo->SignalType(ch) == geo::kCollection) {
89  DefaultColl.SetChannel(ch);
90  fData.AddOrReplaceRow(DefaultColl);
91  }
92  else if (geo->SignalType(ch) == geo::kInduction) {
93  DefaultInd.SetChannel(ch);
94  fData.AddOrReplaceRow(DefaultInd);
95  }
96  else throw IOVDataError("Wire type is not collection or induction!");
97  }
98  }
99  else if (fDataSource == DataSource::File) {
100  cet::search_path sp("FW_SEARCH_PATH");
101  std::string abs_fp = sp.find_file(fileName);
102  std::cout << "Using pedestals from local file: "<<abs_fp<<"\n";
103  std::ifstream file(abs_fp);
104  if (!file) {
105  throw cet::exception("DetPedestalRetrievalAlg")
106  << "File "<<abs_fp<<" is not found.";
107  }
108 
109  std::string line;
110  DetPedestal dp(0);
111  while (std::getline(file, line)) {
112  size_t current_comma = line.find(',');
113  DBChannelID_t ch = (DBChannelID_t)std::stoi(line.substr(0, current_comma));
114  float ped = std::stof( line.substr(current_comma+1, line.find(',',current_comma+1)-(current_comma+1)) );
115 
116  current_comma = line.find(',',current_comma+1);
117  float rms = std::stof( line.substr(current_comma+1, line.find(',',current_comma+1)-(current_comma+1)) );
118 
119  current_comma = line.find(',',current_comma+1);
120  float ped_err = std::stof( line.substr(current_comma+1, line.find(',',current_comma+1)-(current_comma+1)) );
121 
122  current_comma = line.find(',',current_comma+1);
123  float rms_err = std::stof( line.substr(current_comma+1) );
124 
125  dp.SetChannel(ch);
126  dp.SetPedMean(ped);
127  dp.SetPedMeanErr(ped_err);
128  dp.SetPedRms(rms);
129  dp.SetPedRmsErr(rms_err);
130  fData.AddOrReplaceRow(dp);
131  }
132  } // if source from file
133  else {
134  std::cout << "Using pedestals from conditions database\n";
135  }
136  }
virtual void Reconfigure(fhicl::ParameterSet const &p)
Configure using fhicl::ParameterSet.
Base forward iterator browsing all wire IDs in the detector.
Definition: GeometryCore.h:587
std::uint32_t DBChannelID_t
* file
Definition: file_to_url.sh:69
pdgs p
Definition: selectors.fcl:22
Signal from induction planes.
Definition: geo_types.h:145
static IOVTimeStamp MaxTimeStamp()
BEGIN_PROLOG could also be cout
Signal from collection planes.
Definition: geo_types.h:146
bool lariov::DetPedestalRetrievalAlg::Update ( DBTimeStamp_t  ts)

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

Definition at line 148 of file DetPedestalRetrievalAlg.cxx.

148  {
149 
150  fEventTimeStamp = ts;
151  return DBUpdate(ts);
152  }
bool DBUpdate() const
Do actual database updates.
void lariov::DetPedestalRetrievalAlg::UpdateTimeStamp ( DBTimeStamp_t  ts)

Update event time stamp.

Definition at line 141 of file DetPedestalRetrievalAlg.cxx.

141  {
142  mf::LogInfo("DetPedestalRetrievalAlg") << "DetPedestalRetrievalAlg::UpdateTimeStamp called.";
143  fEventTimeStamp = ts;
144  }

Member Data Documentation

DBTimeStamp_t lariov::DetPedestalRetrievalAlg::fCurrentTimeStamp
mutableprivate

Definition at line 100 of file DetPedestalRetrievalAlg.h.

Snapshot<DetPedestal> lariov::DetPedestalRetrievalAlg::fData
mutableprivate

Definition at line 103 of file DetPedestalRetrievalAlg.h.

DataSource::ds lariov::DetPedestalRetrievalAlg::fDataSource
private

Definition at line 102 of file DetPedestalRetrievalAlg.h.

DBTimeStamp_t lariov::DetPedestalRetrievalAlg::fEventTimeStamp
private

Definition at line 99 of file DetPedestalRetrievalAlg.h.

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

Definition at line 86 of file DetPedestalRetrievalAlg.h.

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

Definition at line 88 of file DetPedestalRetrievalAlg.h.

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

Definition at line 84 of file DetPedestalRetrievalAlg.h.


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