rerootjob.cc File Reference

#include <new>
#include <limits.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#include <iomanip>
#include "Rerootjob/RecoControl.h"
#include "REROOT_Classes/REROOT_UserVisitor.h"
#include "REROOT_Classes/REROOT_Geom.h"
#include "TROOT.h"
#include "TFile.h"
#include "TTree.h"
#include "TBranch.h"
#include "TSystem.h"

Go to the source code of this file.

Functions

static void processArgs (int argc, char **argv)
void processSingleFile (RecoControl &app, TTree *&tgeo, TTree *&tevt, REROOT_Geom *&rgeo, REROOT_Event *&revt, Int_t &idcurgeom, Int_t &nb)
int main (int argc, char **argv)

Variables

int nevtot = INT_MAX
char inlist [FILENAME_MAX]
char infile [FILENAME_MAX]
char outfile [FILENAME_MAX]
char optfile [FILENAME_MAX]
char option [FILENAME_MAX]
const char * listFileFlag = "to-be-determined-from-inlist"
const char * optfileDefault = "reco_options"
const char * optfilePath
int quiet = 0

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 164 of file rerootjob.cc.

References gSystem(), infile, inlist, listFileFlag, nevtot, optfile, optfileDefault, optfilePath, option, outfile, processArgs(), processSingleFile(), quiet, REROOT_Geom::set_AvailNuclei_isWanted(), REROOT_Geom::set_BeamSystem_isWanted(), REROOT_Geom::set_CellPos_isWanted(), REROOT_Geom::set_CoilTube_isWanted(), REROOT_Event::set_DigitPln_isWanted(), REROOT_Event::set_EmuDigit_isWanted(), REROOT_Event::set_EmuHit_isWanted(), REROOT_Event::set_EventHistory_isWanted(), REROOT_Event::set_FLSDigiCell_isWanted(), REROOT_Event::set_FLSDigiPln_isWanted(), REROOT_Event::set_FLSDigit_isWanted(), REROOT_Event::set_FLSDigiView_isWanted(), REROOT_Event::set_FLSHit_isWanted(), REROOT_Geom::set_FLSParam_isWanted(), REROOT_Event::set_FluxInfo_isWanted(), REROOT_Event::set_FluxWgt_isWanted(), REROOT_Geom::set_GAFKey_isWanted(), REROOT_Event::set_GAFKey_isWanted(), REROOT_Geom::set_GeomMisc_isWanted(), REROOT_Event::set_HitPln_isWanted(), REROOT_Event::set_LSTHit_isWanted(), REROOT_Event::set_LSTProto_isWanted(), REROOT_Event::set_LSTStrip_isWanted(), REROOT_Event::set_LSTWire_isWanted(), REROOT_Geom::set_MassDistrib_isWanted(), REROOT_Geom::set_Material_isWanted(), REROOT_Geom::set_MdlOrg_isWanted(), REROOT_Geom::set_Mixture_isWanted(), REROOT_Event::set_MuonTrkHeader_isWanted(), REROOT_Event::set_MuonTrkPoint_isWanted(), REROOT_Event::set_NeuKin_isWanted(), REROOT_Event::set_NeuVtx_isWanted(), REROOT_Event::set_PEArrival_isWanted(), REROOT_Geom::set_PlanePos_isWanted(), REROOT_Geom::set_PlaneSpec_isWanted(), REROOT_Geom::set_PlexusAdd_isWanted(), REROOT_Geom::set_Pln2MUX_isWanted(), REROOT_Event::set_RecoMuon_isWanted(), REROOT_Event::set_RecoShwDir_isWanted(), REROOT_Event::set_RecoShwEnergy_isWanted(), REROOT_Event::set_RecoVtx_isWanted(), REROOT_Geom::set_Rotm_isWanted(), REROOT_Event::set_RPCHit_isWanted(), REROOT_Event::set_StdHep_isWanted(), REROOT_Event::set_StdHepHead_isWanted(), REROOT_Geom::set_SubVolPos_isWanted(), REROOT_Geom::set_SubVolSpec_isWanted(), REROOT_Geom::set_SuperModule_isWanted(), REROOT_Geom::set_TMedium_isWanted(), REROOT_Geom::set_TPar_isWanted(), REROOT_Event::set_TstHit_isWanted(), REROOT_Geom::set_TubePixelInfo_isWanted(), and REROOT_Geom::set_TubePixelMap_isWanted().

00165 {
00166    processArgs(argc,argv);
00167 
00168 // Instantiate ROOT engine.
00169    TROOT rerootjob("rerootjob","ROOT interface to reco_MINOS");
00170 
00171    cout << endl << "Instantiate ROOT engine for reco_MINOS." << endl
00172                                                              << endl;
00173 
00174 // Create and initialize ROOT output file for this JOB.
00175    TFile *hfile;
00176    hfile = new TFile(outfile,"RECREATE","ROOT file reroot");
00177 
00178 // Create ROOT Tree.
00179    TTree *tgeo = new TTree("GEOM","REROOT Geometry Tree");
00180    TTree *tevt = new TTree("GEVT","REROOT Event Tree");
00181 
00182    REROOT_Geom  *rgeo = 0;            // Pointer to latest REROOT_Geom.
00183    REROOT_Event *revt = 0;           // Pointer to latest REROOT_Event.
00184 
00185 // Declare branches.
00186    TBranch *bGeom = 0;
00187    TBranch *bEvent = 0;
00188 
00189 // Splitting for REROOT_Geom and REROOT_Event branches.
00190    Int_t gsplit = 1;     // No automatic ROOT splitting for REROOT_Geom.
00191    Int_t esplit = 1;       // Automatic ROOT splitting for REROOT_Event.
00192    Int_t bgsize = 4000;
00193    Int_t besize = 4000;
00194 
00195 // Create REROOT_Geom and REROOT_Event branches.
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 // Specify which ADAMO Class objects to create from GAF buffer.
00202    char* optfilepath = gSystem->ExpandPathName(optfilePath);
00203    //cout << " optfilepath is '" << optfilepath << "'" << endl;
00204    char* realoptfile = gSystem->Which(optfilepath,optfile,kReadPermission);
00205    if ( ! realoptfile ) {
00206      // revert to the default if what was given came up empty
00207      realoptfile = optfile;  // the original buffer
00208      strcpy(optfile,optfileDefault);
00209    }
00210 
00211    cout << "\nRead options from file: " << realoptfile << endl << endl;
00212 
00213    std::ifstream olist(realoptfile);         // Read from option list file.
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;  // Incremented for each REROOT_Geom record.
00328    Int_t nb = 0;
00329 
00330    if ( ! strcmp(infile,listFileFlag) ) { 
00331      // user wants to get file names file a list in another file
00332      cout << "\nRun Recoop on list " << inlist
00333           << " for " << nevtot << " events each file.\n";
00334 
00335      std::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 // Close ROOT output file for this job.
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 }

static void processArgs ( int  argc,
char **  argv 
) [static]

Definition at line 50 of file rerootjob.cc.

References exit(), infile, inlist, listFileFlag, nevtot, optfile, optfileDefault, option, outfile, and quiet.

Referenced by main().

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       // help ...
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 }

void processSingleFile ( RecoControl app,
TTree *&  tgeo,
TTree *&  tevt,
REROOT_Geom *&  rgeo,
REROOT_Event *&  revt,
Int_t &  idcurgeom,
Int_t &  nb 
)

Definition at line 105 of file rerootjob.cc.

References RecoControl::curevent(), RecoControl::curgeom(), RecoControl::GEOM, RecoControl::GEVT, RecoControl::giveEventTo(), RecoControl::giveGeomTo(), infile, RecoControl::init(), nevtot, RecoControl::nextRecord(), RecoControl::NONE, quiet, RecoControl::reconstruction(), and REROOT_Event::Setidcurgeom().

Referenced by main().

00109 {
00110 
00111   app.init(infile,nevtot+1);
00112 
00113   REROOT_UserVisitor auv;  
00114   
00115   Int_t numread = 0;
00116 //rwh:  for (Int_t eventCount=nevtot+1; eventCount>0; eventCount--) {
00117   while (numread<nevtot) {
00118     RecoControl::rectype rectype = app.nextRecord();
00119     if (rectype==RecoControl::NONE) break;  numread++;
00120     
00121     // GEVT record encountered.
00122     if (rectype==RecoControl::GEVT) {
00123       // cout << "Rerootjob: Accept GEVT record" << endl;
00124       app.reconstruction();
00125       if (!quiet && numread<5) app.giveEventTo(auv);
00126       
00127       // Get current REROOT_Event object.
00128       revt = app.curevent();
00129 
00130       // Mark REROOT_Event with ID in JOB of corresponding REROOT_Geom object.
00131       revt->Setidcurgeom(idcurgeom);
00132 
00133       // Fill REROOT_Event branch.
00134       nb += tevt->Fill();
00135       if (quiet < 2)
00136         cout << "ROOT GEVT " << numread 
00137              << " written. nb = " << nb 
00138              << "\r" << flush;
00139       //<< endl;
00140     }
00141     
00142     // GEOM record encountered.
00143     else if (rectype==RecoControl::GEOM) {
00144       numread--; // don't count geometry against evt count
00145       cout << "Rerootjob: Accept GEOM record" << endl;
00146       if (!quiet && numread<5) app.giveGeomTo(auv);
00147       
00148       // Get current REROOT_Geom object.
00149       rgeo = app.curgeom();
00150       
00151       // Increment idcurgeom..
00152       idcurgeom++;
00153       
00154       // Fill REROOT_Geom branch.
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 }


Variable Documentation

char infile[FILENAME_MAX]
char inlist[FILENAME_MAX]

Definition at line 37 of file rerootjob.cc.

Referenced by RawQieErrorStatsBlock::FillAllMaps(), main(), and processArgs().

const char* listFileFlag = "to-be-determined-from-inlist"

Definition at line 43 of file rerootjob.cc.

Referenced by main(), and processArgs().

int nevtot = INT_MAX

Definition at line 35 of file rerootjob.cc.

Referenced by main(), processArgs(), and processSingleFile().

char optfile[FILENAME_MAX]

Definition at line 40 of file rerootjob.cc.

Referenced by main(), and processArgs().

const char* optfileDefault = "reco_options"

Definition at line 44 of file rerootjob.cc.

Referenced by main(), and processArgs().

const char* optfilePath
Initial value:
 
   ".:$SRT_PRIVATE_CONTEXT/Rerootjob:$SRT_PUBLIC_CONTEXT/Rerootjob"

Definition at line 45 of file rerootjob.cc.

Referenced by main().

char option[FILENAME_MAX]
char outfile[FILENAME_MAX]
int quiet = 0

Definition at line 48 of file rerootjob.cc.

Referenced by Anp::RunAlgEvent::Config(), main(), processArgs(), and processSingleFile().


Generated on 14 Dec 2017 for loon by  doxygen 1.6.1