LCOV - code coverage report
Current view: top level - TEvtGen/HepMC - StreamHelpers.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 63 0.0 %
Date: 2016-06-14 17:26:59 Functions: 0 2 0.0 %

          Line data    Source code
       1             : //--------------------------------------------------------------------------
       2             : //
       3             : // GenEventStreamIO.cc
       4             : // Author:  Lynn Garren
       5             : //
       6             : // helper functions used by streaming IO
       7             : //
       8             : // ----------------------------------------------------------------------
       9             : 
      10             : #include <ostream>
      11             : #include <istream>
      12             : #include <sstream>
      13             : 
      14             : #include "HepMC/GenVertex.h"
      15             : #include "HepMC/GenParticle.h"
      16             : #include "HepMC/StreamHelpers.h"
      17             : #include "HepMC/IO_Exception.h"
      18             : 
      19             : namespace HepMC {
      20             : 
      21             : namespace detail {
      22             : 
      23             : std::istream & read_vertex( std::istream & is, 
      24             :                             TempParticleMap & particle_to_end_vertex, 
      25             :                             GenVertex * v )
      26             : {
      27             :     //
      28             :     // make sure the stream is valid
      29           0 :     if ( !is ) {
      30           0 :         std::cerr << "StreamHelpers::detail::read_vertex setting badbit." << std::endl;
      31           0 :         is.clear(std::ios::badbit); 
      32           0 :         return is;
      33             :     } 
      34             :     //
      35             :     // get the vertex line
      36           0 :     std::string line;
      37           0 :     std::getline(is,line);
      38           0 :     std::istringstream iline(line);
      39           0 :     std::string firstc;
      40           0 :     iline >> firstc;
      41             :     //
      42             :     // test to be sure the next entry is of type "V" 
      43           0 :     if ( firstc != "V"  ) {
      44           0 :         std::cerr << "StreamHelpers::detail::read_vertex invalid line type: " 
      45           0 :                   << firstc << std::endl;
      46           0 :         std::cerr << "StreamHelpers::detail::read_vertex setting badbit." << std::endl;
      47           0 :         is.clear(std::ios::badbit); 
      48           0 :         return is;
      49             :     } 
      50             :     // read values into temp variables, then create a new GenVertex object
      51           0 :     int identifier =0, id =0, num_orphans_in =0, 
      52           0 :         num_particles_out = 0, weights_size = 0;
      53           0 :     double x = 0., y = 0., z = 0., t = 0.; 
      54           0 :     iline >> identifier ;
      55           0 :     if(!iline) { throw IO_Exception("read_vertex input stream encounterd invalid data"); }
      56           0 :     iline >> id ;
      57           0 :     if(!iline) { throw IO_Exception("read_vertex input stream encounterd invalid data"); }
      58           0 :     iline >> x ;
      59           0 :     if(!iline) { throw IO_Exception("read_vertex input stream encounterd invalid data"); }
      60           0 :     iline >> y ;
      61           0 :     if(!iline) { throw IO_Exception("read_vertex input stream encounterd invalid data"); }
      62           0 :     iline >> z ;
      63           0 :     if(!iline) { throw IO_Exception("read_vertex input stream encounterd invalid data"); }
      64           0 :     iline >> t;
      65           0 :     if(!iline) { throw IO_Exception("read_vertex input stream encounterd invalid data"); }
      66           0 :     iline >> num_orphans_in ;
      67           0 :     if(!iline) { throw IO_Exception("read_vertex input stream encounterd invalid data"); }
      68           0 :     iline >> num_particles_out ;
      69           0 :     if(!iline) { throw IO_Exception("read_vertex input stream encounterd invalid data"); }
      70           0 :     iline >> weights_size;
      71           0 :     if(!iline) { throw IO_Exception("read_vertex input stream encounterd invalid data"); }
      72           0 :     WeightContainer weights(weights_size);
      73           0 :     for ( int i1 = 0; i1 < weights_size; ++i1 ) {
      74           0 :         iline >> weights[i1];
      75           0 :         if(!iline) { throw IO_Exception("read_vertex input stream encounterd invalid data"); }
      76             :     }
      77           0 :     v->set_position( FourVector(x,y,z,t) );
      78           0 :     v->set_id( id );
      79           0 :     v->weights() = weights;
      80           0 :     v->suggest_barcode( identifier );
      81             :     //
      82             :     // read and create the associated particles. outgoing particles are
      83             :     //  added to their production vertices immediately, while incoming
      84             :     //  particles are added to a map and handled later.
      85           0 :     for ( int i2 = 1; i2 <= num_orphans_in; ++i2 ) {
      86           0 :         GenParticle* p1 = new GenParticle( ); 
      87           0 :         detail::read_particle(is,particle_to_end_vertex,p1);
      88             :     }
      89           0 :     for ( int i3 = 1; i3 <= num_particles_out; ++i3 ) {
      90           0 :         GenParticle* p2 = new GenParticle( ); 
      91           0 :         detail::read_particle(is,particle_to_end_vertex,p2);
      92           0 :         v->add_particle_out( p2 );
      93             :     }
      94             : 
      95             :     return is;
      96           0 : }
      97             : 
      98             : std::istream & find_event_end( std::istream & is ) {
      99             :     // since there is no end of event flag, 
     100             :     // read one line at time until we find the next event 
     101             :     // or the end of event block
     102             :     // don't throw until we find the end of the event
     103           0 :     std::string line, firstc;
     104           0 :     while ( is ) { 
     105           0 :         is >> firstc;
     106           0 :         if( firstc=="E" ) {   // next event
     107           0 :             is.unget();
     108           0 :             throw IO_Exception("input stream encountered invalid data");
     109             :             return is;
     110           0 :         } else if( firstc.size() > 1 ) { // no more events in this block
     111           0 :             throw IO_Exception("input stream encountered invalid data, now at end of event block");
     112             :             return is;
     113             :         }
     114           0 :         std::getline(is,line);
     115             :     }
     116             :     // the stream is bad 
     117           0 :     throw IO_Exception("input stream encountered invalid data, stream is now corrupt");
     118             :     return is;
     119           0 : }
     120             : 
     121             : } // detail
     122             : 
     123             : } // HepMC

Generated by: LCOV version 1.11