|
| 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 | +} |
0 commit comments