EventAnalysis  1.0.0
SparseChain.h
Go to the documentation of this file.
1 /*
2  * SparseChain.h
3  *
4  * Created on: 7 Aug 2019
5  * Author: Nicola Mori
6  */
7 
8 #ifndef SPARSECHAIN_H_
9 #define SPARSECHAIN_H_
10 
11 // Root headers
12 #include "TChain.h"
13 
14 // C/C++ headers
15 #include <algorithm>
16 #include <string>
17 #include <vector>
18 
19 namespace EA {
20 
64 class SparseChain : public TChain {
65 public:
66  using TChain::TChain;
67 
78  template <typename T> Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr = 0);
79 
92  Int_t SetBranchAddress(const char *bname, void *add, TClass *realClass, EDataType datatype, Bool_t isptr);
93 
103  Int_t GetEntry(Long64_t entry = 0, Int_t getall = 0);
104 
105 private:
106  std::vector<std::string> _branchesWithAddress;
107 
108  ClassDef(SparseChain, 1)
109 };
110 
111 template <typename T> Int_t SparseChain::SetBranchAddress(const char *bname, T **add, TBranch **ptr) {
112 
113  auto *branch = GetBranch(bname);
114  if (branch) {
115  std::string branchName(bname);
116  if (std::find(_branchesWithAddress.begin(), _branchesWithAddress.end(), branchName) == _branchesWithAddress.end()) {
117  _branchesWithAddress.push_back(std::move(branchName));
118  }
119  return TChain::SetBranchAddress<T>(bname, add, ptr);
120  }
121  return 0;
122 }
123 
124 } // namespace EA
125 
126 #endif /* SPARSECHAIN_H_ */
std::vector< std::string > _branchesWithAddress
Definition: SparseChain.h:106
IncludeFileExc.h IncludeFileExc class declaration.
Definition: Algorithm.h:21
A chain that reads only branches which have an address.
Definition: SparseChain.h:64
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=0)
Set branch address and adds the branch to the branch list.
Definition: SparseChain.h:111
Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Reads data from branches with an address.
Definition: SparseChain.cpp:12