Hi, I am writing multiple TFiles created over different threads. Now in the end I want to merge all these files into one to be processed in another script. What would be the best way to do that??
Thanks.
ROOT Version: 6.22.08
Platform: Ubuntu
Compiler:
Hi @Siddharth_Parashari ,
TBufferMerger exists for the purpose of writing to the same file from multiple threads.
See ROOT: tutorials/multicore/mt103_fillNtupleFromMultipleThreads.C File Reference .
If instead you want to write to different files and then merge them, you can use the hadd
command line tool that comes with ROOT (see hadd --help
).
Cheers,
Enrico
Thank you so much for this quick suggestion. I think using TBufferMerger would be a good idea for me.
Thanks
Hi @eguiraud ,
I have written a piece of code where I pass a pointer from different TThreads and trying to write a merged file from the files written over multiple TThreads.
Kindly have a look. I am facing some issue, I mean it is not working.
void* write_outfile(void* ptr){
gROOT->cd();
Long64_t* N = (Long64_t*) ptr;
gROOT->SetBatch();
ROOT::EnableThreadSafety();
std::string fileName = oname;
ROOT::Experimental::TBufferMerger merger("testfile.root", "RECREATE");
auto file = merger.GetFile();
for(auto j=N[1]; j<N[2]; j++){
auto tree = new TTree("data","data");
tree->Branch("q",&qcalib,"qcalib[1024]/F");
tree->Branch("t",&tcalib,"tcalib[1024]/l");
chain[N[0]]->GetEntry(j);
for(CHID=channel_start;CHID<=channel_end;CHID++){
if(CHID >63 && CHID <320){continue;}
if(q[CHID]>0 ){
//Float_t S= pow(q[CHID],par[CHID][2]);
//qcalib[CHID]=par[CHID][0]*pow(par[CHID][1],S)+par[CHID][3]*q[CHID]-par[CHID][0];
qcalib[CHID] = q[CHID]*S[CHID];
}
else{continue;}
}
tree->Fill();
}
file->Write();
return 0;
}
Hi @Siddharth_Parashari ,
sorry for the high latency, I was off last week.
You should not use TThread, it’s a very old interface. As in the tutorial I linked above, you should use std::thread
s. Can you try starting from the tutorial code and modifying to do what you want? Then if things break please post a full reproducer and the full error message or stack trace.
Cheers,
Enrico