ROOTANA
TMidasEvent.h
Go to the documentation of this file.
1 //
2 // TMidasEvent.h
3 //
4 
5 #ifndef TMIDASEVENT_H
6 #define TMIDASEVENT_H
7 
8 #include "TMidasStructs.h"
9 
10 ///
11 /// C++ class representing one midas event.
12 ///
13 /// Objects of this class are created by reading
14 /// midas events from a file, by reading
15 /// them from a midas shared memory buffer or by
16 /// receiving them through the mserver
17 ///
18 
19 /// MIDAS event
20 
22 {
23  public:
24 
25  // houskeeping functions
26 
27  TMidasEvent(); ///< default constructor
28  TMidasEvent(const TMidasEvent &); ///< copy constructor
29  ~TMidasEvent(); ///< destructor
30  TMidasEvent& operator=(const TMidasEvent &); ///< assignement operator
31  void Clear(); ///< clear event for reuse
32  void Copy(const TMidasEvent &); ///< copy helper
33  void Print(const char* option = "") const; ///< show all event information
34 
35  // get event information
36 
37  uint16_t GetEventId() const; ///< return the event id
38  uint16_t GetTriggerMask() const; ///< return the triger mask
39  uint32_t GetSerialNumber() const; ///< return the serial number
40  uint32_t GetTimeStamp() const; ///< return the time stamp (unix time in seconds)
41  uint32_t GetDataSize() const; ///< return the event size
42 
43  // get data banks
44 
45  const char* GetBankList() const; ///< return a list of data banks
46  int FindBank(const char* bankName, int* bankLength, int* bankType, void **bankPtr) const;
47  int LocateBank(const void *unused, const char* bankName, void **bankPtr) const;
48 
49  bool IsBank32() const; ///< returns "true" if event uses bk_init32() banks
50  bool IsBank32a() const; ///< returns "true" if event uses bk_init32a() banks
51  int IterateBank(TMidas_BANK **, char **pdata) const; ///< iterate through 16-bit data banks
52  int IterateBank32(TMidas_BANK32 **, char **pdata) const; ///< iterate through 32-bit data banks
53  int IterateBank32a(TMidas_BANK32a **, char **pdata) const; ///< iterate through 32-bit data banks
54 
55  // helpers for event creation
56 
57  TMidas_EVENT_HEADER* GetEventHeader(); ///< return pointer to the event header
58  char* GetData(); ///< return pointer to the data buffer
59 
60  void AllocateData(); ///< allocate data buffer using the existing event header
61  void SetData(uint32_t dataSize, char* dataBuffer); ///< set an externally allocated data buffer
62 
63  int SetBankList(); ///< create the list of data banks, return number of banks
64  bool IsGoodSize() const; ///< validate the event length
65 
66  void SwapBytesEventHeader(); ///< convert event header between little-endian (Linux-x86) and big endian (MacOS-PPC)
67  int SwapBytes(bool); ///< convert event data between little-endian (Linux-x86) and big endian (MacOS-PPC)
68 
69 protected:
70 
71  TMidas_EVENT_HEADER fEventHeader; ///< event header
72  char* fData; ///< event data buffer
73  int fBanksN; ///< number of banks in this event
74  char* fBankList; ///< list of bank names in this event
75  bool fAllocatedByUs; ///< "true" if we own the data buffer
76 };
77 
78 class TMReaderInterface;
79 class TMWriterInterface;
80 
81 // read and write functions
82 bool TMReadEvent(TMReaderInterface* reader, TMidasEvent* event);
83 bool TMWriteEvent(TMWriterInterface* writer, TMidasEvent* event);
84 
85 #endif // TMidasEvent.h
bool TMWriteEvent(TMWriterInterface *writer, TMidasEvent *event)
bool TMReadEvent(TMReaderInterface *reader, TMidasEvent *event)
MIDAS event.
Definition: TMidasEvent.h:22
int FindBank(const char *bankName, int *bankLength, int *bankType, void **bankPtr) const
int SwapBytes(bool)
convert event data between little-endian (Linux-x86) and big endian (MacOS-PPC)
bool IsBank32() const
returns "true" if event uses bk_init32() banks
int IterateBank32(TMidas_BANK32 **, char **pdata) const
iterate through 32-bit data banks
TMidas_EVENT_HEADER * GetEventHeader()
return pointer to the event header
void Clear()
clear event for reuse
Definition: TMidasEvent.cxx:63
uint32_t GetDataSize() const
return the event size
int fBanksN
number of banks in this event
Definition: TMidasEvent.h:73
int SetBankList()
create the list of data banks, return number of banks
int IterateBank32a(TMidas_BANK32a **, char **pdata) const
iterate through 32-bit data banks
void AllocateData()
allocate data buffer using the existing event header
const char * GetBankList() const
return a list of data banks
int IterateBank(TMidas_BANK **, char **pdata) const
iterate through 16-bit data banks
uint16_t GetEventId() const
return the event id
Definition: TMidasEvent.cxx:93
int LocateBank(const void *unused, const char *bankName, void **bankPtr) const
bool IsBank32a() const
returns "true" if event uses bk_init32a() banks
uint32_t GetTimeStamp() const
return the time stamp (unix time in seconds)
TMidasEvent()
default constructor
Definition: TMidasEvent.cxx:15
TMidasEvent & operator=(const TMidasEvent &)
assignement operator
Definition: TMidasEvent.cxx:54
void SetData(uint32_t dataSize, char *dataBuffer)
set an externally allocated data buffer
Definition: TMidasEvent.cxx:83
bool fAllocatedByUs
"true" if we own the data buffer
Definition: TMidasEvent.h:75
char * fData
event data buffer
Definition: TMidasEvent.h:72
void Print(const char *option="") const
show all event information
~TMidasEvent()
destructor
Definition: TMidasEvent.cxx:49
uint32_t GetSerialNumber() const
return the serial number
uint16_t GetTriggerMask() const
return the triger mask
Definition: TMidasEvent.cxx:98
TMidas_EVENT_HEADER fEventHeader
event header
Definition: TMidasEvent.h:71
bool IsGoodSize() const
validate the event length
void Copy(const TMidasEvent &)
copy helper
Definition: TMidasEvent.cxx:30
char * GetData()
return pointer to the data buffer
char * fBankList
list of bank names in this event
Definition: TMidasEvent.h:74
void SwapBytesEventHeader()
convert event header between little-endian (Linux-x86) and big endian (MacOS-PPC)
32-bit data bank
Definition: TMidasStructs.h:41
16-bit data bank
Definition: TMidasStructs.h:33
Event header.
Definition: TMidasStructs.h:16