GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TTdrEvent.cxx
Go to the documentation of this file.
1//
2// TTdrEvent.cxx.
3//
4// $Id: TTdrEvent.cxx 91 2012-04-12 18:36:17Z olchansk $
5//
6
7#include <cstdio>
8#include <cstdlib>
9#include <ctime>
10#include <cstring>
11#include <cassert>
12
13#include "TTdrEvent.h"
14
16{
17 // Default constructor
18 fData.resize(0);
19}
20
21void TTdrEvent::Copy(TObject& rhs) const
22{
23 // Copies the entire TTdrEvent.
24 static_cast<TTdrEvent&>(rhs).fData = fData;
25}
26
28{
29 // Copy ctor.
30 rhs.Copy(*this);
31}
32
37
39{
40 if(&rhs != this) {
41 Clear();
42 }
43
44 rhs.Copy(*this);
45 return *this;
46}
47
48void TTdrEvent::Clear(Option_t*)
49{
50 // Clears the TTdrEvent.
51 fData.clear();
52}
53
54void TTdrEvent::SetHeader(const char* buffer)
55{
56 /// Set the TDR header from buffer (assumes that buffer contains at least 24 bytes worth of data)
57 // Skip first 8 bytes (TTdrFile::Read already tested that these are "EBYEDATA")
58 fHeader.fSequence = *reinterpret_cast<const uint32_t*>(buffer + 8);
59 fHeader.fStream = *reinterpret_cast<const uint16_t*>(buffer + 12);
60 fHeader.fTape = *reinterpret_cast<const uint16_t*>(buffer + 14);
61 fHeader.fHeaderEndian = *reinterpret_cast<const uint16_t*>(buffer + 16);
62 fHeader.fDataEndian = *reinterpret_cast<const uint16_t*>(buffer + 18);
63 fHeader.fDataLength = *reinterpret_cast<const uint32_t*>(buffer + 20);
64 //std::cout<<std::hex<<std::setfill('0');
65 //std::cout<<"sequence 0x"<<fHeader.fSequence<<std::endl;
66 //std::cout<<"stream 0x"<<fHeader.fStream<<std::endl;
67 //std::cout<<"tape 0x"<<fHeader.fTape<<std::endl;
68 //std::cout<<"header endian 0x"<<fHeader.fHeaderEndian<<std::endl;
69 //std::cout<<"data endian 0x"<<fHeader.fDataEndian<<std::endl;
70 //std::cout<<"data length 0x"<<fHeader.fDataLength<<" / 0x"<<GetDataSize()<<std::endl;
71 //std::cout<<std::dec<<std::setfill(' ');
72}
73
74void TTdrEvent::SetData(const std::vector<char>& buffer)
75{
76 // Sets the data in the TTdrEvent as the data argument passed into
77 // this function.
78 fData = std::vector<char>(buffer.begin(), buffer.begin() + fHeader.fDataLength);
79 SwapBytes(false);
80}
81
82uint32_t TTdrEvent::GetDataSize() const
83{
84 return fData.size();
85}
86
88{
89 // returns the allocated data.
90 return fData.data();
91}
92
93void TTdrEvent::Print(const char* option) const
94{
95 /// Print data held in this class.
96 /// \param [in] option If 'a' (for "all") then the raw data will be
97 /// printed out too.
98 ///
99
100 printf("Event start:\n");
101 if(option[0] == 'a') {
102 for(size_t i = 0; i < fData.size() / 4; ++i) {
103 printf("0x%08x", ((uint32_t*)fData.data())[i]);
104 if(i % 10 == 9) {
105 printf("\n");
106 } else {
107 printf(" ");
108 }
109 }
110 }
111}
112
113using BYTE = uint8_t;
114
115/// Byte swapping routine.
116///
117#define QWORD_SWAP(x) \
118 { \
119 BYTE _tmp; \
120 _tmp = *((BYTE*)(x)); \
121 *((BYTE*)(x)) = *(((BYTE*)(x)) + 7); \
122 *(((BYTE*)(x)) + 7) = _tmp; \
123 _tmp = *(((BYTE*)(x)) + 1); \
124 *(((BYTE*)(x)) + 1) = *(((BYTE*)(x)) + 6); \
125 *(((BYTE*)(x)) + 6) = _tmp; \
126 _tmp = *(((BYTE*)(x)) + 2); \
127 *(((BYTE*)(x)) + 2) = *(((BYTE*)(x)) + 5); \
128 *(((BYTE*)(x)) + 5) = _tmp; \
129 _tmp = *(((BYTE*)(x)) + 3); \
130 *(((BYTE*)(x)) + 3) = *(((BYTE*)(x)) + 4); \
131 *(((BYTE*)(x)) + 4) = _tmp; \
132 }
133
134/// Byte swapping routine.
135///
136#define DWORD_SWAP(x) \
137 { \
138 BYTE _tmp; \
139 _tmp = *((BYTE*)(x)); \
140 *((BYTE*)(x)) = *(((BYTE*)(x)) + 3); \
141 *(((BYTE*)(x)) + 3) = _tmp; \
142 _tmp = *(((BYTE*)(x)) + 1); \
143 *(((BYTE*)(x)) + 1) = *(((BYTE*)(x)) + 2); \
144 *(((BYTE*)(x)) + 2) = _tmp; \
145 }
146
147/// Byte swapping routine.
148///
149#define WORD_SWAP(x) \
150 { \
151 BYTE _tmp; \
152 _tmp = *((BYTE*)(x)); \
153 *((BYTE*)(x)) = *(((BYTE*)(x)) + 1); \
154 *(((BYTE*)(x)) + 1) = _tmp; \
155 }
156
158{
159 return 1;
160}
161
162// end
uint8_t BYTE
RAW event.
Definition TRawEvent.h:23
void Copy(TObject &) const override
copy helper
Definition TTdrEvent.cxx:21
void SetHeader(const char *buffer)
set an externally allocated header buffer
Definition TTdrEvent.cxx:54
void Clear(Option_t *opt="") override
clear event for reuse
Definition TTdrEvent.cxx:48
TTdrEventHeader fHeader
event header
Definition TTdrEvent.h:57
TTdrEvent & operator=(const TTdrEvent &)
assignement operator
Definition TTdrEvent.cxx:38
std::vector< char > fData
event data buffer
Definition TTdrEvent.h:58
uint32_t GetDataSize() const override
return the event size
Definition TTdrEvent.cxx:82
TTdrEvent()
default constructor
Definition TTdrEvent.cxx:15
void Print(const char *option="") const override
show all event information
Definition TTdrEvent.cxx:93
void SetData(const std::vector< char > &buffer)
set an externally allocated data buffer
Definition TTdrEvent.cxx:74
int SwapBytes(bool) override
convert event data between little-endian (Linux-x86) and big endian (MacOS-PPC)
char * GetData() override
return pointer to the data buffer
Definition TTdrEvent.cxx:87
~TTdrEvent() override
destructor
Definition TTdrEvent.cxx:33
uint16_t fTape
=1
Definition TTdrEvent.h:25
uint32_t fDataLength
length of data following in bytes
Definition TTdrEvent.h:28
uint16_t fHeaderEndian
written as native 1 by tape server
Definition TTdrEvent.h:26
uint32_t fSequence
within the file
Definition TTdrEvent.h:23
uint16_t fDataEndian
written as native 1 in the hardware structure of the data following
Definition TTdrEvent.h:27
uint16_t fStream
data acquisition stream number (1-4)
Definition TTdrEvent.h:24