Belle II Software development
Time.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#include <iostream>
10#include "trg/trg/Clock.h"
11#include "trg/trg/Time.h"
12#include "trg/trg/Signal.h"
13
14using namespace std;
15
16namespace Belle2 {
23 _time(t._time),
24 _edge(t._edge),
25 _clock(t._clock),
26 _name(t._name)
27 {
28 }
29
30 TRGTime::TRGTime(double timing,
31 bool edge,
32 const TRGClock& clock,
33 const std::string& name) :
34 _time(clock.position(timing)),
35 _edge(edge),
36 _clock(& clock),
37 _name(name)
38 {
39 }
40
41 TRGTime::TRGTime(int timing,
42 bool edge,
43 const TRGClock& clock,
44 const std::string& name) :
45 _time(timing),
46 _edge(edge),
47 _clock(& clock),
48 _name(name)
49 {
50 }
51
53 {
54 }
55
57 TRGTime::operator&(const TRGTime& left) const
58 {
59 TRGSignal t0(* this);
60 TRGSignal t1(left);
61 return t0 & t1;
62 }
63
65 TRGTime::operator&(const TRGSignal& left) const
66 {
67 TRGSignal t0(* this);
68 return t0 & left;
69 }
70
72 TRGTime::operator|(const TRGTime& left) const
73 {
74 TRGSignal t0(* this);
75 TRGSignal t1(left);
76 return t0 | t1;
77 }
78
80 TRGTime::operator|(const TRGSignal& left) const
81 {
82 TRGSignal t0(* this);
83 return t0 | left;
84 }
85
86 void
87 TRGTime:: dump(const std::string& msg,
88 const std::string& pre) const
89 {
90 cout << pre << "time(clock):";
91
92 if (_edge)
93 cout << " o ";
94 else
95 cout << " . ";
96
97 cout << _time;
98 cout << " abs=" << _clock->absoluteTime(_time);
99 if (msg.find("name") != string::npos ||
100 msg.find("detail") != string::npos) {
101 cout << " (" << _name << ")";
102 }
103 cout << endl;
104 }
105
106 bool
108 {
109 if (a.time() < b.time()) {
110 return true;
111 } else if (a.time() == b.time()) {
112 if (a.edge() and (! b.edge()))
113 return true;
114 else if (a.edge() == b.edge())
115 return true;
116 }
117 return false;
118 }
119
120 const TRGClock&
122 {
123 const double t = _clock->absoluteTime(_time);
124 _clock = & c;
125 _time = c.position(t);
126 return * _clock;
127 }
128
130} // namespace Belle2
A class to represent a digitized signal. Unit is nano second.
Definition: Clock.h:38
A class to represent a digitized signal. Unit is nano second.
Definition: Signal.h:23
A class to represent a signal timing in the trigger system.
Definition: Time.h:25
const TRGClock * _clock
Clock.
Definition: Time.h:117
int _time
Time in clock unit.
Definition: Time.h:111
std::string _name
Name.
Definition: Time.h:120
bool _edge
Edge type. true : rising, false : falling.
Definition: Time.h:114
virtual ~TRGTime()
Destructor.
Definition: Time.cc:52
double absoluteTime(int clockPosition) const
returns absolute time of clock position
Definition: Clock.cc:128
const TRGClock & clock(void) const
returns clock.
Definition: Time.h:149
TRGTime(const TRGTime &)
Copy constructor.
Definition: Time.cc:22
TRGSignal operator|(const TRGTime &) const
oring two TRGTime. A result is TRGSignal.
Definition: Time.cc:72
static bool sortByTime(const TRGTime &a, const TRGTime &b)
returns true if a is older than b.
Definition: Time.cc:107
TRGSignal operator&(const TRGTime &) const
adding two TRGTime. A result is TRGSignal.
Definition: Time.cc:57
void dump(const std::string &message="", const std::string &pre="") const
dumps contents.
Definition: Time.cc:87
Abstract base class for different kinds of events.
STL namespace.