ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
GETHeaderBase.cxx
Go to the documentation of this file.
1 #include "GETHeaderBase.h"
2 
3 #include <Rtypes.h>
4 
5 #include <cmath> // IWYU pragma: keep
6 #include <cstring>
7 #include <iostream>
8 #include <string>
9 
11 
13 {
14  Clear();
15 }
16 
18 {
19  return (UInt_t)fMetaType;
20 }
21 UInt_t GETHeaderBase::GetFrameSize(Bool_t inBytes)
22 {
23  return CorrectEndianness(fFrameSize, 3) * (inBytes ? GetUnitBlock() : 1);
24 }
26 {
27  return (UInt_t)fDataSource;
28 }
30 {
31  return CorrectEndianness(fFrameType, 2);
32 }
34 {
35  return (UInt_t)fRevision;
36 }
37 ULong64_t GETHeaderBase::GetFrameSkip(Bool_t rewind)
38 {
39  return GetFrameSize() - GETHEADERBASESIZE * (!rewind);
40 }
41 
43 {
44  return ((GetMetaType() & 0x80) >> 7);
45 }
47 {
48  return ((GetMetaType() & 0x40) >> 6);
49 }
51 {
52  return pow(2, GetMetaType() & 0xf);
53 }
54 
55 ULong64_t GETHeaderBase::CorrectEndianness(uint8_t *variable, Short_t length)
56 {
57  ULong64_t returnVal = 0;
58  ULong64_t returnMask = 0;
59 
60  if (!IsLittleEndian())
61  for (Short_t idx = 0; idx < length; idx++) {
62  returnVal += ((ULong64_t)variable[idx] << (8 * (length - idx - 1)));
63  returnMask += ((ULong64_t)0xff << 8 * idx);
64  }
65  else
66  for (Short_t idx = 0; idx < length; idx++) {
67  returnVal += ((ULong64_t)variable[(length - idx - 1)] << (8 * (length - idx - 1)));
68  returnMask += ((ULong64_t)0xff << 8 * idx);
69  }
70 
71  return (returnVal & returnMask);
72 }
73 
74 void GETHeaderBase::Clear(Option_t *)
75 {
76  memset(&fMetaType, 0, sizeof(uint8_t) * 1);
77  memset(fFrameSize, 0, sizeof(uint8_t) * 3);
78  memset(&fDataSource, 0, sizeof(uint8_t) * 1);
79  memset(fFrameType, 0, sizeof(uint8_t) * 2);
80  memset(&fRevision, 0, sizeof(uint8_t) * 1);
81 }
82 
83 void GETHeaderBase::Read(ifstream &stream, Bool_t rewind)
84 {
85  Clear();
86 
87  stream.read((Char_t *)&fMetaType, 1);
88  stream.read((Char_t *)fFrameSize, 3);
89  stream.read((Char_t *)&fDataSource, 1);
90  stream.read((Char_t *)fFrameType, 2);
91  stream.read((Char_t *)&fRevision, 1);
92 
93  stream.seekg((ULong64_t)stream.tellg() - GETHEADERBASESIZE * rewind);
94 }
95 
97 {
98  cout << showbase << hex;
99  cout << " == GETHeaderBase ================================" << endl;
100  cout << " metaType: " << GetMetaType() << endl;
101  cout << " - Endianness: " << (IsLittleEndian() ? "Little" : "Big") << endl;
102  cout << " - Blobness: " << (IsBlob() ? "YES" : "NO") << endl;
103  cout << " - UnitBlock: " << dec << GetUnitBlock() << " Bytes" << hex << endl;
104  cout << " frameSize: " << GetFrameSize(false) << " (" << dec << GetFrameSize(false)
105  << " Blocks = " << GetFrameSize() << hex << " Bytes)" << endl;
106  cout << " dataSource: " << GetDataSource() << endl;
107  cout << " frameType: " << GetFrameType() << endl;
108  cout << " revision: " << GetRevision() << endl;
109  cout << " =================================================" << endl;
110 }
GETHeaderBase::GetFrameSize
UInt_t GetFrameSize(Bool_t inBytes=kTRUE)
Definition: GETHeaderBase.cxx:21
GETHeaderBase::Clear
void Clear(Option_t *="")
Definition: GETHeaderBase.cxx:74
GETHeaderBase::GetRevision
UInt_t GetRevision()
Definition: GETHeaderBase.cxx:33
GETHeaderBase.h
GETHeaderBase::Print
void Print()
Definition: GETHeaderBase.cxx:96
GETHeaderBase::GetMetaType
UInt_t GetMetaType()
Definition: GETHeaderBase.cxx:17
GETHeaderBase::IsLittleEndian
Bool_t IsLittleEndian()
Definition: GETHeaderBase.cxx:42
GETHeaderBase::GetFrameType
UInt_t GetFrameType()
Definition: GETHeaderBase.cxx:29
GETHeaderBase::IsBlob
Bool_t IsBlob()
Definition: GETHeaderBase.cxx:46
GETHeaderBase::GetUnitBlock
UInt_t GetUnitBlock()
Definition: GETHeaderBase.cxx:50
GETHeaderBase::GETHeaderBase
GETHeaderBase()
Definition: GETHeaderBase.cxx:12
GETHeaderBase::Read
void Read(ifstream &file, Bool_t rewind=kFALSE)
Definition: GETHeaderBase.cxx:83
GETHeaderBase
Definition: GETHeaderBase.h:23
GETHeaderBase::GetDataSource
UInt_t GetDataSource()
Definition: GETHeaderBase.cxx:25
GETHEADERBASESIZE
#define GETHEADERBASESIZE
Definition: GETHeaderBase.h:4
GETHeaderBase::CorrectEndianness
ULong64_t CorrectEndianness(uint8_t *variable, Short_t length)
Definition: GETHeaderBase.cxx:55
ClassImp
ClassImp(GETHeaderBase)
GETHeaderBase::GetFrameSkip
ULong64_t GetFrameSkip(Bool_t rewind=kFALSE)
Definition: GETHeaderBase.cxx:37