LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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/container_algorithms.h"
17 #include "cetlib_except/exception.h"
18 #include "fhiclcpp/ParameterSet.h"
19 
20 // C/C++ standard libraries
21 #include <iterator> // std::inserter()
22 #include <utility> // std::pair<>
23 
24 namespace lariov {
25 
26  //----------------------------------------------------------------------------
28  : fMaxChannel(raw::InvalidChannelID), fMaxPresentChannel(raw::InvalidChannelID)
29  {
30  using chan_vect_t = std::vector<raw::ChannelID_t>;
31 
32  // Read the bad channels as a vector, then convert it into a set
33  auto BadChannels = pset.get<chan_vect_t>("BadChannels", {});
34  cet::copy_all(BadChannels, std::inserter(fBadChannels, fBadChannels.begin()));
35 
36  // Read the noise channels as a vector, then convert it into a set
37  auto NoisyChannels = pset.get<chan_vect_t>("NoisyChannels", {});
38  cet::copy_all(NoisyChannels, std::inserter(fNoisyChannels, fNoisyChannels.begin()));
39 
40  } // SimpleChannelStatus::SimpleChannelStatus()
41 
42  //----------------------------------------------------------------------------
44  {
45 
47  fMaxPresentChannel = MaxGoodChannel;
48 
49  // clear the caches, if any
50  fGoodChannels.reset();
51 
52  } // SimpleChannelStatus::Setup()
53 
54  //----------------------------------------------------------------------------
56  {
58  raw::isValidChannelID(channel) && (channel <= fMaxPresentChannel) :
59  true;
60  } // SimpleChannelStatus::isPresent()
61 
62  //----------------------------------------------------------------------------
64  {
65 
67  return *fGoodChannels;
68 
69  } // SimpleChannelStatus::GoodChannels()
70 
71  //----------------------------------------------------------------------------
73  {
74 
75  if (!fGoodChannels) fGoodChannels.reset(new ChannelSet_t);
76 
78  GoodChannels.clear();
79 
80  std::vector<std::pair<ChannelSet_t::const_iterator, ChannelSet_t::const_iterator>> VetoedIDs;
81 
82  VetoedIDs.emplace_back(fBadChannels.cbegin(), fBadChannels.cend());
83  VetoedIDs.emplace_back(fNoisyChannels.cbegin(), fNoisyChannels.cend());
84 
85  // go for the first (lowest) channel ID...
86  raw::ChannelID_t channel = 0;
87  while (!raw::isValidChannelID(channel))
88  ++channel;
89 
90  // ... to the last present one
91  raw::ChannelID_t last_channel = fMaxChannel;
93  last_channel = fMaxPresentChannel;
94 
95  // if we don't know how many channels
96  if (!raw::isValidChannelID(last_channel)) {
97  // this exception means that the Setup() function was not called
98  // or it was called with an invalid value
99  throw cet::exception("SimpleChannelStatus")
100  << "Can't fill good channel list since no largest channel was set up\n";
101  } // if
102 
103  // add the channels to the set one by one
104  while (channel <= last_channel) {
105  bool bGood = true;
106 
107  // check if this channel is in any of the vetoed lists
108  for (auto iter : VetoedIDs) {
109 
110  // check all the remaining vetoed channels in this list
111  while (iter.first != iter.second) {
112  // if the first vetoed channel is larger than the tested channel,
113  // we are done with this list
114  if (*(iter.first) > channel) break;
115 
116  if (*(iter.first) == channel) { // vetoed!
117  bGood = false;
118  ++(iter.first); // we have found this already
119  break;
120  }
121 
122  // the last vetoed channel is smaller than the tested channel;
123  // maybe the next vetoed channel will be it!
124  ++(iter.first);
125  } // while
126 
127  if (!bGood) break; // already known bad, we are done
128  } // for
129 
130  // add the channel
131  if (bGood) GoodChannels.insert(channel);
132  ++channel;
133  } // while
134 
135  } // SimpleChannelStatus::GoodChannels()
136 
137  //----------------------------------------------------------------------------
138 
139 } // 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.
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:314
Channel quality provider with information from configuration file.
constexpr bool isValidChannelID(raw::ChannelID_t channel)
Definition: RawTypes.h:35
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:28
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