Classes | Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
arttest::SimpleDerivedAnalyzer Class Reference
Inheritance diagram for arttest::SimpleDerivedAnalyzer:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

Classes

struct  Config
 

Public Types

using SimpleDerivedProduct = std::vector< SimpleDerived >
 
using Parameters = Table< Config >
 
- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 

Public Member Functions

 SimpleDerivedAnalyzer (Parameters const &p)
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob ()
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
std::string const & processName () const
 
bool wantAllEvents () const
 
bool wantEvent (Event const &e)
 
fhicl::ParameterSetID selectorConfig () const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

void analyze (art::Event const &e) override
 
void test_getView (art::Event const &e) const
 
void test_getViewReturnFalse (art::Event const &e) const
 
void test_getViewThrowing (art::Event const &e) const
 
void test_PtrVector (art::Event const &e) const
 
template<typename DATA_TYPE >
void test_PtrVector (art::PtrVector< DATA_TYPE > const &v, art::EventNumber_t event_num, std::size_t nElements=expectedSize()) const
 

Static Private Member Functions

static constexpr std::size_t expectedSize ()
 

Private Attributes

art::InputTag const tagWithInstance_
 
art::InputTag const tagForCurrentProcess_
 
std::size_t const nvalues_
 
art::ProductToken< art::PtrVector< SimpleDerived > > const ptrVectorToken_
 
art::ViewToken< dummy > const dummyToken_
 
art::ViewToken< Simple > const simpleToken_
 
art::ViewToken< Simple > const simpleCurrentToken_
 
art::ViewToken< SimpleDerived > const simpleDerivedToken_
 
art::ViewToken< SimpleDerived > const simpleDerivedCurrentToken_
 

Additional Inherited Members

- Protected Member Functions inherited from art::Observer
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &paths, fhicl::ParameterSet const &config)
 
detail::ProcessAndEventSelectorsprocessAndEventSelectors ()
 

Detailed Description

Definition at line 44 of file SimpleDerivedAnalyzer_module.cc.

Member Typedef Documentation

Definition at line 53 of file SimpleDerivedAnalyzer_module.cc.

Definition at line 46 of file SimpleDerivedAnalyzer_module.cc.

Constructor & Destructor Documentation

SimpleDerivedAnalyzer::SimpleDerivedAnalyzer ( Parameters const &  p)
explicit

Definition at line 92 of file SimpleDerivedAnalyzer_module.cc.

94  , tagWithInstance_{p().input_label(), "derived"}
95  , tagForCurrentProcess_{p().input_label(), "derived", "DEVEL"}
96  , nvalues_{p().nvalues()}
97  , ptrVectorToken_{consumes<art::PtrVector<SimpleDerived>>(
98  art::InputTag{p().input_label2()})}
99  , dummyToken_{consumesView<dummy>(art::InputTag{p().input_label()})}
100 {}
art::ProductToken< art::PtrVector< SimpleDerived > > const ptrVectorToken_
p
Definition: test.py:228
art::ViewToken< dummy > const dummyToken_

Member Function Documentation

void SimpleDerivedAnalyzer::analyze ( art::Event const &  e)
overrideprivatevirtual

Implements art::EDAnalyzer.

Definition at line 103 of file SimpleDerivedAnalyzer_module.cc.

104 {
105  test_getView(e);
106  // TODO: uncomment this when getView is modified to return false
107  // upon not finding the right label.
108  // test_getViewReturnFalse(e);
110  test_PtrVector(e);
112  e.getView(simpleDerivedCurrentToken_, v);
113  assert(v.isValid());
115 
117  e.getView(simpleCurrentToken_, vB);
118  assert(vB.isValid());
120 }
void test_PtrVector(art::Event const &e) const
void check_for_conversion(art::View< T > const &v)
art::ViewToken< SimpleDerived > const simpleDerivedCurrentToken_
const double e
art::ViewToken< Simple > const simpleCurrentToken_
void test_getViewThrowing(art::Event const &e) const
Definition: fwd.h:43
auto isValid() const
Definition: View.h:60
void test_getView(art::Event const &e) const
static constexpr std::size_t arttest::SimpleDerivedAnalyzer::expectedSize ( )
inlinestaticprivate

Definition at line 66 of file SimpleDerivedAnalyzer_module.cc.

67  {
68  return 16;
69  }
void SimpleDerivedAnalyzer::test_getView ( art::Event const &  e) const
private

Definition at line 172 of file SimpleDerivedAnalyzer_module.cc.

173 {
174  // Make sure we can get views into products that are present.
177 } // test_getView()
void test_view(art::Event const &e, art::ViewToken< T > const &token, art::ViewToken< T > const &tokenForCurrentProcess, std::size_t const nvalues)
art::ViewToken< SimpleDerived > const simpleDerivedToken_
art::ViewToken< SimpleDerived > const simpleDerivedCurrentToken_
const double e
art::ViewToken< Simple > const simpleCurrentToken_
art::ViewToken< Simple > const simpleToken_
void SimpleDerivedAnalyzer::test_getViewReturnFalse ( art::Event const &  e) const
private

Definition at line 180 of file SimpleDerivedAnalyzer_module.cc.

181 {
182  std::vector<int const*> ints;
183  try {
184  assert(e.getView("nothing with this illegal label", ints) == false);
185  }
186  catch (std::exception& e) {
187  std::cerr << e.what() << '\n';
188  assert("Unexpected exception thrown" == 0);
189  }
190  catch (...) {
191  assert("Unexpected exception thrown" == 0);
192  }
193 }
const double e
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void SimpleDerivedAnalyzer::test_getViewThrowing ( art::Event const &  e) const
private

Definition at line 196 of file SimpleDerivedAnalyzer_module.cc.

197 {
198  // Make sure attempts to get views into products that are not there
199  // fail correctly.
200  std::vector<dummy const*> dummies;
201  try {
202  e.getView(dummyToken_, dummies);
203  assert("Failed to throw required exception" == 0);
204  }
205  catch (art::Exception& e) {
206  assert(e.categoryCode() == art::errors::ProductNotFound);
207  }
208  catch (...) {
209  assert("Wrong exception thrown" == 0);
210  }
211 }
const double e
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
art::ViewToken< dummy > const dummyToken_
void SimpleDerivedAnalyzer::test_PtrVector ( art::Event const &  e) const
private

Definition at line 214 of file SimpleDerivedAnalyzer_module.cc.

215 {
216  auto const event_num = e.id().event();
218  using base_product_t = art::PtrVector<arttest::Simple>;
219 
220  // Read the data.
221  auto const& d = *e.getValidHandle(ptrVectorToken_);
222  auto const sz = d.size();
223  if (sz != expectedSize()) {
224  throw cet::exception("SizeMismatch")
225  << "Expected a PtrVector of size " << expectedSize()
226  << " but the obtained size is " << sz << '\n';
227  }
228  // Test the data
229  test_PtrVector(d, event_num);
230  // Construct from PtrVector<U>
231  {
232  base_product_t s{d};
233  test_PtrVector(s, event_num);
234  product_t p{s};
235  test_PtrVector(p, event_num);
236  }
237  // Construct from initializer list.
238  {
239  auto i(d.cbegin());
240  auto il = {*(i++), *i};
241  base_product_t s{il};
242  test_PtrVector(s, event_num, 2);
243  product_t p({s.front(), s.back()});
244  test_PtrVector(p, event_num, 2);
245  }
246  // Operator= from PtrVector<U>.
247  {
248  base_product_t s;
249  s = d;
250  test_PtrVector(s, event_num);
251  product_t p;
252  p = s;
253  test_PtrVector(p, event_num);
254  }
255  // Operator= from initializer list.
256  {
257  auto i(d.cbegin());
258  base_product_t s;
259  s = {*(i++), *i};
260  test_PtrVector(s, event_num, 2);
261  product_t p;
262  p = {s.front(), s.back()};
263  test_PtrVector(p, event_num, 2);
264  }
265  // Assign from Ptr<U>.
266  {
267  base_product_t s{d};
268  s.assign(1, d.front());
269  test_PtrVector(s, event_num, 1);
270  product_t p{s};
271  p.assign(1, s.front());
272  test_PtrVector(p, event_num, 1);
273  }
274  // Assign from iterators.
275  {
276  base_product_t s{d};
277  s.assign(d.cbegin(), d.cend());
278  test_PtrVector(s, event_num);
279  product_t p{s};
280  p.assign(s.cbegin(), s.cend());
281  test_PtrVector(p, event_num);
282  }
283  // Assign from initializer list.
284  {
285  auto i(d.cbegin());
286  base_product_t s{d};
287  s.assign({*(i++), *i});
288  test_PtrVector(s, event_num, 2);
289  product_t p{s};
290  p.assign({s.front(), s.back()});
291  test_PtrVector(p, event_num, 2);
292  }
293  // Push back.
294  {
295  base_product_t s;
296  s.push_back(d.front());
297  test_PtrVector(s, event_num, 1);
298  product_t p;
299  p.push_back(s.front());
300  test_PtrVector(p, event_num, 1);
301  }
302  // Insert from Ptr<U>.
303  {
304  base_product_t s({d[1]});
305  s.insert(s.begin(), d.front());
306  test_PtrVector(s, event_num, 2);
307  base_product_t p({s.back()});
308  p.insert(p.begin(), s.front());
309  test_PtrVector(p, event_num, 2);
310  }
311  // Insert from iterators.
312  {
313  base_product_t s;
314  s.insert(s.begin(), d.cbegin(), d.cend());
315  test_PtrVector(s, event_num);
316  product_t p;
317  p.insert(p.begin(), s.cbegin(), s.cend());
318  test_PtrVector(p, event_num);
319  }
320  // Erase.
321  {
322  base_product_t s{d};
323  s.erase(s.end() - 1);
324  test_PtrVector(s, event_num, expectedSize() - 1);
325  s.erase(s.begin() + 1, s.end());
326  test_PtrVector(s, event_num, 1);
327  }
328 }
void test_PtrVector(art::Event const &e) const
const double e
static constexpr std::size_t expectedSize()
art::ProductToken< art::PtrVector< SimpleDerived > > const ptrVectorToken_
p
Definition: test.py:228
static const double s
Definition: Units.h:99
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<typename DATA_TYPE >
void SimpleDerivedAnalyzer::test_PtrVector ( art::PtrVector< DATA_TYPE > const &  v,
art::EventNumber_t  event_num,
std::size_t  nElements = expectedSize() 
) const
private

Definition at line 332 of file SimpleDerivedAnalyzer_module.cc.

335 {
336  auto const sz(v.size());
337  if (sz != nElements) {
338  throw cet::exception("SizeMismatch")
339  << "Expected size " << nElements << " but got " << sz << ".\n";
340  }
341  auto const b = v.cbegin();
342  auto const e = v.cbegin() + nElements;
343  for (auto i = b; i != e; ++i) {
344  std::size_t const k = i - b;
345  if (static_cast<std::size_t>((*i)->key) != expectedSize() - k + event_num) {
346  throw cet::exception("KeyMismatch")
347  << "At position " << k << " expected key "
348  << expectedSize() - k + event_num << " but obtained " << (*i)->key
349  << ".\n";
350  }
351  assert(*i == *i); // Check operator ==.
352  if (k == 0 && sz > 1) {
353  assert(*i != *(i + 1)); // Check operator !=.
354  assert(*(i) < *(i + 1)); // Check operator <.
355  }
356 
357  double const expect{1.5 * k + 100.0};
358  if ((*i)->value != expect) {
359  throw cet::exception("ValueMismatch")
360  << "At position " << k << " expected value " << expect
361  << " but obtained " << (*i)->value << ".\n";
362  }
363  if ((*i)->dummy() != 16.25) {
364  throw cet::exception("ValueMismatch")
365  << "At position " << k << " expected dummy value " << 16.25
366  << " but obtained " << (*i)->dummy() << ".\n";
367  }
368  }
369 } // test_PtrVector()
const double e
const_iterator cbegin() const
Definition: PtrVector.h:279
static constexpr std::size_t expectedSize()
size_type size() const
Definition: PtrVector.h:308
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33

Member Data Documentation

art::ViewToken<dummy> const arttest::SimpleDerivedAnalyzer::dummyToken_
private

Definition at line 80 of file SimpleDerivedAnalyzer_module.cc.

std::size_t const arttest::SimpleDerivedAnalyzer::nvalues_
private

Definition at line 78 of file SimpleDerivedAnalyzer_module.cc.

art::ProductToken<art::PtrVector<SimpleDerived> > const arttest::SimpleDerivedAnalyzer::ptrVectorToken_
private

Definition at line 79 of file SimpleDerivedAnalyzer_module.cc.

art::ViewToken<Simple> const arttest::SimpleDerivedAnalyzer::simpleCurrentToken_
private
Initial value:
{
consumesView<Simple>(tagForCurrentProcess_)}

Definition at line 84 of file SimpleDerivedAnalyzer_module.cc.

art::ViewToken<SimpleDerived> const arttest::SimpleDerivedAnalyzer::simpleDerivedCurrentToken_
private
Initial value:
{
consumesView<SimpleDerived>(tagForCurrentProcess_)}

Definition at line 88 of file SimpleDerivedAnalyzer_module.cc.

art::ViewToken<SimpleDerived> const arttest::SimpleDerivedAnalyzer::simpleDerivedToken_
private
Initial value:
{
consumesView<SimpleDerived>(tagWithInstance_)}

Definition at line 86 of file SimpleDerivedAnalyzer_module.cc.

art::ViewToken<Simple> const arttest::SimpleDerivedAnalyzer::simpleToken_
private
Initial value:
{
consumesView<Simple>(tagWithInstance_)}

Definition at line 82 of file SimpleDerivedAnalyzer_module.cc.

art::InputTag const arttest::SimpleDerivedAnalyzer::tagForCurrentProcess_
private

Definition at line 77 of file SimpleDerivedAnalyzer_module.cc.

art::InputTag const arttest::SimpleDerivedAnalyzer::tagWithInstance_
private

Definition at line 76 of file SimpleDerivedAnalyzer_module.cc.


The documentation for this class was generated from the following file: