ROOTANA
Loading...
Searching...
No Matches
midasio.h
Go to the documentation of this file.
1// midasio.h
2
3#ifndef MIDASIO_H
4#define MIDASIO_H
5
6#include <string>
7#include <vector>
8#include <stdint.h>
9
10#ifndef TID_LAST
11/**
12MIDAS Data Type Definitions min max */
13#define TID_BYTE 1 /**< DEPRECATED, use TID_UINT8 instead */
14#define TID_UINT8 1 /**< unsigned byte 0 255 */
15#define TID_SBYTE 2 /**< DEPRECATED, use TID_INT8 instead */
16#define TID_INT8 2 /**< signed byte -128 127 */
17#define TID_CHAR 3 /**< single character 0 255 */
18#define TID_WORD 4 /**< DEPRECATED, use TID_UINT16 instead */
19#define TID_UINT16 4 /**< two bytes 0 65535 */
20#define TID_SHORT 5 /**< DEPRECATED, use TID_INT16 instead */
21#define TID_INT16 5 /**< signed word -32768 32767 */
22#define TID_DWORD 6 /**< DEPRECATED, use TID_UINT32 instead */
23#define TID_UINT32 6 /**< four bytes 0 2^32-1 */
24#define TID_INT 7 /**< DEPRECATED, use TID_INT32 instead */
25#define TID_INT32 7 /**< signed dword -2^31 2^31-1 */
26#define TID_BOOL 8 /**< four bytes bool 0 1 */
27#define TID_FLOAT 9 /**< 4 Byte float format */
28#define TID_FLOAT32 9 /**< 4 Byte float format */
29#define TID_DOUBLE 10 /**< 8 Byte float format */
30#define TID_FLOAT64 10 /**< 8 Byte float format */
31#define TID_BITFIELD 11 /**< 32 Bits Bitfield 0 111... (32) */
32#define TID_STRING 12 /**< zero terminated string */
33#define TID_ARRAY 13 /**< array with unknown contents */
34#define TID_STRUCT 14 /**< structure with fixed length */
35#define TID_KEY 15 /**< key in online database */
36#define TID_LINK 16 /**< link in online database */
37#define TID_INT64 17 /**< 8 bytes int -2^63 2^63-1 */
38#define TID_UINT64 18 /**< 8 bytes unsigned int 0 2^64-1 */
39#define TID_QWORD 18 /**< 8 bytes unsigned int 0 2^64-1 */
40#define TID_LAST 19 /**< end of TID list indicator */
41#endif
42
43class TMBank
44{
45 public:
46 std::string name; ///< bank name, 4 characters max
47 uint32_t type = 0; ///< type of bank data, enum of TID_xxx
48 uint32_t data_size = 0; ///< size of bank data in bytes
49 size_t data_offset = 0; ///< offset of data for this bank in the event data[] container
50};
51
52class TMEvent
53{
54public: // event data
55 bool error; ///< event has an error - incomplete, truncated, inconsistent or corrupted
56
57 uint16_t event_id; ///< MIDAS event ID
58 uint16_t trigger_mask; ///< MIDAS trigger mask
59 uint32_t serial_number; ///< MIDAS event serial number
60 uint32_t time_stamp; ///< MIDAS event time stamp (unix time in sec)
61 uint32_t data_size; ///< MIDAS event data size
62
63 size_t event_header_size; ///< size of MIDAS event header
64 uint32_t bank_header_flags; ///< flags from the MIDAS event bank header
65
66 std::vector<TMBank> banks; ///< list of MIDAS banks, fill using FindAllBanks()
67 std::vector<char> data; ///< MIDAS event bytes
68
69public: // internal data
70
71 bool found_all_banks; ///< all the banks in the event data have been discovered
72 size_t bank_scan_position; ///< location where scan for MIDAS banks was last stopped
73
74public: // constructors
75 TMEvent(); // ctor
76 TMEvent(const void* buf, size_t buf_size); // ctor
77 void Reset(); ///< reset everything
78 void ParseEvent(); ///< parse event data
79 void ParseHeader(const void* buf, size_t buf_size); ///< parse event header
80 void Init(uint16_t event_id, uint16_t trigger_mask = 0, uint32_t serial_number = 0, uint32_t time_stamp = 0, size_t capacity = 0);
81
82public: // read data
83 void FindAllBanks(); ///< scan the MIDAS event, find all data banks
84 TMBank* FindBank(const char* bank_name); ///< scan the MIDAS event
85 char* GetEventData(); ///< get pointer to MIDAS event data
86 const char* GetEventData() const; ///< get pointer to MIDAS event data
87 char* GetBankData(const TMBank*); ///< get pointer to MIDAS data bank
88 const char* GetBankData(const TMBank*) const; ///< get pointer to MIDAS data bank
89
90public: // add data
91 void AddBank(const char* bank_name, int tid, const char* buf, size_t size); ///< add new MIDAS bank
92
93public: // bank manipulation
94 //void DeleteBank(const TMBank*); ///< delete MIDAS bank
95
96public: // information methods
97
98 std::string HeaderToString() const; ///< print the MIDAS event header
99 std::string BankListToString() const; ///< print the list of MIDAS banks
100 std::string BankToString(const TMBank*) const; ///< print definition of one MIDAS bank
101
102 void PrintHeader() const;
103 void PrintBanks(int level = 0);
104 void DumpHeader() const;
105};
106
108{
109 public:
111 virtual int Read(void* buf, int count) = 0;
112 virtual int Close() = 0;
113 virtual ~TMReaderInterface() {};
114 public:
115 bool fError;
116 std::string fErrorString;
117 static bool fgTrace;
118};
119
121{
122 public:
123 virtual int Write(const void* buf, int count) = 0;
124 virtual int Close() = 0;
125 virtual ~TMWriterInterface() {};
126 public:
127 static bool fgTrace;
128};
129
131TMWriterInterface* TMNewWriter(const char* destination);
132
134void TMWriteEvent(TMWriterInterface* writer, const TMEvent* event);
135
136extern bool TMTraceCtorDtor;
137
138#endif
139
140/* emacs
141 * Local Variables:
142 * tab-width: 8
143 * c-basic-offset: 3
144 * indent-tabs-mode: nil
145 * End:
146 */
147
uint32_t type
type of bank data, enum of TID_xxx
Definition midasio.h:47
uint32_t data_size
size of bank data in bytes
Definition midasio.h:48
size_t data_offset
offset of data for this bank in the event data[] container
Definition midasio.h:49
std::string name
bank name, 4 characters max
Definition midasio.h:46
std::string BankListToString() const
print the list of MIDAS banks
void PrintHeader() const
void FindAllBanks()
scan the MIDAS event, find all data banks
std::string HeaderToString() const
print the MIDAS event header
TMBank * FindBank(const char *bank_name)
scan the MIDAS event
bool found_all_banks
all the banks in the event data have been discovered
Definition midasio.h:71
std::vector< TMBank > banks
list of MIDAS banks, fill using FindAllBanks()
Definition midasio.h:66
void Reset()
reset everything
void PrintBanks(int level=0)
void AddBank(const char *bank_name, int tid, const char *buf, size_t size)
add new MIDAS bank
char * GetEventData()
get pointer to MIDAS event data
const char * GetBankData(const TMBank *) const
get pointer to MIDAS data bank
void DumpHeader() const
void Init(uint16_t event_id, uint16_t trigger_mask=0, uint32_t serial_number=0, uint32_t time_stamp=0, size_t capacity=0)
uint32_t time_stamp
MIDAS event time stamp (unix time in sec)
Definition midasio.h:60
size_t bank_scan_position
location where scan for MIDAS banks was last stopped
Definition midasio.h:72
uint32_t bank_header_flags
flags from the MIDAS event bank header
Definition midasio.h:64
void ParseHeader(const void *buf, size_t buf_size)
parse event header
void ParseEvent()
parse event data
std::vector< char > data
MIDAS event bytes.
Definition midasio.h:67
size_t event_header_size
size of MIDAS event header
Definition midasio.h:63
uint32_t serial_number
MIDAS event serial number.
Definition midasio.h:59
uint32_t data_size
MIDAS event data size.
Definition midasio.h:61
const char * GetEventData() const
get pointer to MIDAS event data
uint16_t trigger_mask
MIDAS trigger mask.
Definition midasio.h:58
uint16_t event_id
MIDAS event ID.
Definition midasio.h:57
char * GetBankData(const TMBank *)
get pointer to MIDAS data bank
TMEvent(const void *buf, size_t buf_size)
bool error
event has an error - incomplete, truncated, inconsistent or corrupted
Definition midasio.h:55
std::string BankToString(const TMBank *) const
print definition of one MIDAS bank
virtual int Read(void *buf, int count)=0
virtual int Close()=0
std::string fErrorString
Definition midasio.h:116
virtual ~TMReaderInterface()
Definition midasio.h:113
static bool fgTrace
Definition midasio.h:117
virtual int Close()=0
virtual ~TMWriterInterface()
Definition midasio.h:125
virtual int Write(const void *buf, int count)=0
static bool fgTrace
Definition midasio.h:127
bool TMTraceCtorDtor
void TMWriteEvent(TMWriterInterface *writer, const TMEvent *event)
Definition midasio.cxx:651
TMWriterInterface * TMNewWriter(const char *destination)
Definition midasio.cxx:543
TMEvent * TMReadEvent(TMReaderInterface *reader)
Definition midasio.cxx:585
TMReaderInterface * TMNewReader(const char *source)
Definition midasio.cxx:447
const char * source
Definition mlz4hc.h:181