#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 BcId_Dif() - BcId_Hit. Value is number of entry 00118 tree->GetEntry(evtNum); 00119 00120 // Copy original MTEvent to new processed MTEvent 00121 *updateEvt = *evt; 00122 00123 MTChannel* channel = NULL; 00124 int nbChannel = evt->GetNchannel(); 00125 // Compute dt 00126 for(int i=0;i<nbChannel ;i++) 00127 { 00128 channel = (MTChannel*)evt->GetChannels()->UncheckedAt(i); 00129 UInt_t t2 = channel->GetBcId_Dif(); 00130 UInt_t t3 = channel->GetBcId_Hit(); 00131 UInt_t dt = t2 - t3; 00132 00133 // Add entry for this dt 00134 if (dtMap.find(dt) == dtMap.end()) 00135 { //if this dt doesn't exist yet 00136 dtMap.insert(make_pair(dt,1)); 00137 } 00138 else 00139 { //if this abs time already exist 00140 dtMap[dt] = dtMap[dt]++; 00141 } 00142 } // end for each channel 00143 00144 00145 std::vector<UInt_t>& dtValid = updateEvt->GetDtCandidate(); 00146 dtValid.clear(); 00147 for ( map<UInt_t, UInt_t>::const_iterator iter= dtMap.begin(); iter != dtMap.end(); iter++) 00148 { 00149 UInt_t dt = (*iter).first; 00150 UInt_t value = (*iter).second; 00151 00152 if ( value > threshold ) 00153 { 00154 dtValid.push_back(dt); 00155 } 00156 } 00157 //Write MTEvent into Branch 00158 cout << "Write Event[" << evtNum << "] \r" << flush; 00159 updateTree->Fill(); 00160 } 00161 // free heap memory 00162 //delete evt; 00163 // Write Root Object to TFile 00164 TFile * curFile = updateTree->GetCurrentFile(); 00165 updateTree->Write("", TObject::kOverwrite); 00166 updateTree->SetDirectory(0); 00167 } 00168 00169 00170 00171 00172 infile.Close(); 00173 oufile.Close(); 00174 00175 00176 00177 // Replace original root file by the new processed one 00178 string command = "cp -f "; 00179 command = command + outputfile + " " + inputfile ; 00180 int result = system(command.c_str()); 00181 if ( result == -1 ) { cout << strerror(errno) << endl; } 00182 command = "rm -f " + outputfile; 00183 result = system(command.c_str()); 00184 if ( result == -1 ) { cout << strerror(errno) << endl; } 00185 00186 cout << endl << "Done." << endl; 00187 00188 00189 return 0; 00190 }
int errsv = errno |
Definition at line 33 of file Tag_ramfull.cpp.