CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
FWLiteLumiAccess.cc File Reference
#include <iostream>
#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 15 of file FWLiteLumiAccess.cc.

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

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