artdaq_demo  v3_02_00
CheckIntegrity_module.cc
1 // Class: CheckIntegrity
3 // Module Type: analyzer
4 // File: CheckIntegrity_module.cc
5 // Description: Prints out information about each event.
7 
8 #include "art/Framework/Core/EDAnalyzer.h"
9 #include "art/Framework/Core/ModuleMacros.h"
10 #include "art/Framework/Principal/Event.h"
11 #include "art/Framework/Principal/Handle.h"
12 #include "canvas/Utilities/Exception.h"
13 
14 #include "artdaq-core-demo/Overlays/ToyFragment.hh"
15 #include "artdaq-core/Data/Fragment.hh"
16 
17 #include "messagefacility/MessageLogger/MessageLogger.h"
18 
19 #include <algorithm>
20 #include <cassert>
21 #include <cmath>
22 #include <fstream>
23 #include <iomanip>
24 #include <vector>
25 #include <iostream>
26 
27 namespace demo
28 {
29  class CheckIntegrity;
30 }
31 
35 class demo::CheckIntegrity : public art::EDAnalyzer
36 {
37 public:
46  explicit CheckIntegrity(fhicl::ParameterSet const& pset);
47 
51  virtual ~CheckIntegrity() = default;
52 
57  virtual void analyze(art::Event const& evt);
58 
59 private:
60  std::string raw_data_label_;
61  std::string frag_type_;
62 };
63 
64 
65 demo::CheckIntegrity::CheckIntegrity(fhicl::ParameterSet const& pset)
66  : EDAnalyzer(pset)
67  , raw_data_label_(pset.get<std::string>("raw_data_label"))
68  , frag_type_(pset.get<std::string>("frag_type")) {}
69 
70 void demo::CheckIntegrity::analyze(art::Event const& evt)
71 {
72  art::Handle<artdaq::Fragments> raw;
73  evt.getByLabel(raw_data_label_, frag_type_, raw);
74 
75  if (raw.isValid())
76  {
77  for (size_t idx = 0; idx < raw->size(); ++idx)
78  {
79  const auto& frag((*raw)[idx]);
80 
81  ToyFragment bb(frag);
82 
83  {
84  auto adc_iter = bb.dataBeginADCs();
85  ToyFragment::adc_t expected_adc = 1;
86 
87  for (; adc_iter != bb.dataEndADCs(); adc_iter++ , expected_adc++)
88  {
89  if (*adc_iter != expected_adc)
90  {
91  mf::LogError("CheckIntegrity") << "Error: in run " << evt.run() << ", subrun " << evt.subRun() <<
92  ", event " << evt.event() << ", seqID " << frag.sequenceID() <<
93  ", fragID " << frag.fragmentID() << ": expected an ADC value of " << expected_adc <<
94  ", got " << *adc_iter;
95  return;
96  }
97  }
98 
99  mf::LogDebug("CheckIntegrity") << "In run " << evt.run() << ", subrun " << evt.subRun() <<
100  ", event " << evt.event() << ", everything is fine";
101  }
102  }
103  }
104  else
105  {
106  mf::LogError("CheckIntegrity") << "In run " << evt.run() << ", subrun " << evt.subRun() <<
107  ", event " << evt.event() << ", raw.isValid() returned false";
108  }
109 }
110 
111 DEFINE_ART_MODULE(demo::CheckIntegrity)
virtual void analyze(art::Event const &evt)
Analyze an event. Called by art for each event in run (based on command line options) ...
virtual ~CheckIntegrity()=default
Default destructor.
Demonstration art::EDAnalyzer which checks that all ToyFragment ADC counts are in the defined range...
CheckIntegrity(fhicl::ParameterSet const &pset)
CheckIntegrity Constructor.