11 #include "art_root_io/TFileService.h" 15 #include "artdaq-core/Data/Fragment.hh" 16 #include "artdaq-core/Data/ContainerFragment.hh" 32 class FelixIntegrityTest;
73 <<
"SequenceID: " << sequenceID
74 <<
" fragmentID: " << fragmentID
75 <<
" fragmentType: " << type
76 <<
" Timestamp: " << timestamp
77 <<
" Crate number: " << crate_no
78 <<
" Slot number: " << slot_no
79 <<
" Fiber number: " << fiber_no <<
"\n\n";
80 std::cout <<
"Metadata error: ";
81 meta_err? std::cout <<
"YES\n" : std::cout <<
"NO\n";
82 std::cout <<
"Timestamp error: ";
83 timestamp_err? std::cout <<
"YES\n" : std::cout <<
"NO\n";
84 std::cout <<
"Convert count error: ";
85 convert_count_err? std::cout <<
"YES\n" : std::cout <<
"NO\n";
120 std::cout <<
"-------------------- FELIX Integrity Test -------------------";
128 try { cont_frags->size(); }
130 std::cout <<
"WARNING: Container FELIX data not found in event " << eventNumber <<
std::endl;
136 <<
"Run: " << evt.
run()
137 <<
", SubRun: " << evt.
subRun()
138 <<
", Event: " << evt.
event()
139 <<
" Container Fragment data invalid";
142 for (
auto const& cont : *cont_frags)
144 artdaq::ContainerFragment cont_frag(cont);
145 for (
size_t ii = 0; ii < cont_frag.block_count(); ++ii)
160 try { frags->size(); }
162 std::cout <<
"WARNING: Raw FELIX data not found in event " << eventNumber <<
std::endl;
169 <<
"Run: " << evt.
run()
170 <<
", SubRun: " << evt.
subRun()
171 <<
", Event: " << evt.
event()
172 <<
" Fragment data invalid";
175 for(
auto const& frag: *frags)
188 <<
" FELIX Fragments.\nFound " << n_good_frags
189 <<
" good fragments. Success rate: " 190 << (double)n_good_frags/n_frags <<
"/1.\n\n";
194 uint64_t crate_no, slot_no, fiber_no;
196 if(crate_no == b.crate_no && slot_no == b.slot_no) {
197 return fiber_no < b.fiber_no;
198 }
else if(crate_no == b.crate_no) {
199 return slot_no < b.slot_no;
201 return crate_no < b.crate_no;
205 unsigned long meta_err, timestamp_err, convert_count_err, error_fields_set;
207 meta_err += other.meta_err;
208 timestamp_err += other.timestamp_err;
209 convert_count_err += other.convert_count_err;
210 error_fields_set += other.error_fields_set;
214 std::map<Location, Errors> errMap;
216 Location
loc = {errm.crate_no, errm.slot_no, errm.fiber_no};
217 Errors
err = {(
unsigned long)errm.meta_err, (
unsigned long)errm.timestamp_err,
218 (
unsigned long)errm.convert_count_err, (
unsigned long)errm.error_fields_set};
222 std::cout <<
"Error rates\n";
223 std::cout <<
"Crate:Slot:Fiber | Metadata error | Timestamp error | Convert count error | Error fields set\n" 224 <<
"--------------------------------------------------------------------------------------------\n";
225 for(
const std::pair<Location, Errors>&
p : errMap) {
227 if(
p.second.meta_err) std::cout <<
std::setw(14) << (double)
p.second.meta_err/n_frags <<
" | ";
228 else std::cout <<
std::setw(14) <<
" " <<
" | ";
229 if(
p.second.timestamp_err) std::cout <<
std::setw(15) << (double)
p.second.timestamp_err/n_frags <<
" | ";
230 else std::cout <<
std::setw(15) <<
" " <<
" | ";
231 if(
p.second.convert_count_err) std::cout <<
std::setw(19) << (double)
p.second.convert_count_err/n_frags <<
" | ";
232 else std::cout <<
std::setw(19) <<
" " <<
" | ";
233 if(
p.second.error_fields_set) std::cout <<
std::setw(16) << (double)
p.second.error_fields_set/n_frags;
246 <<
"-------------------- Testing fragment -------------------" <<
'\n' 247 <<
"SequenceID: " << frag.sequenceID()
248 <<
" fragmentID: " << frag.fragmentID()
249 <<
" fragmentType: " << (unsigned)frag.type()
250 <<
" Timestamp: " << frag.timestamp()
253 <<
" Fiber number: " << (
int)flxfrag.
fiber_no() <<
"\n\n";
257 bool meta_failed =
false;
271 <<
"Metadata error." <<
'\n' 272 <<
" This fragment's metadata: " <<
'\n' 274 <<
" Version: " << meta->
version 280 <<
" Expected metadata: " <<
'\n' 290 <<
"Metadata test successful." <<
"\n\n";
295 bool timestamp_failed =
false;
298 timestamp_failed =
true;
300 <<
"First timestamp matching error." <<
'\n' 301 <<
" This fragment's timestamp: " << frag.timestamp()
302 <<
" First frame's timestamp: " << flxfrag.
timestamp(0)
304 <<
" Offset: " << frag.timestamp() - flxfrag.
timestamp(0) <<
"\n\n";
308 timestamp_failed =
true;
310 <<
"Trigger window error." <<
'\n' 311 <<
" This fragment's expected number of frames: " << meta->
window_frames 312 <<
" Number of frames available: " << flxfrag.
timestamp(0) <<
"\n\n";
315 for(
unsigned fi = 1; fi < flxfrag.
total_frames(); ++fi) {
317 timestamp_failed =
true;
319 <<
"Timestamp increase error." <<
'\n' 320 <<
" Timestamp of frame " << fi - 1 <<
": " << flxfrag.
timestamp(fi-1)
321 <<
" Timestamp of frame " << fi <<
": " << flxfrag.
timestamp(fi)
326 if(!timestamp_failed) {
328 <<
"Timestamp test successful." <<
"\n\n";
332 bool convert_count_failed =
false;
334 for(
unsigned fi = 1; fi < flxfrag.
total_frames(); ++fi) {
336 for(
int bi = 0; bi < 2; ++bi) {
342 convert_count_failed =
true;
344 <<
"COLDATA convert count increase error in frame " << fi <<
".\n" 358 if(convert_count_failed)
break;
360 if(!convert_count_failed) {
362 <<
"COLDATA convert count test successful." <<
"\n\n";
366 bool error_field_failed =
false;
398 outem.
type = frag.type();
409 outem.
bad = timestamp_failed || convert_count_failed || error_field_failed;
size_t total_frames() const
EventNumber_t event() const
uint8_t slot_no(const unsigned &frame_ID=0) const
DoubleProduct & operator+=(DoubleProduct &left, DoubleProduct const &right)
Handle< PROD > getHandle(SelectorBase const &) const
std::vector< ErrorMetrics > test_results
uint8_t crate_no(const unsigned &frame_ID=0) const
FelixIntegrityTest & operator=(FelixIntegrityTest const &)=delete
#define MF_LOG_ERROR(category)
EDAnalyzer(fhicl::ParameterSet const &pset)
bool operator<(ProductInfo const &a, ProductInfo const &b)
#define DEFINE_ART_MODULE(klass)
dune::FelixFragmentBase::Metadata run_meta
dune::FelixFragmentBase::Metadata meta
SubRunNumber_t subRun() const
bool _expect_container_fragments
uint16_t coldata_convert_count(const unsigned &frame_ID, const uint8_t &block_num) const
void err(const char *fmt,...)
Q_EXPORT QTSManip setw(int w)
const uint64_t timestamp_increase
const uint16_t convert_count_increase
uint8_t fiber_no(const unsigned &frame_ID=0) const
FelixIntegrityTest(fhicl::ParameterSet const &p)
void analyze(const art::Event &evt) override
IDNumber_t< Level::Event > EventNumber_t
auto const & get(AssnsNode< L, R, D > const &r)
std::string to_string(ModuleType const mt)
std::vector< Fragment > Fragments
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
ErrorMetrics _process(const artdaq::Fragment &frag)
uint64_t timestamp(const unsigned &frame_ID=0) const