LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
SIOVChannelStatusProvider.cxx
Go to the documentation of this file.
1 
9 #ifndef SIOVCHANNELSTATUSPROVIDER_CXX
10 #define SIOVCHANNELSTATUSPROVIDER_CXX 1
11 
12 // Our header
14 
15 // LArSoft libraries
18 #include "WebError.h"
19 #include "larevt/CalibrationDBI/IOVData/IOVDataConstants.h"
20 
21 // C/C++ standard libraries
22 #include <vector>
23 #include <algorithm> // std::copy()
24 #include <iterator> // std::inserter()
25 #include <utility> // std::pair<>
26 #include <fstream>
27 
28 
29 namespace lariov {
30 
31 
32  //----------------------------------------------------------------------------
34  : DatabaseRetrievalAlg(pset.get<fhicl::ParameterSet>("DatabaseRetrievalAlg"))
35  , fDefault(0)
36  {
37 
38  bool UseDB = pset.get<bool>("UseDB", false);
39  bool UseFile = pset.get<bool>("UseFile", false);
40  std::string fileName = pset.get<std::string>("FileName", "");
41 
42  //priority: (1) use db, (2) use table, (3) use defaults
43  //If none are specified, use defaults
44  if ( UseDB ) fDataSource = DataSource::Database;
45  else if (UseFile) fDataSource = DataSource::File;
46  else fDataSource = DataSource::Default;
47 
48  if (fDataSource == DataSource::Default) {
49  std::cout << "Using default channel status value: "<<kGOOD<<"\n";
50  fDefault.SetStatus(kGOOD);
51  }
52  else if (fDataSource == DataSource::File) {
53  cet::search_path sp("FW_SEARCH_PATH");
54  std::string abs_fp = sp.find_file(fileName);
55  std::cout << "Using channel statuses from local file: "<<abs_fp<<"\n";
56  std::ifstream file(abs_fp);
57  if (!file) {
58  throw cet::exception("SIOVChannelStatusProvider")
59  << "File "<<abs_fp<<" is not found.";
60  }
61 
62  std::string line;
63  ChannelStatus cs(0);
64  while (std::getline(file, line)) {
65  DBChannelID_t ch = (DBChannelID_t)std::stoi(line.substr(0, line.find(',')));
66  int status = std::stoi(line.substr(line.find(',')+1));
67 
68  cs.SetChannel(ch);
69  cs.SetStatus( ChannelStatus::GetStatusFromInt(status) );
70  fData.AddOrReplaceRow(cs);
71  }
72  } // if source from file
73  else {
74  std::cout << "Using channel statuses from conditions database\n";
75  }
76  }
77 
78  bool SIOVChannelStatusProvider::Update(DBTimeStamp_t ts) {
79 
80  fNewNoisy.Clear();
81  if (fDataSource != DataSource::Database) return false;
82  if (!this->UpdateFolder(ts)) return false;
83 
84  //DBFolder was updated, so now update the Snapshot
85  fData.Clear();
86  fData.SetIoV(this->Begin(), this->End());
87 
88  std::vector<DBChannelID_t> channels;
89  fFolder->GetChannelList(channels);
90  for (auto it = channels.begin(); it != channels.end(); ++it) {
91 
92  long status;
93  fFolder->GetNamedChannelData(*it, "status", status);
94 
95  ChannelStatus cs(*it);
96  cs.SetStatus( ChannelStatus::GetStatusFromInt((int)status) );
97 
98  fData.AddOrReplaceRow(cs);
99  }
100  return true;
101  }
102 
103 
104  //----------------------------------------------------------------------------
106  if (fDataSource == DataSource::Default) {
107  return fDefault;
108  }
109 
110  if (fNewNoisy.HasChannel(rawToDBChannel(ch))) {
111  return fNewNoisy.GetRow(rawToDBChannel(ch));
112  }
113  else {
114  return fData.GetRow(rawToDBChannel(ch));
115  }
116  }
117 
118 
119  //----------------------------------------------------------------------------
120  SIOVChannelStatusProvider::ChannelSet_t
122 
123  ChannelSet_t retSet;
124  retSet.clear();
125  DBChannelID_t maxChannel = art::ServiceHandle<geo::Geometry>()->Nchannels() - 1;
126  if (fDataSource == DataSource::Default) {
127  if (fDefault.Status() == status) {
128  std::vector<DBChannelID_t> chs;
129  for (DBChannelID_t ch=0; ch != maxChannel; ++ch) {
130  chs.push_back(ch);
131  }
132  retSet.insert(chs.begin(), chs.end());
133  }
134  }
135  else {
136  std::vector<DBChannelID_t> chs;
137  for (DBChannelID_t ch=0; ch != maxChannel; ++ch) {
138  if (this->GetChannelStatus(ch).Status() == status) chs.push_back(ch);
139  }
140 
141  retSet.insert(chs.begin(), chs.end());
142  }
143  return retSet;
144  }
145 
146 
147  //----------------------------------------------------------------------------
148  SIOVChannelStatusProvider::ChannelSet_t
150  return GetChannelsWithStatus(kGOOD);
151  }
152 
153 
154  //----------------------------------------------------------------------------
155  SIOVChannelStatusProvider::ChannelSet_t
157  ChannelSet_t dead = GetChannelsWithStatus(kDEAD);
158  ChannelSet_t ln = GetChannelsWithStatus(kLOWNOISE);
159  dead.insert(ln.begin(),ln.end());
160  return dead;
161  }
162 
163 
164  //----------------------------------------------------------------------------
165  SIOVChannelStatusProvider::ChannelSet_t
167  return GetChannelsWithStatus(kNOISY);
168  }
169 
170 
171  //----------------------------------------------------------------------------
173 
174  // for c2: ISO C++17 does not allow 'register' storage class specifier
175  //register DBChannelID_t const dbch = rawToDBChannel(ch);
176  DBChannelID_t const dbch = rawToDBChannel(ch);
177  if (!this->IsBad(dbch) && this->IsPresent(dbch)) {
178  ChannelStatus cs(dbch);
179  cs.SetStatus(kNOISY);
180  fNewNoisy.AddOrReplaceRow(cs);
181  }
182  }
183 
184 
185 
186  //----------------------------------------------------------------------------
187 
188 } // namespace lariov
189 
190 #endif
std::unique_ptr< DBFolder > fFolder
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.
ChannelSet_t GoodChannels() const override
Returns a copy of set of bad channel IDs for the current run.
ChannelSet_t BadChannels() const override
Returns a copy of set of bad channel IDs for the current run.
bool UpdateFolder(DBTimeStamp_t ts)
Return true if fFolder is successfully updated.
bool IsBad(raw::ChannelID_t channel) const override
Returns whether the specified channel is bad in the current run.
parameter set interface
T get(std::string const &key) const
Definition: ParameterSet.h:231
const IOVTimeStamp & End() const
Filters for channels, events, etc.
ChannelSet_t GetChannelsWithStatus(chStatus status) const
TFile * file
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 Update(DBTimeStamp_t)
Allows a service to add to the list of noisy channels.
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:27
ChannelSet_t NoisyChannels() const override
Returns a copy of set of noisy channel IDs for the current run.
Collection of exception classes for WebDBI.
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33