Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:45

0001 #include <TROOT.h>
0002 #include <TFile.h>
0003 #include <TTree.h>
0004 #include <TBranch.h>
0005 #include <TSystem.h>
0006 
0007 #include <iostream>
0008 #include <string>
0009 #include <assert.h>
0010 #include <stdlib.h>
0011 
0012 // needed for timing studies
0013 #include "DataFormats/HLTReco/interface/ModuleTiming.h"
0014 // needed for event-id info
0015 #include "DataFormats/Provenance/interface/EventAuxiliary.h"
0016 //
0017 #include "FWCore/FWLite/interface/FWLiteEnabler.h"
0018 
0019 #include "HLTrigger/Timer/test/AnalyzeTiming.h"
0020 
0021 using std::cout;
0022 using std::endl;
0023 using std::string;
0024 
0025 #define PRINT_EVTRUN_NO 0
0026 
0027 // Christos Leonidopoulos, July 2006
0028 
0029 /* usage: analyzeTiming <ROOT file> <process name> <N_bins> <Max_time>
0030    where, 
0031    <ROOT file>: file with HLT information to be analyzed (default: hlt.root)
0032    <process name>: name for cmsRun job in config file (default: PRODHLT)
0033    <N_bins>: # of bins for timing histograms (default: 100)
0034    <Max_time>: upper edge for timing histograms in ms (default: 1000)
0035 */
0036 int main(int argc, char **argv) {
0037   // load libraries
0038   gSystem->Load("libFWCoreFWLite");
0039   FWLiteEnabler::enable();
0040 
0041   // default arguments
0042   string filename = "hlt.root";
0043   string process_name = "PRODHLT";
0044   unsigned int N_bins = 100;
0045   float Max_time = 1000;  // in ms
0046   // get parameters from command line
0047   if (argc >= 2)
0048     filename = argv[1];
0049   if (argc >= 3)
0050     process_name = argv[2];
0051   if (argc >= 4)
0052     N_bins = atoi(argv[3]);
0053   if (argc >= 5)
0054     Max_time = 1. * atoi(argv[4]);
0055 
0056   // open file
0057   TFile file(filename.c_str());
0058   if (file.IsZombie()) {
0059     cout << " *** Error opening file " << filename << endl;
0060     exit(-1);
0061   }
0062   TTree *events = dynamic_cast<TTree *>(file.Get("Events"));
0063   assert(events);
0064 
0065   TBranch *TBevtTime = 0;
0066   TBranch *TBevtAux = events->GetBranch("EventAuxiliary");
0067   assert(TBevtAux);
0068   //  std::cout << " TBevtAux = " << int(TBevtAux) << std::endl;
0069 
0070   // structure holding the timing info
0071   edm::EventTime evtTime;
0072 
0073 #if PRINT_EVTRUN_NO
0074   // structure holding event information
0075   edm::EventAuxiliary *evtAux = new edm::EventAuxiliary;
0076 
0077   TBevtAux->SetAddress((void *)&evtAux);
0078 #endif
0079 
0080   AnalyzeTiming *tt = 0;
0081 
0082   char tmp_name[1024];
0083   snprintf(tmp_name, 1024, "edmEventTime_myTimer__%s.obj", process_name.c_str());
0084   TBevtTime = events->GetBranch(tmp_name);
0085   assert(TBevtTime);
0086   TBevtTime->SetAddress((void *)&evtTime);
0087   tt = new AnalyzeTiming(N_bins, 0, Max_time);
0088 
0089   int n_evts = events->GetEntries();
0090 
0091   for (int i = 0; i != n_evts; ++i) {
0092 #if PRINT_EVTRUN_NO
0093     TBevtAux->GetEntry(i);
0094     cout << " Run # = " << evtAux->id().run() << " event # = " << evtAux->id().event() << " entry # = " << i << "\n";
0095 #endif
0096 
0097     TBevtTime->GetEntry(i);
0098     tt->analyze(evtTime);
0099 
0100   }  // loop over all events
0101 
0102   // get results, do cleanup
0103 
0104   tt->getResults();
0105   delete tt;
0106 
0107 #if PRINT_EVTRUN_NO
0108   delete evtAux;
0109 #endif
0110 
0111   return 0;
0112 }