00001
00002
00003
00004
00005
00006
00007 #include <new>
00008 #include <limits.h>
00009 #include <string.h>
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012
00013 #include <unistd.h>
00014
00015 #include <iostream>
00016 #include <iomanip>
00017 using std::cout;
00018 using std::cerr;
00019 using std::endl;
00020 using std::flush;
00021
00022 #include "Rerootjob/RecoControl.h"
00023 #include "REROOT_Classes/REROOT_UserVisitor.h"
00024 #include "REROOT_Classes/REROOT_Geom.h"
00025
00026
00027
00028
00029 #include "TROOT.h"
00030 #include "TFile.h"
00031 #include "TTree.h"
00032 #include "TBranch.h"
00033 #include "TSystem.h"
00034
00035 int nevtot = INT_MAX;
00036
00037 char inlist[FILENAME_MAX];
00038 char infile[FILENAME_MAX];
00039 char outfile[FILENAME_MAX];
00040 char optfile[FILENAME_MAX];
00041 char option[FILENAME_MAX];
00042
00043 const char* listFileFlag = "to-be-determined-from-inlist";
00044 const char* optfileDefault = "reco_options";
00045 const char* optfilePath =
00046 ".:$SRT_PRIVATE_CONTEXT/Rerootjob:$SRT_PUBLIC_CONTEXT/Rerootjob";
00047
00048 int quiet = 0;
00049
00050 static void processArgs(int argc, char** argv)
00051 {
00052 strcpy(inlist,"reco_minos.gaf_list");
00053 strcpy(infile,listFileFlag);
00054 strcpy(outfile,"reroot.root");
00055 strcpy(optfile,optfileDefault);
00056 strcpy(option,"");
00057
00058 int copt;
00059 const char* optlist = "n:l:f:o:qO:h";
00060 while (( copt = getopt(argc,argv,optlist)) != EOF) {
00061 switch (copt) {
00062 case 'n':
00063 nevtot = atoi(optarg);
00064 break;
00065 case 'l':
00066 strcpy(inlist,optarg);
00067 break;
00068 case 'f':
00069 strcpy(infile,optarg);
00070 break;
00071 case 'o':
00072 strcpy(outfile,optarg);
00073 break;
00074 case 'q':
00075 quiet += 1;
00076 break;
00077 case 'O':
00078 strcpy(optfile,optarg);
00079 break;
00080 case 'h':
00081
00082 printf("%s: usage\n",argv[0]);
00083 printf(" -l inlist-filename (reco_minos.gaf_list)\n");
00084 printf(" -f gaf-filename (no-default, overrides -l flag)\n");
00085 printf(" -o output-filename (reroot.root)\n");
00086 printf(" -O option-filename (reco_options)\n");
00087 printf(" uses a path of .:$SRT_PUBLIC_CONTEXT:$SRT_PRIVATE_CONTEXT, full path okay\n");
00088 printf(" -n nevt-per-file (%d)\n",nevtot);
00089 printf(" -q quiet, no TTree->Print(), no visitor output\n");
00090 printf(" repeat for turning off status count\n");
00091 printf(" -h this miserable help\n");
00092 exit(1);
00093 break;
00094 default:
00095 printf("%s: unrecognized option '%c'\n",argv[0],(char)optopt);
00096 exit(1);
00097 break;
00098 }
00099 }
00100
00101 return;
00102 }
00103
00104
00105 void processSingleFile(RecoControl& app,
00106 TTree*& tgeo, TTree*& tevt,
00107 REROOT_Geom*& rgeo, REROOT_Event*& revt,
00108 Int_t& idcurgeom, Int_t& nb)
00109 {
00110
00111 app.init(infile,nevtot+1);
00112
00113 REROOT_UserVisitor auv;
00114
00115 Int_t numread = 0;
00116
00117 while (numread<nevtot) {
00118 RecoControl::rectype rectype = app.nextRecord();
00119 if (rectype==RecoControl::NONE) break; numread++;
00120
00121
00122 if (rectype==RecoControl::GEVT) {
00123
00124 app.reconstruction();
00125 if (!quiet && numread<5) app.giveEventTo(auv);
00126
00127
00128 revt = app.curevent();
00129
00130
00131 revt->Setidcurgeom(idcurgeom);
00132
00133
00134 nb += tevt->Fill();
00135 if (quiet < 2)
00136 cout << "ROOT GEVT " << numread
00137 << " written. nb = " << nb
00138 << "\r" << flush;
00139
00140 }
00141
00142
00143 else if (rectype==RecoControl::GEOM) {
00144 numread--;
00145 cout << "Rerootjob: Accept GEOM record" << endl;
00146 if (!quiet && numread<5) app.giveGeomTo(auv);
00147
00148
00149 rgeo = app.curgeom();
00150
00151
00152 idcurgeom++;
00153
00154
00155 nb += tgeo->Fill();
00156 cout << "ROOT GEOM written. nb = " << nb << endl;
00157 }
00158 }
00159
00160 cout << "\nLeave Event Loop for file " << infile
00161 << " after " << numread << " records." << endl;
00162 }
00163
00164 int main(int argc, char** argv)
00165 {
00166 processArgs(argc,argv);
00167
00168
00169 TROOT rerootjob("rerootjob","ROOT interface to reco_MINOS");
00170
00171 cout << endl << "Instantiate ROOT engine for reco_MINOS." << endl
00172 << endl;
00173
00174
00175 TFile *hfile;
00176 hfile = new TFile(outfile,"RECREATE","ROOT file reroot");
00177
00178
00179 TTree *tgeo = new TTree("GEOM","REROOT Geometry Tree");
00180 TTree *tevt = new TTree("GEVT","REROOT Event Tree");
00181
00182 REROOT_Geom *rgeo = 0;
00183 REROOT_Event *revt = 0;
00184
00185
00186 TBranch *bGeom = 0;
00187 TBranch *bEvent = 0;
00188
00189
00190 Int_t gsplit = 1;
00191 Int_t esplit = 1;
00192 Int_t bgsize = 4000;
00193 Int_t besize = 4000;
00194
00195
00196 bGeom = tgeo->Branch("REROOT_Geom",
00197 "REROOT_Geom", &rgeo, bgsize, gsplit);
00198 bEvent = tevt->Branch("REROOT_Event",
00199 "REROOT_Event", &revt, besize, esplit);
00200
00201
00202 char* optfilepath = gSystem->ExpandPathName(optfilePath);
00203
00204 char* realoptfile = gSystem->Which(optfilepath,optfile,kReadPermission);
00205 if ( ! realoptfile ) {
00206
00207 realoptfile = optfile;
00208 strcpy(optfile,optfileDefault);
00209 }
00210
00211 cout << "\nRead options from file: " << realoptfile << endl << endl;
00212
00213 ifstream olist(realoptfile);
00214 while (olist>>option) {
00215 if (!strcmp(option,"REROOT_Event::DigitPln"))
00216 REROOT_Event::set_DigitPln_isWanted(kTRUE);
00217 else if (!strcmp(option,"REROOT_Event::EmuDigit"))
00218 REROOT_Event::set_EmuDigit_isWanted(kTRUE);
00219 else if (!strcmp(option,"REROOT_Event::EmuHit"))
00220 REROOT_Event::set_EmuHit_isWanted(kTRUE);
00221 else if (!strcmp(option,"REROOT_Event::EventHistory"))
00222 REROOT_Event::set_EventHistory_isWanted(kTRUE);
00223 else if (!strcmp(option,"REROOT_Event::FLSDigiCell"))
00224 REROOT_Event::set_FLSDigiCell_isWanted(kTRUE);
00225 else if (!strcmp(option,"REROOT_Event::FLSDigiPln"))
00226 REROOT_Event::set_FLSDigiPln_isWanted(kTRUE);
00227 else if (!strcmp(option,"REROOT_Event::FLSDigit"))
00228 REROOT_Event::set_FLSDigit_isWanted(kTRUE);
00229 else if (!strcmp(option,"REROOT_Event::FLSDigiView"))
00230 REROOT_Event::set_FLSDigiView_isWanted(kTRUE);
00231 else if (!strcmp(option,"REROOT_Event::FLSHit"))
00232 REROOT_Event::set_FLSHit_isWanted(kTRUE);
00233 else if (!strcmp(option,"REROOT_Event::FluxWgt"))
00234 REROOT_Event::set_FluxWgt_isWanted(kTRUE);
00235 else if (!strcmp(option,"REROOT_Event::FluxInfo"))
00236 REROOT_Event::set_FluxInfo_isWanted(kTRUE);
00237 else if (!strcmp(option,"REROOT_Event::GAFKey"))
00238 REROOT_Event::set_GAFKey_isWanted(kTRUE);
00239 else if (!strcmp(option,"REROOT_Event::HitPln"))
00240 REROOT_Event::set_HitPln_isWanted(kTRUE);
00241 else if (!strcmp(option,"REROOT_Event::LSTHit"))
00242 REROOT_Event::set_LSTHit_isWanted(kTRUE);
00243 else if (!strcmp(option,"REROOT_Event::LSTProto"))
00244 REROOT_Event::set_LSTProto_isWanted(kTRUE);
00245 else if (!strcmp(option,"REROOT_Event::LSTStrip"))
00246 REROOT_Event::set_LSTStrip_isWanted(kTRUE);
00247 else if (!strcmp(option,"REROOT_Event::LSTWire"))
00248 REROOT_Event::set_LSTWire_isWanted(kTRUE);
00249 else if (!strcmp(option,"REROOT_Event::MuonTrkHeader"))
00250 REROOT_Event::set_MuonTrkHeader_isWanted(kTRUE);
00251 else if (!strcmp(option,"REROOT_Event::MuonTrkPoint"))
00252 REROOT_Event::set_MuonTrkPoint_isWanted(kTRUE);
00253 else if (!strcmp(option,"REROOT_Event::NeuKin"))
00254 REROOT_Event::set_NeuKin_isWanted(kTRUE);
00255 else if (!strcmp(option,"REROOT_Event::NeuVtx"))
00256 REROOT_Event::set_NeuVtx_isWanted(kTRUE);
00257 else if (!strcmp(option,"REROOT_Event::PEArrival"))
00258 REROOT_Event::set_PEArrival_isWanted(kTRUE);
00259 else if (!strcmp(option,"REROOT_Event::RecoMuon"))
00260 REROOT_Event::set_RecoMuon_isWanted(kTRUE);
00261 else if (!strcmp(option,"REROOT_Event::RecoShwDir"))
00262 REROOT_Event::set_RecoShwDir_isWanted(kTRUE);
00263 else if (!strcmp(option,"REROOT_Event::RecoShwEnergy"))
00264 REROOT_Event::set_RecoShwEnergy_isWanted(kTRUE);
00265 else if (!strcmp(option,"REROOT_Event::RecoVtx"))
00266 REROOT_Event::set_RecoVtx_isWanted(kTRUE);
00267 else if (!strcmp(option,"REROOT_Event::RPCHit"))
00268 REROOT_Event::set_RPCHit_isWanted(kTRUE);
00269 else if (!strcmp(option,"REROOT_Event::StdHep"))
00270 REROOT_Event::set_StdHep_isWanted(kTRUE);
00271 else if (!strcmp(option,"REROOT_Event::StdHepHead"))
00272 REROOT_Event::set_StdHepHead_isWanted(kTRUE);
00273 else if (!strcmp(option,"REROOT_Event::TstHit"))
00274 REROOT_Event::set_TstHit_isWanted(kTRUE);
00275
00276 else if (!strcmp(option,"REROOT_Geom::AvailNuclei"))
00277 REROOT_Geom::set_AvailNuclei_isWanted(kTRUE);
00278 else if (!strcmp(option,"REROOT_Geom::BeamSystem"))
00279 REROOT_Geom::set_BeamSystem_isWanted(kTRUE);
00280 else if (!strcmp(option,"REROOT_Geom::CellPos"))
00281 REROOT_Geom::set_CellPos_isWanted(kTRUE);
00282 else if (!strcmp(option,"REROOT_Geom::CoilTube"))
00283 REROOT_Geom::set_CoilTube_isWanted(kTRUE);
00284 else if (!strcmp(option,"REROOT_Geom::FLSParam"))
00285 REROOT_Geom::set_FLSParam_isWanted(kTRUE);
00286 else if (!strcmp(option,"REROOT_Geom::GAFKey"))
00287 REROOT_Geom::set_GAFKey_isWanted(kTRUE);
00288 else if (!strcmp(option,"REROOT_Geom::GeomMisc"))
00289 REROOT_Geom::set_GeomMisc_isWanted(kTRUE);
00290 else if (!strcmp(option,"REROOT_Geom::MassDistrib"))
00291 REROOT_Geom::set_MassDistrib_isWanted(kTRUE);
00292 else if (!strcmp(option,"REROOT_Geom::Material"))
00293 REROOT_Geom::set_Material_isWanted(kTRUE);
00294 else if (!strcmp(option,"REROOT_Geom::MdlOrg"))
00295 REROOT_Geom::set_MdlOrg_isWanted(kTRUE);
00296 else if (!strcmp(option,"REROOT_Geom::Mixture"))
00297 REROOT_Geom::set_Mixture_isWanted(kTRUE);
00298 else if (!strcmp(option,"REROOT_Geom::PlanePos"))
00299 REROOT_Geom::set_PlanePos_isWanted(kTRUE);
00300 else if (!strcmp(option,"REROOT_Geom::PlaneSpec"))
00301 REROOT_Geom::set_PlaneSpec_isWanted(kTRUE);
00302 else if (!strcmp(option,"REROOT_Geom::PlexusAdd"))
00303 REROOT_Geom::set_PlexusAdd_isWanted(kTRUE);
00304 else if (!strcmp(option,"REROOT_Geom::Pln2MUX"))
00305 REROOT_Geom::set_Pln2MUX_isWanted(kTRUE);
00306 else if (!strcmp(option,"REROOT_Geom::Rotm"))
00307 REROOT_Geom::set_Rotm_isWanted(kTRUE);
00308 else if (!strcmp(option,"REROOT_Geom::SubVolPos"))
00309 REROOT_Geom::set_SubVolPos_isWanted(kTRUE);
00310 else if (!strcmp(option,"REROOT_Geom::SubVolSpec"))
00311 REROOT_Geom::set_SubVolSpec_isWanted(kTRUE);
00312 else if (!strcmp(option,"REROOT_Geom::SuperModule"))
00313 REROOT_Geom::set_SuperModule_isWanted(kTRUE);
00314 else if (!strcmp(option,"REROOT_Geom::TMedium"))
00315 REROOT_Geom::set_TMedium_isWanted(kTRUE);
00316 else if (!strcmp(option,"REROOT_Geom::TPar"))
00317 REROOT_Geom::set_TPar_isWanted(kTRUE);
00318 else if (!strcmp(option,"REROOT_Geom::TubePixelInfo"))
00319 REROOT_Geom::set_TubePixelInfo_isWanted(kTRUE);
00320 else if (!strcmp(option,"REROOT_Geom::TubePixelMap"))
00321 REROOT_Geom::set_TubePixelMap_isWanted(kTRUE);
00322 else
00323 cout << "Bad option ignored: " << option << endl;
00324 }
00325
00326 RecoControl app;
00327 Int_t idcurgeom = -1;
00328 Int_t nb = 0;
00329
00330 if ( ! strcmp(infile,listFileFlag) ) {
00331
00332 cout << "\nRun Recoop on list " << inlist
00333 << " for " << nevtot << " events each file.\n";
00334
00335 ifstream clist(inlist);
00336 while (clist>>infile) {
00337 char firstChar = infile[0];
00338 if (firstChar != '#' && firstChar != '!' ) {
00339 cout << "\nRun Recoop on file " << infile
00340 << " for " << nevtot << " events in file." << endl;
00341 processSingleFile(app,tgeo,tevt,rgeo,revt,idcurgeom,nb);
00342 }
00343 else {
00344 cout << "\nSkip processing for entry: " << infile << endl;
00345 }
00346 }
00347 cout << "\nFinish list of event files: " << inlist << endl;
00348 }
00349 else {
00350 cout << "\nRun Recoop on file " << infile
00351 << " for " << nevtot << " events in file." << endl;
00352 processSingleFile(app,tgeo,tevt,rgeo,revt,idcurgeom,nb);
00353 }
00354
00355
00356 cout << "Close ROOT file: " << outfile << endl;
00357 hfile->Write();
00358 if (!quiet) { tgeo->Print(); tevt->Print(); }
00359 hfile->Close();
00360 cout << "ROOT file " << outfile << " closed." << endl;
00361
00362 return 0;
00363 }