lcio/src/cpp/include/UTIL
diff -u -r1.3 -r1.4
--- LCStdHepRdr.h 8 Nov 2007 14:32:23 -0000 1.3
+++ LCStdHepRdr.h 12 Nov 2007 16:39:04 -0000 1.4
@@ -3,6 +3,14 @@
#include "IMPL/LCCollectionVec.h"
#include "UTIL/lStdHep.hh"
+#include "EVENT/LCIO.h"
+#include "Exceptions.h"
+
+namespace IMPL{
+
+class LCEventImpl ;
+
+}
namespace UTIL{
@@ -11,7 +19,7 @@
* file information.
*
* @author cassell
- * @version $Id: LCStdHepRdr.h,v 1.3 2007/11/08 14:32:23 gaede Exp $
+ * @version $Id: LCStdHepRdr.h,v 1.4 2007/11/12 16:39:04 gaede Exp $
*/
class LCStdHepRdr{
@@ -25,10 +33,22 @@
*/
~LCStdHepRdr() ;
- /** Read an event and return a LCCollectionVec of MCParticles.
+ /** Read an event and return an LCCollectionVec of MCParticles.
+ * @deprecated please use updateEvent()
*/
IMPL::LCCollectionVec * readEvent() ;
+ /** Reads the next stdhep event and adds a new MCParticle collection to the
+ * the event with default name 'MCParticle'
+ * @throw IO::EndOfDataException if no event in stdhep file
+ */
+ void updateNextEvent( IMPL::LCEventImpl* evt , const char* colName=EVENT::LCIO::MCPARTICLE ) ;
+
+
+ /** Print the file header to the given ostream.
+ */
+ void printHeader(std::ostream& os = std::cout ) ;
+
/** Return the charge of the particle times 3 - code copied from HepPDT package.
*/
lcio/src/cpp/src/UTIL
diff -u -r1.6 -r1.7
--- LCStdHepRdr.cc 8 Nov 2007 14:32:23 -0000 1.6
+++ LCStdHepRdr.cc 12 Nov 2007 16:39:05 -0000 1.7
@@ -1,6 +1,7 @@
#include "UTIL/LCStdHepRdr.h"
#include "EVENT/MCParticle.h"
#include "IMPL/MCParticleImpl.h"
+#include "IMPL/LCEventImpl.h"
#include "lcio.h"
#include "EVENT/LCIO.h"
#include <sstream>
@@ -12,6 +13,9 @@
using namespace IMPL ;
+#define IDRUP_NAME "_idrup"
+#define EVTWGT_NAME "_weight"
+
namespace UTIL{
LCStdHepRdr::LCStdHepRdr(const char* evfile){
@@ -25,11 +29,62 @@
throw IO::IOException( description.str() );
}
- _reader->printFileHeader() ;
+ // _reader->printFileHeader() ;
+
+ }
+ LCStdHepRdr::~LCStdHepRdr(){
+ delete _reader ;
}
- LCStdHepRdr::~LCStdHepRdr(){}
+
+
+ void LCStdHepRdr::printHeader(std::ostream& os ) {
+
+ if( os == std::cout ) {
+
+ _reader->printFileHeader() ;
+ }
+
+ }
+
+
+
+ void LCStdHepRdr::updateNextEvent( IMPL::LCEventImpl* evt , const char* colName ) {
+
+ if( evt == 0 ) {
+ throw EVENT::Exception( " LCStdHepRdr::updateEvent - null pointer for event " );
+ }
+
+ IMPL::LCCollectionVec* mcpCol = readEvent() ;
+
+ if( mcpCol == 0 ) {
+
+ throw IO::EndOfDataException( " LCStdHepRdr::updateEvent: EOF " ) ;
+ }
+
+ // copy event parameters from the collection to the event:
+ // FIXME: make this more efficient - not going through paramer map twice....
+
+ int idrup = mcpCol->getParameters().getIntVal( IDRUP_NAME ) ;
+
+ if( idrup !=0 ) {
+
+ evt->parameters().setValue( IDRUP_NAME , idrup ) ;
+ }
+
+ double evtwgt = mcpCol->getParameters().getFloatVal( EVTWGT_NAME ) ;
+
+ evt->setWeight( evtwgt ) ;
+
+
+ // ---- end event parameters ------------------
+
+
+ evt->addCollection( mcpCol , colName ) ;
+ }
+
+
//
// Read an event and return a LCCollectionVec of MCParticles
//
@@ -40,22 +95,36 @@
//
// Read the event, check for errors
//
- if(_reader->more()){
+// if( _reader->more() ){
- if( int errorcode = _reader->readEvent() ) {
- std::stringstream description ;
- description << "LCStdHepRdr::readEvent: error when reading event: " << errorcode << std::ends ;
- throw IO::IOException( description.str() );
- return mcVec;
+ int errorcode = _reader->readEvent() ;
+
+ if( errorcode != LSH_SUCCESS ){
+
+ if( errorcode != LSH_ENDOFFILE ) {
+
+ std::stringstream description ;
+ description << "LCStdHepRdr::readEvent: error when reading event: " << errorcode << std::ends ;
+
+ throw IO::IOException( description.str() );
+ }
+
+ else {
+
+ throw IO::EndOfDataException( " LCStdHepRdr::readEvent EOF " ) ;
+ }
}
- } else {
- //
- // End of File :: ??? Exception ???
- // -> FG: EOF is not an exception as it happens for every file at the end !
- //
- return mcVec;
- }
+
+
+// } else {
+// //
+// // End of File :: ??? Exception ???
+// // -> FG: EOF is not an exception as it happens for every file at the end !
+// //
+// return mcVec; // == null !
+// }
+
//
// Create a Collection Vector
//
@@ -66,6 +135,21 @@
// Loop over particles
//
int NHEP = _reader->nTracks();
+
+ // user defined process id
+ long idrup = _reader->idrup() ;
+
+ if( idrup != 0 ) {
+
+ mcVec->parameters().setValue( IDRUP_NAME , (int) idrup ) ;
+ }
+
+ double evtWeight = _reader->eventweight() ;
+
+
+ mcVec->parameters().setValue( EVTWGT_NAME , (float) evtWeight ) ;
+
+
for( int IHEP=0; IHEP<NHEP; IHEP++ )
{