Project
Loading...
Searching...
No Matches
DigitTreeReader.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 "DigitTreeReader.h"
13#include <limits>
14#include <fmt/format.h>
15
16namespace o2::mch::raw
17{
18
19void AssertBranch(ROOT::Internal::TTreeReaderValueBase& value)
20{
21 if (value.GetSetupStatus() < 0) {
22 throw std::invalid_argument(fmt::format("Error {} setting up tree reader for branch {}",
23 (int)value.GetSetupStatus(), value.GetBranchName()));
24 }
25}
26
27DigitTreeReader::DigitTreeReader(TTree* tree) : mCurrentRof{std::numeric_limits<size_t>::max()}
28{
29 if (!tree) {
30 throw std::invalid_argument("cannot work with a null tree pointer");
31 }
32 mTreeReader.SetTree(tree);
33 mTreeReader.Restart();
34 mTreeReader.Next();
35 mCurrentRof = 0;
36 AssertBranch(mDigits);
37 AssertBranch(mRofs);
38}
39
40bool DigitTreeReader::nextDigits(o2::mch::ROFRecord& rof, std::vector<o2::mch::Digit>& digits)
41{
42 if (mCurrentRof >= mRofs->size()) {
43 if (!mTreeReader.Next()) {
44 return false;
45 }
46 mCurrentRof = 0;
47 }
48
49 if (mRofs->empty()) {
50 return false;
51 }
52 rof = (*mRofs)[mCurrentRof];
53 digits.clear();
54 auto& tfDigits = *mDigits;
55 digits.insert(digits.begin(), tfDigits.begin() + rof.getFirstIdx(), tfDigits.begin() + rof.getLastIdx() + 1);
56 ++mCurrentRof;
57 return true;
58}
59} // namespace o2::mch::raw
int getLastIdx() const
get the index of the last associated object
Definition ROFRecord.h:59
int getFirstIdx() const
get the index of the first associated object
Definition ROFRecord.h:57
bool nextDigits(o2::mch::ROFRecord &rof, std::vector< o2::mch::Digit > &digits)
GLsizei const GLfloat * value
Definition glcorearb.h:819
void AssertBranch(ROOT::Internal::TTreeReaderValueBase &value)
Defining DataPointCompositeObject explicitly as copiable.
constexpr size_t max
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))
std::vector< Digit > digits