SimpleChannelStatus.cpp
Go to the documentation of this file.
1 /**
2  * @file SimpleChannelStatus.cpp
3  * @brief Channel quality provider with information from configuration file
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date November 25th, 2014
6  * @see SimpleChannelStatus.h
7  */
8 
9 // Our header
11 
12 // LArSoft library
13 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::isValidChannelID()
14 
15 // Framework libraries
16 #include "fhiclcpp/ParameterSet.h"
18 #include "cetlib_except/exception.h"
19 
20 
21 // C/C++ standard libraries
22 #include <iterator> // std::inserter()
23 #include <utility> // std::pair<>
24 
25 namespace lariov {
26 
27 
28  //----------------------------------------------------------------------------
30  : fMaxChannel(raw::InvalidChannelID)
31  , fMaxPresentChannel(raw::InvalidChannelID)
32  {
33  using chan_vect_t = std::vector<raw::ChannelID_t>;
34 
35  // Read the bad channels as a vector, then convert it into a set
36  auto BadChannels = pset.get<chan_vect_t>("BadChannels", {});
38  std::inserter(fBadChannels, fBadChannels.begin()));
39 
40  // Read the noise channels as a vector, then convert it into a set
41  auto NoisyChannels = pset.get<chan_vect_t>("NoisyChannels", {});
43  std::inserter(fNoisyChannels, fNoisyChannels.begin()));
44 
45  } // SimpleChannelStatus::SimpleChannelStatus()
46 
47 
48  //----------------------------------------------------------------------------
51  {
52 
54  fMaxPresentChannel = MaxGoodChannel;
55 
56  // clear the caches, if any
57  fGoodChannels.reset();
58 
59  } // SimpleChannelStatus::Setup()
60 
61 
62  //----------------------------------------------------------------------------
65  ? raw::isValidChannelID(channel) && (channel <= fMaxPresentChannel)
66  : true;
67  } // SimpleChannelStatus::isPresent()
68 
69 
70  //----------------------------------------------------------------------------
72 
74  return *fGoodChannels;
75 
76  } // SimpleChannelStatus::GoodChannels()
77 
78 
79  //----------------------------------------------------------------------------
81 
82  if (!fGoodChannels) fGoodChannels.reset(new ChannelSet_t);
83 
85  GoodChannels.clear();
86 
88  <std::pair<ChannelSet_t::const_iterator, ChannelSet_t::const_iterator>>
89  VetoedIDs;
90 
91  VetoedIDs.emplace_back(fBadChannels.cbegin(), fBadChannels.cend());
92  VetoedIDs.emplace_back(fNoisyChannels.cbegin(), fNoisyChannels.cend());
93 
94  // go for the first (lowest) channel ID...
96  while (!raw::isValidChannelID(channel)) ++channel;
97 
98  // ... to the last present one
99  raw::ChannelID_t last_channel = fMaxChannel;
101  && (fMaxPresentChannel < last_channel))
102  last_channel = fMaxPresentChannel;
103 
104  // if we don't know how many channels
105  if (!raw::isValidChannelID(last_channel)) {
106  // this exception means that the Setup() function was not called
107  // or it was called with an invalid value
108  throw cet::exception("SimpleChannelStatus")
109  << "Can't fill good channel list since no largest channel was set up\n";
110  } // if
111 
112  // add the channels to the set one by one
113  while (channel <= last_channel) {
114  bool bGood = true;
115 
116  // check if this channel is in any of the vetoed lists
117  for (auto iter: VetoedIDs) {
118 
119  // check all the remaining vetoed channels in this list
120  while (iter.first != iter.second) {
121  // if the first vetoed channel is larger than the tested channel,
122  // we are done with this list
123  if (*(iter.first) > channel) break;
124 
125  if (*(iter.first) == channel) { // vetoed!
126  bGood = false;
127  ++(iter.first); // we have found this already
128  break;
129  }
130 
131  // the last vetoed channel is smaller than the tested channel;
132  // maybe the next vetoed channel will be it!
133  ++(iter.first);
134  } // while
135 
136  if (!bGood) break; // already known bad, we are done
137  } // for
138 
139  // add the channel
140  if (bGood) GoodChannels.insert(channel);
141  ++channel;
142  } // while
143 
144  } // SimpleChannelStatus::GoodChannels()
145 
146 
147  //----------------------------------------------------------------------------
148 
149 } // 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::set< raw::ChannelID_t > ChannelSet_t
Type of set of channel IDs.
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.
struct vector vector
Raw data description.
uint8_t channel
Definition: CRTFragment.hh:201
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 connected to wire.
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Definition: RawTypes.h:32
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:271
Channel quality provider with information from configuration file.
constexpr bool isValidChannelID(raw::ChannelID_t channel)
Definition: RawTypes.h:37
lariov::ChannelStatusProvider::ChannelSet_t ChannelSet_t
Filters for channels, events, etc.
void FillGoodChannels() const
Fills the collection of good channels.
auto copy_all(FwdCont &, FwdIter)
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:28
virtual ChannelSet_t GoodChannels() const override
Returns a copy of set of good 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