Juggler
Juggling algorithms and event processing using gaudi framework
rootutils.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-or-later
2 // Copyright (C) 2022 Sylvester Joosten, Wouter Deconinck
3 
4 #ifndef PODIO_ROOT_UTILS_H
5 #define PODIO_ROOT_UTILS_H
6 
7 #include "podio/podioVersion.h"
8 #include "podio/CollectionBase.h"
9 #include "podio/CollectionBranches.h"
10 
11 #include "TBranch.h"
12 #include "TClass.h"
13 
14 #include <vector>
15 #include <string>
16 
17 namespace podio::root_utils {
18 // Workaround slow branch retrieval for 6.22/06 performance degradation
19 // see: https://root-forum.cern.ch/t/serious-degradation-of-i-o-performance-from-6-20-04-to-6-22-06/43584/10
20 template<class Tree>
21 TBranch* getBranch(Tree* chain, const char* name) {
22  return static_cast<TBranch*>(chain->GetListOfBranches()->FindObject(name));
23 }
24 
25 inline std::string refBranch(const std::string& name, size_t index) {
26  return name + "#" + std::to_string(index);
27 }
28 
29 inline std::string vecBranch(const std::string& name, size_t index) {
30  return name + "_" + std::to_string(index);
31 }
32 
33 
34 inline void setCollectionAddresses(podio::CollectionBase* collection, const CollectionBranches& branches) {
35  auto buffers = collection->getBuffers();
36  auto data = buffers.data;
37  auto references = buffers.references;
38  auto vecmembers = buffers.vectorMembers;
39 
40  if (data) {
41  branches.data->SetAddress(data);
42  }
43 
44  if (references) {
45  for (size_t i = 0; i < references->size(); ++i) {
46  branches.refs[i]->SetAddress(&(*references)[i]);
47  }
48  }
49 
50  if (vecmembers) {
51  for (size_t i = 0; i < vecmembers->size(); ++i) {
52  branches.vecs[i]->SetAddress((*vecmembers)[i].second);
53  }
54  }
55 }
56 
57 }
58 
59 #endif
podio::root_utils::refBranch
std::string refBranch(const std::string &name, size_t index)
Definition: rootutils.h:25
podio::root_utils::vecBranch
std::string vecBranch(const std::string &name, size_t index)
Definition: rootutils.h:29
podio::root_utils::setCollectionAddresses
void setCollectionAddresses(podio::CollectionBase *collection, const CollectionBranches &branches)
Definition: rootutils.h:34
podio::root_utils::getBranch
TBranch * getBranch(Tree *chain, const char *name)
Definition: rootutils.h:21
podio::root_utils
Definition: rootutils.h:17