Project
Loading...
Searching...
No Matches
MilleRecordReader.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
13
14#include "Framework/Logger.h"
15
17
18using namespace o2::fwdalign;
19
21
22//__________________________________________________________________________
24 : mDataTree(nullptr),
25 mIsSuccessfulInit(false),
26 mIsConstraintsRec(false),
27 mIsReadEntryOk(false),
28 mDataTreeName("o2sim"),
29 mDataBranchName("data"),
30 mRecord(nullptr),
31 mCurrentDataID(-1),
32 mNEntries(0)
33{
35}
36
37//__________________________________________________________________________
39{
40 if (mDataTree) {
41 mDataTree->Reset();
42 }
43 if (mRecord) {
44 delete mRecord;
45 }
46}
47
48//__________________________________________________________________________
49void MilleRecordReader::changeDataBranchName(const bool isConstraintsRec)
50{
51 mIsConstraintsRec = isConstraintsRec;
52 if (!mIsConstraintsRec) {
53 mDataBranchName = TString("data");
54 } else {
55 mDataBranchName = TString("constraints");
56 }
57}
58
59//__________________________________________________________________________
61{
62 mIsSuccessfulInit = false;
63
64 if (mDataTree) {
65 LOG(warning) << "MilleRecordReader::connectToChain() - input chain already initialized";
66 mIsSuccessfulInit = true;
67 return;
68 }
69 if (!ch) {
70 LOG(fatal) << "MilleRecordReader::connectToChain() - input chain is a null pointer";
71 return;
72 }
73 Long64_t nEntries = ch->GetEntries();
74 if (nEntries < 1) {
75 LOG(fatal) << "MilleRecordReader::connectToChain() - input chain is empty";
76 return;
77 }
78 mDataTree = ch;
79 mNEntries = mDataTree->GetEntries();
80 mDataTree->SetBranchAddress(mDataBranchName.Data(), &mRecord);
81 if (!mIsConstraintsRec) {
82 LOGF(info,
83 "MilleRecordReader::connectToChain() - found %lld derivatives records",
84 mNEntries);
85 } else {
86 LOGF(info,
87 "MilleRecordReader::connectToChain() - found %lld constraints records",
88 mNEntries);
89 }
90 mIsSuccessfulInit = true;
91 mCurrentDataID = -1;
92}
93
94//__________________________________________________________________________
95void MilleRecordReader::readNextEntry(const bool doPrint)
96{
97 mIsReadEntryOk = false;
98 if (!isReaderOk()) {
99 LOG(error) << "MilleRecordReader::readNextEntry() - aborted, connectToChain() was not ok !";
100 return;
101 }
105 return;
106 }
107 mDataTree->GetEntry(mCurrentDataID);
108 if (doPrint) {
109 LOGF(info, "MilleRecordReader::readNextEntry() - read entry %i", mCurrentDataID);
110 mRecord->Print();
111 }
112 mIsReadEntryOk = true;
113}
114
115//__________________________________________________________________________
116void MilleRecordReader::readEntry(const Long_t id, const bool doPrint)
117{
118 mIsReadEntryOk = false;
119 if (!isReaderOk()) {
120 LOG(error) << "MilleRecordReader::readEntry() - aborted, connectToChain() was not ok !";
121 return;
122 }
125 return;
126 }
127 mDataTree->GetEntry(mCurrentDataID);
128 if (doPrint) {
129 LOGF(info, "MilleRecordReader::readEntry() - read entry %i", mCurrentDataID);
130 mRecord->Print();
131 }
132 mIsReadEntryOk = true;
133}
ClassImp(o2::fwdalign::MilleRecordReader)
Class dedicated to read MillePedeRecords from ROOT files.
Store residuals and local/global deriavtives from a single track processing.
void Print(const Option_t *opt="") const override
print itself
Long64_t mCurrentDataID
counter indicating the ID of the current record in the tree
void changeDataBranchName(const bool isConstraintsRec=true)
choose data records filename
o2::fwdalign::MillePedeRecord * mRecord
the running record
void readNextEntry(const bool doPrint=false)
read the next entry in the tree
TChain * mDataTree
TChain container that stores the records.
bool mIsReadEntryOk
boolean to know if the last operation readNextEntry() was ok
bool mIsConstraintsRec
boolean to know if these are data records or constraints records
void readEntry(const Long_t id, const bool doPrint=false)
read the entry # id in the tree
bool mIsSuccessfulInit
boolean to monitor the success of the initialization
void connectToChain(TChain *ch)
connect to input TChain
bool isReaderOk() const
check if connect to input TChain went well
TString mDataBranchName
name of the branch where records will be stored
Long64_t mNEntries
number of entries in the read TChain
GLuint id
Definition glcorearb.h:650
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"