LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 ChannelStatus & GetChannelStatus (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 IOVTimeStamp & Begin () const
 Get Timestamp information. More...
 
const IOVTimeStamp & End () 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< ChannelStatus > fData
 
Snapshot< ChannelStatus > fNewNoisy
 
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 35 of file SIOVChannelStatusProvider.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 34 of file SIOVChannelStatusProvider.cxx.

References fData, fDataSource, fDefault, file, and fhicl::ParameterSet::get().

35  : DatabaseRetrievalAlg(pset.get<fhicl::ParameterSet>("DatabaseRetrievalAlg"))
36  , fEventTimeStamp(0)
38  , fDefault(0)
39  {
40 
41  bool UseDB = pset.get<bool>("UseDB", false);
42  bool UseFile = pset.get<bool>("UseFile", false);
43  std::string fileName = pset.get<std::string>("FileName", "");
44 
45  //priority: (1) use db, (2) use table, (3) use defaults
46  //If none are specified, use defaults
47  if ( UseDB ) fDataSource = DataSource::Database;
48  else if (UseFile) fDataSource = DataSource::File;
49  else fDataSource = DataSource::Default;
50 
51  if (fDataSource == DataSource::Default) {
52  std::cout << "Using default channel status value: "<<kGOOD<<"\n";
53  fDefault.SetStatus(kGOOD);
54  }
55  else if (fDataSource == DataSource::File) {
56  cet::search_path sp("FW_SEARCH_PATH");
57  std::string abs_fp = sp.find_file(fileName);
58  std::cout << "Using channel statuses from local file: "<<abs_fp<<"\n";
59  std::ifstream file(abs_fp);
60  if (!file) {
61  throw cet::exception("SIOVChannelStatusProvider")
62  << "File "<<abs_fp<<" is not found.";
63  }
64 
65  std::string line;
66  ChannelStatus cs(0);
67  while (std::getline(file, line)) {
68  DBChannelID_t ch = (DBChannelID_t)std::stoi(line.substr(0, line.find(',')));
69  int status = std::stoi(line.substr(line.find(',')+1));
70 
71  cs.SetChannel(ch);
72  cs.SetStatus( ChannelStatus::GetStatusFromInt(status) );
73  fData.AddOrReplaceRow(cs);
74  }
75  } // if source from file
76  else {
77  std::cout << "Using channel statuses from conditions database\n";
78  }
79  }
TFile * file
DatabaseRetrievalAlg(const std::string &foldername, const std::string &url, const std::string &tag="")
Constructors.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
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 210 of file SIOVChannelStatusProvider.cxx.

References fNewNoisy, IsBad(), IsPresent(), and rawToDBChannel().

Referenced by Status().

210  {
211 
212  // for c2: ISO C++17 does not allow 'register' storage class specifier
213  //register DBChannelID_t const dbch = rawToDBChannel(ch);
214  DBChannelID_t const dbch = rawToDBChannel(ch);
215  if (!this->IsBad(dbch) && this->IsPresent(dbch)) {
216  ChannelStatus cs(dbch);
217  cs.SetStatus(kNOISY);
218  fNewNoisy.AddOrReplaceRow(cs);
219  }
220  }
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 194 of file SIOVChannelStatusProvider.cxx.

References GetChannelsWithStatus().

Referenced by Status().

194  {
195  ChannelSet_t dead = GetChannelsWithStatus(kDEAD);
196  ChannelSet_t ln = GetChannelsWithStatus(kLOWNOISE);
197  dead.insert(ln.begin(),ln.end());
198  return dead;
199  }
ChannelSet_t GetChannelsWithStatus(chStatus status) const
const IOVTimeStamp& lariov::DatabaseRetrievalAlg::Begin ( ) const
inlineinherited
bool lariov::SIOVChannelStatusProvider::DBUpdate ( ) const
private

Do actual database updates.

Definition at line 100 of file SIOVChannelStatusProvider.cxx.

References fEventTimeStamp.

Referenced by GetChannelStatus(), rawToDBChannel(), and Update().

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

Definition at line 107 of file SIOVChannelStatusProvider.cxx.

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

107  {
108 
109  bool result = false;
110  if(fDataSource == DataSource::Database && ts != fCurrentTimeStamp) {
111 
112  mf::LogInfo("SIOVChannelStatusProvider") << "SIOVChannelStatusProvider::DBUpdate called with new timestamp.";
113 
114  fCurrentTimeStamp = ts;
115 
116  // Call non-const base class method.
117 
118  result = const_cast<SIOVChannelStatusProvider*>(this)->UpdateFolder(ts);
119  if(result) {
120  //DBFolder was updated, so now update the Snapshot
121  fData.Clear();
122  fData.SetIoV(this->Begin(), this->End());
123 
124  std::vector<DBChannelID_t> channels;
125  fFolder->GetChannelList(channels);
126  for (auto it = channels.begin(); it != channels.end(); ++it) {
127 
128  long status;
129  fFolder->GetNamedChannelData(*it, "status", status);
130 
131  ChannelStatus cs(*it);
132  cs.SetStatus( ChannelStatus::GetStatusFromInt((int)status) );
133 
134  fData.AddOrReplaceRow(cs);
135  }
136  }
137  }
138  return result;
139  }
std::unique_ptr< DBFolder > fFolder
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
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 55 of file DatabaseRetrievalAlg.h.

References lariov::DatabaseRetrievalAlg::fFolder.

55 {return fFolder->FolderName();}
std::unique_ptr< DBFolder > fFolder
const ChannelStatus & lariov::SIOVChannelStatusProvider::GetChannelStatus ( raw::ChannelID_t  channel) const

Returns Channel Status.

Definition at line 143 of file SIOVChannelStatusProvider.cxx.

References DBUpdate(), fData, fDataSource, fDefault, fNewNoisy, and rawToDBChannel().

Referenced by GetChannelsWithStatus(), IsBad(), IsGood(), IsNoisy(), IsPresent(), and Status().

143  {
144  if (fDataSource == DataSource::Default) {
145  return fDefault;
146  }
147  DBUpdate();
148  if (fNewNoisy.HasChannel(rawToDBChannel(ch))) {
149  return fNewNoisy.GetRow(rawToDBChannel(ch));
150  }
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 159 of file SIOVChannelStatusProvider.cxx.

References fDataSource, fDefault, and GetChannelStatus().

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

159  {
160 
161  ChannelSet_t retSet;
162  retSet.clear();
163  DBChannelID_t maxChannel = art::ServiceHandle<geo::Geometry>()->Nchannels() - 1;
164  if (fDataSource == DataSource::Default) {
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  }
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 187 of file SIOVChannelStatusProvider.cxx.

References GetChannelsWithStatus().

Referenced by Status().

187  {
188  return GetChannelsWithStatus(kGOOD);
189  }
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 63 of file SIOVChannelStatusProvider.h.

References GetChannelStatus(), and IsPresent().

Referenced by AddNoisyChannel().

63  {
64  return GetChannelStatus(channel).IsDead() || GetChannelStatus(channel).IsLowNoise() || !IsPresent(channel);
65  }
bool IsPresent(raw::ChannelID_t channel) const override
Returns whether the specified channel is bad in the current run.
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 73 of file SIOVChannelStatusProvider.h.

References GetChannelStatus().

73  {
74  return GetChannelStatus(channel).IsGood();
75  }
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 68 of file SIOVChannelStatusProvider.h.

References GetChannelStatus().

68  {
69  return GetChannelStatus(channel).IsNoisy();
70  }
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 58 of file SIOVChannelStatusProvider.h.

References GetChannelStatus().

Referenced by AddNoisyChannel(), and IsBad().

58  {
59  return GetChannelStatus(channel).IsPresent();
60  }
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 204 of file SIOVChannelStatusProvider.cxx.

References GetChannelsWithStatus().

Referenced by Status().

204  {
205  return GetChannelsWithStatus(kNOISY);
206  }
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 110 of file SIOVChannelStatusProvider.h.

References DBUpdate().

Referenced by AddNoisyChannel(), and GetChannelStatus().

111  { 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 9 of file DatabaseRetrievalAlg.cxx.

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

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

9  {
10 
11  std::string foldername = p.get<std::string>("DBFolderName");
12  std::string url = p.get<std::string>("DBUrl");
13  std::string tag = p.get<std::string>("DBTag", "");
14  fFolder.reset(new DBFolder(foldername, url, tag));
15  }
std::unique_ptr< DBFolder > fFolder
Status_t lariov::SIOVChannelStatusProvider::Status ( raw::ChannelID_t  channel) const
inlineoverride

Definition at line 78 of file SIOVChannelStatusProvider.h.

References AddNoisyChannel(), BadChannels(), GetChannelStatus(), GoodChannels(), NoisyChannels(), Update(), and UpdateTimeStamp().

78  {
79  return (Status_t) this->GetChannelStatus(channel).Status();
80  }
const ChannelStatus & GetChannelStatus(raw::ChannelID_t channel) const
Returns Channel Status.
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::SIOVChannelStatusProvider::Update ( DBTimeStamp_t  ts)

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

Definition at line 91 of file SIOVChannelStatusProvider.cxx.

References DBUpdate(), fEventTimeStamp, and fNewNoisy.

Referenced by Status().

91  {
92 
93  fEventTimeStamp = ts;
94  fNewNoisy.Clear();
95  return DBUpdate(ts);
96  }
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 lariov::SIOVPmtGainProvider::DBUpdate(), lariov::SIOVElectronicsCalibProvider::DBUpdate(), lariov::DetPedestalRetrievalAlg::DBUpdate(), and DBUpdate().

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

Update event time stamp.

Definition at line 83 of file SIOVChannelStatusProvider.cxx.

References fEventTimeStamp, and fNewNoisy.

Referenced by lariov::SIOVChannelStatusService::PreProcessEvent(), and Status().

83  {
84  mf::LogInfo("SIOVChannelStatusProvider") << "SIOVChannelStatusProvider::UpdateTimeStamp called.";
85  fNewNoisy.Clear();
86  fEventTimeStamp = ts;
87  }
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::SIOVChannelStatusProvider::fCurrentTimeStamp
mutableprivate

Definition at line 123 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 122 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: