Hi,
I want to initialize multiple TTreeReaders from various trees from various files which I can do within main as such:
TTree* exampleTree_1;
exampleTree_1= (TTree*)exampleFile_1->Get("exampleName_1");
TTreeReader readerExample_1(exampleTree_1);
TTree* exampleTree_2;
exampleTree_2= (TTree*)exampleFile_2->Get("exampleName_2");
TTreeReader readerExample_2(exampleTree_2);
etc and so on.
However I’d much prefer to have this as a function so I’m not repeating code, however when I try to do so I am not able to.
I have tried:
TTreeReader initiateTTreeReaderFromFile(TFile* file, std::string nameOfTree){
TTree* tree;
tree = (TTree*)file->Get(nameOfTree.c_str());
TreeReader reader(tree);
return reader;
}
However this fails compilation because of:
error: call to implicitly-deleted copy constructor of ‘TTreeReader’
return reader;
^~~~~~
note: copy constructor of ‘TTreeReader’ is implicitly deleted because field ‘fProxies’ has an inaccessible copy constructor
THashTable fProxies; ///< attached ROOT::TNamedBranchProxies; owned
I have also tried
void initiateTTreeReaderFromFile(TTreeReader& reader,TFile* file, std::string nameOfTree){
TTree* tree;
tree = (TTree*)file->Get(nameOfTree.c_str());
reader = TTreeReader(tree);
}
However this fails compilation because of:
error: object of type ‘TTreeReader’ cannot be assigned because its copy assignment operator is implicitly deleted
reader = TTreeReader(tree);
^
note: copy assignment operator of ‘TTreeReader’ is implicitly deleted because field ‘fProxies’ has an inaccessible copy assignment operator THashTable fProxies; ///< attached ROOT::TNamedBranchProxies; owned
I have also tried
void initiateTTreeReaderFromFile(TTreeReader* readerPointer,TFile* file, std::string nameOfTree){
TTree* tree;
tree = (TTree*)file->Get(nameOfTree.c_str());
TTreeReader reader (tree);
readerPointer = &reader;
}
And then dereferencing the pointer in main, this doesn’t fail at compilation but the memory that readerPointer points to is empty.
How can I manage to initialize TTreeReader within a function and then pass this to main?
Thank you,
Jack