CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
FWLiteLumiAccess.cc File Reference
#include <TFile.h>
#include <TSystem.h>
#include "DataFormats/FWLite/interface/Event.h"
#include "DataFormats/FWLite/interface/Handle.h"
#include "FWCore/FWLite/interface/AutoLibraryLoader.h"
#include "DataFormats/FWLite/interface/Run.h"
#include "DataFormats/FWLite/interface/LuminosityBlock.h"
#include "DataFormats/Luminosity/interface/LumiSummary.h"
#include "PhysicsTools/FWLite/interface/CommandLineParser.h"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 14 of file FWLiteLumiAccess.cc.

References fwlite::Run::atEnd(), fwlite::LuminosityBlock::atEnd(), fwlite::Event::atEnd(), LumiSummary::avgInsRecLumi(), gather_cfg::cout, AutoLibraryLoader::enable(), fwlite::Handle< T >::getByLabel(), fwlite::Event::getLuminosityBlock(), fwlite::LuminosityBlock::getRun(), fwlite::Event::getRun(), edm::RunBase::id(), edm::LuminosityBlockBase::id(), python.rootplot.utilities::ls(), optutl::CommandLineParser::parseArguments(), geometryXMLtoCSV::parser, alignCSCRings::r, optutl::VariableMapCont::stringVector(), edmLumisInFiles::summary, fwlite::Run::toBegin(), fwlite::LuminosityBlock::toBegin(), and fwlite::Event::toBegin().

14  {
15  // load framework libraries
16  gSystem->Load( "libFWCoreFWLite" );
18 
19  // initialize command line parser
20  optutl::CommandLineParser parser ("Analyze FWLite Histograms");
21 
22  // parse arguments
23  parser.parseArguments (argc, argv);
24  std::vector<std::string> inputFiles_ = parser.stringVector("inputFiles");
25 
26  for(unsigned int iFile=0; iFile<inputFiles_.size(); ++iFile){
27  // open input file (can be located on castor)
28  TFile* inFile = TFile::Open(inputFiles_[iFile].c_str());
29  if( inFile ){
30  fwlite::Event ev(inFile);
32 
33  std::cout << "----------- Accessing by event ----------------" << std::endl;
34 
35  // get run and luminosity blocks from events as well as associated
36  // products. (This works for both ChainEvent and MultiChainEvent.)
37  for(ev.toBegin(); !ev.atEnd(); ++ev){
38  // get the Luminosity block ID from the event
39  std::cout << " Luminosity ID " << ev.getLuminosityBlock().id() << std::endl;
40  // get the Run ID from the event
41  std::cout <<" Run ID " << ev.getRun().id()<< std::endl;
42  // get the Run ID from the luminosity block you got from the event
43  std::cout << "Run via lumi " << ev.getLuminosityBlock().getRun().id() << std::endl;
44  // get the integrated luminosity (or any luminosity product) from
45  // the event
46  summary.getByLabel(ev.getLuminosityBlock(),"lumiProducer");
47  }
48 
49  std::cout << "----------- Accessing by lumi block ----------------" << std::endl;
50 
51  double lumi_tot = 0.0;
52  // loop over luminosity blocks (in analogy to looping over events)
54  for(ls.toBegin(); !ls.atEnd(); ++ls){
55  summary.getByLabel(ls,"lumiProducer");
56  std::cout << ls.id() << " Inst. Luminosity = " << summary->avgInsRecLumi() << std::endl;
57  // get the associated run from this lumi
58  std::cout << "Run from lumi " << ls.getRun().id() << std::endl;
59  // add up the luminosity by lumi block
60  lumi_tot += summary->avgInsRecLumi();
61  }
62  // print the result
63  std::cout << "----------------------------------------------------" << std::endl;
64  std::cout << "Total luminosity from lumi sections = " << lumi_tot << std::endl;
65  std::cout << "----------------------------------------------------" << std::endl;
66 
67  std::cout << "----------- Accessing by run ----------------" << std::endl;
68 
69  // do the same for runs
70  fwlite::Run r(inFile);
71  for(r.toBegin(); !r.atEnd(); ++r) {
72  std::cout << "Run " << r.id() << std::endl;
73  }
74  // close input file
75  inFile->Close();
76  }
77  }
78  return 0;
79 }
float avgInsRecLumi() const
Definition: LumiSummary.cc:98
void getByLabel(const P &iP, const char *iModuleLabel, const char *iProductInstanceLabel=0, const char *iProcessLabel=0)
Definition: Handle.h:94
tuple argc
Definition: dir2webdir.py:41
static void enable()
enable automatic library loading
tuple cout
Definition: gather_cfg.py:121