All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SimpleChannelStatusTest_module.cc
Go to the documentation of this file.
1 /**
2  * @file SimpleChannelStatusTest_module.cc
3  * @brief Integration test for SimpleChannelStatusService
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date November 25th, 2014
6  */
7 
8 // C/C++ standard library
9 
10 // Framework includes
11 #include "fhiclcpp/ParameterSet.h"
12 #include "messagefacility/MessageLogger/MessageLogger.h"
13 #include "art/Framework/Core/ModuleMacros.h"
14 #include "art/Framework/Core/EDAnalyzer.h"
15 #include "art/Framework/Services/Registry/ServiceHandle.h"
16 #include "art/Framework/Principal/Run.h"
17 
18 // LArSoft includes
21 
22 
23 
24 namespace art { class Event; } // art::Event declaration
25 
26 ///tracking algorithms
27 namespace lariov {
28  /**
29  * @brief Tests an instanciation of the ChannelStatusService
30  *
31  * Configuration parameters
32  * =========================
33  *
34  * - **TestBadChannels** (list of integers, default: empty): test singularly
35  * these channels and verify they are bad
36  * - **TestGoodChannels** (list of integers, default: empty): test singularly
37  * these channels and verify they are not bad nor noisy
38  * - **TestNoisyChannels** (list of integers, default: empty): test singularly
39  * these channels and verify they are noisy
40  */
41  class SimpleChannelStatusTest: public art::EDAnalyzer {
42  public:
43  explicit SimpleChannelStatusTest(fhicl::ParameterSet const& pset);
44 
45  virtual void analyze(art::Event const&) override {}
46  virtual void beginRun(art::Run const& run) override;
47 
48  private:
49  std::vector<unsigned int> KnownGoodChannels;
50  std::vector<unsigned int> KnownNoisyChannels;
51  std::vector<unsigned int> KnownBadChannels;
52 
53  template <typename Obj>
54  unsigned int testObject(Obj const* pChStatus) const;
55 
56 
57  static const std::vector<unsigned int> EmptyVect; ///< for initializations
58  }; // class SimpleChannelStatusTest
59 
60 } // namespace lariov
61 
62 
63 //------------------------------------------------------------------------------
64 
65 
66 namespace lariov {
67 
68  const std::vector<unsigned int> SimpleChannelStatusTest::EmptyVect;
69 
70  //......................................................................
72  (fhicl::ParameterSet const& pset)
73  : EDAnalyzer(pset)
74  , KnownGoodChannels
75  (pset.get<std::vector<unsigned int>>("TestGoodChannels", EmptyVect))
76  , KnownNoisyChannels
77  (pset.get<std::vector<unsigned int>>("TestNoisyChannels", EmptyVect))
78  , KnownBadChannels
79  (pset.get<std::vector<unsigned int>>("TestBadChannels", EmptyVect))
80  {
81  mf::LogInfo log("SimpleChannelStatusTest");
82 
83  log << "Channels known as good: " << KnownGoodChannels.size();
84  if (!KnownGoodChannels.empty()) {
85  log << " (";
86  for (unsigned int chId: KnownGoodChannels) log << " " << chId;
87  log << ")";
88  } // if known good channels
89 
90  log << "\nChannels known as noisy: " << KnownNoisyChannels.size();
91  if (!KnownNoisyChannels.empty()) {
92  log << " (";
93  for (unsigned int chId: KnownNoisyChannels) log << " " << chId;
94  log << ")";
95  } // if known noisy channels
96 
97  log << "\nChannels known as bad: " << KnownBadChannels.size();
98  if (!KnownBadChannels.empty()) {
99  log << " (";
100  for (unsigned int chId: KnownBadChannels) log << " " << chId;
101  log << ")";
102  } // if known bad channels
103 
104  } // SimpleChannelStatusTest::SimpleChannelStatusTest()
105 
106 
107  //......................................................................
108  void SimpleChannelStatusTest::beginRun(art::Run const& run) {
109 
110  mf::LogInfo("SimpleChannelStatusTest") << "New run: " << run.run();
111 
112  unsigned int nErrors = 0;
113 
114  //---
115  mf::LogVerbatim("SimpleChannelStatusTest")
116  << "\nTesting service interface...";
117  art::ServiceHandle<lariov::ChannelStatusService const> StatusSrvHandle;
118  /* // since the service does not share the interface of the provider,
119  // this test can't be
120  const lariov::ChannelStatusService* pStatusSrv = &*StatusSrvHandle;
121  nErrors = testObject(pStatusSrv);
122  if (nErrors > 0) {
123  throw art::Exception(art::errors::LogicError)
124  << nErrors << " errors while testing ChannelStatusService!";
125  } // if errors
126  */
127 
128  //---
129  mf::LogVerbatim("SimpleChannelStatusTest")
130  << "\nTesting base interface...";
131  lariov::ChannelStatusProvider const* pChStatus
132  = StatusSrvHandle->GetProviderPtr();
133  nErrors = testObject(pChStatus);
134  if (nErrors > 0) {
135  throw art::Exception(art::errors::LogicError)
136  << nErrors << " errors while testing ChannelStatusProvider!";
137  } // if errors
138 
139  } // SimpleChannelStatusTest::beginRun()
140 
141 
142  //......................................................................
143  template <typename Obj>
144  unsigned int SimpleChannelStatusTest::testObject(Obj const* pChStatus) const
145  {
146  // 1. print all the channels marked non-good
147  {
148  mf::LogInfo log("SimpleChannelStatusTest");
149 
150 
151  // this is a copy of the list;
152  // to avoid creating temporary objects, check channels one by one
153  auto BadChannels = pChStatus->BadChannels();
154  log << "\nChannels marked as bad: " << BadChannels.size();
155  if (!BadChannels.empty()) {
156  log << " (";
157  for (unsigned int chId: BadChannels) log << " " << chId;
158  log << ")";
159  } // if bad channels
160 
161  auto NoisyChannels = pChStatus->NoisyChannels();
162  log << "\nChannels marked as noisy: " << NoisyChannels.size();
163  if (!NoisyChannels.empty()) {
164  log << " (";
165  for (unsigned int chId: NoisyChannels) log << " " << chId;
166  log << ")";
167  } // if noisy channels
168  } // print test
169 
170  // 2. test the channels as in the configuration
171  unsigned int nErrors = 0;
172  for (const auto chId: KnownBadChannels) {
173  if (!pChStatus->IsBad(chId)) {
174  mf::LogError("SimpleChannelStatusTest")
175  << "channel #" << chId << " is not bad as it should";
176  ++nErrors;
177  }
178  } // for knwon bad channels
179 
180  for (const auto chId: KnownNoisyChannels) {
181  if (!pChStatus->IsNoisy(chId)) {
182  mf::LogError("SimpleChannelStatusTest")
183  << "channel #" << chId << " is not noisy as it should";
184  ++nErrors;
185  }
186  } // for knwon noisy channels
187 
188  for (const auto chId: KnownGoodChannels) {
189  if (pChStatus->IsBad(chId)) {
190  mf::LogError("SimpleChannelStatusTest")
191  << "channel #" << chId << " is bad, while it should not";
192  ++nErrors;
193  }
194  if (pChStatus->IsNoisy(chId)) {
195  mf::LogError("SimpleChannelStatusTest")
196  << "channel #" << chId << " is noisy, while it should not";
197  ++nErrors;
198  }
199  } // for knwon good channels
200 
201  return nErrors;
202  } // SimpleChannelStatusTest::testObject()
203 
204 
205  DEFINE_ART_MODULE(SimpleChannelStatusTest)
206 
207 } // namespace lariov
virtual void beginRun(art::Run const &run) override
SimpleChannelStatusTest(fhicl::ParameterSet const &pset)
static const std::vector< unsigned int > EmptyVect
for initializations
virtual void analyze(art::Event const &) override
Tests an instanciation of the ChannelStatusService.
Class providing information about the quality of channels.
BEGIN_PROLOG NoisyChannels
std::vector< unsigned int > KnownNoisyChannels
Interface for experiment-specific channel quality info provider.
unsigned int testObject(Obj const *pChStatus) const
Interface for experiment-specific service for channel quality info.