10#include "RootIOManager.h"
19#include "InputDataInfo.h"
21#include <TBranchElement.h>
23#include <TCollection.h>
24#include <TDirectoryFile.h>
26#include <TFriendElement.h>
31#include <TObjString.h>
39 Bool_t RootIOManager::InitInternal() {
42 fEntries = fInChain->GetEntries();
43 fOutFile =
new TFile(fOutFileName,
"recreate");
44 fOutTree =
new TTree(fOutTreeName, fOutTreeName);
50 RootIOManager::~RootIOManager() {
51 if (fInChain)
delete fInChain;
52 for (
auto obj : fObjects) {
55 if (fOutFile)
delete fOutFile;
59 TObjArray* list_branch = fInChain->GetListOfBranches();
61 for (
auto name : branches) {
62 TBranch* branch = fInChain->GetBranch(name);
63 if (
FindBranch(name).GetFlag() != BranchInfo::EFlag::kNull)
continue;
65 TString className = branch->GetClassName();
66 auto classInfo = TClass::GetClass(className, 1);
69 if (classInfo->InheritsFrom(
"TObject")) {
object =
true; }
72 TObject** obj =
new TObject*();
74 fInChain->SetBranchAddress(name, obj);
75 AddBranch(branch->GetName(), obj[0], BranchInfo::EFlag::kInPassive);
77 AddBranch(branch->GetName(),
nullptr, BranchInfo::EFlag::kInPassive);
83 if (toFile) { fOutTree->Branch(name, obj); }
87 if (toFile) { fOutTree->Branch(name, obj); }
100 fInChain->GetEntry(i, flag);
108 if (branch.GetFlag() == BranchInfo::EFlag::kInPassive) {
109 fInChain->SetBranchStatus(branch.GetBranchName(), 0);
110 HalCoutDebug(Form(
"Locking branch %s", branch.GetBranchName().Data()));
117 auto convert = [](std::vector<TString>& res, TObjArray* objar) {
118 for (
int i = 0; i < objar->GetEntriesFast(); i++) {
119 TBranchElement* branch = (TBranchElement*) objar->At(i);
120 TString name = branch->GetName();
124 std::vector<TString> list;
125 TObjArray* list_branch = chain->GetListOfBranches();
126 convert(list, list_branch);
128 auto friends_trees = chain->GetListOfFriends();
130 for (
int i = 0; i < friends_trees->GetEntries(); i++) {
131 auto tree = ((TFriendElement*) friends_trees->At(i))->GetTree();
132 auto lista = tree->GetListOfBranches();
133 convert(list, lista);
static void PrintInfo(TString text, Hal::EInfo status)
std::vector< Hal::BranchInfo > fBranches
BranchInfo FindBranch(TString name) const
void AddBranch(TString name, TObject *object, BranchInfo::EFlag flag)
void LockUnusedBranches()
virtual void UpdateBranches()
virtual void RegisterInternal(const char *name, const char *folderName, TNamed *obj, Bool_t toFile)
void PushTObject(TObject **obj)
static std::vector< TString > GetListOfBranches(TChain *chain, Bool_t friends)
virtual void CloseManager()
Int_t GetEntry(Int_t i, Int_t flag=1)
RootIOManager(TString name)
void SetInChain(TChain *tempChain, Int_t ident=-1)