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

Class providing information about the quality of channels. More...

#include "SIOVChannelStatusProvider.h"

Inheritance diagram for lariov::SIOVChannelStatusProvider:
lariov::DatabaseRetrievalAlg

Public Member Functions

 SIOVChannelStatusProvider (fhicl::ParameterSet const &pset)
 Constructor. More...
 
virtual ~SIOVChannelStatusProvider ()=default
 Default destructor. More...
 
const ChannelStatusGetChannelStatus (raw::ChannelID_t channel) const
 Returns Channel Status. More...
 
Status_t Status (raw::ChannelID_t channel) const override
 
void UpdateTimeStamp (DBTimeStamp_t ts)
 Update event time stamp. More...
 
virtual void Reconfigure (fhicl::ParameterSet const &p)
 Configure using fhicl::ParameterSet. 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
 
Single channel queries

Returns whether the specified channel is physical and connected to wire

bool IsPresent (raw::ChannelID_t channel) const override
 Returns whether the specified channel is bad in the current run. More...
 
bool IsBad (raw::ChannelID_t channel) const override
 Returns whether the specified channel is bad in the current run. More...
 
bool IsNoisy (raw::ChannelID_t channel) const override
 Returns whether the specified channel is noisy in the current run. More...
 
bool IsGood (raw::ChannelID_t channel) const override
 Returns whether the specified channel is physical and good. More...
 
Global channel queries

Returns a copy of set of good channel IDs for the current run

ChannelSet_t GoodChannels () const override
 Returns a copy of set of bad channel IDs for the current run. More...
 
ChannelSet_t BadChannels () const override
 Returns a copy of set of bad channel IDs for the current run. More...
 
ChannelSet_t NoisyChannels () const override
 Returns a copy of set of noisy channel IDs for the current run. More...
 
Configuration functions

Prepares the object to provide information about the specified time

bool Update (DBTimeStamp_t)
 Allows a service to add to the list of noisy channels. More...
 
void AddNoisyChannel (raw::ChannelID_t ch)
 Allows a service to add to the list of noisy channels. More...
 

Static Public Member Functions

static DBChannelID_t rawToDBChannel (raw::ChannelID_t channel)
 Converts LArSoft channel ID in the one proper for the DB. More...
 

Protected Attributes

std::unique_ptr< DBFolderfFolder
 

Private Member Functions

bool DBUpdate () const
 Do actual database updates. More...
 
bool DBUpdate (DBTimeStamp_t ts) const
 
ChannelSet_t GetChannelsWithStatus (chStatus status) const
 

Private Attributes

DBTimeStamp_t fEventTimeStamp
 
DBTimeStamp_t fCurrentTimeStamp
 
DataSource::ds fDataSource
 
Snapshot< ChannelStatusfData
 
Snapshot< ChannelStatusfNewNoisy
 
ChannelStatus fDefault
 

Detailed Description

Class providing information about the quality of channels.


This class serves information read from a FHiCL configuration file and/or a database.

LArSoft interface to this class is through the service SIOVChannelStatusService.

Definition at line 37 of file SIOVChannelStatusProvider.h.

Constructor & Destructor Documentation

lariov::SIOVChannelStatusProvider::SIOVChannelStatusProvider ( fhicl::ParameterSet const &  pset)

Constructor.

Definition at line 26 of file SIOVChannelStatusProvider.cxx.

References lariov::DataSource::Database, lariov::DataSource::Default, fData, fDataSource, fDefault, file, lariov::DataSource::File, fhicl::ParameterSet::get(), lariov::ChannelStatus::GetStatusFromInt(), lariov::kGOOD, lariov::ChData::SetChannel(), and lariov::ChannelStatus::SetStatus().

27  : DatabaseRetrievalAlg(pset.get<fhicl::ParameterSet>("DatabaseRetrievalAlg"))
28  , fEventTimeStamp(0)
30  , fDefault(0)
31  {
32 
33  bool UseDB = pset.get<bool>("UseDB", false);
34  bool UseFile = pset.get<bool>("UseFile", false);
35  std::string fileName = pset.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)
41  else if (UseFile)
43  else
45 
47  std::cout << "Using default channel status value: " << kGOOD << "\n";
48  fDefault.SetStatus(kGOOD);
49  }
50  else if (fDataSource == DataSource::File) {
51  cet::search_path sp("FW_SEARCH_PATH");
52  std::string abs_fp = sp.find_file(fileName);
53  std::cout << "Using channel statuses from local file: " << abs_fp << "\n";
54  std::ifstream file(abs_fp);
55  if (!file) {
56  throw cet::exception("SIOVChannelStatusProvider") << "File " << abs_fp << " is not found.";
57  }
58 
59  std::string line;
60  ChannelStatus cs(0);
61  while (std::getline(file, line)) {
62  DBChannelID_t ch = (DBChannelID_t)std::stoi(line.substr(0, line.find(',')));
63  int status = std::stoi(line.substr(line.find(',') + 1));
64 
65  cs.SetChannel(ch);
66  cs.SetStatus(ChannelStatus::GetStatusFromInt(status));
67  fData.AddOrReplaceRow(cs);
68  }
69  } // if source from file
70  else {
71  std::cout << "Using channel statuses from conditions database\n";
72  }
73  }
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 chStatus GetStatusFromInt(int status)
Definition: ChannelStatus.h:51
TFile * file
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void SetStatus(chStatus status)
Definition: ChannelStatus.h:49
virtual lariov::SIOVChannelStatusProvider::~SIOVChannelStatusProvider ( )
virtualdefault

Default destructor.

Member Function Documentation

void lariov::SIOVChannelStatusProvider::AddNoisyChannel ( raw::ChannelID_t  ch)

Allows a service to add to the list of noisy channels.

Definition at line 206 of file SIOVChannelStatusProvider.cxx.

References fNewNoisy, IsBad(), IsPresent(), lariov::kNOISY, rawToDBChannel(), and lariov::ChannelStatus::SetStatus().

207  {
208 
209  // for c2: ISO C++17 does not allow 'register' storage class specifier
210  //register DBChannelID_t const dbch = rawToDBChannel(ch);
211  DBChannelID_t const dbch = rawToDBChannel(ch);
212  if (!this->IsBad(dbch) && this->IsPresent(dbch)) {
213  ChannelStatus cs(dbch);
214  cs.SetStatus(kNOISY);
215  fNewNoisy.AddOrReplaceRow(cs);
216  }
217  }
bool IsPresent(raw::ChannelID_t channel) const override
Returns whether the specified channel is bad in the current run.
static DBChannelID_t rawToDBChannel(raw::ChannelID_t channel)
Converts LArSoft channel ID in the one proper for the DB.
bool IsBad(raw::ChannelID_t channel) const override
Returns whether the specified channel is bad in the current run.
SIOVChannelStatusProvider::ChannelSet_t lariov::SIOVChannelStatusProvider::BadChannels ( ) const
override

Returns a copy of set of bad channel IDs for the current run.

Definition at line 191 of file SIOVChannelStatusProvider.cxx.

References GetChannelsWithStatus(), lariov::kDEAD, and lariov::kLOWNOISE.

192  {
193  ChannelSet_t dead = GetChannelsWithStatus(kDEAD);
194  ChannelSet_t ln = GetChannelsWithStatus(kLOWNOISE);
195  dead.insert(ln.begin(), ln.end());
196  return dead;
197  }
ChannelSet_t GetChannelsWithStatus(chStatus status) const
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(), lariov::DetPedestalRetrievalAlg::DBUpdate(), and DBUpdate().

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

Do actual database updates.

Definition at line 97 of file SIOVChannelStatusProvider.cxx.

References fEventTimeStamp.

Referenced by GetChannelStatus(), and Update().

98  {
99  return DBUpdate(fEventTimeStamp);
100  }
bool DBUpdate() const
Do actual database updates.
bool lariov::SIOVChannelStatusProvider::DBUpdate ( DBTimeStamp_t  ts) const
private

Definition at line 105 of file SIOVChannelStatusProvider.cxx.

References lariov::DatabaseRetrievalAlg::Begin(), lariov::DataSource::Database, lariov::DatabaseRetrievalAlg::End(), fCurrentTimeStamp, fData, fDataSource, lariov::DatabaseRetrievalAlg::fFolder, lariov::ChannelStatus::GetStatusFromInt(), lariov::ChannelStatus::SetStatus(), and lariov::DatabaseRetrievalAlg::UpdateFolder().

106  {
107 
108  // A static mutex that is shared across all invocations of the function.
109  static std::mutex mutex;
110  std::lock_guard<std::mutex> lock(mutex);
111 
112  bool result = false;
114 
115  mf::LogInfo("SIOVChannelStatusProvider")
116  << "SIOVChannelStatusProvider::DBUpdate called with new timestamp.";
117 
118  fCurrentTimeStamp = ts;
119 
120  // Call non-const base class method.
121 
122  result = const_cast<SIOVChannelStatusProvider*>(this)->UpdateFolder(ts);
123  if (result) {
124  //DBFolder was updated, so now update the Snapshot
125  fData.Clear();
126  fData.SetIoV(this->Begin(), this->End());
127 
128  std::vector<DBChannelID_t> channels;
129  fFolder->GetChannelList(channels);
130  for (auto it = channels.begin(); it != channels.end(); ++it) {
131 
132  long status;
133  fFolder->GetNamedChannelData(*it, "status", status);
134 
135  ChannelStatus cs(*it);
136  cs.SetStatus(ChannelStatus::GetStatusFromInt((int)status));
137 
138  fData.AddOrReplaceRow(cs);
139  }
140  }
141  }
142  return result;
143  }
std::unique_ptr< DBFolder > fFolder
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
static chStatus GetStatusFromInt(int status)
Definition: ChannelStatus.h:51
bool UpdateFolder(DBTimeStamp_t ts)
Return true if fFolder is successfully updated.
const IOVTimeStamp & End() const
const IOVTimeStamp & Begin() const
Get Timestamp information.
SIOVChannelStatusProvider(fhicl::ParameterSet const &pset)
Constructor.
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 ChannelStatus & lariov::SIOVChannelStatusProvider::GetChannelStatus ( raw::ChannelID_t  channel) const

Returns Channel Status.

Definition at line 146 of file SIOVChannelStatusProvider.cxx.

References DBUpdate(), lariov::DataSource::Default, fData, fDataSource, fDefault, fNewNoisy, and rawToDBChannel().

Referenced by GetChannelsWithStatus().

147  {
148  if (fDataSource == DataSource::Default) { return fDefault; }
149  DBUpdate();
150  if (fNewNoisy.HasChannel(rawToDBChannel(ch))) { return fNewNoisy.GetRow(rawToDBChannel(ch)); }
151  else {
152  return fData.GetRow(rawToDBChannel(ch));
153  }
154  }
static DBChannelID_t rawToDBChannel(raw::ChannelID_t channel)
Converts LArSoft channel ID in the one proper for the DB.
bool DBUpdate() const
Do actual database updates.
SIOVChannelStatusProvider::ChannelSet_t lariov::SIOVChannelStatusProvider::GetChannelsWithStatus ( chStatus  status) const
private

Definition at line 157 of file SIOVChannelStatusProvider.cxx.

References lariov::DataSource::Default, fDataSource, fDefault, GetChannelStatus(), and lariov::ChannelStatus::Status().

Referenced by BadChannels(), GoodChannels(), and NoisyChannels().

159  {
160 
161  ChannelSet_t retSet;
162  retSet.clear();
163  DBChannelID_t maxChannel = art::ServiceHandle<geo::Geometry const>()->Nchannels() - 1;
165  if (fDefault.Status() == status) {
166  std::vector<DBChannelID_t> chs;
167  for (DBChannelID_t ch = 0; ch != maxChannel; ++ch) {
168  chs.push_back(ch);
169  }
170  retSet.insert(chs.begin(), chs.end());
171  }
172  }
173  else {
174  std::vector<DBChannelID_t> chs;
175  for (DBChannelID_t ch = 0; ch != maxChannel; ++ch) {
176  if (this->GetChannelStatus(ch).Status() == status) chs.push_back(ch);
177  }
178 
179  retSet.insert(chs.begin(), chs.end());
180  }
181  return retSet;
182  }
chStatus Status() const
Definition: ChannelStatus.h:47
const ChannelStatus & GetChannelStatus(raw::ChannelID_t channel) const
Returns Channel Status.
SIOVChannelStatusProvider::ChannelSet_t lariov::SIOVChannelStatusProvider::GoodChannels ( ) const
override

Returns a copy of set of bad channel IDs for the current run.

Definition at line 185 of file SIOVChannelStatusProvider.cxx.

References GetChannelsWithStatus(), and lariov::kGOOD.

186  {
188  }
ChannelSet_t GetChannelsWithStatus(chStatus status) const
bool lariov::SIOVChannelStatusProvider::IsBad ( raw::ChannelID_t  channel) const
inlineoverride

Returns whether the specified channel is bad in the current run.

Definition at line 65 of file SIOVChannelStatusProvider.h.

References lariov::ChannelStatus::IsDead(), and lariov::ChannelStatus::IsLowNoise().

Referenced by AddNoisyChannel().

66  {
67  return GetChannelStatus(channel).IsDead() || GetChannelStatus(channel).IsLowNoise() ||
68  !IsPresent(channel);
69  }
bool IsPresent(raw::ChannelID_t channel) const override
Returns whether the specified channel is bad in the current run.
bool IsLowNoise() const
Definition: ChannelStatus.h:43
bool IsDead() const
Definition: ChannelStatus.h:42
const ChannelStatus & GetChannelStatus(raw::ChannelID_t channel) const
Returns Channel Status.
bool lariov::SIOVChannelStatusProvider::IsGood ( raw::ChannelID_t  channel) const
inlineoverride

Returns whether the specified channel is physical and good.

Definition at line 78 of file SIOVChannelStatusProvider.h.

References lariov::ChannelStatus::IsGood().

79  {
80  return GetChannelStatus(channel).IsGood();
81  }
bool IsGood() const
Definition: ChannelStatus.h:46
const ChannelStatus & GetChannelStatus(raw::ChannelID_t channel) const
Returns Channel Status.
bool lariov::SIOVChannelStatusProvider::IsNoisy ( raw::ChannelID_t  channel) const
inlineoverride

Returns whether the specified channel is noisy in the current run.

Definition at line 72 of file SIOVChannelStatusProvider.h.

References lariov::ChannelStatus::IsNoisy().

73  {
74  return GetChannelStatus(channel).IsNoisy();
75  }
bool IsNoisy() const
Definition: ChannelStatus.h:44
const ChannelStatus & GetChannelStatus(raw::ChannelID_t channel) const
Returns Channel Status.
bool lariov::SIOVChannelStatusProvider::IsPresent ( raw::ChannelID_t  channel) const
inlineoverride

Returns whether the specified channel is bad in the current run.

Definition at line 59 of file SIOVChannelStatusProvider.h.

References lariov::ChannelStatus::IsPresent().

Referenced by AddNoisyChannel().

60  {
61  return GetChannelStatus(channel).IsPresent();
62  }
bool IsPresent() const
Definition: ChannelStatus.h:45
const ChannelStatus & GetChannelStatus(raw::ChannelID_t channel) const
Returns Channel Status.
SIOVChannelStatusProvider::ChannelSet_t lariov::SIOVChannelStatusProvider::NoisyChannels ( ) const
override

Returns a copy of set of noisy channel IDs for the current run.

Definition at line 200 of file SIOVChannelStatusProvider.cxx.

References GetChannelsWithStatus(), and lariov::kNOISY.

201  {
203  }
ChannelSet_t GetChannelsWithStatus(chStatus status) const
static DBChannelID_t lariov::SIOVChannelStatusProvider::rawToDBChannel ( raw::ChannelID_t  channel)
inlinestatic

Converts LArSoft channel ID in the one proper for the DB.

Definition at line 115 of file SIOVChannelStatusProvider.h.

Referenced by AddNoisyChannel(), and GetChannelStatus().

115 { return DBChannelID_t(channel); }
void lariov::DatabaseRetrievalAlg::Reconfigure ( fhicl::ParameterSet const &  p)
virtualinherited

Configure using fhicl::ParameterSet.

Reimplemented in lariov::DetPedestalRetrievalAlg, lariov::SIOVElectronicsCalibProvider, and lariov::SIOVPmtGainProvider.

Definition at line 11 of file DatabaseRetrievalAlg.cxx.

References lariov::DatabaseRetrievalAlg::fFolder, and fhicl::ParameterSet::get().

Referenced by lariov::SIOVPmtGainProvider::Reconfigure(), lariov::SIOVElectronicsCalibProvider::Reconfigure(), and lariov::DetPedestalRetrievalAlg::Reconfigure().

12  {
13 
14  std::string foldername = p.get<std::string>("DBFolderName");
15  std::string url = p.get<std::string>("DBUrl");
16  std::string url2 = p.get<std::string>("DBUrl2", "");
17  std::string tag = p.get<std::string>("DBTag", "");
18  bool usesqlite = p.get<bool>("UseSQLite", false);
19  bool testmode = p.get<bool>("TestMode", false);
20  fFolder.reset(new DBFolder(foldername, url, url2, tag, usesqlite, testmode));
21  }
std::unique_ptr< DBFolder > fFolder
Status_t lariov::SIOVChannelStatusProvider::Status ( raw::ChannelID_t  channel) const
inlineoverride

Definition at line 84 of file SIOVChannelStatusProvider.h.

References lariov::ChannelStatus::Status(), and tca::Update().

85  {
86  return (Status_t)this->GetChannelStatus(channel).Status();
87  }
chStatus Status() const
Definition: ChannelStatus.h:47
const ChannelStatus & GetChannelStatus(raw::ChannelID_t channel) const
Returns Channel Status.
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::SIOVChannelStatusProvider::Update ( DBTimeStamp_t  ts)

Allows a service to add to the list of noisy channels.

Definition at line 87 of file SIOVChannelStatusProvider.cxx.

References DBUpdate(), fEventTimeStamp, and fNewNoisy.

88  {
89 
90  fEventTimeStamp = ts;
91  fNewNoisy.Clear();
92  return DBUpdate(ts);
93  }
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(), lariov::DetPedestalRetrievalAlg::DBUpdate(), and DBUpdate().

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

Update event time stamp.

Definition at line 77 of file SIOVChannelStatusProvider.cxx.

References fEventTimeStamp, and fNewNoisy.

Referenced by DECLARE_ART_SERVICE_INTERFACE_IMPL().

78  {
79  mf::LogInfo("SIOVChannelStatusProvider")
80  << "SIOVChannelStatusProvider::UpdateTimeStamp called.";
81  fNewNoisy.Clear();
82  fEventTimeStamp = ts;
83  }
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::SIOVChannelStatusProvider::fCurrentTimeStamp
mutableprivate

Definition at line 126 of file SIOVChannelStatusProvider.h.

Referenced by DBUpdate().

Snapshot<ChannelStatus> lariov::SIOVChannelStatusProvider::fData
mutableprivate
DataSource::ds lariov::SIOVChannelStatusProvider::fDataSource
private
ChannelStatus lariov::SIOVChannelStatusProvider::fDefault
private
DBTimeStamp_t lariov::SIOVChannelStatusProvider::fEventTimeStamp
private

Definition at line 125 of file SIOVChannelStatusProvider.h.

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

Snapshot<ChannelStatus> lariov::SIOVChannelStatusProvider::fNewNoisy
private

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