SIOVChannelStatusProvider.cxx
Go to the documentation of this file.
1 /**
2  * @file SIOVChannelStatusProvider.cxx
3  * @brief Channel quality provider with information from configuration file
4  * @author Brandon Eberly (eberly@fnal.gov)
5  * @date August 24, 2015
6  * @see SIOVChannelStatusProvider.h
7  */
8 
9 // Our header
11 
12 // LArSoft libraries
14 #include "fhiclcpp/ParameterSet.h"
19 
20 // C/C++ standard libraries
21 #include <fstream>
22 
23 namespace lariov {
24 
25 
26  //----------------------------------------------------------------------------
28  : DatabaseRetrievalAlg(pset.get<fhicl::ParameterSet>("DatabaseRetrievalAlg"))
29  , fEventTimeStamp(0)
30  , fCurrentTimeStamp(0)
31  , fDefault(0)
32  {
33 
34  bool UseDB = pset.get<bool>("UseDB", false);
35  bool UseFile = pset.get<bool>("UseFile", false);
36  std::string fileName = pset.get<std::string>("FileName", "");
37 
38  //priority: (1) use db, (2) use table, (3) use defaults
39  //If none are specified, use defaults
40  if ( UseDB ) fDataSource = DataSource::Database;
41  else if (UseFile) fDataSource = DataSource::File;
43 
45  std::cout << "Using default channel status value: "<<kGOOD<<"\n";
46  fDefault.SetStatus(kGOOD);
47  }
48  else if (fDataSource == DataSource::File) {
49  cet::search_path sp("FW_SEARCH_PATH");
50  std::string abs_fp = sp.find_file(fileName);
51  std::cout << "Using channel statuses from local file: "<<abs_fp<<"\n";
52  std::ifstream file(abs_fp);
53  if (!file) {
54  throw cet::exception("SIOVChannelStatusProvider")
55  << "File "<<abs_fp<<" is not found.";
56  }
57 
59  ChannelStatus cs(0);
60  while (std::getline(file, line)) {
61  DBChannelID_t ch = (DBChannelID_t)std::stoi(line.substr(0, line.find(',')));
62  int status = std::stoi(line.substr(line.find(',')+1));
63 
64  cs.SetChannel(ch);
66  fData.AddOrReplaceRow(cs);
67  }
68  } // if source from file
69  else {
70  std::cout << "Using channel statuses from conditions database\n";
71  }
72  }
73 
74  // This method saves the time stamp of the latest event.
75 
77  mf::LogInfo("SIOVChannelStatusProvider") << "SIOVChannelStatusProvider::UpdateTimeStamp called.";
78  fNewNoisy.Clear();
79  fEventTimeStamp = ts;
80  }
81 
82  // Maybe update method cached data (public non-const version).
83 
85 
86  fEventTimeStamp = ts;
87  fNewNoisy.Clear();
88  return DBUpdate(ts);
89  }
90 
91  // Maybe update method cached data (private const version using current event time).
92 
94  return DBUpdate(fEventTimeStamp);
95  }
96 
97  // Maybe update method cached data (private const version).
98  // This is the function that does the actual work of updating data from database.
99 
101 
102  bool result = false;
104 
105  mf::LogInfo("SIOVChannelStatusProvider") << "SIOVChannelStatusProvider::DBUpdate called with new timestamp.";
106 
107  fCurrentTimeStamp = ts;
108 
109  // Call non-const base class method.
110 
111  result = const_cast<SIOVChannelStatusProvider*>(this)->UpdateFolder(ts);
112  if(result) {
113  //DBFolder was updated, so now update the Snapshot
114  fData.Clear();
115  fData.SetIoV(this->Begin(), this->End());
116 
117  std::vector<DBChannelID_t> channels;
118  fFolder->GetChannelList(channels);
119  for (auto it = channels.begin(); it != channels.end(); ++it) {
120 
121  long status;
122  fFolder->GetNamedChannelData(*it, "status", status);
123 
124  ChannelStatus cs(*it);
125  cs.SetStatus( ChannelStatus::GetStatusFromInt((int)status) );
126 
127  fData.AddOrReplaceRow(cs);
128  }
129  }
130  }
131  return result;
132  }
133 
134 
135  //----------------------------------------------------------------------------
138  return fDefault;
139  }
140  DBUpdate();
141  if (fNewNoisy.HasChannel(rawToDBChannel(ch))) {
142  return fNewNoisy.GetRow(rawToDBChannel(ch));
143  }
144  else {
145  return fData.GetRow(rawToDBChannel(ch));
146  }
147  }
148 
149 
150  //----------------------------------------------------------------------------
153 
154  ChannelSet_t retSet;
155  retSet.clear();
156  DBChannelID_t maxChannel = art::ServiceHandle<geo::Geometry const>()->Nchannels() - 1;
158  if (fDefault.Status() == status) {
159  std::vector<DBChannelID_t> chs;
160  for (DBChannelID_t ch=0; ch != maxChannel; ++ch) {
161  chs.push_back(ch);
162  }
163  retSet.insert(chs.begin(), chs.end());
164  }
165  }
166  else {
167  std::vector<DBChannelID_t> chs;
168  for (DBChannelID_t ch=0; ch != maxChannel; ++ch) {
169  if (this->GetChannelStatus(ch).Status() == status) chs.push_back(ch);
170  }
171 
172  retSet.insert(chs.begin(), chs.end());
173  }
174  return retSet;
175  }
176 
177 
178  //----------------------------------------------------------------------------
182  }
183 
184 
185  //----------------------------------------------------------------------------
190  dead.insert(ln.begin(),ln.end());
191  return dead;
192  }
193 
194 
195  //----------------------------------------------------------------------------
199  }
200 
201 
202  //----------------------------------------------------------------------------
204 
205  // for c2: ISO C++17 does not allow 'register' storage class specifier
206  //register DBChannelID_t const dbch = rawToDBChannel(ch);
207  DBChannelID_t const dbch = rawToDBChannel(ch);
208  if (!this->IsBad(dbch) && this->IsPresent(dbch)) {
209  ChannelStatus cs(dbch);
210  cs.SetStatus(kNOISY);
211  fNewNoisy.AddOrReplaceRow(cs);
212  }
213  }
214 
215 
216 
217  //----------------------------------------------------------------------------
218 
219 } // namespace lariov
std::unique_ptr< DBFolder > fFolder
bool IsPresent(raw::ChannelID_t channel) const override
Returns whether the specified channel is physical and connected to wire.
std::set< raw::ChannelID_t > ChannelSet_t
Type of set of channel IDs.
static QCString result
static DBChannelID_t rawToDBChannel(raw::ChannelID_t channel)
Converts LArSoft channel ID in the one proper for the DB.
chStatus Status() const
Definition: ChannelStatus.h:41
ChannelSet_t GoodChannels() const override
Returns a copy of set of good channel IDs for the current run.
ChannelSet_t BadChannels() const override
Returns a copy of set of bad channel IDs for the current run.
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::uint32_t DBChannelID_t
std::uint64_t DBTimeStamp_t
void UpdateTimeStamp(DBTimeStamp_t ts)
Update event time stamp.
art framework interface to geometry description
Class providing information about the quality of channels.
static chStatus GetStatusFromInt(int status)
Definition: ChannelStatus.h:45
bool UpdateFolder(DBTimeStamp_t ts)
Return true if fFolder is successfully updated.
fileName
Definition: dumpTree.py:9
bool IsBad(raw::ChannelID_t channel) const override
Returns whether the specified channel is bad in the current run.
T get(std::string const &key) const
Definition: ParameterSet.h:271
void SetChannel(unsigned int ch)
Definition: ChData.h:34
const IOVTimeStamp & End() const
Filters for channels, events, etc.
ChannelSet_t GetChannelsWithStatus(chStatus status) const
void line(double t, double *p, double &x, double &y, double &z)
const ChannelStatus & GetChannelStatus(raw::ChannelID_t channel) const
Returns Channel Status.
std::string find_file(std::string const &filename) const
Definition: search_path.cc:96
Channel quality provider with information from configuration file.
const IOVTimeStamp & Begin() const
Get Timestamp information.
static TemplateFilterFactory::AutoRegister< FilterDefault > fDefault("default")
bool DBUpdate() const
Do actual database updates.
SIOVChannelStatusProvider(fhicl::ParameterSet const &pset)
Constructor.
void AddNoisyChannel(raw::ChannelID_t ch)
Allows a service to add to the list of noisy channels.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
const char * cs
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
ChannelSet_t NoisyChannels() const override
Returns a copy of set of noisy channel IDs for the current run.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void SetStatus(chStatus status)
Definition: ChannelStatus.h:43