/
DigitReaderSpec.cxx
110 lines (93 loc) · 3.73 KB
/
DigitReaderSpec.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// @file DigitReaderSpec.cxx
#include <vector>
#include "TTree.h"
#include "Framework/ControlService.h"
#include "ITSWorkflow/DigitReaderSpec.h"
#include "ITSMFTBase/Digit.h"
#include "SimulationDataFormat/MCCompLabel.h"
#include "SimulationDataFormat/MCTruthContainer.h"
#include "DataFormatsITSMFT/ROFRecord.h"
using namespace o2::framework;
using namespace o2::ITSMFT;
namespace o2
{
namespace ITS
{
void DigitReader::init(InitContext& ic)
{
auto filename = ic.options().get<std::string>("its-digit-infile");
mFile = std::make_unique<TFile>(filename.c_str(), "OLD");
if (!mFile->IsOpen()) {
LOG(ERROR) << "Cannot open the " << filename.c_str() << " file !";
mState = 0;
return;
}
mState = 1;
}
void DigitReader::run(ProcessingContext& pc)
{
if (mState != 1) {
return;
}
std::unique_ptr<TTree> treeDig((TTree*)mFile->Get("o2sim"));
std::unique_ptr<TTree> treeROF((TTree*)mFile->Get("ITSDigitROF"));
std::unique_ptr<TTree> treeMC2ROF((TTree*)mFile->Get("ITSDigitMC2ROF"));
if (treeDig && treeROF && treeMC2ROF) {
std::vector<o2::ITSMFT::Digit> allDigits;
std::vector<o2::ITSMFT::Digit> digits, *pdigits = &digits;
treeDig->SetBranchAddress("ITSDigit", &pdigits);
o2::dataformats::MCTruthContainer<o2::MCCompLabel> allLabels;
o2::dataformats::MCTruthContainer<o2::MCCompLabel> labels, *plabels = &labels;
treeDig->SetBranchAddress("ITSDigitMCTruth", &plabels);
std::vector<ROFRecord> rofs, *profs = &rofs;
treeROF->SetBranchAddress("ITSDigitROF", &profs);
treeROF->GetEntry(0);
std::vector<MC2ROFRecord> mc2rofs, *pmc2rofs = &mc2rofs;
treeMC2ROF->SetBranchAddress("ITSDigitMC2ROF", &pmc2rofs);
treeMC2ROF->GetEntry(0);
int ne = treeDig->GetEntries();
for (int e = 0; e < ne; e++) { // RS normally we should not have multiple entries here, if it happens, the references will be wrong
treeDig->GetEntry(e);
std::copy(digits.begin(), digits.end(), std::back_inserter(allDigits));
allLabels.mergeAtBack(labels);
}
LOG(INFO) << "ITSDigitReader pushed " << allDigits.size() << " digits, in "
<< profs->size() << " RO frames and "
<< pmc2rofs->size() << " MC events";
pc.outputs().snapshot(Output{ "ITS", "DIGITS", 0, Lifetime::Timeframe }, allDigits);
pc.outputs().snapshot(Output{ "ITS", "DIGITSMCTR", 0, Lifetime::Timeframe }, allLabels);
pc.outputs().snapshot(Output{ "ITS", "ITSDigitROF", 0, Lifetime::Timeframe }, *profs);
pc.outputs().snapshot(Output{ "ITS", "ITSDigitMC2ROF", 0, Lifetime::Timeframe }, *pmc2rofs);
} else {
LOG(ERROR) << "Cannot read the ITS digits !";
return;
}
mState = 2;
//pc.services().get<ControlService>().readyToQuit(true);
}
DataProcessorSpec getDigitReaderSpec()
{
return DataProcessorSpec{
"its-digit-reader",
Inputs{},
Outputs{
OutputSpec{ "ITS", "DIGITS", 0, Lifetime::Timeframe },
OutputSpec{ "ITS", "DIGITSMCTR", 0, Lifetime::Timeframe },
OutputSpec{ "ITS", "ITSDigitROF", 0, Lifetime::Timeframe },
OutputSpec{ "ITS", "ITSDigitMC2ROF", 0, Lifetime::Timeframe } },
AlgorithmSpec{ adaptFromTask<DigitReader>() },
Options{
{ "its-digit-infile", VariantType::String, "itsdigits.root", { "Name of the input file" } } }
};
}
} // namespace ITS
} // namespace o2