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