$treeview $search $mathjax $extrastylesheet
artdaq_demo
v3_04_01
$projectbrief
|
$projectbrief
|
$searchbox |
00001 00002 // Class: CheckIntegrity 00003 // Module Type: analyzer 00004 // File: CheckIntegrity_module.cc 00005 // Description: Prints out information about each event. 00007 00008 #include "art/Framework/Core/EDAnalyzer.h" 00009 #include "art/Framework/Core/ModuleMacros.h" 00010 #include "art/Framework/Principal/Event.h" 00011 #include "art/Framework/Principal/Handle.h" 00012 #include "canvas/Utilities/Exception.h" 00013 00014 #include "artdaq-core-demo/Overlays/ToyFragment.hh" 00015 #include "artdaq-core/Data/ContainerFragment.hh" 00016 #include "artdaq-core/Data/Fragment.hh" 00017 00018 #include "tracemf.h" // TLOG 00019 #define TRACE_NAME "CheckIntegrity" 00020 00021 #include <algorithm> 00022 #include <cassert> 00023 #include <cmath> 00024 #include <fstream> 00025 #include <iomanip> 00026 #include <vector> 00027 #include <iostream> 00028 00029 namespace demo 00030 { 00031 class CheckIntegrity; 00032 } 00033 00037 class demo::CheckIntegrity : public art::EDAnalyzer 00038 { 00039 public: 00048 explicit CheckIntegrity(fhicl::ParameterSet const& pset); 00049 00053 virtual ~CheckIntegrity() = default; 00054 00059 virtual void analyze(art::Event const& evt); 00060 00061 private: 00062 std::string raw_data_label_; 00063 }; 00064 00065 00066 demo::CheckIntegrity::CheckIntegrity(fhicl::ParameterSet const& pset) 00067 : EDAnalyzer(pset) 00068 , raw_data_label_(pset.get<std::string>("raw_data_label")) 00069 {} 00070 00071 void demo::CheckIntegrity::analyze(art::Event const& evt) 00072 { 00073 00074 00075 artdaq::Fragments fragments; 00076 artdaq::FragmentPtrs containerFragments; 00077 std::vector<std::string> fragment_type_labels{ "TOY1", "TOY2", "ContainerTOY1", "ContainerTOY2" }; 00078 00079 for (auto label : fragment_type_labels) 00080 { 00081 art::Handle<artdaq::Fragments> fragments_with_label; 00082 00083 evt.getByLabel(raw_data_label_, label, fragments_with_label); 00084 if (!fragments_with_label.isValid()) continue; 00085 00086 if (label == "Container" || label == "ContainerTOY1" || label == "ContainerTOY2") 00087 { 00088 for (auto cont : *fragments_with_label) 00089 { 00090 artdaq::ContainerFragment contf(cont); 00091 for (size_t ii = 0; ii < contf.block_count(); ++ii) 00092 { 00093 containerFragments.push_back(contf[ii]); 00094 fragments.push_back(*containerFragments.back()); 00095 } 00096 } 00097 } 00098 else 00099 { 00100 for (auto frag : *fragments_with_label) 00101 { 00102 fragments.emplace_back(frag); 00103 } 00104 } 00105 } 00106 00107 TLOG(TLVL_INFO) << "Run " << evt.run() << ", subrun " << evt.subRun() 00108 << ", event " << evt.event() << " has " << fragments.size() 00109 << " fragment(s) of type TOY1 or TOY2"; 00110 00111 bool err = false; 00112 for (const auto& frag : fragments) 00113 { 00114 ToyFragment bb(frag); 00115 00116 if (bb.hdr_event_size() * sizeof(ToyFragment::Header::data_t) != frag.dataSize() * sizeof(artdaq::RawDataType)) 00117 { 00118 TLOG(TLVL_ERROR) << "Error: in run " << evt.run() << ", subrun " << evt.subRun() << 00119 ", event " << evt.event() << ", seqID " << frag.sequenceID() << 00120 ", fragID " << frag.fragmentID() << ": Size mismatch!" << 00121 " ToyFragment Header reports size of " << bb.hdr_event_size() * sizeof(ToyFragment::Header::data_t) << " bytes, Fragment report size of " << frag.dataSize() * sizeof(artdaq::RawDataType) << " bytes."; 00122 continue; 00123 } 00124 00125 00126 { 00127 auto adc_iter = bb.dataBeginADCs(); 00128 ToyFragment::adc_t expected_adc = 1; 00129 00130 for (; adc_iter != bb.dataEndADCs(); adc_iter++, expected_adc++) 00131 { 00132 if (expected_adc > bb.adc_range(frag.metadata<ToyFragment::Metadata>()->num_adc_bits)) expected_adc = 0; 00133 00134 // ELF 7/10/18: Distribution type 2 is the monotonically-increasing one 00135 if (bb.hdr_distribution_type() == 2 && *adc_iter != expected_adc) 00136 { 00137 TLOG(TLVL_ERROR) << "Error: in run " << evt.run() << ", subrun " << evt.subRun() << 00138 ", event " << evt.event() << ", seqID " << frag.sequenceID() << 00139 ", fragID " << frag.fragmentID() << ": expected an ADC value of " << expected_adc << 00140 ", got " << *adc_iter; 00141 err = true; 00142 break; 00143 } 00144 00145 // ELF 7/10/18: As of now, distribution types 3 and 4 are uninitialized, and can therefore produce out-of-range counts. 00146 if (bb.hdr_distribution_type() < 3 && *adc_iter > bb.adc_range(frag.metadata<ToyFragment::Metadata>()->num_adc_bits)) 00147 { 00148 TLOG(TLVL_ERROR) << "Error: in run " << evt.run() << ", subrun " << evt.subRun() << 00149 ", event " << evt.event() << ", seqID " << frag.sequenceID() << 00150 ", fragID " << frag.fragmentID() << ": " << *adc_iter << " is out-of-range for this Fragment type"; 00151 err = true; 00152 break; 00153 } 00154 } 00155 00156 } 00157 } 00158 if (!err) { 00159 TLOG(TLVL_DEBUG) << "In run " << evt.run() << ", subrun " << evt.subRun() << 00160 ", event " << evt.event() << ", everything is fine"; 00161 } 00162 } 00163 00164 DEFINE_ART_MODULE(demo::CheckIntegrity)