LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIOEventHandler.cc
Go to the documentation of this file.
1 #include "SIO/SIOEventHandler.h"
2 #include "SIO/LCSIO.h"
3 
4 #include "EVENT/LCEvent.h"
5 #include "EVENT/LCIO.h"
6 #include "IOIMPL/LCEventIOImpl.h"
8 #include "SIO/SIOLCParameters.h"
9 
10 // -- sio headers
11 #include <sio/io_device.h>
12 #include <sio/version.h>
13 
14 namespace SIO {
15 
16 
18  sio::block( LCSIO::HeaderBlockName, LCSIO::blockVersion() ) {
19  /* nop */
20  }
21 
22  //----------------------------------------------------------------------------
23 
25  _event = evt ;
26  }
27 
28  //----------------------------------------------------------------------------
29 
31  _colSubSet = colnames ;
32  }
33 
34  //----------------------------------------------------------------------------
35 
36  void SIOEventHandler::read( sio::read_device &device, sio::version_type vers ) {
37  LCSIO::checkVersion( vers ) ;
38  auto evt = dynamic_cast<IOIMPL::LCEventIOImpl*>( _event ) ;
39  SIO_SDATA( device , evt->_runNumber ) ;
40  SIO_SDATA( device , evt->_eventNumber ) ;
41  SIO_SDATA( device , evt->_timeStamp ) ;
42  std::string detName ;
43  SIO_SDATA( device, detName ) ;
44  evt->setDetectorName( detName ) ;
45  int nCol ;
46  SIO_SDATA( device, nCol ) ;
47  // read collection types and names
48  // not needed for the event record
49  // but SIO crashes if block is not read completely ...
50  for( int i=0; i<nCol ; i++ ) {
51  std::string colName, colType ;
52  SIO_SDATA( device, colName ) ;
53  SIO_SDATA( device, colType ) ;
54  std::string::size_type idx ;
55  if( ( idx = colType.rfind( SIOEventHandler::SubsetPostfix ) ) != std::string::npos ) {
56  colType = std::string( colType , 0 , idx ) ;
57  }
58  // if we have a list with the sub set of collection names to be read we only add these to the event
59  if( _colSubSet.empty() || _colSubSet.find( colName ) != _colSubSet.end() ) {
60  evt->addCollection( new IOIMPL::LCCollectionIOVec( colType ) , colName) ;
61  }
62  }
63  // read parameters
64  if( vers > SIO_VERSION_ENCODE( 1, 1 ) ) {
65  SIOLCParameters::read( device, evt->parameters(), vers ) ;
66  }
67  }
68 
69  //----------------------------------------------------------------------------
70 
71  void SIOEventHandler::write( sio::write_device &device ) {
72  auto colNames = _event->getCollectionNames() ;
73  unsigned int nCol = 0 ;
74  for(unsigned int i=0 ; i < colNames->size() ; i++ ) {
75  if( ( not _colSubSet.empty() ) and ( _colSubSet.end() == _colSubSet.find( (*colNames)[i] ) ) ) {
76  continue ;
77  }
78  if( _event->getCollection( (*colNames)[i] )->isTransient() ) {
79  continue ;
80  }
81  nCol++ ;
82  }
83  SIO_SDATA( device, _event->getRunNumber() ) ;
84  SIO_SDATA( device, _event->getEventNumber() ) ;
85  SIO_SDATA( device, _event->getTimeStamp() ) ;
86  SIO_SDATA( device, _event->getDetectorName() ) ;
87  SIO_SDATA( device, nCol ) ;
88  for(unsigned int i=0 ; i < colNames->size() ; i++ ) {
89  auto col = _event->getCollection( (*colNames)[i] ) ;
90  if( col->isTransient() ) {
91  continue ;
92  }
93  if( ( not _colSubSet.empty() ) and ( _colSubSet.end() == _colSubSet.find( (*colNames)[i] ) ) ) {
94  continue ;
95  }
96  std::string colType( col->getTypeName() ) ;
97  if( col->isSubset() ) {
99  }
100  SIO_SDATA( device, (*colNames)[i] ) ;
101  SIO_SDATA( device, colType ) ;
102  }
104  }
105 
106 }
virtual bool isTransient() const =0
True if collection is transient, i.e.
T empty(T...args)
static void write(sio::write_device &device, const EVENT::LCParameters &params)
Writes lcio objects to an SIO stream.
virtual const LCParameters & getParameters() const =0
Parameters defined for this event.
void write(sio::write_device &device) override
T rfind(T...args)
T end(T...args)
virtual int getRunNumber() const =0
Return the run number off this event.
static void checkVersion(sio::version_type versionID)
Check for old version of LCIO (&gt; v01-08 ar no longer supported) Throws an exception if not supported...
Definition: LCSIO.cc:10
Adding stuff needed for io (friend declarations, etc.)
virtual const std::vector< std::string > * getCollectionNames() const =0
Returns the names of the collections in the event.
Collection of constants and helper functions.
Definition: LCSIO.h:16
virtual long64 getTimeStamp() const =0
Returns the time stamp of the event.
void read(sio::read_device &device, sio::version_type vers) override
STL class.
EVENT::LCEvent * _event
void setCollectionNames(const std::set< std::string > &colnames)
Set the collection to read or write only.
virtual LCCollection * getCollection(const std::string &name) const =0
Returns the collection for the given name.
SIOEventHandler()
Constructor.
virtual const std::string & getDetectorName() const =0
Returns the name of the detector setup used in the simulation.
Adding stuff needed for io (friend declarations, etc.)
Definition: LCEventIOImpl.h:26
void setEvent(EVENT::LCEvent *evt)
Set the event to read/write.
T find(T...args)
The main event interface.
Definition: LCEvent.h:31
static void read(sio::read_device &device, EVENT::LCParameters &params, sio::version_type vers)
Reads objects from an SIO stream.
virtual int getEventNumber() const =0
Returns this event&#39;s number .
static constexpr const char * SubsetPostfix
std::set< std::string > _colSubSet
List of collection to read only.