LCIO  "2.7.4"
 All Classes Namespaces Functions Variables Typedefs Friends Pages
LCSIO.h
1 #ifndef SIO_LCSIO_H
2 #define SIO_LCSIO_H 1
3 
4 #include "LCIOTypes.h"
5 
6 #include "SIO_record.h"
7 #include "SIO_definitions.h"
8 
9 #include <string>
10 
11 // record and block names used in LCIO-SIO
12 #define LCSIO_RUNRECORDNAME "LCRunHeader"
13 #define LCSIO_RUNBLOCKNAME "RunHeader"
14 #define LCSIO_EVENTRECORDNAME "LCEvent"
15 #define LCSIO_EVENTBLOCKNAME "Event"
16 #define LCSIO_HEADERRECORDNAME "LCEventHeader"
17 #define LCSIO_HEADERBLOCKNAME "EventHeader"
18 
19 #define LCSIO_ACCESSRECORDNAME "LCIORandomAccess"
20 #define LCSIO_ACCESSBLOCKNAME "LCIORandomAccess"
21 #define LCSIO_RANDOMACCESS_SIZE 136
22 #define LCSIO_INDEXRECORDNAME "LCIOIndex"
23 #define LCSIO_INDEXBLOCKNAME "LCIOIndex"
24 
25 
26 class SIO_stream ;
27 
28 namespace SIO {
29 
30  class LCSIO ;
31 
37  class SIORecords {
38 
39  friend class LCSIO ;
40  public:
41 
42  enum ID{
43  Event=0,
44  Header,
45  Run,
46  Access,
47  Index,
48  NumberOfRecords
49  } ;
50  //-----------------------------------------------
56  class Unpack{
57  public:
58  static const unsigned Event = 0x0001 << SIORecords::Event ;
59  static const unsigned Header = 0x0001 << SIORecords::Header ;
60  static const unsigned Run = 0x0001 << SIORecords::Run ;
61  static const unsigned Access = 0x0001 << SIORecords::Access ;
62  static const unsigned Index = 0x0001 << SIORecords::Index ;
63 
64  static const unsigned All = 0xFFFFFFFF ;
65 
66  Unpack( unsigned recordFlag ) ;
67  ~Unpack() ;
68 
69  protected:
70  bool _flags[ NumberOfRecords ] ;
71  };
72  //-----------------------------------------------
73 
74 
75  SIO_record* operator[](size_t idx) ;
76 
77  void setCompress( bool flag=true ) ;
78 
79  protected:
80  void add(SIO_record*& rec, const char* name) ;
81 
82  SIO_record* _records[ NumberOfRecords ] ;
83 
84  SIORecords() ;
85  } ;
86 
87 
88 #define LCSIO_READ( rec, pnt ) status = LCSIO::read( (rec), (pnt) ); if( !(status & 1) ) return status;
89 #define LCSIO_READ_LEN( rec, pnt , len ) status = LCSIO::read( (rec), (pnt) , (len) ); if( !(status & 1) ) return status;
90 
91 #define LCSIO_WRITE( rec, pnt ) status = LCSIO::write( (rec), (pnt) ); if( !(status & 1) ) return status;
92 
100  class LCSIO{
101 
102  public :
103 
104  static SIORecords& records() ;
105 
106 // // define some names of records and blocks
107 // static const char* RUNRECORDNAME ;
108 // static const char* RUNBLOCKNAME ;
109 // static const char* EVENTRECORDNAME ;
110 // static const char* EVENTBLOCKNAME;
111 // static const char* HEADERRECORDNAME ;
112 // static const char* HEADERBLOCKNAME;
113 
114  static const char* FILE_EXTENSION ;
115 
118  static const bool COMPRESSION = true ;
119 
120 
123  static void checkVersion(int versionID ) ;
124 
130  static unsigned int read( SIO_stream* stream ,char** c , int* len=0) ;
131 
132 // /** This version checks the versionId to be able to read 'old' files with
133 // * trailing '\00' (version <= 00-02).
134 // * Remove this method after a reasonable transition period...
135 // */
136 // static unsigned int read( SIO_stream* stream ,char** c, int versionID) ;
137 
140  static unsigned int write( SIO_stream* stream , int i) ;
141 
144  static unsigned int write( SIO_stream* stream , unsigned int i) ;
145 
148 #if defined(_LP64) || defined(__APPLE_CC__)
149 // static unsigned int write( SIO_stream* stream , SIO_POINTER_DECL i) ;
150  static unsigned int write( SIO_stream* stream , size_t i) ;
151 #endif
152 
155  static unsigned int write( SIO_stream* stream , EVENT::long64 i) ;
156 
159  static unsigned int write( SIO_stream* stream , float f) ;
160 
164  static unsigned int write(SIO_stream* stream , const std::string& s) ;
165 
166 
171  static std::string getValidSIOName(const std::string& aName ) ;
172  // static const char* getValidSIOName(const std::string& aName ) ;
173 
174 
178  static void seekStream( SIO_stream* stream , EVENT::long64 pos) ;
179 
180 
181  private:
182 
183  static char* dummy ;
184  static int dummy_size ;
185  static int uid ;
186  static const int dummy_initial_size = 1024 ;
187 
188  } ;
189 
190 } // namespace
191 #endif // ifndef SIO_LCSIO_H
Manager class that holds instances of all known LCIO-SIO records.
Definition: LCSIO.h:37
static const bool COMPRESSION
the compression mode for SIO
Definition: LCSIO.h:118
static std::string getValidSIOName(const std::string &aName)
Creates a valid SIO name (basically equivalent to a valid C++ name) by replacing every [...
Definition: LCSIO.cc:223
static unsigned int write(SIO_stream *stream, int i)
This version checks the versionId to be able to read 'old' files with trailing '\00' (version <= 00-0...
Definition: LCSIO.cc:154
Collection of static helper functions for reading and writing data with SIO.
Definition: LCSIO.h:100
long long long64
64 bit signed integer,e.g.to be used for timestamps
Definition: LCIOTypes.h:14
Definition: lcrtrelation.cc:19
static void seekStream(SIO_stream *stream, EVENT::long64 pos)
Seek stream to the given absolute position - if pos<0 from end of file.
Definition: LCSIO.cc:94
static void checkVersion(int versionID)
Checks the version of the file - oldefile (version < v00-08) are no longer supported.
Definition: LCSIO.cc:116
static unsigned int read(SIO_stream *stream, char **c, int *len=0)
Read a string from the stream into a dummy buffer.
Definition: LCSIO.cc:127
Helper class that sets the unpack flag of known SIO records as specified by the constructor.
Definition: LCSIO.h:56