LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
SimpleChannelStatus.cpp
Go to the documentation of this file.
1 
9 // Our header
11 
12 // LArSoft library
13 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::isValidChannelID()
14 
15 // Framework libraries
16 #include "cetlib_except/exception.h"
17 
18 
19 // C/C++ standard libraries
20 #include <vector>
21 #include <algorithm> // std::copy()
22 #include <iterator> // std::inserter()
23 #include <utility> // std::pair<>
24 
25 
26 namespace lariov {
27 
28 
29  //----------------------------------------------------------------------------
31  : fMaxChannel(raw::InvalidChannelID)
32  , fMaxPresentChannel(raw::InvalidChannelID)
33  {
34 
35  using chan_vect_t = std::vector<raw::ChannelID_t>;
36 
37  // Read the bad channels as a vector, then convert it into a set
38  chan_vect_t BadChannels
39  = pset.get<chan_vect_t>("BadChannels", chan_vect_t());
40  std::copy(
41  BadChannels.begin(), BadChannels.end(),
42  std::inserter(fBadChannels, fBadChannels.begin())
43  );
44 
45  // Read the noise channels as a vector, then convert it into a set
46  chan_vect_t NoisyChannels
47  = pset.get<chan_vect_t>("NoisyChannels", chan_vect_t());
48  std::copy(
49  NoisyChannels.begin(), NoisyChannels.end(),
50  std::inserter(fNoisyChannels, fNoisyChannels.begin())
51  );
52 
53  } // SimpleChannelStatus::SimpleChannelStatus()
54 
55 
56  //----------------------------------------------------------------------------
59  {
60 
62  fMaxPresentChannel = MaxGoodChannel;
63 
64  // clear the caches, if any
65  fGoodChannels.reset();
66 
67  } // SimpleChannelStatus::Setup()
68 
69 
70  //----------------------------------------------------------------------------
73  ? raw::isValidChannelID(channel) && (channel <= fMaxPresentChannel)
74  : true;
75  } // SimpleChannelStatus::isPresent()
76 
77 
78  //----------------------------------------------------------------------------
80 
82  return *fGoodChannels;
83 
84  } // SimpleChannelStatus::GoodChannels()
85 
86 
87  //----------------------------------------------------------------------------
89 
90  if (!fGoodChannels) fGoodChannels.reset(new ChannelSet_t);
91 
93  GoodChannels.clear();
94 
96  <std::pair<ChannelSet_t::const_iterator, ChannelSet_t::const_iterator>>
97  VetoedIDs;
98 
99  VetoedIDs.emplace_back(fBadChannels.cbegin(), fBadChannels.cend());
100  VetoedIDs.emplace_back(fNoisyChannels.cbegin(), fNoisyChannels.cend());
101 
102  // go for the first (lowest) channel ID...
103  raw::ChannelID_t channel = 0;
104  while (!raw::isValidChannelID(channel)) ++channel;
105 
106  // ... to the last present one
107  raw::ChannelID_t last_channel = fMaxChannel;
109  && (fMaxPresentChannel < last_channel))
110  last_channel = fMaxPresentChannel;
111 
112  // if we don't know how many channels
113  if (!raw::isValidChannelID(last_channel)) {
114  // this exception means that the Setup() function was not called
115  // or it was called with an invalid value
116  throw cet::exception("SimpleChannelStatus")
117  << "Can't fill good channel list since no largest channel was set up\n";
118  } // if
119 
120  // add the channels to the set one by one
121  while (channel <= last_channel) {
122  bool bGood = true;
123 
124  // check if this channel is in any of the vetoed lists
125  for (auto iter: VetoedIDs) {
126 
127  // check all the remaining vetoed channels in this list
128  while (iter.first != iter.second) {
129  // if the first vetoed channel is larger than the tested channel,
130  // we are done with this list
131  if (*(iter.first) > channel) break;
132 
133  if (*(iter.first) == channel) { // vetoed!
134  bGood = false;
135  ++(iter.first); // we have found this already
136  break;
137  }
138 
139  // the last vetoed channel is smaller than the tested channel;
140  // maybe the next vetoed channel will be it!
141  ++(iter.first);
142  } // while
143 
144  if (!bGood) break; // already known bad, we are done
145  } // for
146 
147  // add the channel
148  if (bGood) GoodChannels.insert(channel);
149  ++channel;
150  } // while
151 
152  } // SimpleChannelStatus::GoodChannels()
153 
154 
155  //----------------------------------------------------------------------------
156 
157 } // namespace filter
ChannelSet_t fNoisyChannels
set of noisy channels
void Setup(raw::ChannelID_t MaxChannel, raw::ChannelID_t MaxGoodChannel)
Sets the service provider up.
std::unique_ptr< ChannelSet_t > fGoodChannels
cached set of good channels (lazy evaluation)
raw::ChannelID_t MaxChannel() const
Returns the ID of the largest known channel.
Raw data description.
Definition: RawTypes.h:6
raw::ChannelID_t fMaxPresentChannel
largest ID among present channels
virtual bool IsPresent(raw::ChannelID_t channel) const override
Returns whether the specified channel is physical and good.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Definition: RawTypes.h:31
ChannelSet_t fBadChannels
set of bad channels
virtual ChannelSet_t NoisyChannels() const override
Returns a copy of set of noisy channel IDs for the current run.
T get(std::string const &key) const
Definition: ParameterSet.h:231
Channel quality provider with information from configuration file.
constexpr bool isValidChannelID(raw::ChannelID_t channel)
Definition: RawTypes.h:36
lariov::ChannelStatusProvider::ChannelSet_t ChannelSet_t
Filters for channels, events, etc.
void FillGoodChannels() const
Fills the collection of good channels.
virtual ChannelSet_t BadChannels() const override
Returns a copy of set of bad channel IDs for the current run.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:27
virtual ChannelSet_t GoodChannels() const override
Returns a copy of set of bad channel IDs for the current run.
raw::ChannelID_t fMaxChannel
largest ID among existing channels
SimpleChannelStatus(fhicl::ParameterSet const &pset)
Configuration.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33