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