00001
00002 #include "tools/Log.hh"
00003 #include "tools/Toolbox.hh"
00004
00005 #include "root/MTRun.hh"
00006 #include "root/MTChannel.hh"
00007 #include "root/MTEvent.hh"
00008 #include "root/MTTrack.hh"
00009 #include "MicroException.hh"
00010
00011 #include "mysql/Mysql.hh"
00012
00013
00014 #include "mysql/Mysql.hh"
00015
00016 #include "TFile.h"
00017 #include "TTree.h"
00018 #include "TKey.h"
00019 #include "TBranch.h"
00020 #include "TRandom.h"
00021
00022
00023 #include <sstream>
00024 #include <sys/types.h>
00025 #include <unistd.h>
00026 #include <stdio.h>
00027
00028
00029 using namespace std;
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 int main(int argc, char**argv){
00041
00042 if ( argc != 2 ) {
00043 FILE_LOG(logERROR) << "usage:" << endl;
00044 FILE_LOG(logERROR) << ":process_example fileToProcess" << endl;
00045 exit(1);
00046 }
00047 string inputfile = argv[1] ;
00048
00049
00050 pid_t pid = getpid();
00051 std::ostringstream oss;
00052 oss << "/tmp/" << pid << ".root";
00053 string outputfile = oss.str();
00054
00055
00056 TFile infile(inputfile.c_str(),"READ");
00057
00058
00059 TFile oufile(outputfile.c_str(),"RECREATE");
00060
00061
00062 oufile.cd();
00063
00064
00065
00066
00067 TIter nextkey(infile.GetListOfKeys());
00068 TKey *key;
00069 MTEvent *updateEvt = new MTEvent();
00070
00071 while (key = (TKey*)nextkey())
00072 {
00073 TTree *tree = (TTree*)key->ReadObj();
00074
00075
00076 string treeName = tree->GetName();
00077 treeName = treeName + "_preprocessed" ;
00078
00079 TTree *updateTree = new TTree(treeName.c_str(),"MicroMegas event");
00080 updateTree->Branch("MTEvent",&updateEvt,16000,2);
00081
00082 MTRun * run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun");
00083
00084
00085 run->SetProcessed(true);
00086
00087
00088 updateTree->GetUserInfo()->Add(run);
00089 MTEvent *evt = new MTEvent();
00090 TBranch *branch= tree->GetBranch("MTEvent");
00091 branch->SetAddress(&evt);
00092
00093
00094 MTChannel* channel =NULL;
00095 int nbEntries = tree->GetEntries();
00096 TRandom random;
00097
00098 for ( int evtNum = 0; evtNum < 10 ; evtNum++)
00099 {
00100 tree->GetEntry(evtNum);
00101
00102
00103 *updateEvt = *evt;
00104
00105
00106 Float_t ax =0.;
00107 Float_t bx =0.;
00108 Float_t ay =0.;
00109 Float_t by=0.;
00110 ax = random.Rndm();
00111 bx = random.Rndm();
00112 ay = random.Rndm();
00113 by = random.Rndm();
00114
00115 MTTrack *track = new MTTrack(true,
00116 false,
00117 true ,
00118 false,
00119 ax,
00120 bx,
00121 ay,
00122 by);
00123
00124 updateEvt->SetTimeInfo(false);
00125 updateEvt->SetSquareEvt(true);
00126 updateEvt->SetTrack(track);
00127
00128
00129 cout << "Write Event[" << evtNum << "] \t\t\t\t\t\t\t\t\t\t\t\r" << flush;
00130 updateTree->Fill();
00131 delete track;
00132
00133 }
00134
00135
00136 TFile *curFile =updateTree->GetCurrentFile();
00137 updateTree->Write("", TObject::kOverwrite);
00138 updateTree->SetDirectory(0);
00139
00140
00141 delete evt;
00142 }
00143
00144
00145 infile.Close();
00146 oufile.Close();
00147
00148
00149
00150
00151 rename(outputfile.c_str(),inputfile.c_str());
00152
00153 cout << endl << "Done." << endl;
00154
00155
00156
00157 Mysql mysql;
00158 mysql.updateRunProcessInfo(10211,
00159 12.2,
00160 45.3,
00161 123.1,
00162 37.4,
00163 45 );
00164
00165 mysql.addRunChamberProcessInfo(10211,
00166 10,
00167 1.2,
00168 2.3,
00169 99.3,
00170 15.5,
00171 8) ;
00172
00173
00174 ui32 runId = 10211;
00175 ui16 chamberId = 10;
00176
00177 cout << "OffsetX: " << mysql.getRunOffsetX( runId) << endl;
00178 cout << "OffsetY: " << mysql.getRunOffsetY( runId) << endl;
00179 cout << "Pressure: " << mysql.getRunPressure( runId) << endl;
00180 cout << "Temperature: " << mysql.getRunTemperature( runId) << endl;
00181 cout << "DeltaTMax: " << mysql.getRunDeltaTMax( runId) << endl;
00182
00183 cout << "XMean: " << mysql.getRunChamberXMean( runId, chamberId) << endl;
00184 cout << "YMean: " << mysql.getRunChamberYMean( runId, chamberId) << endl;
00185 cout << "Inefficiency: " << mysql.getRunChamberInefficiency( runId, chamberId) << endl;
00186 cout << "NHitMean: " << mysql.getRunChamberNHitMean( runId, chamberId) << endl;
00187 cout << "DeltaTMax: " << mysql.getRunChamberDeltaTMax( runId, chamberId) << endl;
00188
00189
00190 return 0;
00191 }