Belle II Software  release-08-01-10
HepevtReader.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 
11 #include <framework/core/FrameworkExceptions.h>
12 #include <mdst/dataobjects/MCParticleGraph.h>
13 #include <boost/tokenizer.hpp>
14 
15 #include <string>
16 #include <fstream>
17 
18 namespace Belle2 {
33  class HepevtReader {
34 
35  public:
36 
37  //Define exceptions
39  BELLE2_DEFINE_EXCEPTION(HepEvtCouldNotOpenFileError, "Could not open file %1% !");
41  BELLE2_DEFINE_EXCEPTION(HepEvtInvalidDaughterIndicesError,
42  "Line %1%: Invalid daughter indices d1=%2%, d2=%3%, N=%4% (0<=d1<=d2<=N required)");
44  BELLE2_DEFINE_EXCEPTION(HepEvtHeaderNotValidError, "Line %1%: Event header not understood: %2%");
46  BELLE2_DEFINE_EXCEPTION(HepEvtConvertFieldError, "Line %1%: Could not convert field %2%: %3%");
48  BELLE2_DEFINE_EXCEPTION(HepEvtParticleFormatError, "Line %1%: Particle format not understood, got %2% fields !");
50  BELLE2_DEFINE_EXCEPTION(HepEvtEmptyEventError,
51  "Line %1%: Number of particles in event is %2% ! (This could mean EOF is reached.) ");
56 
60  ~HepevtReader() { if (m_input) m_input.close(); }
61 
66  void open(const std::string& filename);
67 
71  void closeCurrentInputFile() {m_input.close();}
72 
79  int getEvent(MCParticleGraph& graph, double& weight);
80 
86  bool skipEvents(int n);
87 
88  int m_nVirtual;
91  protected:
93  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
95  static const boost::char_separator<char> sep;
96 
97  int m_lineNr;
98  std::ifstream m_input;
100  // /* int eventID; /**< The event ID number if provided in HepEvtfile else -1. */ */
102 
103 
108  std::string getLine();
109 
116  int readEventHeader(int& eventID, double& eventWeight);
117 
123  };
124 
126 }
Class to read Hepevt files and store the content in a MCParticle graph.
Definition: HepevtReader.h:33
BELLE2_DEFINE_EXCEPTION(HepEvtHeaderNotValidError, "Line %1%: Event header not understood: %2%")
Exception is thrown if the header specifying the event header could not be parsed.
bool skipEvents(int n)
Skips a given number of events.
Definition: HepevtReader.cc:79
std::string getLine()
Returns the current line from the Hepevt ascii file.
Definition: HepevtReader.cc:96
BELLE2_DEFINE_EXCEPTION(HepEvtInvalidDaughterIndicesError, "Line %1%: Invalid daughter indices d1=%2%, d2=%3%, N=%4% (0<=d1<=d2<=N required)")
Exception is thrown if the given indices of the daughters are not valid.
HepevtReader()
Constructor.
Definition: HepevtReader.h:55
BELLE2_DEFINE_EXCEPTION(HepEvtParticleFormatError, "Line %1%: Particle format not understood, got %2% fields !")
Exception is thrown if the format of a line of the HepEvt file could not be parsed.
static const boost::char_separator< char > sep
The characters at which to split, defaults to ",; \t".
Definition: HepevtReader.h:95
~HepevtReader()
Destructor.
Definition: HepevtReader.h:60
int m_lineNr
The current line number within the ascii file.
Definition: HepevtReader.h:97
void open(const std::string &filename)
Opens an ascii file and prepares it for reading.
Definition: HepevtReader.cc:27
void closeCurrentInputFile()
Closes the current input file to allow opening the next one.
Definition: HepevtReader.h:71
std::ifstream m_input
The input stream of the ascii file.
Definition: HepevtReader.h:98
boost::tokenizer< boost::char_separator< char > > tokenizer
Just a typedef for simple use of the boost::tokenizer to split the lines.
Definition: HepevtReader.h:93
int readEventHeader(int &eventID, double &eventWeight)
Reads the event header from the hepevt file.
int getEvent(MCParticleGraph &graph, double &weight)
Reads the next event and stores the result in the given MCParticle graph.
Definition: HepevtReader.cc:35
BELLE2_DEFINE_EXCEPTION(HepEvtCouldNotOpenFileError, "Could not open file %1% !")
Exception is thrown if the HepEvt file could not be opened.
BELLE2_DEFINE_EXCEPTION(HepEvtEmptyEventError, "Line %1%: Number of particles in event is %2% ! (This could mean EOF is reached.) ")
Exception is thrown if the number of particles for this event is 0 or less.
bool m_wrongSignPz
Bool to indicate that HER and LER were swapped.
Definition: HepevtReader.h:89
void readParticle(MCParticleGraph::GraphParticle &particle)
Reads the information for a single particle from the Hepevt file.
BELLE2_DEFINE_EXCEPTION(HepEvtConvertFieldError, "Line %1%: Could not convert field %2%: %3%")
Exception is thrown if a field in the HepEvt file could not be converted to a number.
int m_nVirtual
The number of particles in each event with a set Virtual flag.
Definition: HepevtReader.h:88
Class to represent Particle data in graph.
Class to build, validate and sort a particle decay chain.
Abstract base class for different kinds of events.