Project
Loading...
Searching...
No Matches
test-raw-conversion.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
12#include <filesystem>
13#include <TTree.h>
14#include "Framework/Logger.h"
16#include <TFile.h>
17#include <cstring>
18
19using namespace o2::fdd;
20
21int main(int argc, char* argv[])
22{
23 const std::string genDigDile{"fdddigits.root"};
24 const std::string decDigDile{"o2_fdddigits.root"};
25 const std::string branchBC{"FDDDIGITSBC"};
26 const std::string branchCH{"FDDDIGITSCH"};
27
28 if (!std::filesystem::exists(genDigDile)) {
29 LOG(fatal) << "Generated digits file " << genDigDile << " is absent";
30 }
31 TFile flIn(genDigDile.c_str());
32 std::unique_ptr<TTree> tree((TTree*)flIn.Get("o2sim"));
33 if (!flIn.IsOpen() || flIn.IsZombie() || !tree) {
34 LOG(fatal) << "Failed to get tree from generated digits file " << genDigDile;
35 }
36 std::vector<o2::fdd::Digit> digitsBC, *fddBCDataPtr = &digitsBC;
37 std::vector<o2::fdd::ChannelData> digitsCh, *fddChDataPtr = &digitsCh;
38 tree->SetBranchAddress("FDDDIGITSBC", &fddBCDataPtr);
39 tree->SetBranchAddress("FDDDIGITSCH", &fddChDataPtr);
40
41 if (!std::filesystem::exists(decDigDile)) {
42 LOG(fatal) << "Decoded digits file " << genDigDile << " is absent";
43 }
44
45 TFile flIn2(decDigDile.c_str());
46 std::unique_ptr<TTree> tree2((TTree*)flIn2.Get("o2sim"));
47 if (!flIn2.IsOpen() || flIn2.IsZombie() || !tree2) {
48 LOG(fatal) << "Failed to get tree from decoded digits file " << genDigDile;
49 }
50 std::vector<o2::fdd::Digit> digitsBC2, *fddBCDataPtr2 = &digitsBC2;
51 std::vector<o2::fdd::ChannelData> digitsCh2, *fddChDataPtr2 = &digitsCh2;
52 tree2->SetBranchAddress("FDDDIGITSBC", &fddBCDataPtr2);
53 tree2->SetBranchAddress("FDDDIGITSCH", &fddChDataPtr2);
54
55 int nbc = 0, nbc2 = 0, nch = 0, nch2 = 0;
56 for (int ient = 0; ient < tree->GetEntries(); ient++) {
57 tree->GetEntry(ient);
58 int nbcEntry = digitsBC.size();
59 nbc += nbcEntry;
60 for (int ibc = 0; ibc < nbcEntry; ibc++) {
61 auto& bcd = digitsBC[ibc];
62 int bc = bcd.getBC();
63 auto channels = bcd.getBunchChannelData(digitsCh);
64 nch += channels.size();
65 }
66 }
67
68 for (int ient = 0; ient < tree2->GetEntries(); ient++) {
69 tree2->GetEntry(ient);
70 int nbc2Entry = digitsBC2.size();
71 nbc2 += nbc2Entry;
72 for (int ibc = 0; ibc < nbc2Entry; ibc++) {
73 auto& bcd2 = digitsBC2[ibc];
74 int bc2 = bcd2.getBC();
75 auto channels2 = bcd2.getBunchChannelData(digitsCh2);
76 nch2 += channels2.size();
77 }
78 }
79 LOG(info) << "FDD simulated: " << nbc << " triggers with " << nch << " channels";
80 LOG(info) << "FDD decoded : " << nbc2 << " triggers with " << nch2 << " channels";
81 if (nbc != nbc2 || nch != nch2) {
82 LOG(fatal) << "Mismatch between the number of encoded and decoded objects";
83 }
84
85 return 0;
86}
uint64_t bc
Definition RawEventData.h:5
#define main
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
TFile flIn("test_ctf_cpv.root")
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))
std::vector< ChannelData > channels