Belle II Software development
SignalVector.cc
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#define TRG_SHORT_NAMES
10
11#include <string>
12#include <algorithm>
13#include <limits>
14#include <iostream>
15#include "trg/trg/Utilities.h"
16#include "trg/trg/Clock.h"
17#include "trg/trg/Signal.h"
18#include "trg/trg/SignalVector.h"
19#include "trg/trg/State.h"
20
21using namespace std;
22
23namespace Belle2 {
30 const TRGClock& c,
31 unsigned size)
32 : _name(name),
33 _clock(& c)
34 {
35 for (unsigned i = 0; i < size; i++) {
36 const string n = _name + ":bit" + TRGUtilities::itostring(i);
37 TRGSignal t(n, c);
38 push_back(t);
39 }
40 }
41
43 std::vector<TRGSignal>(),
44 _name("CopyOf" + t._name)
45 {
46 _clock = t._clock;
47 const unsigned n = t.size();
48 for (unsigned i = 0; i < n; i++)
49 push_back(t[i]);
50 }
51
53 _name("VectorOf" + t.name())
54 {
55 _clock = & t.clock();
56 push_back(t);
57 }
58
60 {
61 }
62
63 void
64 TRGSignalVector::dump(const string& msg,
65 const string& pre) const
66 {
67
68 cout << pre << _name << ":" << size() << " signal(s)" << endl;
69
70 const bool det = msg.find("detail") != string::npos;
71 const bool clk = msg.find("clock") != string::npos;
72
73 if (det || clk)
74 cout << pre << ":clock=" << _clock->name();
75
76 if (det)
77 for (unsigned i = 0; i < size(); i++)
78 (* this)[i].dump(msg, " " + pre + "bit" +
79 TRGUtil::itostring(i) + ":");
80 else
81 for (unsigned i = 0; i < size(); i++)
82 if ((* this)[i].active())
83 (* this)[i].dump(msg, " " + pre + "bit" +
84 TRGUtil::itostring(i) + ":");
85 }
86
87// TRGSignalVector
88// TRGSignalVector::operator+(const TRGSignalVector & left) const {
89// TRGSignalVector t;
90// t.push_back(this);
91// t.push_back(& left);
92// return t;
93// }
94
97 {
98 push_back(left);
99 return * this;
100 }
101
104 {
105 for (unsigned i = 0; i < left.size(); i++)
106 push_back(left[i]);
107 return * this;
108 }
109
110 bool
112 {
113 for (unsigned i = 0; i < size(); i++)
114 if ((* this)[i].active())
115 return true;
116 return false;
117 }
118
119 bool
121 {
122 TRGState s = state(c);
123 if (s.active())
124 return true;
125 else
126 return false;
127 }
128
129 std::vector<int>
131 {
132 std::vector<int> list;
133 const unsigned n = size();
134 for (unsigned i = 0; i < n; i++) {
135 vector<int> a = (* this)[i].stateChanges();
136 for (unsigned j = 0; j < a.size(); j++)
137 list.push_back(a[j]);
138 }
139
140 //...Sorting...
141 std::sort(list.begin(), list.end());
142
143 //...Remove duplicated clock...
144 std::vector<int> list2;
145 int last = numeric_limits<int>::min();
146 for (unsigned i = 0; i < list.size(); i++) {
147 const int j = list[i];
148 if (j != last) {
149 list2.push_back(j);
150 last = j;
151 }
152 }
153
154 return list2;
155 }
156
158 TRGSignalVector::state(int clockPosition) const
159 {
160 std::vector<bool> list;
161 const unsigned n = size();
162 for (unsigned i = 0; i < n; i++)
163 list.push_back((* this)[i].state(clockPosition));
164 return TRGState(list);
165 }
166
167 const TRGClock&
169 {
170 _clock = & c;
171
172 for (unsigned i = 0; i < size(); i++) {
173 TRGSignal& t = (* this)[i];
174 t.clock(c);
175 }
176
177 return * _clock;
178 }
179
180 const TRGSignalVector&
182 {
183 const unsigned n = s.size();
184 for (unsigned i = 0; i < n; i++) {
185 TRGSignal& signal = (* this)[i];
186 signal.set(cp, cp + 1, s[i]);
187 }
188 return * this;
189 }
190
191 bool
193 {
194 if (size() != a.size()) {
195 // cout << "TRGSignalVector::operator== : different size:"
196 // << size() << "," << a.size() << endl;
197 return false;
198 }
199 for (unsigned i = 0; i < size(); i++) {
200 if ((* this)[i] != a[i]) {
201 // cout << "TRGSignalVector::operator== : different signal:i="
202 // << i << endl;
203 // (* this)[i].dump();
204 // a[i].dump();
205 return false;
206 }
207 }
208
209 return true;
210 }
211
212
214} // namespace Belle2
A class to represent a digitized signal. Unit is nano second.
Definition: Clock.h:38
A class to represent a bundle of digitized signals.
Definition: SignalVector.h:26
const TRGClock * _clock
Clock.
Definition: SignalVector.h:104
std::string _name
Name.
Definition: SignalVector.h:101
A class to represent a digitized signal. Unit is nano second.
Definition: Signal.h:23
A class to represent a state of multi bits.
Definition: State.h:24
const TRGSignalVector & set(const TRGState &, int clockPosition)
sets state at given clock.
TRGState state(int clockPosition) const
returns state at given clock position.
TRGSignalVector & operator+=(const TRGSignal &)
appends TRGSignal.
Definition: SignalVector.cc:96
const TRGClock & clock(void) const
returns clock.
Definition: SignalVector.h:125
const std::string & name(void) const
returns name.
Definition: Clock.h:157
std::vector< int > stateChanges(void) const
returns a list of clock position of state change.
virtual ~TRGSignalVector()
Destructor.
Definition: SignalVector.cc:59
static std::string itostring(int i)
converts int to string. (Use boost::lexical_cast)
Definition: Utilities.cc:50
bool operator==(const TRGSignalVector &) const
compare two TRGSignalVectors.
bool active(void) const
returns true if there is a signal.
TRGSignalVector(const std::string &name, const TRGClock &, unsigned size=0)
Default constructor.
Definition: SignalVector.cc:29
void dump(const std::string &message="", const std::string &pre="") const
dumps contents.
Definition: SignalVector.cc:64
Abstract base class for different kinds of events.
STL namespace.