-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathORBasicTreeWriter.cc
66 lines (58 loc) · 2.23 KB
/
ORBasicTreeWriter.cc
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
// ORBasicTreeWriter.cc
#include "ORBasicTreeWriter.hh"
#include "ORLogger.hh"
using namespace std;
ORBasicTreeWriter::ORBasicTreeWriter(ORVBasicTreeDecoder* decoder, string treeName, string branchPrefix) :
ORVTreeWriter(decoder, treeName)
{
fBasicTreeDecoder = decoder;
fBranchPrefix = branchPrefix;
// ORBasicTreeWriters don't leave the filling of the tree to
// ORVTreeWriter. For example, when a record has multiple rows to
// write to a tree, each one must be written in sequence during
// ProcessMyDataRecord(). For this reason, ORBasicTreeWriters write
// to a unique tree and consist use a single decoder. If you require
// a more complex tree filling, then you need something more than a
// "basic" tree.
SetDoNotAutoFillTree();
}
ORBasicTreeWriter::~ORBasicTreeWriter()
{
for (unsigned i=0; i<fParameters.size(); i++) delete fParameters[i];
}
ORDataProcessor::EReturnCode ORBasicTreeWriter::InitializeBranches()
{
ORLog(kTrace) << "Initializing branches..." << endl;
for (size_t iPar=0; iPar<fBasicTreeDecoder->GetNPars(); iPar++) {
fParameters.push_back(new UInt_t);
fTree->Branch(
(fBranchPrefix + fBasicTreeDecoder->GetParName(iPar)).c_str(),
fParameters[iPar],
(fBranchPrefix + fBasicTreeDecoder->GetParName(iPar)+"/i").c_str()
);
}
ORLog(kTrace) << "Initialized " << fBasicTreeDecoder->GetNPars() << " branches." << endl;
return kSuccess;
}
ORDataProcessor::EReturnCode ORBasicTreeWriter::ProcessMyDataRecord(UInt_t* record)
{
for (size_t iRow=0; iRow<fBasicTreeDecoder->GetNRows(record); iRow++) {
for (size_t iPar=0; iPar<fBasicTreeDecoder->GetNPars(); iPar++) {
*(fParameters[iPar]) = fBasicTreeDecoder->GetPar(record, iPar, iRow);
if(ORLogger::GetSeverity() <= ORLogger::kDebug) {
ORLog(kDebug) << fBranchPrefix+fBasicTreeDecoder->GetParName(iPar) << ": "
<< *(fParameters[iPar]) << endl;
}
}
fTree->Fill();
}
return kSuccess;
}
void ORBasicTreeWriter::Clear()
{
ORLog(kWarning) << "You should never have to use ORBasicTreeWriter::Clear(), "
<< "since ORBasicTreeWriter writes to a unique tree" << endl;
for (size_t iPar=0; iPar<fBasicTreeDecoder->GetNPars(); iPar++) {
(*(fParameters[iPar])) = 0;
}
}