GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TPPG.h
Go to the documentation of this file.
1#ifndef TPPG_H
2#define TPPG_H
3
4/** \addtogroup Sorting
5 * @{
6 */
7
8/*
9 * Author: R.Dunlop, <rdunlop@uoguelph.ca>
10 *
11 * Please indicate changes with your initials.
12 *
13 *
14 */
15
16//////////////////////////////////////////////////////////////////////////
17///
18/// \class TPPG
19///
20/// The TPPG is designed to hold all of the information about the
21/// PPG status.
22///
23//////////////////////////////////////////////////////////////////////////
24
25#include <map>
26#include <utility>
27#include <iostream>
28#include <cstdint>
29
30#include "TObject.h"
31#include "TCollection.h"
32
33#include "Globals.h"
34#include "TSingleton.h"
35
36enum class EPpgPattern : std::uint8_t {
37 kBeamOn = 0x01,
38 kDecay = 0x04,
39 kTapeMove = 0x08,
40 kBackground = 0x02,
41 // kSync = 0xc000,
42 kJunk = 0xFF
43};
44
45class TPPGData : public TObject {
46public:
47 TPPGData();
48 TPPGData(const TPPGData&);
49 TPPGData(TPPGData&&) = default;
50 ~TPPGData() = default;
51
52 TPPGData& operator=(const TPPGData&) = default;
54
55 void Copy(TObject& rhs) const override;
56
57 void Print(Option_t* opt = "") const override;
58 void Clear(Option_t* opt = "") override;
59
60 // -------------------- setter functions
61 void SetLowTimeStamp(UInt_t lowTime)
62 {
63 fLowTimeStamp = lowTime;
65 }
66 void SetHighTimeStamp(UInt_t highTime)
67 {
68 fHighTimeStamp = highTime;
70 }
71 void SetNewPPG(EPpgPattern newPpg) { fNewPpg = newPpg; }
72 void SetNewPPG(UInt_t newPpg)
73 {
74 fNewPpg = static_cast<EPpgPattern>(newPpg & 0xff);
75 switch(fNewPpg) {
81 break;
82 default:
83 if(newPpg != 0) { std::cout << "Warning, unknown ppg pattern " << hex(newPpg, 8) << ", setting new pattern to kJunk!" << std::endl; }
85 }
86 }
87 void SetOldPPG(EPpgPattern oldPpg) { fOldPpg = oldPpg; }
88 void SetOldPPG(UInt_t oldPpg)
89 {
90 fOldPpg = static_cast<EPpgPattern>(oldPpg & 0xff);
91 switch(fOldPpg) {
97 break;
98 default:
99 if(oldPpg != 0) { std::cout << "Warning, unknown ppg pattern " << hex(oldPpg, 8) << ", setting old pattern to kJunk!" << std::endl; }
101 }
102 }
103 void SetNetworkPacketId(UInt_t packet) { fNetworkPacketId = packet; }
104
105 void SetTimeStamp();
106
107 // -------------------- getter functions
108 UInt_t GetLowTimeStamp() const { return fLowTimeStamp; }
109 UInt_t GetHighTimeStamp() const { return fHighTimeStamp; }
110 EPpgPattern GetNewPPG() const { return fNewPpg; }
111 EPpgPattern GetOldPPG() const { return fOldPpg; }
112 UInt_t GetNetworkPacketId() const { return fNetworkPacketId; }
113
114 ULong64_t GetTimeStamp() const { return fTimeStamp; }
115
116private:
117 static int16_t fTimestampUnits; ///< timestamp units of the PPG (10 ns)
118 ULong64_t fTimeStamp{0}; ///< time stamp in ns
122 UInt_t fLowTimeStamp{0}; ///< low bits of time stamp in 10 ns
123 UInt_t fHighTimeStamp{0}; ///< high bits of time stamp in 10 ns
124
125 /// \cond CLASSIMP
126 ClassDefOverride(TPPGData, 3) // NOLINT(readability-else-after-return)
127 /// \endcond
128};
129
130class TPPG : public TSingleton<TPPG> {
131public:
132 friend class TSingleton<TPPG>;
133
134 using PPGMap_t = std::map<ULong_t, TPPGData*>;
135
136 TPPG();
137 TPPG(const TPPG&); // the copy constructor needs to create a deep-copy
138 TPPG(TPPG&&) = default; // the move constructor can be default?
139 ~TPPG();
140
141 TPPG& operator=(const TPPG&); // the copy assignment needs to create a deep-copy
142 TPPG& operator=(TPPG&&) = default; // the move assignment can be default?
143
144 void Copy(TObject& obj) const override;
145 // why do we have a non-const version that just calls the const version?
146 // the arguments are needed to match the TObject version and thus override it
147 Int_t Write(const char* name = nullptr, Int_t option = 0, Int_t bufsize = 0) override
148 {
149 return static_cast<const TPPG*>(this)->Write(name, option, bufsize);
150 }
151 Int_t Write(const char* name = nullptr, Int_t option = 0, Int_t bufsize = 0) const override;
152
153 void Print(Option_t* opt = "") const override;
154 void Clear(Option_t* opt = "") override;
155
156 void Setup();
157 bool Correct(bool verbose = false);
158
159 void AddData(TPPGData* pat);
160 EPpgPattern GetStatus(ULong64_t time) const;
161 EPpgPattern GetNextStatus(ULong64_t time) const;
162 ULong64_t GetLastStatusTime(ULong64_t time, EPpgPattern pat = EPpgPattern::kJunk) const;
163 ULong64_t GetNextStatusTime(ULong64_t time, EPpgPattern pat = EPpgPattern::kJunk) const;
164 Bool_t MapIsEmpty() const;
165 std::size_t PPGSize() const { return fPPGStatusMap->size() - 1; }
166 std::size_t OdbPPGSize() const { return fOdbPPGCodes.size(); }
167 int16_t OdbPPGCode(size_t index) const { return fOdbPPGCodes.at(index); }
168 int OdbDuration(size_t index) const { return fOdbDurations.at(index); }
169 Long64_t OdbCycleLength() const
170 {
171 Long64_t result = 0;
172 for(auto dur : fOdbDurations) { result += dur; }
173 return result;
174 }
175 Long64_t Merge(TCollection* list);
176 void Add(const TPPG* ppg);
177
178 void operator+=(const TPPG& rhs);
179
180 void SetCycleLength(ULong64_t length) { fCycleLength = length; }
181
182 // -------------------- getter functions
183 ULong64_t GetCycleLength();
184 ULong64_t GetNumberOfCycles();
185 ULong64_t GetTimeInCycle(ULong64_t real_time);
186 ULong64_t GetCycleNumber(ULong64_t real_time);
187
188 ULong64_t GetStatusStart(EPpgPattern);
189
190 const TPPGData* Next();
191 const TPPGData* Previous();
192 const TPPGData* First();
193 const TPPGData* Last();
194
195 void SetOdbCycle(std::vector<int16_t> ppgCodes, std::vector<int> durations)
196 {
197 fOdbPPGCodes = std::move(ppgCodes);
198 fOdbDurations = std::move(durations);
199 }
200
201 bool OdbMatchesData(bool verbose = false);
202 void SetOdbFromData(bool verbose = false);
203
204private:
205 bool CalculateCycleFromData(bool verbose = false);
206
207 PPGMap_t::iterator MapBegin() const { return ++(fPPGStatusMap->begin()); }
208 PPGMap_t::iterator MapEnd() const { return fPPGStatusMap->end(); }
209 PPGMap_t::iterator fCurrIterator; //!<!
210
212 ULong64_t fCycleLength{0};
213 std::map<ULong64_t, int> fNumberOfCycleLengths;
214
215 std::vector<int16_t> fOdbPPGCodes; ///< ppg state codes read from odb
216 std::vector<int> fOdbDurations; ///< duration of ppg state as read from odb
217
218 bool fCycleSet{false}; //!<! flag to indicate whether the codes and durations have been calculated from the data
219 std::vector<int16_t> fPPGCodes{0x8, 0x2, 0x1, 0x4}; //!<! ppg state codes (these are always set)
220 std::vector<ULong64_t> fDurations{0, 0, 0, 0}; //!<! duration of ppg state calculated from data
221
222 /// \cond CLASSIMP
223 ClassDefOverride(TPPG, 6) // NOLINT(readability-else-after-return)
224 /// \endcond
225};
226/*! @} */
227#endif
std::string hex(T val, int width=-1)
Definition Globals.h:129
TPPGData()
Definition TPPG.cxx:10
ULong64_t GetTimeStamp() const
Definition TPPG.h:114
ULong64_t fTimeStamp
time stamp in ns
Definition TPPG.h:118
void Copy(TObject &rhs) const override
Definition TPPG.cxx:21
TPPGData(TPPGData &&)=default
void Clear(Option_t *opt="") override
Definition TPPG.cxx:39
void SetNetworkPacketId(UInt_t packet)
Definition TPPG.h:103
void SetHighTimeStamp(UInt_t highTime)
Definition TPPG.h:66
void SetNewPPG(UInt_t newPpg)
Definition TPPG.h:72
UInt_t GetLowTimeStamp() const
Definition TPPG.h:108
EPpgPattern GetOldPPG() const
Definition TPPG.h:111
void SetTimeStamp()
Definition TPPG.cxx:31
void SetOldPPG(UInt_t oldPpg)
Definition TPPG.h:88
void SetNewPPG(EPpgPattern newPpg)
Definition TPPG.h:71
UInt_t fNetworkPacketId
Definition TPPG.h:121
void Print(Option_t *opt="") const override
Definition TPPG.cxx:51
void SetOldPPG(EPpgPattern oldPpg)
Definition TPPG.h:87
TPPGData & operator=(TPPGData &&)=default
UInt_t fHighTimeStamp
high bits of time stamp in 10 ns
Definition TPPG.h:123
EPpgPattern GetNewPPG() const
Definition TPPG.h:110
EPpgPattern fOldPpg
Definition TPPG.h:119
EPpgPattern fNewPpg
Definition TPPG.h:120
TPPGData & operator=(const TPPGData &)=default
static int16_t fTimestampUnits
timestamp units of the PPG (10 ns)
Definition TPPG.h:117
UInt_t GetHighTimeStamp() const
Definition TPPG.h:109
UInt_t fLowTimeStamp
low bits of time stamp in 10 ns
Definition TPPG.h:122
UInt_t GetNetworkPacketId() const
Definition TPPG.h:112
~TPPGData()=default
void SetLowTimeStamp(UInt_t lowTime)
Definition TPPG.h:61
Definition TPPG.h:130
bool fCycleSet
! flag to indicate whether the codes and durations have been calculated from the data
Definition TPPG.h:218
int OdbDuration(size_t index) const
Definition TPPG.h:168
PPGMap_t::iterator MapBegin() const
Definition TPPG.h:207
void Print(Option_t *opt="") const override
Definition TPPG.cxx:216
ULong64_t GetCycleNumber(ULong64_t real_time)
Definition TPPG.cxx:623
TPPG & operator=(const TPPG &)
Definition TPPG.cxx:79
const TPPGData * First()
Definition TPPG.cxx:597
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) override
Definition TPPG.h:147
ULong64_t GetTimeInCycle(ULong64_t real_time)
Definition TPPG.cxx:615
void Clear(Option_t *opt="") override
Definition TPPG.cxx:432
const TPPGData * Next()
Definition TPPG.cxx:572
TPPG()
Definition TPPG.cxx:56
std::vector< int16_t > fOdbPPGCodes
ppg state codes read from odb
Definition TPPG.h:215
void SetCycleLength(ULong64_t length)
Definition TPPG.h:180
ULong64_t fCycleLength
Definition TPPG.h:212
ULong64_t GetNumberOfCycles()
Definition TPPG.cxx:654
PPGMap_t::iterator fCurrIterator
!
Definition TPPG.h:209
ULong64_t GetStatusStart(EPpgPattern)
Definition TPPG.cxx:671
std::vector< ULong64_t > fDurations
! duration of ppg state calculated from data
Definition TPPG.h:220
bool OdbMatchesData(bool verbose=false)
Definition TPPG.cxx:341
Bool_t MapIsEmpty() const
Definition TPPG.cxx:113
const TPPGData * Last()
Definition TPPG.cxx:590
ULong64_t GetNextStatusTime(ULong64_t time, EPpgPattern pat=EPpgPattern::kJunk) const
Definition TPPG.cxx:161
ULong64_t GetCycleLength()
Definition TPPG.cxx:631
EPpgPattern GetStatus(ULong64_t time) const
Definition TPPG.cxx:189
std::vector< int16_t > fPPGCodes
! ppg state codes (these are always set)
Definition TPPG.h:219
TPPG(TPPG &&)=default
Long64_t OdbCycleLength() const
Definition TPPG.h:169
std::map< ULong64_t, int > fNumberOfCycleLengths
Definition TPPG.h:213
void Add(const TPPG *ppg)
Definition TPPG.cxx:682
void operator+=(const TPPG &rhs)
Definition TPPG.cxx:677
std::map< ULong_t, TPPGData * > PPGMap_t
Definition TPPG.h:134
PPGMap_t::iterator MapEnd() const
Definition TPPG.h:208
ULong64_t GetLastStatusTime(ULong64_t time, EPpgPattern pat=EPpgPattern::kJunk) const
Definition TPPG.cxx:133
void AddData(TPPGData *pat)
Definition TPPG.cxx:121
void SetOdbFromData(bool verbose=false)
Definition TPPG.cxx:366
bool CalculateCycleFromData(bool verbose=false)
Definition TPPG.cxx:381
int16_t OdbPPGCode(size_t index) const
Definition TPPG.h:167
std::size_t PPGSize() const
Definition TPPG.h:165
TPPG & operator=(TPPG &&)=default
void SetOdbCycle(std::vector< int16_t > ppgCodes, std::vector< int > durations)
Definition TPPG.h:195
void Setup()
Definition TPPG.cxx:462
~TPPG()
Definition TPPG.cxx:68
void Copy(TObject &obj) const override
Definition TPPG.cxx:93
const TPPGData * Previous()
Definition TPPG.cxx:581
EPpgPattern GetNextStatus(ULong64_t time) const
Definition TPPG.cxx:201
std::size_t OdbPPGSize() const
Definition TPPG.h:166
std::vector< int > fOdbDurations
duration of ppg state as read from odb
Definition TPPG.h:216
Long64_t Merge(TCollection *list)
Definition TPPG.cxx:659
PPGMap_t * fPPGStatusMap
Definition TPPG.h:211
bool Correct(bool verbose=false)
Definition TPPG.cxx:484
EPpgPattern
Definition TPPG.h:36