#include "tools/Log.hh"
#include "tools/Toolbox.hh"
#include "root/MTRun.hh"
#include "root/MTChannel.hh"
#include "root/MTEvent.hh"
#include "root/MTTrack.hh"
#include "MicroException.hh"
#include "mysql/Mysql.hh"
#include "TFile.h"
#include "TTree.h"
#include "TKey.h"
#include "TBranch.h"
#include "TRandom.h"
#include "TProfile.h"
#include "TH2I.h"
#include "TF1.h"
#include <sstream>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for Tag_ramfull.cpp:
Go to the source code of this file.
Functions | |
int | main (int argc, char **argv) |
Variables | |
int | errsv = errno |
int main | ( | int | argc, | |
char ** | argv | |||
) |
Definition at line 45 of file Tag_ramfull.cpp.
00045 { 00046 00047 if ( argc != 3 ) { 00048 FILE_LOG(logERROR) << "usage:" << endl; 00049 FILE_LOG(logERROR) << ":Tag_ramfull fileToProcess threshold" << endl; 00050 exit(1); 00051 } 00052 string inputfile = argv[1] ; 00053 00054 UInt_t threshold = atoi(argv[2]); 00055 00056 // build temporaly fill path and name 00057 pid_t pid = getpid(); 00058 std::ostringstream oss; 00059 oss << "/tmp/" << pid << ".root"; 00060 string outputfile = oss.str(); 00061 00062 cout<<"Read "<<inputfile<<endl; 00063 00064 00065 00066 // Open Root TFile in read only mode 00067 TFile infile(inputfile.c_str(),"READ"); 00068 00069 // Open Root TFile in write mode 00070 TFile oufile(outputfile.c_str(),"RECREATE"); 00071 // Change current directory to "this" directory 00072 // Mandatory to use updateTree->GetCurrentFile() later 00073 oufile.cd(); 00074 00075 00076 00077 // Loop over original TTrees 00078 TIter nextkey(infile.GetListOfKeys()); 00079 MTEvent *updateEvt = new MTEvent(); 00080 00081 TKey* key = NULL;//(TKey*)nextkey(); 00082 TTree *updateTree = NULL; 00083 while (key = (TKey*)nextkey()) 00084 //key = (TKey*)nextkey(); 00085 { 00086 TTree *tree = (TTree*)key->ReadObj(); 00087 00088 // Create new TTree which will contain processed MTRun and MTEvent 00089 string treeName = tree->GetName(); 00090 treeName = treeName + "_preprocessed"; 00091 updateTree = new TTree(treeName.c_str(),"MicroMegas event"); 00092 updateTree->Branch("MTEvent",&updateEvt,16000,2); 00093 00094 MTRun * run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun"); 00095 00096 // Set Processed flag to MTRun 00097 run->SetProcessed(true); 00098 00099 // Save MTRun information to new processed TTree 00100 updateTree->GetUserInfo()->Add(run); 00101 MTEvent *evt = new MTEvent(); 00102 TBranch *branch= tree->GetBranch("MTEvent"); 00103 branch->SetAddress(&evt); 00104 00105 00106 //MTChannel* channel =NULL; 00107 int nbEntries = tree->GetEntries(); 00108 MTEvent* prev_evt = NULL; 00109 00110 cout<<endl; 00111 cout<<"NUMBER OF EVENTS = "<<nbEntries<<endl; 00112 cout<<endl; 00113 00114 00115 for ( int evtNum = 0; evtNum < nbEntries ; evtNum++) 00116 { 00117 map<UInt_t, UInt_t> dtMap; // key is ( BcIdDif() - BcIdHit. Value is number of entry 00118 tree->GetEntry(evtNum); 00119 //cout << "tree->GetEntry("<< evtNum <<")" << endl; 00120 00121 // Copy original MTEvent to new processed MTEvent 00122 *updateEvt = *evt; 00123 00124 MTChannel* channel = NULL; 00125 int nbChannel = evt->GetNchannel(); 00126 // Compute dt 00127 for(int i=0;i<nbChannel ;i++) 00128 { 00129 channel = (MTChannel*)evt->GetChannels()->UncheckedAt(i); 00130 UInt_t t2 = channel->GetBcIdDif(); 00131 UInt_t t3 = channel->GetBcIdHit(); 00132 UInt_t dt = t2 - t3; 00133 00134 // Add entry for this dt 00135 if (dtMap.find(dt) == dtMap.end()) 00136 { //if this dt doesn't exist yet 00137 dtMap.insert(make_pair(dt,1)); 00138 } 00139 else 00140 { //if this abs time already exist 00141 dtMap[dt] = dtMap[dt]++; 00142 //cout << "Event [" << evtNum << "] BcIdDif[" << t2 << "], BcIdHit[" << t3 << "], dt[" << dt << "], count " << dtMap[dt] << endl; 00143 } 00144 } // end for each channel 00145 00146 00147 std::vector<UInt_t>& dtValid = updateEvt->GetDtCandidate(); 00148 dtValid.clear(); 00149 for ( map<UInt_t, UInt_t>::const_iterator iter= dtMap.begin(); iter != dtMap.end(); iter++) 00150 { 00151 UInt_t dt = (*iter).first; 00152 UInt_t value = (*iter).second; 00153 00154 if ( value > threshold ) 00155 { 00156 dtValid.push_back(dt); 00157 //cout << "cout << dtValid.push_back( "<< dt << ")" << endl; 00158 } 00159 } 00160 sort(dtValid.begin(),dtValid.end()); 00161 //Write MTEvent into Branch 00162 cout << "Write Event[" << evtNum << "] \r" << flush; 00163 updateTree->Fill(); 00164 } 00165 // free heap memory 00166 //delete evt; 00167 // Write Root Object to TFile 00168 TFile * curFile = updateTree->GetCurrentFile(); 00169 updateTree->Write("", TObject::kOverwrite); 00170 updateTree->SetDirectory(0); 00171 } 00172 00173 00174 00175 00176 infile.Close(); 00177 oufile.Close(); 00178 00179 00180 00181 // Replace original root file by the new processed one 00182 string command = "cp -f "; 00183 command = command + outputfile + " " + inputfile ; 00184 int result = system(command.c_str()); 00185 if ( result == -1 ) { cout << strerror(errno) << endl; } 00186 command = "rm -f " + outputfile; 00187 result = system(command.c_str()); 00188 if ( result == -1 ) { cout << strerror(errno) << endl; } 00189 00190 cout << endl << "Done." << endl; 00191 00192 00193 return 0; 00194 }
int errsv = errno |
Definition at line 33 of file Tag_ramfull.cpp.