evio  6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EvioCompactReader.h
Go to the documentation of this file.
1 //
2 // Copyright 2020, Jefferson Science Associates, LLC.
3 // Subject to the terms in the LICENSE file found in the top-level directory.
4 //
5 // EPSCI Group
6 // Thomas Jefferson National Accelerator Facility
7 // 12000, Jefferson Ave, Newport News, VA 23606
8 // (757)-269-7100
9 
10 
11 #ifndef EVIO_6_0_EVIOCOMPACTREADER_H
12 #define EVIO_6_0_EVIOCOMPACTREADER_H
13 
14 
15 #include <fstream>
16 #include <stdexcept>
17 #include <mutex>
18 
19 
20 #include "IEvioCompactReader.h"
21 #include "EvioCompactReaderV4.h"
22 #include "EvioCompactReaderV6.h"
23 #include "EvioReader.h"
24 #include "Util.h"
25 
26 
27 namespace evio {
28 
29 
30 
42 
43  private:
44 
46  uint32_t evioVersion = 4;
47 
50 
52  std::shared_ptr<ByteBuffer> byteBuffer;
53 
55  size_t initialPosition = 0UL;
56 
58  bool synced = false;
59 
61  std::recursive_mutex mtx;
62 
63  //------------------------
64  // Object to delegate to
65  //------------------------
66  std::shared_ptr<IEvioCompactReader> reader;
67 
68 
69  public:
70 
71  EvioCompactReader(std::string const & path, bool sync = false);
72  EvioCompactReader(std::shared_ptr<ByteBuffer> & byteBuffer, bool sync = false) ;
73 
74  public:
75 
76  bool isFile() override;
77  bool isCompressed() override;
78 
79  void setBuffer(std::shared_ptr<ByteBuffer> & buf) override;
80 
81  bool isClosed() override;
82 
83  ByteOrder getByteOrder() override;
84  uint32_t getEvioVersion() override;
85  std::string getPath() override;
86  ByteOrder getFileByteOrder() override;
87 
88  std::string getDictionaryXML() override ;
89  std::shared_ptr<EvioXMLDictionary> getDictionary() override ;
90  bool hasDictionary() override;
91 
92  std::shared_ptr<ByteBuffer> getByteBuffer() override;
93 
94  size_t fileSize() override;
95 
96  std::shared_ptr<EvioNode> getEvent(size_t eventNumber) override;
97  std::shared_ptr<EvioNode> getScannedEvent(size_t eventNumber) override;
98  std::shared_ptr<IBlockHeader> getFirstBlockHeader() override;
99 
100  void searchEvent(size_t eventNumber, uint16_t tag, uint8_t num, std::vector<std::shared_ptr<EvioNode>> & vec) override ;
101  void searchEvent(size_t eventNumber, std::string const & dictName,
102  std::shared_ptr<EvioXMLDictionary> & dictionary,
103  std::vector<std::shared_ptr<EvioNode>> & vec) override ;
104 
105  std::shared_ptr<ByteBuffer> removeEvent(size_t eventNumber) override;
106  std::shared_ptr<ByteBuffer> removeStructure(std::shared_ptr<EvioNode> & removeNode) override;
107  std::shared_ptr<ByteBuffer> addStructure(size_t eventNumber, ByteBuffer & addBuffer) override;
108 
109  std::shared_ptr<ByteBuffer> getData(std::shared_ptr<EvioNode> & node) override;
110  std::shared_ptr<ByteBuffer> getData(std::shared_ptr<EvioNode> & node, bool copy) override;
111 
112  std::shared_ptr<ByteBuffer> getData(std::shared_ptr<EvioNode> & node,
113  std::shared_ptr<ByteBuffer> & buf) override;
114  std::shared_ptr<ByteBuffer> getData(std::shared_ptr<EvioNode> & node,
115  std::shared_ptr<ByteBuffer> & buf, bool copy) override;
116 
117  std::shared_ptr<ByteBuffer> getEventBuffer(size_t eventNumber) override;
118  std::shared_ptr<ByteBuffer> getEventBuffer(size_t eventNumber, bool copy) override;
119 
120  std::shared_ptr<ByteBuffer> getStructureBuffer(std::shared_ptr<EvioNode> & node) override;
121  std::shared_ptr<ByteBuffer> getStructureBuffer(std::shared_ptr<EvioNode> & node, bool copy) override;
122 
123  void close() override;
124 
125  uint32_t getEventCount() override;
126  uint32_t getBlockCount() override;
127 
128  void toFile(std::string const & fileName) override;
129  };
130 
131 
132 
133 }
134 
135 #endif //EVIO_6_0_EVIOCOMPACTREADER_H
This class is copied from one of the same name in the Java programming language.
Definition: ByteBuffer.h:42
This class is used to read an evio formatted file or buffer and extract specific evio containers (ban...
Definition: EvioCompactReader.h:41
std::string getDictionaryXML() override
Get the XML format dictionary is there is one.if object closed and dictionary still unread XML format...
Definition: EvioCompactReader.cpp:143
std::shared_ptr< EvioNode > getEvent(size_t eventNumber) override
Get the EvioNode object associated with a particular event number.number of event (place in file/buff...
Definition: EvioCompactReader.cpp:175
bool hasDictionary() override
Does this evio file have an associated XML dictionary?true if this evio file has an associated XML di...
Definition: EvioCompactReader.cpp:163
bool isCompressed() override
Is the data in the file/buffer compressed?true if data is compressed.
Definition: EvioCompactReader.cpp:109
uint32_t getEventCount() override
This is the number of events in the file/buffer.Any dictionary event is not included in the count...
Definition: EvioCompactReader.cpp:340
bool isFile() override
Is this reader reading a file?true if reading file, false if reading buffer
Definition: EvioCompactReader.cpp:105
size_t fileSize() override
Get the size of the file being read, in bytes.For small files, obtain the file size using the memory ...
Definition: EvioCompactReader.cpp:171
void close() override
This sets the position to its initial value and marks reader as closed.
Definition: EvioCompactReader.cpp:330
void toFile(std::string const &fileName) override
Save the internal byte buffer to the given file (overwrites existing file).name of file to write if e...
Definition: EvioCompactReader.cpp:348
Numerical values associated with endian byte order.
Definition: ByteOrder.h:53
void searchEvent(size_t eventNumber, uint16_t tag, uint8_t num, std::vector< std::shared_ptr< EvioNode >> &vec) override
This method searches the specified event in a file/buffer and returns a vector of objects each of whi...
Definition: EvioCompactReader.cpp:193
std::shared_ptr< EvioNode > getScannedEvent(size_t eventNumber) override
Get the EvioNode object associated with a particular event number which has been scanned so all subst...
Definition: EvioCompactReader.cpp:181
std::shared_ptr< IBlockHeader > getFirstBlockHeader() override
This returns the FIRST block (or record) header.(Not the file header of evio version 6+ files)...
Definition: EvioCompactReader.cpp:187
void setBuffer(std::shared_ptr< ByteBuffer > &buf) override
This method can be used to avoid creating additional EvioCompactReader objects by reusing this one wi...
Definition: EvioCompactReader.cpp:113
std::shared_ptr< ByteBuffer > removeEvent(size_t eventNumber) override
This method removes the data of the given event from the buffer.It also marks any existing EvioNodes ...
Definition: EvioCompactReader.cpp:216
std::string getPath() override
Get the path to the file.path to the file
Definition: EvioCompactReader.cpp:135
std::shared_ptr< ByteBuffer > getByteBuffer() override
Get the byte buffer being read directly or corresponding to the event file.the byte buffer being read...
Definition: EvioCompactReader.cpp:167
std::shared_ptr< ByteBuffer > getStructureBuffer(std::shared_ptr< EvioNode > &node) override
Get an evio structure (bank, seg, or tagseg) in ByteBuffer form.The returned buffer is a view into th...
Definition: EvioCompactReader.cpp:310
uint32_t getBlockCount() override
This is the number of blocks in the file/buffer including the empty block at the end.the number of blocks in the file/buffer (estimate for version 3 files)
Definition: EvioCompactReader.cpp:344
std::shared_ptr< ByteBuffer > addStructure(size_t eventNumber, ByteBuffer &addBuffer) override
This method adds an evio container (bank, segment, or tag segment) as the last structure contained in...
Definition: EvioCompactReader.cpp:236
std::shared_ptr< ByteBuffer > getData(std::shared_ptr< EvioNode > &node) override
Get the data associated with an evio structure in ByteBuffer form.The returned buffer is a view into ...
Definition: EvioCompactReader.cpp:246
ByteOrder getFileByteOrder() override
When reading a file, this method&#39;s return value is the byte order of the evio data in the file...
Definition: EvioCompactReader.cpp:139
std::shared_ptr< EvioXMLDictionary > getDictionary() override
Get the evio dictionary if is there is one.if object closed and dictionary still unread evio dictiona...
Definition: EvioCompactReader.cpp:153
This is an interface for a compact reader of evio format files and buffers.
Definition: IEvioCompactReader.h:41
ByteOrder getByteOrder() override
Get the byte order of the file/buffer being read.byte order of the file/buffer being read...
Definition: EvioCompactReader.cpp:127
uint32_t getEvioVersion() override
Get the evio version number.evio version number.
Definition: EvioCompactReader.cpp:131
std::shared_ptr< ByteBuffer > removeStructure(std::shared_ptr< EvioNode > &removeNode) override
This method removes the data, represented by the given node, from the buffer.It also marks the node a...
Definition: EvioCompactReader.cpp:226
std::shared_ptr< ByteBuffer > getEventBuffer(size_t eventNumber) override
Get an evio bank or event in ByteBuffer form.The returned buffer is a view into the data of this read...
Definition: EvioCompactReader.cpp:290
EvioCompactReader(std::string const &path, bool sync=false)
Constructor for reading an event file.
Definition: EvioCompactReader.cpp:27
static const ByteOrder ENDIAN_LOCAL
Local host&#39;s byte order.
Definition: ByteOrder.h:61
bool isClosed() override
Has close() been called (without reopening by calling setBuffer(std::shared_ptr&lt;ByteBuffer&gt; &amp;))...
Definition: EvioCompactReader.cpp:117