Commit 8f1948a6 authored by Lynn Garren's avatar Lynn Garren
Browse files

matching examples to 1.24

parent ad2bd1a8
......@@ -27,6 +27,7 @@ endif
INCDIR = -I$(CLHEP_DIR)/include
HepMCinc = $(INCDIR)/CLHEP/HepMC
PythiaLIB = $(LULIB)/pydata.o $(LULIB)/liblund.a $(LULIB)/libpydum.a
HerwigLIB = $(HERWIG_DIR)/lib/libherwig.a $(HERWIG_DIR)/lib/libherdum.a
LIBNAME = $(CLHEP_DIR)/lib/libCLHEP-1.9.0.0.a
......@@ -94,6 +95,12 @@ all: $(examples)
run: $(runList) $(runListAscii)
example_MyHerwig.exe: example_MyHerwig$(SFX).o IO_HERWIG$(SFX).o
@echo "Building $@ ..."
$(CXX) $(FLAGS) example_MyHerwig$(SFX).o IO_HERWIG$(SFX).o \
$(LIBNAME) \
$(HerwigLIB) $(LINK_LIBS) -o $@
example_MyPythia.exe: example_MyPythia$(SFX).o $(initpydata_OBJ) $(Ascii_OBJ)
@echo "Building $@ ..."
$(CXX) $(FLAGS) example_MyPythia$(SFX).o $(initpydata_OBJ) $(Ascii_OBJ) \
......
......@@ -224,15 +224,6 @@ namespace HepMC {
m_file << comment << std::endl;
}
bool IO_Ascii::write_end_listing() {
if ( m_finished_first_event_io && m_mode&HepIOS::out ) {
m_file << "HepMC::IO_Ascii-END_EVENT_LISTING\n" << std::flush;
m_finished_first_event_io = 0;
return 1;
}
return 0;
}
void IO_Ascii::write_vertex( GenVertex* v ) {
// assumes mode has already been checked
if ( !v || !m_file ) {
......@@ -379,6 +370,15 @@ namespace HepMC {
return p;
}
bool IO_Ascii::write_end_listing() {
if ( m_finished_first_event_io && m_mode&HepIOS::out ) {
m_file << "HepMC::IO_Ascii-END_EVENT_LISTING\n" << std::flush;
m_finished_first_event_io = 0;
return 1;
}
return 0;
}
bool IO_Ascii::search_for_key_end( std::istream& in, const char* key ) {
// reads characters from in until the string of characters matching
// key is found (success) or EOF is reached (failure).
......@@ -395,6 +395,20 @@ namespace HepMC {
return 0;
}
bool IO_Ascii::search_for_key_beginning( std::istream& in,
const char* key ) {
// not tested and NOT used anywhere!
if ( search_for_key_end( in, key) ) {
int i = strlen(key);
while ( i>=0 ) in.putback(key[i--]);
return 1;
} else {
in.putback(EOF);
in.clear();
return 0;
}
}
bool IO_Ascii::eat_key( std::iostream& in, const char* key ) {
// eats the character string key from istream in - only if the key
// is the very next occurence in the stream
......@@ -423,4 +437,11 @@ namespace HepMC {
return 0;
}
int IO_Ascii::find_in_map( const std::map<GenVertex*,int>& m,
GenVertex* v ) const {
std::map<GenVertex*,int>::const_iterator iter = m.find(v);
if ( iter == m.end() ) return 0;
return iter->second;
}
} // HepMC
......@@ -25,10 +25,6 @@
// "HepMC::IO_Ascii-START_EVENT_LISTING\n"
// and terminated by the key:
// "HepMC::IO_Ascii-END_EVENT_LISTING\n"
// GenParticle Data tables are preceded by the key:
// "HepMC::IO_Ascii-START_PARTICLE_DATA\n"
// and terminated by the key:
// "HepMC::IO_Ascii-END_PARTICLE_DATA\n"
// Comments are allowed. They need not be preceded by anything, though if
// a comment is written using write_comment( const string ) then it will be
// preceded by "HepMC::IO_Ascii-COMMENT\n"
......@@ -38,11 +34,22 @@
// any of the 4 start/stop keys.
//
// this is done in CLHEP/HepMC/defs.h
// --> HANDLE COMPILER INCONSISTENCIES
//#if __GNUC__ && (__GNUC__ > 2) // Linux gcc 3.x
//#define USE_OPENMODE_INSTEAD_OF_OPEN_MODE
//#endif // Platform
//
//#ifdef USE_OPENMODE_INSTEAD_OF_OPEN_MODE
//#define open_mode openmode
//#endif // USE_OPENMODE_INSTEAD_OF_OPEN_MODE
#include <fstream>
#include <string>
#include <map>
#include <vector>
#include <iostream>
#include "CLHEP/HepMC/defs.h"
#include "CLHEP/HepMC/GenEvent.h"
......@@ -56,7 +63,6 @@ namespace HepMC {
void write_event( const GenEvent* evt );
bool fill_next_event( GenEvent* evt );
GenEvent* read_next_event();
// insert a comment directly into the output file --- normally you
// only want to do this at the beginning or end of the file. All
// comments are preceded with "HepMC::IO_Ascii-COMMENT\n"
......@@ -67,6 +73,12 @@ namespace HepMC {
void print( std::ostream& ostr = std::cout ) const;
//
// read_next_event() differs from
// the fill_***() method in that it creates a new event or pdt
// before calling the correspondingfill_*** method
// (they are not intended to be over-ridden)
GenEvent* read_next_event();
//
// The overloaded stream operators >>,<< are identical to
// read_next_event and write_event methods respectively.
// the event argument for the overloaded stream operators is a pointer,
......@@ -91,7 +103,11 @@ namespace HepMC {
bool write_end_listing();
bool search_for_key_end( std::istream& in,
const char* key);
bool search_for_key_beginning( std::istream& in,
const char* key );
bool eat_key( std::iostream& in, const char* key );
int find_in_map( const std::map<GenVertex*,int>& m,
GenVertex* v) const;
void output( const double& );
void output( const int& );
void output( const long int& );
......@@ -99,7 +115,7 @@ namespace HepMC {
private: // use of copy constructor is not allowed
IO_Ascii( const IO_Ascii& ) {}
private: // data members
HepIOSOpenMode m_mode;
HepIOSOpenMode m_mode;
std::fstream m_file;
bool m_finished_first_event_io;
};
......@@ -108,7 +124,6 @@ namespace HepMC {
// Inlines //
//////////////
inline void IO_Ascii::output( const double& d ) {
if ( d == 0. ) {
m_file << ' ' << (int)0;
......@@ -137,6 +152,7 @@ namespace HepMC {
delete evt;
return 0;
}
inline GenEvent*& IO_Ascii::operator>>( GenEvent*& evt ){
evt = read_next_event();
return evt;
......@@ -157,6 +173,3 @@ namespace HepMC {
#endif // HEPMC_IO_ASCII_H
//--------------------------------------------------------------------------
......@@ -40,7 +40,7 @@ int main() {
call_pyinit( "CMS", "p", "p", 14000. );
//........................................Particle Data Table
const char infile[] = "../../HepPDT/examples/data/pythia.tbl";
const char infile[] = "../src/HepPDT/examples/data/pythia.tbl";
// open input file
std::ifstream pdfile( infile );
if( !pdfile ) {
......
......@@ -66,6 +66,25 @@ int main() {
HepMC::GenEvent* evt = conv.getGenEventfromHEPEVT();
//
//.......................USER WOULD PROCESS EVENT HERE
// Begin Peter sherwood's suggested code:
//count particles
int npart =0;
HepMC::GenEvent::particle_const_iterator it= evt->particles_begin();
HepMC::GenEvent::particle_const_iterator en= evt->particles_end();
for(;it!=en;++it) ++npart;
//check event size
int ndumpv=evt->vertices_size();
int ndumpp=evt->particles_size();
if ( npart!=ndumpp ) {
std::cout << "Event " << i << std::endl;
std::cout << "Total vertices count as dumped "<<ndumpv<< std::endl;
std::cout << "Total particle count as copied "<<npart<< std::endl;
std::cout << "Total particle count as dumped "<<ndumpp<< std::endl;
}
//
// we also need to delete the created event from memory
delete evt;
......
......@@ -47,6 +47,12 @@ int main() {
// an event has been prepared in advance for this example, read it
// into memory using the IO_Ascii input strategy
HepMC::IO_Ascii ascii_in("example_UsingIterators.txt",HepIOS::in);
if ( ascii_in.rdstate() == HepIOS::failbit ) {
std::cerr << "ERROR input file example_UsingIterators.txt is needed "
<< "and does not exist. "
<< "\n Look for it in HepMC/examples, Exit." << std::endl;
return 1;
}
HepMC::GenEvent* evt = ascii_in.read_next_event();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment