SimpleChannelStatus_test.cxx
Go to the documentation of this file.
1 /**
2  * @file SimpleChannelStatus_test.cxx
3  * @brief Test of SimpleChannelStatus
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date July 17th, 2015
6  */
7 
8 // Boost libraries
9 /*
10  * Boost Magic: define the name of the module;
11  * and do that before the inclusion of Boost unit test headers
12  * because it will change what they provide.
13  * Among the those, there is a main() function and some wrapping catching
14  * unhandled exceptions and considering them test failures, and probably more.
15  * This also makes fairly complicate to receive parameters from the command line
16  * (for example, a random seed).
17  */
18 #define BOOST_TEST_MODULE ( simple_channel_status_test )
19 #include "boost/test/unit_test.hpp"
20 
21 // LArSoft libraries
24 
25 // framework libraries
26 #include "fhiclcpp/ParameterSet.h"
27 #include "fhiclcpp/coding.h"
28 
29 // C/C++ standard library
30 #include <any>
31 #include <iostream>
32 #include <ostream>
33 #include <set>
34 #include <memory> // std::unique_ptr<>
35 #include <algorithm> // std::equal(), std::transform()
36 
37 
38 namespace std {
39 
40  template <typename T>
41  fhicl::detail::ps_sequence_t encode(std::set<T> const& s) {
43  result.reserve(s.size());
44  std::transform(s.begin(), s.end(), std::inserter(result, result.end()),
45  [](T const& value) { return std::any(fhicl::detail::encode(value)); }
46  );
47  return result;
48  } // encode(set<T>)
49 
50 
51  template <typename T>
52  std::ostream& operator<< (std::ostream& out, std::set<T> const& s) {
53  out << "{";
54  typename std::set<T>::const_iterator begin = s.cbegin(), end = s.cend();
55  if (begin != end) {
56  out << " " << *begin;
57  while (++begin != end) out << ", " << *begin;
58  out << " ";
59  } // if not empty
60  out << "}";
61  return out;
62  } // operator<< (ostream, set<T>)
63 
64 } // namespace std
65 
66 //------------------------------------------------------------------------------
68  public:
71  const std::set<unsigned int> fBadChannels;
72  const std::set<unsigned int> fNoisyChannels;
73 
75  const raw::ChannelID_t MaxChannel,
76  const raw::ChannelID_t MaxPresentChannel,
77  const std::set<unsigned int> BadChannels,
78  const std::set<unsigned int> NoisyChannels
79  )
80  : fMaxChannel(MaxChannel)
81  , fMaxPresentChannel(MaxPresentChannel)
82  , fBadChannels(BadChannels)
83  , fNoisyChannels(NoisyChannels)
84  {}
85 
86  std::unique_ptr<lariov::SimpleChannelStatus> operator() () const
87  { return CreateStatus(); }
88 
89 
92 
93  std::any any {fhicl::detail::encode(fNoisyChannels)};
94  cfg.put("NoisyChannels", fNoisyChannels);
95  cfg.put("BadChannels", fBadChannels);
96 
97  return cfg;
98  } // CreateConfiguration()
99 
100 
101  std::unique_ptr<lariov::SimpleChannelStatus> CreateStatus() const {
102  fhicl::ParameterSet config = CreateConfiguration();
103 
105  = new lariov::SimpleChannelStatus(config);
106  pStatus->Setup(fMaxChannel, fMaxPresentChannel);
107 
108  std::cout
109  << "\nConfiguration:"
110  << "\n { " << config.to_string() << " }"
111  << "\nLoaded from configuration:"
112  << "\n - " << pStatus->BadChannels().size() << " bad channels: "
113  << pStatus->BadChannels()
114  << "\n - " << pStatus->NoisyChannels().size() << " noisy channels: "
115  << pStatus->NoisyChannels()
116  << "\n - largest channel ID: " << pStatus->MaxChannel()
117  << ", largest present: " << pStatus->MaxChannelPresent()
118  << std::endl;
119 
120  return std::unique_ptr<lariov::SimpleChannelStatus>(pStatus);
121  } // CreateStatus()
122 
123 
124 }; // class StatusConfiguration
125 
126 
128 
129  StatusConfiguration statusCreator(
130  /* MaxChannel */ 20,
131  /* MaxPresentChannel */ 15,
132  /* BadChannels */ { 1, 9, 13 },
133  /* NoisyChannels */ { 6, 8, 10, 11, 12, 13 }
134  );
135 
136  BOOST_TEST_CHECKPOINT("Creating simple status");
137  std::unique_ptr<lariov::SimpleChannelStatus> StatusOwner
138  = statusCreator.CreateStatus();
139 
140  lariov::SimpleChannelStatus const* pSimpleStatus = StatusOwner.get();
141 
142  // check the values of the extremes
143  BOOST_TEST(pSimpleStatus->MaxChannel() == statusCreator.fMaxChannel);
144  BOOST_TEST
145  (pSimpleStatus->MaxChannelPresent() == statusCreator.fMaxPresentChannel);
146 
147  // downcast to the interface to test interface stuff
148  lariov::ChannelStatusProvider const* pStatus = pSimpleStatus;
149 
150  /**
151  *
152  * Public interface:
153  *
154  * bool isPresent(raw::ChannelID_t channel) const
155  *
156  * bool isGood(raw::ChannelID_t channel) const
157  *
158  * bool isBad(raw::ChannelID_t channel) const
159  *
160  * bool isNoisy(raw::ChannelID_t channel) const
161  *
162  * ChannelSet_t GoodChannels() const
163  *
164  * ChannelSet_t BadChannels() const
165  *
166  * ChannelSet_t NoisyChannels() const
167  *
168  */
169 
170  // ChannelStatusBaseInterface::BadChannels()
171  std::set<raw::ChannelID_t> StatusBadChannels = pStatus->BadChannels();
172  BOOST_TEST
173  (StatusBadChannels.size() == statusCreator.fBadChannels.size());
174  BOOST_TEST(StatusBadChannels == statusCreator.fBadChannels);
175 
176  // ChannelStatusBaseInterface::NoisyChannels()
177  std::set<raw::ChannelID_t> StatusNoisyChannels = pStatus->NoisyChannels();
178  BOOST_TEST
179  (StatusNoisyChannels.size() == statusCreator.fNoisyChannels.size());
180  BOOST_TEST(StatusNoisyChannels == statusCreator.fNoisyChannels);
181 
182  std::set<raw::ChannelID_t> GoodChannels;
183 
184  for (raw::ChannelID_t channel = 0; channel <= statusCreator.fMaxChannel;
185  ++channel
186  ) {
187 
188  const bool bPresent = raw::isValidChannelID(channel)
189  && (channel <= statusCreator.fMaxPresentChannel);
190  const bool bBad = (statusCreator.fBadChannels.count(channel) > 0);
191  const bool bNoisy = (statusCreator.fNoisyChannels.count(channel) > 0);
192  const bool bGood = bPresent && !bBad && !bNoisy;
193 
194  if (bGood) GoodChannels.insert(channel);
195 
196  BOOST_TEST(pStatus->IsPresent(channel) == bPresent);
197  BOOST_TEST(pStatus->IsBad(channel) == bBad);
198  BOOST_TEST(pStatus->IsNoisy(channel) == bNoisy);
199 
200  BOOST_TEST(pStatus->IsGood(channel) == bGood);
201 
202  } // for channel
203 
204  // ChannelStatusBaseInterface::GoodChannels()
205  std::set<raw::ChannelID_t> StatusGoodChannels = pStatus->GoodChannels();
206  BOOST_TEST(StatusGoodChannels.size() == GoodChannels.size());
207  BOOST_TEST(StatusGoodChannels == GoodChannels);
208 
209 } // test_simple_status()
210 
211 
212 //
213 // test
214 //
215 BOOST_AUTO_TEST_CASE(SimpleStatusTest) {
217 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
raw::ChannelID_t MaxChannelPresent() const
Returns the ID of the largest present channel.
void Setup(raw::ChannelID_t MaxChannel, raw::ChannelID_t MaxGoodChannel)
Sets the service provider up.
static QCString result
ps_atom_t encode(std::string const &)
Definition: coding.cc:87
raw::ChannelID_t MaxChannel() const
Returns the ID of the largest known channel.
STL namespace.
intermediate_table::const_iterator const_iterator
const raw::ChannelID_t fMaxPresentChannel
uint8_t channel
Definition: CRTFragment.hh:201
fhicl::ParameterSet CreateConfiguration() const
std::vector< std::any > ps_sequence_t
Definition: coding.h:45
virtual ChannelSet_t NoisyChannels() const override
Returns a copy of set of noisy channel IDs for the current run.
static Config * config
Definition: config.cpp:1054
Channel quality provider with information from configuration file.
constexpr bool isValidChannelID(raw::ChannelID_t channel)
Definition: RawTypes.h:37
Class providing information about the quality of channels.
const std::set< unsigned int > fNoisyChannels
std::unique_ptr< lariov::SimpleChannelStatus > CreateStatus() const
virtual ChannelSet_t BadChannels() const override
Returns a copy of set of bad channel IDs for the current run.
StatusConfiguration(const raw::ChannelID_t MaxChannel, const raw::ChannelID_t MaxPresentChannel, const std::set< unsigned int > BadChannels, const std::set< unsigned int > NoisyChannels)
Class providing information about the quality of channels.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
BOOST_AUTO_TEST_CASE(SimpleStatusTest)
static QCString * s
Definition: config.cpp:1042
void put(std::string const &key)
const raw::ChannelID_t fMaxChannel
QTextStream & endl(QTextStream &s)
const std::set< unsigned int > fBadChannels
std::string to_string() const
Definition: ParameterSet.h:153
void test_simple_status()