Project
Loading...
Searching...
No Matches
ConstMCTruthContainer.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
16#include <TFile.h>
17#include <TTree.h>
18#include <iostream>
19
20using namespace o2::dataformats;
21
23{
25 o2::dataformats::IOMCTruthContainerView* labelROOTbuffer = nullptr;
27
28 auto branch = tree->GetBranch(brname.c_str());
29 if (!branch) {
30 return nullptr;
31 }
32 auto labelClass = branch->GetClassName();
33 bool oldlabelformat = false;
34
35 // we check how the labels are persisted and react accordingly
36 if (TString(labelClass).Contains("IOMCTruthContainer")) {
37 branch->SetAddress(&labelROOTbuffer);
38 branch->GetEntry(entry);
39 if (labelROOTbuffer) {
40 labelROOTbuffer->copyandflatten(*constlabels);
41 delete labelROOTbuffer;
42 }
43 } else {
44 // case when we directly streamed MCTruthContainer
45 // TODO: support more cases such as ConstMCTruthContainer etc
46 std::string serializedtype("o2::dataformats::MCTruthContainer<o2::MCCompLabel>");
47 if (!TString(labelClass).EqualTo(serializedtype.c_str())) {
48 std::cerr << "Error: expected serialized type " << serializedtype << " but found " << labelClass;
49 return nullptr;
50 }
51 branch->SetAddress(&labels);
52 branch->GetEntry(entry);
53 if (labels) {
54 labels->flatten_to(*constlabels);
55 delete labels;
56 }
57 }
58 return constlabels;
59}
A const (ready only) version of MCTruthContainer.
A special IO container - splitting a given vector to enable ROOT IO.
Definition of a container to keep Monte Carlo truth external to simulation objects.
A read-only version of MCTruthContainer allowing for storage optimisation.
void copyandflatten(std::vector< char, Alloc > &output) const
static ConstMCTruthContainer< o2::MCCompLabel > * loadFromTTree(TTree *tree, std::string const &brname, int entry)
A container to hold and manage MC truth information/labels.
size_t flatten_to(ContainerType &container) const
GLuint entry
Definition glcorearb.h:5735
Definition of a container to keep/associate and arbitrary number of labels associated to an index wit...
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))