GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TMidasFile.h
Go to the documentation of this file.
1#ifndef TMIDASFILE_H
2#define TMIDASFILE_H
3
4/** \addtogroup Sorting
5 * @{
6 */
7
8/////////////////////////////////////////////////////////////////
9///
10/// \class TMidasFile
11///
12/// This Class is used to read and write MIDAS files in the
13/// root framework. It reads and writes TMidasEvents.
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 "TRawFile.h"
26
27#include "TXMLOdb.h"
28#include "TMidasEvent.h"
29
30/// Reader for MIDAS .mid files
31
32class TMidasFile : public TRawFile {
33public:
34 TMidasFile(); ///< default constructor
35 explicit TMidasFile(const char* filename, TRawFile::EOpenType open_type = TRawFile::EOpenType::kRead);
36 TMidasFile(const TMidasFile&) = default;
37 TMidasFile(TMidasFile&&) noexcept = default;
38 TMidasFile& operator=(const TMidasFile&) = default;
39 TMidasFile& operator=(TMidasFile&&) noexcept = default;
40 ~TMidasFile() override; ///< destructor
41
42 bool Open(const char* filename) override; ///< Open input file
43 bool OutOpen(const char* filename); ///< Open output file
44
45 void Close() override; ///< Close input file
46 void OutClose(); ///< Close output file
47
48 using TObject::Read;
49 using TObject::Write;
50#ifndef __CINT__
51 int Read(std::shared_ptr<TRawEvent> event) override; ///< Read one event from the file
52 bool Write(const std::shared_ptr<TMidasEvent>& midasEvent,
53 Option_t* opt = ""); ///< Write one event to the output file
54#endif
55 void Skip(size_t nofEvents) override; ///< Skip nofEvents from the file
56 std::string Status(bool long_file_description = true) override;
57
58#ifndef __CINT__
59 void FillBuffer(const std::shared_ptr<TMidasEvent>& midasEvent,
60 Option_t* opt = ""); // Fill buffer to write out chunks of data
61#endif
62 bool WriteBuffer();
63 // int GetBufferSize() const { return fWriteBuffer.size(); }
64
65 int GetLastErrno() const { return fLastErrno; } ///< Get error value for the last file error
66 const char* GetLastError() const { return fLastError.c_str(); } ///< Get error text for the last file error
67
68#ifndef __CINT__
69 std::shared_ptr<TRawEvent> GetOdbEvent() override
70 {
71 return std::static_pointer_cast<TRawEvent>(fOdbEvent);
72 }
73#endif
74
75 int GetRunNumber() override;
76 int GetSubRunNumber() override;
77
78 void SetMaxBufferSize(int maxsize);
79
80#ifndef __CINT__
81 std::shared_ptr<TRawEvent> NewEvent() override
82 {
83 return std::make_shared<TMidasEvent>();
84 }
85#endif
86
87private:
88 void ReadMoreBytes(size_t bytes);
89
90 void SetFileOdb();
91 void SetRunInfo(uint32_t time);
92 void SetEPICSOdb();
93 void SetTIGOdb();
94 void SetGRIFFOdb();
95 void SetTIGDAQOdb();
96
97#ifndef __CINT__
98 std::shared_ptr<TMidasEvent> fOdbEvent;
99#endif
100
101#ifdef HAS_XML
103#endif
104
105 std::string fOutFilename; ///< name of the currently open file
106
107 std::vector<char> fWriteBuffer;
109 uint32_t fMaxBufferSize{1000000};
110
111 int fLastErrno{0}; ///< errno from the last operation
112 std::string fLastError; ///< error string from last errno
114
115 bool fDoByteSwap{false}; ///< "true" if file has to be byteswapped
116
117 int fFile{-1}; ///< open input file descriptor
118 void* fGzFile{nullptr}; ///< zlib compressed input file reader
119 void* fPoFile{nullptr}; ///< popen() input file reader
120 int fOutFile{-1}; ///< open output file descriptor
121 void* fOutGzFile{nullptr}; ///< zlib compressed output file reader
122
123 /// \cond CLASSIMP
124 ClassDefOverride(TMidasFile, 0) // Used to open and write Midas Files // NOLINT(readability-else-after-return)
125 /// \endcond
126};
127/*! @} */
128#endif // TMidasFile.h
Reader for MIDAS .mid files.
Definition TMidasFile.h:32
bool OutOpen(const char *filename)
Open output file.
void SetTIGDAQOdb()
void OutClose()
Close output file.
TMidasFile(TMidasFile &&) noexcept=default
std::string fLastError
error string from last errno
Definition TMidasFile.h:112
std::string Status(bool long_file_description=true) override
bool Open(const char *filename) override
Open input file.
uint32_t fCurrentBufferSize
Definition TMidasFile.h:108
std::shared_ptr< TRawEvent > NewEvent() override
Definition TMidasFile.h:81
void SetMaxBufferSize(int maxsize)
void SetRunInfo(uint32_t time)
int Read(std::shared_ptr< TRawEvent > event) override
Read one event from the file.
std::string fOutFilename
name of the currently open file
Definition TMidasFile.h:105
int GetSubRunNumber() override
TXMLOdb * fOdb
Definition TMidasFile.h:102
void * fOutGzFile
zlib compressed output file reader
Definition TMidasFile.h:121
int GetLastErrno() const
Get error value for the last file error.
Definition TMidasFile.h:65
std::vector< char > fWriteBuffer
Definition TMidasFile.h:107
int fCurrentEventNumber
Definition TMidasFile.h:113
bool Write(const std::shared_ptr< TMidasEvent > &midasEvent, Option_t *opt="")
Write one event to the output file.
void SetEPICSOdb()
int fFile
open input file descriptor
Definition TMidasFile.h:117
void Skip(size_t nofEvents) override
Skip nofEvents from the file.
void SetFileOdb()
void Close() override
Close input file.
bool WriteBuffer()
bool fDoByteSwap
"true" if file has to be byteswapped
Definition TMidasFile.h:115
void FillBuffer(const std::shared_ptr< TMidasEvent > &midasEvent, Option_t *opt="")
TMidasFile()
default constructor
void * fGzFile
zlib compressed input file reader
Definition TMidasFile.h:118
void SetTIGOdb()
int fOutFile
open output file descriptor
Definition TMidasFile.h:120
std::shared_ptr< TRawEvent > GetOdbEvent() override
Definition TMidasFile.h:69
const char * GetLastError() const
Get error text for the last file error.
Definition TMidasFile.h:66
void SetGRIFFOdb()
uint32_t fMaxBufferSize
Definition TMidasFile.h:109
int fLastErrno
errno from the last operation
Definition TMidasFile.h:111
TMidasFile(const TMidasFile &)=default
void ReadMoreBytes(size_t bytes)
std::shared_ptr< TMidasEvent > fOdbEvent
Definition TMidasFile.h:98
void * fPoFile
popen() input file reader
Definition TMidasFile.h:119
int GetRunNumber() override
Reader for raw files.
Definition TRawFile.h:31