Project
Loading...
Searching...
No Matches
testTRUDataHandler.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11#define BOOST_TEST_MODULE Test EMCAL Reconstruction
12#define BOOST_TEST_MAIN
13#define BOOST_TEST_DYN_LINK
14#include <boost/test/unit_test.hpp>
15#include <set>
16#include <TRandom.h>
19
20namespace o2
21{
22namespace emcal
23{
24
25BOOST_AUTO_TEST_CASE(TRUDataHandler_test)
26{
27 o2::emcal::TRUDataHandler testhandler;
28
29 // no patch set
30 BOOST_CHECK_EQUAL(testhandler.hasAnyPatch(), false);
31 for (int ipatch = 0; ipatch < o2::emcal::TriggerMappingV2::PATCHESINTRU; ipatch++) {
32 BOOST_CHECK_EQUAL(testhandler.hasPatch(ipatch), false);
33 }
34
35 // set all patches with L0 time 8
36 for (int ipatch = 0; ipatch < o2::emcal::TriggerMappingV2::PATCHESINTRU; ipatch++) {
37 testhandler.setPatch(ipatch, 8);
38 }
39 BOOST_CHECK_EQUAL(testhandler.hasAnyPatch(), true);
40 for (int ipatch = 0; ipatch < o2::emcal::TriggerMappingV2::PATCHESINTRU; ipatch++) {
41 BOOST_CHECK_EQUAL(testhandler.hasPatch(ipatch), true);
42 BOOST_CHECK_EQUAL(testhandler.getPatchTime(ipatch), 8);
43 }
44
45 // test reset
46 testhandler.reset();
47 BOOST_CHECK_EQUAL(testhandler.hasAnyPatch(), false);
48 for (int ipatch = 0; ipatch < o2::emcal::TriggerMappingV2::PATCHESINTRU; ipatch++) {
49 BOOST_CHECK_EQUAL(testhandler.hasPatch(ipatch), false);
50 }
51
52 // test error handling
53 for (int8_t index = o2::emcal::TriggerMappingV2::PATCHESINTRU; index < INT8_MAX; index++) {
54 BOOST_CHECK_EXCEPTION(testhandler.hasPatch(index), o2::emcal::TRUDataHandler::PatchIndexException, [index](const o2::emcal::TRUDataHandler::PatchIndexException& e) { return e.getIndex() == index; });
55 BOOST_CHECK_EXCEPTION(testhandler.setPatch(index, 8), o2::emcal::TRUDataHandler::PatchIndexException, [index](const o2::emcal::TRUDataHandler::PatchIndexException& e) { return e.getIndex() == index; });
56 }
57
58 for (int iiter = 0; iiter < 100; iiter++) {
59 // For 100 iterations simulate patch index and time
60 std::map<uint8_t, uint8_t> patchtimes;
61 int npatches_expect = static_cast<int>(gRandom->Uniform(0, o2::emcal::TriggerMappingV2::PATCHESINTRU));
62 while (patchtimes.size() < npatches_expect) {
63 auto patchindex = static_cast<int>(gRandom->Uniform(0, o2::emcal::TriggerMappingV2::PATCHESINTRU));
64 if (patchtimes.find(patchindex) == patchtimes.end()) {
65 auto patchtime = static_cast<int>(gRandom->Gaus(8, 1));
66 if (patchtime >= 12) {
67 patchtime = 11;
68 }
69 patchtimes[patchindex] = patchtime;
70 }
71 }
72 o2::emcal::TRUDataHandler iterhandler;
73 iterhandler.setFired(npatches_expect > 0);
74 for (auto [patchindex, patchtime] : patchtimes) {
75 iterhandler.setPatch(patchindex, patchtime);
76 }
77
78 BOOST_CHECK_EQUAL(iterhandler.isFired(), npatches_expect > 0);
79 BOOST_CHECK_EQUAL(iterhandler.hasAnyPatch(), npatches_expect > 0);
80 for (auto ipatch = 0; ipatch < o2::emcal::TriggerMappingV2::PATCHESINTRU; ipatch++) {
81 auto hasPatch = patchtimes.find(ipatch) != patchtimes.end();
82 BOOST_CHECK_EQUAL(iterhandler.hasPatch(ipatch), hasPatch);
83 if (hasPatch) {
84 BOOST_CHECK_EQUAL(iterhandler.getPatchTime(ipatch), patchtimes[ipatch]);
85 }
86 }
87 }
88}
89
90} // namespace emcal
91
92} // namespace o2
Handler of errors related to invalid trigger patch IDs.
Helper class to handle decoded TRU data during the reconstruction.
bool hasPatch(unsigned int index) const
Check whehther the patch at the given index has fired.
uint8_t getPatchTime(unsigned int index) const
Get the trigger time of the trigger patch at a given index.
void setPatch(unsigned int index, unsigned int time)
Set reconstructed trigger patch.
bool isFired() const
Check whether the TRU was fired (at least one patch above threshold)
void setFired(bool fired)
Mark TRU as fired (containing at least one patch above threshold)
bool hasAnyPatch() const
Check whether the TRU has any patch fired.
void reset()
Reset handler.
static constexpr unsigned int PATCHESINTRU
GLuint index
Definition glcorearb.h:781
BOOST_AUTO_TEST_CASE(asynch_schedule_test)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())