evio  6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EvioCompactReaderV6.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 
12 #ifndef EVIO_6_0_EVIOCOMPACTREADERV6_H
13 #define EVIO_6_0_EVIOCOMPACTREADERV6_H
14 
15 
16 #include <stdexcept>
17 #include <vector>
18 #include <memory>
19 #include <mutex>
20 #include <limits>
21 #include <string>
22 #include <cstdio>
23 #include <fcntl.h>
24 #include <sys/stat.h>
25 #include <unistd.h>
26 #include <fstream>
27 #include <sys/mman.h>
28 
29 
30 #include "ByteBuffer.h"
31 #include "ByteOrder.h"
32 #include "BaseStructure.h"
33 #include "IEvioCompactReader.h"
34 #include "IEvioReader.h"
35 #include "Reader.h"
36 #include "IBlockHeader.h"
37 #include "EvioNode.h"
38 #include "RecordNode.h"
39 
40 
41 namespace evio {
42 
43 
53 
54  private:
55 
57  Reader reader;
58 
60  bool closed = false;
61 
63  std::shared_ptr<EvioXMLDictionary> dictionary = nullptr;
64 
66  std::string path;
67 
68  public:
69 
70  explicit EvioCompactReaderV6(std::string const & path);
71  explicit EvioCompactReaderV6(std::shared_ptr<ByteBuffer> & byteBuffer);
72 
73  void setBuffer(std::shared_ptr<ByteBuffer> & buf) override ;
74 
75  bool isFile() override ;
76  bool isCompressed() override ;
77  bool isClosed() override ;
78  ByteOrder getByteOrder() override ;
79  uint32_t getEvioVersion() override ;
80  std::string getPath() override ;
81  ByteOrder getFileByteOrder() override ;
82  std::string getDictionaryXML() override ;
83  std::shared_ptr<EvioXMLDictionary> getDictionary() override ;
84  bool hasDictionary() override ;
85 
86 
87  public:
88 
89  std::shared_ptr<ByteBuffer> getByteBuffer() override;
90  size_t fileSize() override ;
91 
92  std::shared_ptr<EvioNode> getEvent(size_t eventNumber) override ;
93  std::shared_ptr<EvioNode> getScannedEvent(size_t eventNumber) override ;
94  std::shared_ptr<IBlockHeader> getFirstBlockHeader() override ;
95 
96  private:
97 
98  std::shared_ptr<EvioNode> scanStructure(size_t eventNumber);
99 
100  public:
101 
102  void searchEvent(size_t eventNumber, uint16_t tag, uint8_t num,
103  std::vector<std::shared_ptr<EvioNode>> & vec) override ;
104  void searchEvent(size_t eventNumber, std::string const & dictName,
105  std::shared_ptr<EvioXMLDictionary> & dictionary,
106  std::vector<std::shared_ptr<EvioNode>> & vec) override ;
107 
108 
109  std::shared_ptr<ByteBuffer> removeEvent(size_t eventNumber) override ;
110 
111  std::shared_ptr<ByteBuffer> removeStructure(std::shared_ptr<EvioNode> & removeNode) override ;
112  std::shared_ptr<ByteBuffer> addStructure(size_t eventNumber, ByteBuffer & addBuffer) override ;
113 
114  std::shared_ptr<ByteBuffer> getData(std::shared_ptr<EvioNode> & node) override ;
115  std::shared_ptr<ByteBuffer> getData(std::shared_ptr<EvioNode> & node, bool copy) override ;
116 
117  std::shared_ptr<ByteBuffer> getData(std::shared_ptr<EvioNode> & node,
118  std::shared_ptr<ByteBuffer> & buf) override ;
119  std::shared_ptr<ByteBuffer> getData(std::shared_ptr<EvioNode> & node,
120  std::shared_ptr<ByteBuffer> & buf, bool copy) override ;
121 
122  std::shared_ptr<ByteBuffer> getEventBuffer(size_t eventNumber) override ;
123  std::shared_ptr<ByteBuffer> getEventBuffer(size_t eventNumber, bool copy) override ;
124 
125  std::shared_ptr<ByteBuffer> getStructureBuffer(std::shared_ptr<EvioNode> & node) override ;
126  std::shared_ptr<ByteBuffer> getStructureBuffer(std::shared_ptr<EvioNode> & node, bool copy) override ;
127 
128  void close() override ;
129 
130  uint32_t getEventCount() override ;
131  uint32_t getBlockCount() override ;
132 
133  void toFile(std::string const & fileName) override ;
134  };
135 }
136 
137 
138 #endif //EVIO_6_0_EVIOCOMPACTREADERV6_H
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: EvioCompactReaderV6.cpp:288
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: EvioCompactReaderV6.cpp:125
This class is copied from one of the same name in the Java programming language.
Definition: ByteBuffer.h:42
void close() override
This sets the position to its initial value and marks reader as closed.
Definition: EvioCompactReaderV6.cpp:382
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: EvioCompactReaderV6.cpp:259
std::string getPath() override
Get the path to the file.path to the file
Definition: EvioCompactReaderV6.cpp:88
bool hasDictionary() override
Does this evio file have an associated XML dictionary?true if this evio file has an associated XML di...
Definition: EvioCompactReaderV6.cpp:117
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: EvioCompactReaderV6.cpp:140
bool isCompressed() override
Is the data in the file/buffer compressed?true if data is compressed.
Definition: EvioCompactReaderV6.cpp:72
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: EvioCompactReaderV6.cpp:397
Numerical values associated with endian byte order.
Definition: ByteOrder.h:53
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: EvioCompactReaderV6.cpp:282
bool isFile() override
Is this reader reading a file?true if reading file, false if reading buffer
Definition: EvioCompactReaderV6.cpp:68
bool isClosed() override
Has close() been called (without reopening by calling setBuffer(std::shared_ptr&lt;ByteBuffer&gt; &amp;))...
Definition: EvioCompactReaderV6.cpp:76
Reader class that reads files stored in the HIPO format.
Definition: Reader.h:117
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: EvioCompactReaderV6.cpp:129
EvioCompactReaderV6(std::string const &path)
Constructor for reading a file.
Definition: EvioCompactReaderV6.cpp:23
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: EvioCompactReaderV6.cpp:55
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: EvioCompactReaderV6.cpp:393
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: EvioCompactReaderV6.cpp:294
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: EvioCompactReaderV6.cpp:121
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: EvioCompactReaderV6.cpp:329
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: EvioCompactReaderV6.cpp:100
This is an interface for a compact reader of evio format files and buffers.
Definition: IEvioCompactReader.h:41
uint32_t getEventCount() override
This is the number of events in the file/buffer.Any dictionary event is not included in the count...
Definition: EvioCompactReaderV6.cpp:389
uint32_t getEvioVersion() override
Get the evio version number.evio version number.
Definition: EvioCompactReaderV6.cpp:84
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: EvioCompactReaderV6.cpp:359
std::string getDictionaryXML() override
Get the XML format dictionary is there is one.if object closed and dictionary still unread XML format...
Definition: EvioCompactReaderV6.cpp:96
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: EvioCompactReaderV6.cpp:92
ByteOrder getByteOrder() override
Get the byte order of the file/buffer being read.byte order of the file/buffer being read...
Definition: EvioCompactReaderV6.cpp:80
This class is used to read an evio format version 6 formatted file or buffer.
Definition: EvioCompactReaderV6.h:52
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: EvioCompactReaderV6.cpp:187
std::shared_ptr< IBlockHeader > getFirstBlockHeader() override
This returns the FIRST block (or record) header.(Not the file header of evio version 6+ files)...
Definition: EvioCompactReaderV6.cpp:150