LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LCIORandomAccessMgr.h
Go to the documentation of this file.
1 #ifndef SIO_LCIORandomAccessMgr_H
2 #define SIO_LCIORandomAccessMgr_H 1
3 
4 // -- lcio headers
5 #include "SIO/LCIORandomAccess.h"
6 #include "SIO/LCIORecords.h"
7 #include "SIO/RunEventMap.h"
8 
9 // -- sio headers
10 #include <sio/definitions.h>
11 #include <sio/buffer.h>
12 
13 // -- std headers
14 #include <iostream>
15 #include <map>
16 #include <list>
17 
18 namespace SIO {
19 
20  class LCIORandomAccessMgr ;
21  class SIOIndexHandler ;
22  class SIORandomAccessHandler ;
23 
24  std::ostream & operator<<(std::ostream& os, const LCIORandomAccessMgr& ra ) ;
25 
44  friend class SIOIndexHandler ;
45  friend class SIORandomAccessHandler ;
46  friend std::ostream & operator<<(std::ostream& os, const LCIORandomAccessMgr& ra ) ;
47 
48  public:
51 
52  public:
53  LCIORandomAccessMgr() = default ;
54  LCIORandomAccessMgr(const LCIORandomAccessMgr&) = delete ;
56  ~LCIORandomAccessMgr() = default ;
57 
61  long64 getPosition( const RunEvent& re ) {
62  return _runEvtMap->getPosition( re ) ;
63  }
64 
67  void add(const RunEvent& re, long64 pos ) {
68  _runEvtMap->add( re , pos ) ;
69  }
70 
74  bool createEventMap( sio::ifstream &stream ) ;
75 
79 
83  bool initAppend( sio::ifstream &stream ) ;
84 
85 
88  void writeRandomAccessRecords( sio::ofstream &stream ) ;
89 
91  void clear() ;
92 
94  void seekStream( sio::ifstream &stream, long64 pos ) ;
95 
96  protected:
97 
100 
103 
105  bool readLCIORandomAccessAt( sio::ifstream &stream , long64 pos) ;
106 
108  bool readLCIOIndexAt( sio::ifstream &stream , long64 pos) ;
109 
111  bool recreateEventMap( sio::ifstream &stream ) ;
112 
114  bool readLCIORandomAccess( sio::ifstream &stream ) ;
115 
117  bool readLCIOIndex( sio::ifstream &stream ) ;
118 
119 
121  void createFileRecord() ;
122 
125  return (_list.empty() ? 0 : _list.back() ) ;
126  }
127 
128  private:
129  sio::buffer _rawBuffer { 32*sio::kbyte } ;
130 
131  sio::buffer _compressBuffer { 32*sio::kbyte } ;
133  std::shared_ptr<RunEventMap> _runEvtMap {std::make_shared<RunEventMap>()} ;
138  };
139 } // namespace
140 #endif
Manager class for LCIO direct access.
std::shared_ptr< LCIORandomAccess > _fileRecord
The file record summary.
T empty(T...args)
bool createEventMap(sio::ifstream &stream)
Get the run and event header map from the stream - either by reading the random access records or by ...
std::list< std::shared_ptr< LCIORandomAccess > > LCIORandomAccessList
bool initAppend(sio::ifstream &stream)
Initialize random access for append mode: read last LCIORandomAccess record if it exists - recreate t...
std::shared_ptr< LCIORandomAccess > createFromEventMap() const
Prepare an LCIORandomAccess object from the current contents of RunEventMap (all file locations set t...
Helper struct that stores run and event positions in the file.
Definition: RunEventMap.h:14
bool readLCIOIndex(sio::ifstream &stream)
Helper for reading the next LCIOIndex record (need preceeding call to LCSIO::seek() ) ...
void addLCIORandomAccess(std::shared_ptr< LCIORandomAccess > ra)
Add a new LCIORandomAccess object to the list.
std::ostream & operator<<(std::ostream &os, const LCIORandomAccess &ra)
bool recreateEventMap(sio::ifstream &stream)
Fill the RunEventMap from the event and run header records in the file.
bool readLCIORandomAccess(sio::ifstream &stream)
Helper for reading the next LCIORandomAccess record (need preceeding call to LCSIO::seek() ) ...
void add(const RunEvent &re, long64 pos)
Add a new entry to the event map - if the RunEvent already exists the new position will be stored...
Handler for LCIOrandomAccess and LCIOIndex objects/blocks.
friend std::ostream & operator<<(std::ostream &os, const LCIORandomAccessMgr &ra)
long long long64
Definition: RunEventMap.h:15
const std::shared_ptr< LCIORandomAccess > lastLCIORandomAccess() const
Pointer to the last LCIORandomAccess in the list.
bool readLCIORandomAccessAt(sio::ifstream &stream, long64 pos)
Read the LCIORandomAccess record at the specified position.
bool readLCIOIndexAt(sio::ifstream &stream, long64 pos)
Read the LCIOIndex record at the specified position.
void writeRandomAccessRecords(sio::ofstream &stream)
Write the current random access records LCIOIndex and LCIORandomAccess to the stream.
void createFileRecord()
Create file record from all LCIORandomAccess records.
T back(T...args)
LCIORandomAccessList _list
List of LCIORandomAccess objects.
std::shared_ptr< RunEventMap > getEventMap()
Return the event map - it will be empty, if not yet created.
std::shared_ptr< RunEventMap > _runEvtMap
Map with RunHeader and EventHeader record positions.
void clear()
Clear all lists and maps before closing a file.
void seekStream(sio::ifstream &stream, long64 pos)
Seek the stream at the given position.
long64 getPosition(const RunEvent &re)
Return the position of the specified Event record or Run record respectively (if EventNum == -1 )...
STL class.
Handler for LCIOrandomAccess and LCIOIndex objects/blocks.
LCIORandomAccessMgr & operator=(const LCIORandomAccessMgr &)=delete
EVENT::long64 long64
Definition: LCReader.cc:27