All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
13 #include "art/Framework/Services/Registry/ServiceHandle.h"
14 #include "fhiclcpp/ParameterSet.h"
18 #include "messagefacility/MessageLogger/MessageLogger.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 
58  std::string line;
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
ChannelSet_t GoodChannels() const override
Returns a copy of set of good channel IDs for the current run.
std::unique_ptr< DBFolder > fFolder
std::set< raw::ChannelID_t > ChannelSet_t
Type of set of channel IDs.
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
std::uint32_t DBChannelID_t
* file
Definition: file_to_url.sh:69
ChannelSet_t NoisyChannels() const override
Returns a copy of set of noisy channel IDs for the current run.
std::uint64_t DBTimeStamp_t
void UpdateTimeStamp(DBTimeStamp_t ts)
Update event time stamp.
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.
void SetChannel(unsigned int ch)
Definition: ChData.h:34
const IOVTimeStamp & End() const
ChannelSet_t BadChannels() const override
Returns a copy of set of bad channel IDs for the current run.
bool IsBad(raw::ChannelID_t channel) const override
Returns whether the specified channel is bad in the current run.
ChannelSet_t GetChannelsWithStatus(chStatus status) const
const ChannelStatus & GetChannelStatus(raw::ChannelID_t channel) const
Returns Channel Status.
Channel quality provider with information from configuration file.
const IOVTimeStamp & Begin() const
Get Timestamp information.
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
bool IsPresent(raw::ChannelID_t channel) const override
Returns whether the specified channel is physical and connected to wire.
art framework interface to geometry description
BEGIN_PROLOG could also be cout
void SetStatus(chStatus status)
Definition: ChannelStatus.h:43