Run Class Reference

#include <Run.hh>

Collaboration diagram for Run:

Collaboration graph
[legend]

List of all members.


Detailed Description

Definition at line 15 of file Run.hh.


Public Member Functions

Standard constructors and destructors. */
 Run (AnalysisHandler &ah)
 The standard constructor.
 ~Run ()
 The destructor.
Set run properties
RunsetCrossSection (const double xs)
 Get the cross-section for this run.
RunsetListAnalyses (const bool dolist)
 Declare whether to list available analyses.
File processing stages
bool init (const std::string &evtfile)
 Set up HepMC file readers.
bool openFile (const std::string &evtfile)
 Open a HepMC GenEvent file.
bool readEvent ()
 Read the next HepMC event.
bool processEvent ()
 Handle next event.
bool finalize ()
 Close up HepMC I/O.

Private Attributes

AnalysisHandler_ah
 AnalysisHandler object.
bool _listAnalyses
 Flag to show list of analyses.
Run variables obtained from events or command line
double _xs
 Cross-section from command line.
HepMC I/O members
shared_ptr< GenEvent > _evt
 Current event.
shared_ptr< std::istream > _istr
 Output stream for HepMC writer.
shared_ptr< HepMC::IO_GenEvent > _io
 HepMC I/O writer.

Constructor & Destructor Documentation

Run ( AnalysisHandler ah  ) 

The standard constructor.

Definition at line 11 of file Run.cc.

00012     : _ah(ah), _xs(-1.0)
00013   { }

~Run (  ) 

The destructor.

Definition at line 16 of file Run.cc.

00016 { }


Member Function Documentation

Run & setCrossSection ( const double  xs  ) 

Get the cross-section for this run.

Definition at line 19 of file Run.cc.

References Run::_xs.

00019                                            {
00020     _xs = xs;
00021     return *this;
00022   }

Run & setListAnalyses ( const bool  dolist  ) 

Declare whether to list available analyses.

Definition at line 25 of file Run.cc.

References Run::_listAnalyses.

00025                                              {
00026     _listAnalyses = dolist;
00027     return *this;
00028   }

bool init ( const std::string &  evtfile  ) 

Set up HepMC file readers.

Definition at line 61 of file Run.cc.

References Run::_ah, Run::_evt, Run::_listAnalyses, Run::_xs, AnalysisHandler::analysisNames(), Log::DEBUG, Log::ERROR, Log::getLog(), AnalysisHandler::init(), Run::openFile(), Run::readEvent(), and AnalysisHandler::setCrossSection().

00061                                          {
00062     if (!openFile(evtfile)) return false;
00063 
00064     // Read first event to define run conditions
00065     bool ok = readEvent();
00066     if (!ok) return false;
00067     if (_evt->particles_size() == 0) {
00068       Log::getLog("Rivet.Run") << Log::ERROR << "Empty first event." << endl;
00069       return false;
00070     }
00071 
00072     // Initialise AnalysisHandler with beam information from first event
00073     _ah.init(*_evt);
00074 
00075     // Set cross-section from command line
00076     if (_xs >= 0.0) {
00077       Log::getLog("Rivet.Run") 
00078         << Log::DEBUG << "Setting user cross-section = " << _xs << " pb" << endl;
00079       _ah.setCrossSection(_xs);
00080     }
00081 
00082     // List the chosen & compatible analyses if requested
00083     if (_listAnalyses) {
00084       foreach (const std::string& ana, _ah.analysisNames()) {
00085         cout << ana << endl;
00086       }
00087     }
00088 
00089     return true;
00090   }

bool openFile ( const std::string &  evtfile  ) 

Open a HepMC GenEvent file.

Definition at line 44 of file Run.cc.

References Run::_io, Run::_istr, Log::ERROR, and Log::getLog().

Referenced by Run::init().

00044                                              {
00045     // Set up HepMC input reader objects
00046     if (evtfile == "-") {
00047       _io.reset(new HepMC::IO_GenEvent(std::cin));
00048     } else {
00049       // Ignore the HepMC::IO_GenEvent(filename, ios) constructor, since it's only available from HepMC 2.4
00050       _istr.reset(new std::fstream(evtfile.c_str(), std::ios::in));
00051       _io.reset(new HepMC::IO_GenEvent(*_istr));
00052     }
00053     if (_io->rdstate() != 0) {
00054       Log::getLog("Rivet.Run") << Log::ERROR << "Read error on file " << evtfile << endl;
00055       return false;
00056     }
00057     return true;
00058   }

bool readEvent (  ) 

Read the next HepMC event.

Todo:
Clear rather than new the GenEvent object per-event?

Definition at line 32 of file Run.cc.

References Run::_evt, Run::_io, Log::DEBUG, and Log::getLog().

Referenced by Run::init().

00032                       {
00033     /// @todo Clear rather than new the GenEvent object per-event?
00034     _evt.reset(new GenEvent());
00035     if (_io->rdstate() != 0 || !_io->fill_next_event(_evt.get()) ) {
00036       Log::getLog("Rivet.Run") << Log::DEBUG
00037             << "Read failed. End of file?" << endl;
00038       return false;
00039     }
00040     return true;
00041   }

bool processEvent (  ) 

Handle next event.

Definition at line 93 of file Run.cc.

References Run::_ah, Run::_evt, AnalysisHandler::analyze(), Log::DEBUG, Log::ERROR, Log::getLog(), AnalysisHandler::hasCrossSection(), AnalysisHandler::needCrossSection(), and AnalysisHandler::setCrossSection().

00093                          {
00094     // Set cross-section if found in event and not from command line
00095     #ifdef HEPMC_HAS_CROSS_SECTION
00096     if (_xs < 0.0 && _evt->cross_section()) {
00097       const double xs = _evt->cross_section()->cross_section(); //< in pb
00098       Log::getLog("Rivet.Run")
00099         << Log::DEBUG << "Setting cross-section = " << xs << " pb" << endl;
00100       _ah.setCrossSection(xs);
00101     }
00102     #endif
00103     // Complain about absence of cross-section if required!
00104     if (_ah.needCrossSection() && !_ah.hasCrossSection()) {
00105       Log::getLog("Rivet.Run") 
00106         << Log::ERROR
00107         << "Total cross-section needed for at least one of the analyses. "
00108         << "Please set it (on the command line with '-x' if using the 'rivet' program)" << endl;
00109       return false;
00110     }
00111      
00112     // Analyze event
00113     _ah.analyze(*_evt);
00114  
00115     return true;
00116   }

bool finalize (  ) 

Close up HepMC I/O.

Definition at line 119 of file Run.cc.

References Run::_evt, Run::_io, and Run::_istr.

00119                      {
00120     _evt.reset();
00121     _istr.reset();
00122     _io.reset();
00123     return true;
00124   }


Member Data Documentation

AnalysisHandler& _ah [private]

AnalysisHandler object.

Definition at line 67 of file Run.hh.

Referenced by Run::init(), and Run::processEvent().

double _xs [private]

Cross-section from command line.

Definition at line 74 of file Run.hh.

Referenced by Run::init(), and Run::setCrossSection().

bool _listAnalyses [private]

Flag to show list of analyses.

Definition at line 80 of file Run.hh.

Referenced by Run::init(), and Run::setListAnalyses().

shared_ptr<GenEvent> _evt [private]

Current event.

Definition at line 87 of file Run.hh.

Referenced by Run::finalize(), Run::init(), Run::processEvent(), and Run::readEvent().

shared_ptr<std::istream> _istr [private]

Output stream for HepMC writer.

Definition at line 90 of file Run.hh.

Referenced by Run::finalize(), and Run::openFile().

shared_ptr<HepMC::IO_GenEvent> _io [private]

HepMC I/O writer.

Definition at line 93 of file Run.hh.

Referenced by Run::finalize(), Run::openFile(), and Run::readEvent().


The documentation for this class was generated from the following files: