LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LCIORecords.cc
Go to the documentation of this file.
1 #include "SIO/LCIORecords.h"
2 
4 #include <SIO/SIOEventHandler.h>
7 #include <SIO/SIOIndexHandler.h>
8 #include <EVENT/LCEvent.h>
9 #include <Exceptions.h>
10 
11 // -- sio headers
12 #include <sio/exception.h>
13 #include <sio/api.h>
14 
15 namespace SIO {
16 
17  void SIOEventHeaderRecord::readBlocks( const sio::buffer_span &buffer, EVENT::LCEvent *event, const std::vector<std::string> &readCol ) {
18  sio::block_list blocks {} ;
19  auto headerBlock = std::make_shared<SIOEventHandler>() ;
20  headerBlock->setEvent( event ) ;
21  headerBlock->setCollectionNames( std::set<std::string>( readCol.begin(), readCol.end() ) ) ;
22  blocks.push_back( headerBlock ) ;
23  sio::api::read_blocks( buffer, blocks ) ;
24  }
25 
26  //----------------------------------------------------------------------------
27 
28  void SIOEventHeaderRecord::writeRecord( sio::buffer &outbuf, EVENT::LCEvent *event, sio::record_info& rec_info, sio::options_type opts ) {
29  sio::block_list blocks {} ;
30  auto headerBlock = std::make_shared<SIOEventHandler>() ;
31  headerBlock->setEvent( event ) ;
32  blocks.push_back( headerBlock ) ;
33  rec_info = sio::api::write_record( LCSIO::HeaderRecordName, outbuf, blocks, opts ) ;
34  }
35 
36  //----------------------------------------------------------------------------
37 
38  void SIOEventHeaderRecord::writeRecord( sio::buffer &outbuf, EVENT::LCEvent *event, sio::record_info& rec_info, const std::set<std::string> &colsOnly, sio::options_type opts ) {
39  sio::block_list blocks {} ;
40  auto headerBlock = std::make_shared<SIOEventHandler>() ;
41  headerBlock->setEvent( event ) ;
42  headerBlock->setCollectionNames( colsOnly ) ;
43  blocks.push_back( headerBlock ) ;
44  rec_info = sio::api::write_record( LCSIO::HeaderRecordName, outbuf, blocks, opts ) ;
45  }
46 
47  //----------------------------------------------------------------------------
48  //----------------------------------------------------------------------------
49 
50  void SIOEventRecord::setupBlocks( EVENT::LCEvent *event, const SIOHandlerMgr &handlerMgr, sio::block_list &blocks, const std::set<std::string> &colsOnly ) {
51  auto collectionNames = event->getCollectionNames();
52  for( auto collectionName : *collectionNames ) {
53  auto collection = event->getCollection( collectionName ) ;
54  // this is never true while reading. Can only appear on writing
55  if( collection->isTransient() ) {
56  continue;
57  }
58  if( ( not colsOnly.empty() ) and ( colsOnly.end() == colsOnly.find(collectionName) ) ) {
59  continue ;
60  }
61  auto handler = handlerMgr.getHandler( collection->getTypeName() ) ;
62  auto block = std::make_shared<SIOCollectionHandler>( collectionName, handler ) ;
63  block->setCollection( collection );
64  blocks.push_back( block ) ;
65  }
66  }
67 
68  //----------------------------------------------------------------------------
69 
70  void SIOEventRecord::readBlocks( const sio::buffer_span &buffer, EVENT::LCEvent *event, const SIOHandlerMgr &handlerMgr ) {
71  sio::block_list blocks {} ;
72  SIOEventRecord::setupBlocks( event, handlerMgr, blocks ) ;
73  sio::api::read_blocks( buffer, blocks ) ;
74  }
75 
76  //----------------------------------------------------------------------------
77 
78  void SIOEventRecord::writeRecord( sio::buffer &outbuf, EVENT::LCEvent *event, const SIOHandlerMgr &handlerMgr, sio::record_info& rec_info, sio::options_type opts ) {
79  sio::block_list blocks {} ;
80  SIOEventRecord::setupBlocks( event, handlerMgr, blocks ) ;
81  rec_info = sio::api::write_record( LCSIO::EventRecordName, outbuf, blocks, opts ) ;
82  }
83 
84  //----------------------------------------------------------------------------
85 
86  void SIOEventRecord::writeRecord( sio::buffer &outbuf, EVENT::LCEvent *event, const SIOHandlerMgr &handlerMgr, sio::record_info& rec_info, const std::set<std::string> &colsOnly, sio::options_type opts ) {
87  sio::block_list blocks {} ;
88  SIOEventRecord::setupBlocks( event, handlerMgr, blocks, colsOnly ) ;
89  rec_info = sio::api::write_record( LCSIO::EventRecordName, outbuf, blocks, opts ) ;
90  }
91 
92  //----------------------------------------------------------------------------
93  //----------------------------------------------------------------------------
94 
95  void SIORunHeaderRecord::readBlocks( const sio::buffer_span &buffer, EVENT::LCRunHeader *rhdr ) {
96  sio::block_list blocks {} ;
97  auto runBlock = std::make_shared<SIORunHeaderHandler>() ;
98  runBlock->setRunHeader( rhdr ) ;
99  blocks.push_back( runBlock ) ;
100  sio::api::read_blocks( buffer, blocks ) ;
101  }
102 
103  //----------------------------------------------------------------------------
104 
105  void SIORunHeaderRecord::writeRecord( sio::buffer &outbuf, EVENT::LCRunHeader *rhdr, sio::record_info& rec_info, sio::options_type opts ) {
106  sio::block_list blocks {} ;
107  auto runBlock = std::make_shared<SIORunHeaderHandler>() ;
108  runBlock->setRunHeader( rhdr ) ;
109  blocks.push_back( runBlock ) ;
110  rec_info = sio::api::write_record( LCSIO::RunRecordName, outbuf, blocks, opts ) ;
111  }
112 
113 } // namespace
static void writeRecord(sio::buffer &outbuf, EVENT::LCEvent *event, sio::record_info &rec_info, sio::options_type opts=0)
Write an event header to the raw sio buffer.
Definition: LCIORecords.cc:28
T empty(T...args)
Interface for the run header.
Definition: LCRunHeader.h:23
struct opts_t opts
static constexpr const char * RunRecordName
Definition: LCSIO.h:23
LCEvent * event
Definition: lsh.cc:80
static void writeRecord(sio::buffer &outbuf, EVENT::LCRunHeader *rhdr, sio::record_info &rec_info, sio::options_type opts=0)
Write a run header record to the sio buffer.
Definition: LCIORecords.cc:105
T end(T...args)
static void readBlocks(const sio::buffer_span &buffer, EVENT::LCRunHeader *rhdr)
Read the block(s) from the sio buffer and decode a run header.
Definition: LCIORecords.cc:95
static void writeRecord(sio::buffer &outbuf, EVENT::LCEvent *event, const SIOHandlerMgr &handlerMgr, sio::record_info &rec_info, sio::options_type opts=0)
Write an event record.
Definition: LCIORecords.cc:78
static void readBlocks(const sio::buffer_span &buffer, EVENT::LCEvent *event, const SIOHandlerMgr &handlerMgr)
Read the blocks (collections) from the sio buffer.
Definition: LCIORecords.cc:70
T find(T...args)
The main event interface.
Definition: LCEvent.h:31
T begin(T...args)
Holds instances of all types of SIOObjectHandlers.
Definition: SIOHandlerMgr.h:20
std::shared_ptr< SIOObjectHandler > getHandler(const std::string &type) const
Returns the instance of the handler for the given type - null if it doesn&#39;t exist.
static constexpr const char * HeaderRecordName
Definition: LCSIO.h:27
static void setupBlocks(EVENT::LCEvent *event, const SIOHandlerMgr &handlerMgr, sio::block_list &blocks, const std::set< std::string > &colsOnly={})
Setup the record blocks for the given event.
Definition: LCIORecords.cc:50
static constexpr const char * EventRecordName
Definition: LCSIO.h:25
static void readBlocks(const sio::buffer_span &buffer, EVENT::LCEvent *event, const std::vector< std::string > &readCol)
Read an event header record.
Definition: LCIORecords.cc:17