Belle II Software development
BitStream.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#ifndef TRGBitStream_FLAG_
10#define TRGBitStream_FLAG_
11
12#include <vector>
13#include <string>
14#include "trg/trg/Signal.h"
15
16//...Data structure of TRGBitStreamFile...
17// 4 byte : record type
18// 4 byte : size in bit
19// variable(size / 8) byte : data
20
21//...TRGBitStream record definition...
22#define TRGBSRecord_Comment 0xffff0000
23#define TRGBSRecord_BeginRun 0xffff00A0
24#define TRGBSRecord_EndRun 0xffff00A1
25#define TRGBSRecord_BeginEvent 0xffff00B0
26#define TRGBSRecord_EndEvent 0xffff00B1
27#define TRGBSRecord_Clock 0xffff00C0
28#define TRGBSRecord_SegmentSL0 0xffff00F0
29#define TRGBSRecord_SegmentSL1 0xffff00F1
30#define TRGBSRecord_SegmentSL2 0xffff00F2
31#define TRGBSRecord_SegmentSL3 0xffff00F3
32#define TRGBSRecord_SegmentSL4 0xffff00F4
33#define TRGBSRecord_SegmentSL5 0xffff00F5
34#define TRGBSRecord_SegmentSL6 0xffff00F6
35#define TRGBSRecord_SegmentSL7 0xffff00F7
36#define TRGBSRecord_SegmentSL8 0xffff00F8
37
38namespace Belle2 {
46
47 public:
48
51
53 explicit TRGBitStream(int size, const std::string& name = "unknown");
54
57
59 TRGBitStream(const char* const, unsigned sizeInBit);
60
62 virtual ~TRGBitStream();
63
64 public:// Selectors
65
67 const std::string& name(void) const;
68
70 const std::string& name(const std::string& newName);
71
73 void dump(const std::string& message = "",
74 const std::string& pre = "") const;
75
77 unsigned size(void) const;
78
80 unsigned sizeInChar(void) const;
81
83 char c(unsigned positionInChar) const;
84
86 bool bit(unsigned positionInBit) const;
87
88 public:// Modifiers
89
91 void clear(void);
92
94 void append(bool);
95
97 void append(int);
98
100 void append(unsigned);
101
102 public:// Utility functions
103
105 static std::vector<TRGSignal> TRGBitStream2TRGSignal(
106 const TRGClock& clock,
107 int initialClockPosition,
108 std::vector<TRGBitStream*> stream);
109
110 private:
111
113 std::string _name;
114
116 unsigned _sizeMax;
117
119 unsigned _size;
120
122 std::vector<unsigned* > _stream;
123 };
124
125//-----------------------------------------------------------------------------
126
127 inline
128 const std::string&
130 {
131 return _name;
132 }
133
134 inline
135 const std::string&
136 TRGBitStream::name(const std::string& newName)
137 {
138 return _name = newName;
139 }
140
141 inline
142 void
144 {
145 _stream.clear();
146 }
147
148 inline
149 unsigned
151 {
152 return _size;
153 }
154
155 inline
156 void
158 {
159 if (a)
160 append(true);
161 else
162 append(false);
163 }
164
165 inline
166 void
168 {
169 if (a)
170 append(true);
171 else
172 append(false);
173 }
174
175 inline
176 unsigned
178 {
179 unsigned s = _size / 8;
180 if (_size % 8)
181 ++s;
182 return s;
183 }
184
185 inline
186 char
187 TRGBitStream::c(unsigned a) const
188 {
189 unsigned p = a / sizeof(unsigned);
190 unsigned q = a % sizeof(unsigned);
191 unsigned v = * _stream[p];
192 return (v >> (q * 8)) & 0xff;
193 }
194
195 inline
196 bool
197 TRGBitStream::bit(unsigned a) const
198 {
199 unsigned p = a / (sizeof(unsigned) * 8);
200 unsigned q = a % (sizeof(unsigned) * 8);
201 unsigned v = * _stream[p];
202 return (v & (1 << q));
203 }
204
206} // namespace Belle2
207
208#endif /* TRGBitStream_FLAG_ */
A class to represent a bit stream.
Definition: BitStream.h:45
unsigned _size
Bit stream size.
Definition: BitStream.h:119
unsigned _sizeMax
Bit stream max size.
Definition: BitStream.h:116
std::string _name
Name.
Definition: BitStream.h:113
std::vector< unsigned * > _stream
Bit stream storage.
Definition: BitStream.h:122
A class to represent a digitized signal. Unit is nano second.
Definition: Clock.h:38
unsigned size(void) const
returns size of stream in unit of bit.
Definition: BitStream.h:150
unsigned sizeInChar(void) const
returns size in char's.
Definition: BitStream.h:177
bool bit(unsigned positionInBit) const
returns true if given position is active.
Definition: BitStream.h:197
const std::string & name(void) const
returns name.
Definition: BitStream.h:129
TRGBitStream()
Default constructor.
Definition: BitStream.cc:21
virtual ~TRGBitStream()
Destructor.
Definition: BitStream.cc:69
static std::vector< TRGSignal > TRGBitStream2TRGSignal(const TRGClock &clock, int initialClockPosition, std::vector< TRGBitStream * > stream)
Make trigger signals from bit stream.
Definition: BitStream.cc:127
char c(unsigned positionInChar) const
returns a pointer to char's.
Definition: BitStream.h:187
void clear(void)
clears contents.
Definition: BitStream.h:143
void append(bool)
appends a bit to a stream.
Definition: BitStream.cc:98
void dump(const std::string &message="", const std::string &pre="") const
dumps contents. "message" is to select information to dump. "pre" will be printed in head of each lin...
Definition: BitStream.cc:76
Abstract base class for different kinds of events.