puco4
September 3, 2017, 7:15pm
1
Hi, I’m trying to generalize this code: https://root.cern.ch/root/html/tutorials/io/loopdir.C.html with the idea to read from multiple files (that have the same structure) at the same time.
I’m trying:
//Open directory in each file
f1->cd();
gDirectory->cd(dir);
TDirectory* d1= gDirectory;
f2->cd();
gDirectory->cd(dir);
TDirectory* d2= gDirectory;
//Read keys in the directories
TList* key_ring1 = d1->GetListOfKeys();
TList* key_ring2 = d2->GetListOfKeys();
//Create iterators and objects to read from
TIter it1(key_ring1), it2(key_ring2);
TObject *o1, *o2;
//Read different keys
TKey* key1, key2;
while ((key1 = (TKey*)it1())){
key2 = (TKey*)it2();
o1=key1->ReadObj();
o2=key2->ReadObj();
}
But it does not seem to like key2 = (TKey*)it2()
(no viable overloaded ‘=’). Any ideas?
Thank you.
ganis
September 4, 2017, 6:21am
2
Dear puco4,
What’s the exact error?
Did you try this?
//Read keys in the directories
TList* key_ring1 = f1->GetListOfKeys();
TList* key_ring2 = f2->GetListOfKeys();
//Create iterators and objects to read from
TIter it1(key_ring1), it2(key_ring2);
TObject *o1, *o2;
//Read different keys
TKey* key1, key2;
while ((key1 = (TKey*)it1()) && (key2 = (TKey*)it2())){
o1 = key1->ReadObj();
o2 = key2->ReadObj();
}
G Ganis
puco4
September 4, 2017, 9:48am
3
Hi Ganis, thank you for your answer.
Yes, that was the first thing I tried.
I have also tried a for loop:
for(key1 = (TKey*) it1(), key2 = (TKey*) it2(); key1!=NULL; key1 = (TKey*) it1(), key2 = (TKey*) it2()){
}
In all cases I get this error:
error: no viable overloaded '='
while ((key1 = (TKey*)it1()) && (key2 = (TKey*)it2())){
~~~~ ^ ~~~~~~~~~~~~
/opt/root/include/TKey.h:31:10: note: candidate function not viable: no known co
nversion from 'TKey *' to 'const TKey'
for 1st argument; dereference the argument with *
TKey& operator=(const TKey&); // TKey objects are not copiable.
^
puco4
September 4, 2017, 3:13pm
4
Ah, I was just doing an error and I did not realize, sorry to bother you.
TKey* key1, key2;
should have been TKey *key1, *key2;
.
system
Closed
September 18, 2017, 3:13pm
5
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.