Belle II Software  release-05-02-19
Signal.h
1 //-----------------------------------------------------------------------------
2 // $Id$
3 //-----------------------------------------------------------------------------
4 // Filename : TRGSignal.h
5 // Section : TRG
6 // Owner : Yoshihito Iwasaki
7 // Email : yoshihito.iwasaki@kek.jp
8 //-----------------------------------------------------------------------------
9 // Description : A class to represent a digitized signal.
10 //-----------------------------------------------------------------------------
11 // $Log$
12 //-----------------------------------------------------------------------------
13 
14 #ifndef TRGSignal_FLAG_
15 #define TRGSignal_FLAG_
16 
17 #include <vector>
18 #include "trg/trg/Clock.h"
19 #include "trg/trg/Time.h"
20 
21 namespace Belle2 {
27  class TRGSignal {
29 
30  public:
31 
33  TRGSignal(const TRGClock& = Belle2_GDL::GDLSystemClock);
34 
36  TRGSignal(const TRGTime& t0, const TRGTime& t1);
37 
39  TRGSignal(const TRGClock& c, int t0, int t1);
40 
43  TRGSignal(const TRGClock& c, double t0, double t1);
44 
46  TRGSignal(const std::string& name,
47  const TRGClock& = Belle2_GDL::GDLSystemClock);
48 
50  TRGSignal(const TRGSignal&);
51 
53  TRGSignal(const TRGTime&);
54 
56  virtual ~TRGSignal();
57 
58  public:// Selectors
59 
61  const std::string& name(void) const;
62 
64  const TRGClock& clock(void) const;
65 
67  unsigned nSignals(void) const;
68 
70  unsigned nEdges(void) const;
71 
73  unsigned width(unsigned i = 0) const;
74 
76  bool active(void) const;
77 
79  bool active(int clk0, int clk1) const;
80 
82  bool state(int clockPosition) const;
83 
86  bool riseEdge(int clockPosition) const;
87 
89  std::vector<int> stateChanges(void) const;
90 
93  void dump(const std::string& message = "",
94  const std::string& pre = "") const;
95 
96  public:// Modifiers
97 
99  const std::string& name(const std::string& newName);
100 
102  void clear(void);
103 
105  const TRGClock& clock(const TRGClock&);
106 
109  const TRGSignal& set(double t0, double t1);
110 
113  const TRGSignal& set(int t0, int t1, bool state = true);
114 
117  const TRGSignal& unset(int t0, int t1);
118 
120  const TRGSignal& invert(void);
121 
122  public:// Operators
123 
125  TRGSignal operator&(const TRGSignal&) const;
126 
128  TRGSignal operator&(const TRGTime&) const;
129 
131  TRGSignal& operator&=(const TRGSignal&);
132 
134  TRGSignal& operator&=(const TRGTime&);
135 
137  TRGSignal operator|(const TRGSignal&) const;
138 
140  TRGSignal operator|(const TRGTime&) const;
141 
143  TRGSignal& operator|=(const TRGSignal&);
144 
146  TRGSignal& operator|=(const TRGTime&);
147 
149  TRGSignal& widen(unsigned width);
150 
152  const TRGTime* operator[](unsigned i) const;
153 
155  bool operator==(const TRGSignal&) const;
156 
158  bool operator!=(const TRGSignal&) const;
159 
160  private:
161 
162  // /// And operation.
163  // static std::vector<TRGTime> andOperation(const std::vector<TRGTime>&);
164 
166  static std::vector<TRGTime> orOperation(const std::vector<TRGTime>&);
167 
169  void sort(void);
170 
172  bool consistencyCheck(void) const;
173 
174  private:
175 
177  std::string _name;
178 
180  const TRGClock* _clock;
181 
183  std::vector<TRGTime> _history;
184  };
185 
186 //-----------------------------------------------------------------------------
187 
188  inline
189  const std::string&
190  TRGSignal::name(void) const
191  {
192  return _name;
193  }
194 
195  inline
196  const std::string&
197  TRGSignal::name(const std::string& newName)
198  {
199  return _name = newName;
200  }
201 
202  inline
203  TRGSignal
205  {
206  TRGSignal t(* this);
207  TRGSignal left(l);
208  return t & left;
209  }
210 
211  inline
212  TRGSignal&
214  {
215  TRGSignal left(l);
216 
217 #if TRG_DEBUG
219 #endif
220 
221  return (* this) &= left;
222  }
223 
224  inline
225  TRGSignal
227  {
228  TRGSignal t(* this);
229  TRGSignal left(l);
230 
231 #if TRG_DEBUG
233 #endif
234 
235  return t | left;
236  }
237 
238  inline
239  TRGSignal&
241  {
242  TRGSignal left(l);
243 
244 #if TRG_DEBUG
246 #endif
247 
248  return (* this) |= left;
249  }
250 
251  inline
252  unsigned
254  {
255  return _history.size() / 2;
256  }
257 
258  inline
259  unsigned
260  TRGSignal::nEdges(void) const
261  {
262  return _history.size();
263  }
264 
265  inline
266  void
268  {
269 
270 #if TRG_DEBUG
272 #endif
273 
274  _history.clear();
275  }
276 
277  inline
278  bool
279  TRGSignal::active(void) const
280  {
281  if (_history.size())
282  return true;
283  return false;
284  }
285 
286  inline
287  bool
288  TRGSignal::state(int a) const
289  {
290  if (_history.size()) {
291  bool last = false;
292  for (unsigned i = 0; i < _history.size(); i++) {
293  if (_history[i].time() <= a)
294  last = _history[i].edge();
295  else if (_history[i].time() > a)
296  break;
297  }
298  return last;
299  }
300  return false;
301 
302  }
303 
304  inline
305  bool
306  TRGSignal::riseEdge(int a) const
307  {
308  if (_history.size()) {
309  bool last = false;
310  for (unsigned i = 0; i < _history.size(); i++) {
311  if (_history[i].time() < a) {
312  continue;
313  } else if (_history[i].time() == a) {
314  last = _history[i].edge();
315  } else if (_history[i].time() > a) {
316  break;
317  }
318  }
319  return last;
320  } else
321  return false;
322  }
323 
324  inline
325  const TRGTime*
326  TRGSignal::operator[](unsigned i) const
327  {
328  return & _history[i];
329  }
330 
331  inline
332  const TRGClock&
333  TRGSignal::clock(void) const
334  {
335  return * _clock;
336  }
337 
338  inline
339  bool
341  {
342  return (! operator==(a));
343  }
344 
345  inline
346  bool
347  TRGSignal::active(int c0, int c1) const
348  {
349  for (unsigned i = 0; i < _history.size(); i++) {
350  if (! _history[i].edge()) {
351  const int t0 = _history[i - 1].time();
352  const int t1 = _history[i].time();
353 
354  if ((c1 > t0) && (c0 < t1))
355  return true;
356  if ((c1 < t0) && (c1 < t1))
357  return false;
358  }
359  }
360  return false;
361  }
362 
364 } // namespace Belle2
365 
366 #endif /* TRGSignal_FLAG_ */
Belle2::TRGSignal
A class to represent a digitized signal. Unit is nano second.
Definition: Signal.h:28
Belle2::TRGSignal::width
unsigned width(unsigned i=0) const
returns width of i'th signal (i=0,1,2,...).
Definition: Signal.cc:393
Belle2::TRGSignal::stateChanges
std::vector< int > stateChanges(void) const
returns a list of clock position of state change.
Definition: Signal.cc:354
Belle2::TRGSignal::operator[]
const TRGTime * operator[](unsigned i) const
returns timing of i'th edge.
Definition: Signal.h:326
Belle2::TRGSignal::operator&
TRGSignal operator&(const TRGSignal &) const
returns AND result.
Definition: Signal.cc:170
Belle2::TRGSignal::operator|=
TRGSignal & operator|=(const TRGSignal &)
returns OR result.
Definition: Signal.cc:278
Belle2::TRGSignal::unset
const TRGSignal & unset(int t0, int t1)
clear(or unset) with leading edge at clock t0 and with trailing edge at clock t1.
Definition: Signal.cc:431
Belle2::TRGSignal::consistencyCheck
bool consistencyCheck(void) const
Self-consitency check. True is return if something wrong.
Definition: Signal.cc:457
Belle2::TRGSignal::state
bool state(int clockPosition) const
returns true if signal is active in given clock position.
Definition: Signal.h:288
Belle2::TRGSignal::name
const std::string & name(void) const
returns name.
Definition: Signal.h:190
Belle2::TRGSignal::active
bool active(void) const
returns true if there is a signal.
Definition: Signal.h:279
Belle2::TRGSignal::_history
std::vector< TRGTime > _history
Timing history.
Definition: Signal.h:183
Belle2::TRGSignal::dump
void dump(const std::string &message="", const std::string &pre="") const
dumps contents.
Definition: Signal.cc:144
Belle2::TRGSignal::_clock
const TRGClock * _clock
Clock.
Definition: Signal.h:180
Belle2::TRGSignal::clock
const TRGClock & clock(void) const
returns clock.
Definition: Signal.h:333
Belle2::TRGSignal::sort
void sort(void)
Sort operation.
Definition: Signal.cc:447
Belle2::TRGSignal::riseEdge
bool riseEdge(int clockPosition) const
returns true if signal is active and rising edge in give clock position.
Definition: Signal.h:306
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TRGSignal::nEdges
unsigned nEdges(void) const
returns # of edges.
Definition: Signal.h:260
Belle2::TRGSignal::nSignals
unsigned nSignals(void) const
returns # of signals.
Definition: Signal.h:253
Belle2::TRGSignal::operator|
TRGSignal operator|(const TRGSignal &) const
returns OR result.
Definition: Signal.cc:262
Belle2::TRGSignal::set
const TRGSignal & set(double t0, double t1)
makes a pulse with leading edge at t0 and with trailing edge at t1.
Belle2::TRGSignal::operator==
bool operator==(const TRGSignal &) const
returns true if two are the same.
Definition: Signal.cc:536
Belle2::TRGSignal::clear
void clear(void)
clears contents.
Definition: Signal.h:267
Belle2::TRGSignal::TRGSignal
TRGSignal(const TRGClock &=Belle2_GDL::GDLSystemClock)
Constructor.
Definition: Signal.cc:28
Belle2::TRGSignal::invert
const TRGSignal & invert(void)
makes signal inverted.
Definition: Signal.cc:504
Belle2::TRGTime
A class to represent a signal timing in the trigger system.
Definition: Time.h:30
Belle2::TRGSignal::~TRGSignal
virtual ~TRGSignal()
Destructor.
Definition: Signal.cc:136
Belle2::TRGSignal::orOperation
static std::vector< TRGTime > orOperation(const std::vector< TRGTime > &)
Or operation.
Definition: Signal.cc:297
Belle2::TRGClock
A class to represent a digitized signal. Unit is nano second.
Definition: Clock.h:43
Belle2::TRGSignal::operator&=
TRGSignal & operator&=(const TRGSignal &)
returns AND result.
Definition: Signal.cc:215
Belle2::TRGSignal::widen
TRGSignal & widen(unsigned width)
returns widen signals. Signals wider than "width" will be untouched.
Definition: Signal.cc:326
Belle2::TRGSignal::operator!=
bool operator!=(const TRGSignal &) const
returns true if two are the same.
Definition: Signal.h:340
Belle2::TRGSignal::_name
std::string _name
Name.
Definition: Signal.h:177