#include <map>
#include <stdlib.h>
#include <string>
#include <set>
#include <list>
#include "TKey.h"
#include <TRint.h>
#include <TTree.h>
#include <TFile.h>
#include <iostream>
#include <sstream>
#include "tools/Log.hh"
#include "tools/Toolbox.hh"
#include "root/MTEvent.hh"
#include "MicroException.hh"
Include dependency graph for addDifSynchro.cpp:
Go to the source code of this file.
Functions | |
int | main (int argc, char **argv) |
int main | ( | int | argc, | |
char ** | argv | |||
) |
Definition at line 41 of file addDifSynchro.cpp.
00041 { 00042 00043 if ( argc !=2 ) { 00044 FILE_LOG(logERROR) << "usage: addDifSynchro rootfile" << endl; 00045 exit(1); 00046 } 00047 00048 // Get root file name from command arguments and open it 00049 string rootName; 00050 rootName.assign(argv[1]); 00051 TFile f(rootName.c_str(),"READONLY"); 00052 TIter nextkey(f.GetListOfKeys()); 00053 00054 00055 // Recherche du TTree Dif_synchro 00056 TKey *key; 00057 vector<string> slabTreeNames; 00058 00059 TTree *difTree = NULL; 00060 MTEvent *findDifevt = new MTEvent(); 00061 00062 while (key = (TKey*)nextkey()) 00063 { 00064 TTree* tmp = (TTree*)key->ReadObj(); 00065 TBranch *branch= tmp->GetBranch("MTEvent"); 00066 branch->SetAddress(&findDifevt); 00067 tmp->GetEntry(0); 00068 00069 // Si DifSynchro > 0 c'est un fichier DIF SYNCHRO 00070 if ( findDifevt->GetDifSynchro() > 0 ) 00071 { 00072 difTree = tmp; 00073 cout << "Dif tree[" << (tmp->GetName()) << "]"<< endl; 00074 } 00075 else 00076 { // SINON C'EST UN FICHIER SLAB 00077 slabTreeNames.push_back(string(tmp->GetName())); 00078 } 00079 00080 } 00081 delete findDifevt; 00082 00083 00084 00085 // Fill DifSynchro vector 00086 if ( difTree == NULL ) { cout << "Could not find DIF SYNCRO TTRee! "<< endl; exit(-1); } 00087 vector<ULong64_t> difSynchro; 00088 MTEvent *difEvt = new MTEvent(); 00089 difTree->SetBranchAddress("MTEvent", &difEvt); 00090 for ( int eventNum =0 ; eventNum < difTree->GetEntries() ; eventNum++ ) 00091 { 00092 difTree->GetEntry(eventNum); 00093 difSynchro.push_back(difEvt->GetDifSynchro()); 00094 } 00095 delete difEvt; 00096 00097 string mergeFileName = rootName.substr(0,rootName.find("root")-1)+"_DS.root"; 00098 TFile *newFile = new TFile(mergeFileName.c_str(), "RECREATE"); 00099 newFile->cd(); 00100 00101 00102 TTree* mergedTree = NULL; 00103 for(vector<string>::iterator slabNameIt=slabTreeNames.begin(); slabNameIt!=slabTreeNames.end(); slabNameIt++) 00104 { 00105 00106 TTree* readTree = (TTree*)f.Get((*slabNameIt).c_str()); 00107 if ( readTree->GetEntries() != difTree->GetEntries() ) { cout << "nb entries differ !!!" << endl; exit(0); } 00108 00109 FILE_LOG(logINFO ) << "Add Dif Synchro to TTree[" << readTree->GetName() << "]" <<endl; 00110 mergedTree = readTree->CloneTree(0); 00111 00112 // Set the Dif_Syncho parameter 00113 MTEvent *readEvt = new MTEvent(); 00114 readTree->SetBranchAddress("MTEvent",&readEvt); 00115 00116 for ( int eventNum =0 ; eventNum < readTree->GetEntries() ; eventNum++ ) 00117 { 00118 readTree->GetEntry(eventNum); 00119 readEvt->SetDifSynchro(difSynchro[eventNum]); 00120 mergedTree->Fill(); 00121 if ( eventNum % 100 == 0) 00122 { 00123 FILE_LOG(logINFO ) << "Done for entry " << eventNum << " / " << readTree->GetEntries() << " \r" << flush; 00124 } 00125 00126 } 00127 delete readEvt; 00128 mergedTree->Write("", TObject::kOverwrite); 00129 } 00130 00131 00132 newFile->Close(); 00133 FILE_LOG(logINFO ) << endl << "Done." << endl; 00134 00135 }