GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TRawFile.h
Go to the documentation of this file.
1#ifndef TRAWFILE_H
2#define TRAWFILE_H
3
4/** \addtogroup Sorting
5 * @{
6 */
7
8/////////////////////////////////////////////////////////////////
9///
10/// \class TRawFile
11///
12/// This Class is used to read and write raw files in the
13/// root framework.
14///
15/////////////////////////////////////////////////////////////////
16
17#include <string>
18
19#ifdef __APPLE__
20#include <_types/_uint32_t.h>
21#else
22#include <cstdint>
23#endif
24
25#include "TObject.h"
26
27#include "TRawEvent.h"
28
29/// Reader for raw files
30
31class TRawFile : public TObject {
32public:
33 enum class EOpenType { kRead,
34 kWrite };
35
36 TRawFile() = default; ///< default constructor
37 explicit TRawFile(const char*, EOpenType = EOpenType::kRead) {}
38 TRawFile(const TRawFile&) = default;
39 TRawFile(TRawFile&&) noexcept = default;
40 TRawFile& operator=(const TRawFile&) = default;
41 TRawFile& operator=(TRawFile&&) noexcept = default;
42 ~TRawFile() = default; ///< destructor
43
44 virtual bool Open(const char* filename) = 0; ///< Open input file
45
46 virtual void Close() = 0; ///< Close input file
47
48 using TObject::Read;
49 using TObject::Write;
50#ifndef __CINT__
51 virtual int Read(std::shared_ptr<TRawEvent> event) = 0; ///< Read one event from the file
52#endif
53 virtual void Skip(size_t nofEvents) = 0; ///< Skip nofEvents events in file
54 virtual std::string Status(bool long_file_description = true) = 0;
55
56 virtual const char* GetFilename() const { return fFilename.c_str(); } ///< Get the name of this file
57
58 virtual int GetRunNumber() = 0;
59 virtual int GetSubRunNumber() = 0;
60
61 virtual size_t BytesRead() { return fBytesRead; }
62 void IncrementBytesRead(size_t val = 1) { fBytesRead += val; }
63 virtual size_t FileSize() { return fFileSize; }
64 void FileSize(size_t fileSize) { fFileSize = fileSize; }
65
66 virtual std::string Filename() const { return fFilename; } ///< Get the name of this file
67 virtual void Filename(const char* val) { fFilename = val; }
68
69 size_t BufferSize() const { return fReadBuffer.size(); }
70 char* BufferData() { return fReadBuffer.data(); }
71 void ClearBuffer() { fReadBuffer.clear(); }
72 void ResizeBuffer(size_t newSize) { fReadBuffer.resize(newSize); }
73
74#ifndef __CINT__
75 virtual std::shared_ptr<TRawEvent> GetOdbEvent()
76 {
77 return nullptr;
78 }
79 virtual std::shared_ptr<TRawEvent> NewEvent() = 0;
80#endif
81
82private:
83 std::string fFilename; ///< name of the currently open file
84
85 std::vector<char> fReadBuffer;
86
87 size_t fBytesRead{0};
88 size_t fFileSize{0};
89
90 /// \cond CLASSIMP
91 ClassDefOverride(TRawFile, 0) // NOLINT(readability-else-after-return)
92 /// \endcond
93};
94/*! @} */
95#endif // TRawFile.h
void Write(const std::shared_ptr< TMidasEvent > &evt, TMidasFile *outfile)
Reader for raw files.
Definition TRawFile.h:31
virtual bool Open(const char *filename)=0
Open input file.
size_t fFileSize
Definition TRawFile.h:88
TRawFile()=default
default constructor
TRawFile(TRawFile &&) noexcept=default
virtual int GetSubRunNumber()=0
virtual int Read(std::shared_ptr< TRawEvent > event)=0
Read one event from the file.
virtual void Close()=0
Close input file.
void ClearBuffer()
Definition TRawFile.h:71
virtual const char * GetFilename() const
Get the name of this file.
Definition TRawFile.h:56
size_t BufferSize() const
Definition TRawFile.h:69
virtual void Skip(size_t nofEvents)=0
Skip nofEvents events in file.
TRawFile(const TRawFile &)=default
virtual std::shared_ptr< TRawEvent > GetOdbEvent()
Definition TRawFile.h:75
size_t fBytesRead
Definition TRawFile.h:87
char * BufferData()
Definition TRawFile.h:70
std::vector< char > fReadBuffer
Definition TRawFile.h:85
virtual size_t FileSize()
Definition TRawFile.h:63
TRawFile(const char *, EOpenType=EOpenType::kRead)
Definition TRawFile.h:37
virtual void Filename(const char *val)
Definition TRawFile.h:67
virtual std::string Filename() const
Get the name of this file.
Definition TRawFile.h:66
void IncrementBytesRead(size_t val=1)
Definition TRawFile.h:62
std::string fFilename
name of the currently open file
Definition TRawFile.h:83
virtual size_t BytesRead()
Definition TRawFile.h:61
virtual std::shared_ptr< TRawEvent > NewEvent()=0
void ResizeBuffer(size_t newSize)
Definition TRawFile.h:72
virtual std::string Status(bool long_file_description=true)=0
virtual int GetRunNumber()=0
void FileSize(size_t fileSize)
Definition TRawFile.h:64