Skip to content

Commit 321f716

Browse files
committed
Add HMPID to CTF workflows + CTF unit test
1 parent 2bcb3db commit 321f716

File tree

6 files changed

+130
-1
lines changed

6 files changed

+130
-1
lines changed

Detectors/CTF/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,11 @@ o2_add_test(trd
9595
SOURCES test/test_ctf_io_trd.cxx
9696
COMPONENT_NAME ctf
9797
LABELS ctf)
98+
99+
o2_add_test(hmpid
100+
PUBLIC_LINK_LIBRARIES O2::CTFWorkflow
101+
O2::DataFormatsHMP
102+
O2::HMPIDReconstruction
103+
SOURCES test/test_ctf_io_hmpid.cxx
104+
COMPONENT_NAME ctf
105+
LABELS ctf)
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#define BOOST_TEST_MODULE Test HMPIDCTFIO
12+
#define BOOST_TEST_MAIN
13+
#define BOOST_TEST_DYN_LINK
14+
#include <boost/test/unit_test.hpp>
15+
#include "DetectorsCommonDataFormats/NameConf.h"
16+
#include "HMPIDReconstruction/CTFCoder.h"
17+
#include "DataFormatsHMP/CTF.h"
18+
#include "Framework/Logger.h"
19+
#include <TFile.h>
20+
#include <TRandom.h>
21+
#include <TStopwatch.h>
22+
#include <TSystem.h>
23+
#include <cstring>
24+
25+
using namespace o2::hmpid;
26+
27+
BOOST_AUTO_TEST_CASE(CTFTest)
28+
{
29+
std::vector<Trigger> triggers;
30+
std::vector<Digit> digits;
31+
TStopwatch sw;
32+
sw.Start();
33+
o2::InteractionRecord ir(0, 0);
34+
Digit clu;
35+
for (int irof = 0; irof < 1000; irof++) {
36+
ir += 1 + gRandom->Integer(200);
37+
38+
auto start = digits.size();
39+
uint8_t chID = 0;
40+
int n = 0;
41+
while ((chID += gRandom->Integer(10)) < 0xff) {
42+
uint16_t q = gRandom->Integer(0xffff);
43+
uint8_t ph = gRandom->Integer(0xff);
44+
uint8_t x = gRandom->Integer(0xff);
45+
uint8_t y = gRandom->Integer(0xff);
46+
digits.emplace_back(chID, ph, x, y, q);
47+
}
48+
triggers.emplace_back(ir, start, digits.size() - start);
49+
}
50+
51+
sw.Start();
52+
std::vector<o2::ctf::BufferType> vec;
53+
{
54+
CTFCoder coder;
55+
coder.encode(vec, triggers, digits); // compress
56+
}
57+
sw.Stop();
58+
LOG(INFO) << "Compressed in " << sw.CpuTime() << " s";
59+
60+
// writing
61+
{
62+
sw.Start();
63+
auto* ctfImage = o2::hmpid::CTF::get(vec.data());
64+
TFile flOut("test_ctf_hmpid.root", "recreate");
65+
TTree ctfTree(std::string(o2::base::NameConf::CTFTREENAME).c_str(), "O2 CTF tree");
66+
ctfImage->print();
67+
ctfImage->appendToTree(ctfTree, "HMP");
68+
ctfTree.Write();
69+
sw.Stop();
70+
LOG(INFO) << "Wrote to tree in " << sw.CpuTime() << " s";
71+
}
72+
73+
// reading
74+
vec.clear();
75+
LOG(INFO) << "Start reading from tree ";
76+
{
77+
sw.Start();
78+
TFile flIn("test_ctf_hmpid.root");
79+
std::unique_ptr<TTree> tree((TTree*)flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()));
80+
BOOST_CHECK(tree);
81+
o2::hmpid::CTF::readFromTree(vec, *(tree.get()), "HMP");
82+
sw.Stop();
83+
LOG(INFO) << "Read back from tree in " << sw.CpuTime() << " s";
84+
}
85+
86+
std::vector<Trigger> triggersD;
87+
std::vector<Digit> digitsD;
88+
89+
sw.Start();
90+
const auto ctfImage = o2::hmpid::CTF::getImage(vec.data());
91+
{
92+
CTFCoder coder;
93+
coder.decode(ctfImage, triggersD, digitsD); // decompress
94+
}
95+
sw.Stop();
96+
LOG(INFO) << "Decompressed in " << sw.CpuTime() << " s";
97+
98+
BOOST_CHECK(triggersD.size() == triggers.size());
99+
BOOST_CHECK(digitsD.size() == digits.size());
100+
101+
BOOST_TEST(triggersD == triggers, boost::test_tools::per_element());
102+
BOOST_TEST(digitsD == digits, boost::test_tools::per_element());
103+
}

Detectors/CTF/workflow/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ o2_add_library(CTFWorkflow
2323
O2::DataFormatsMID
2424
O2::DataFormatsPHOS
2525
O2::DataFormatsCPV
26-
O2::DataFormatsZDC
26+
O2::DataFormatsZDC
27+
O2::DataFormatsHMP
2728
O2::DataFormatsParameters
2829
O2::ITSMFTWorkflow
2930
O2::TPCWorkflow
@@ -37,6 +38,7 @@ o2_add_library(CTFWorkflow
3738
O2::PHOSWorkflow
3839
O2::CPVWorkflow
3940
O2::ZDCWorkflow
41+
O2::HMPIDWorkflow
4042
O2::Algorithm
4143
O2::CommonUtils)
4244

Detectors/CTF/workflow/src/CTFReaderSpec.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "DataFormatsPHOS/CTF.h"
3636
#include "DataFormatsCPV/CTF.h"
3737
#include "DataFormatsZDC/CTF.h"
38+
#include "DataFormatsHMP/CTF.h"
3839
#include "Algorithm/RangeTokenizer.h"
3940
#include <TStopwatch.h>
4041

@@ -224,6 +225,13 @@ void CTFReaderSpec::run(ProcessingContext& pc)
224225
setFirstTFOrbit(det.getName());
225226
}
226227

228+
det = DetID::HMP;
229+
if (detsTF[det]) {
230+
auto& bufVec = pc.outputs().make<std::vector<o2::ctf::BufferType>>({det.getName()}, sizeof(o2::hmpid::CTF));
231+
o2::hmpid::CTF::readFromTree(bufVec, *(tree.get()), det.getName());
232+
setFirstTFOrbit(det.getName());
233+
}
234+
227235
mTimer.Stop();
228236
LOG(INFO) << "Read CTF " << inputFile << " in " << mTimer.CpuTime() - cput << " s";
229237

Detectors/CTF/workflow/src/CTFWriterSpec.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "DataFormatsITSMFT/CTF.h"
2525
#include "DataFormatsTPC/CTF.h"
2626
#include "DataFormatsTRD/CTF.h"
27+
#include "DataFormatsHMP/CTF.h"
2728
#include "DataFormatsFT0/CTF.h"
2829
#include "DataFormatsFV0/CTF.h"
2930
#include "DataFormatsFDD/CTF.h"
@@ -225,6 +226,7 @@ void CTFWriterSpec::run(ProcessingContext& pc)
225226
processDet<o2::phos::CTF>(pc, DetID::PHS, header, treeOut.get());
226227
processDet<o2::cpv::CTF>(pc, DetID::CPV, header, treeOut.get());
227228
processDet<o2::zdc::CTF>(pc, DetID::ZDC, header, treeOut.get());
229+
processDet<o2::hmpid::CTF>(pc, DetID::HMP, header, treeOut.get());
228230

229231
mTimer.Stop();
230232

@@ -299,6 +301,8 @@ void CTFWriterSpec::storeDictionaries()
299301
storeDictionary<o2::phos::CTF>(DetID::PHS, header);
300302
storeDictionary<o2::cpv::CTF>(DetID::CPV, header);
301303
storeDictionary<o2::zdc::CTF>(DetID::ZDC, header);
304+
storeDictionary<o2::hmpid::CTF>(DetID::HMP, header);
305+
302306
// close remnants
303307
if (mDictTreeOut) {
304308
closeDictionaryTreeAndFile(header);

Detectors/CTF/workflow/src/ctf-reader-workflow.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "ITSMFTWorkflow/EntropyDecoderSpec.h"
2424
#include "TPCWorkflow/EntropyDecoderSpec.h"
2525
#include "TRDWorkflow/EntropyDecoderSpec.h"
26+
#include "HMPIDWorkflow/EntropyDecoderSpec.h"
2627
#include "FT0Workflow/EntropyDecoderSpec.h"
2728
#include "FV0Workflow/EntropyDecoderSpec.h"
2829
#include "FDDWorkflow/EntropyDecoderSpec.h"
@@ -112,6 +113,9 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
112113
if (dets[DetID::ZDC]) {
113114
specs.push_back(o2::zdc::getEntropyDecoderSpec());
114115
}
116+
if (dets[DetID::HMP]) {
117+
specs.push_back(o2::hmpid::getEntropyDecoderSpec());
118+
}
115119

116120
return std::move(specs);
117121
}

0 commit comments

Comments
 (0)