GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TScaler.h
Go to the documentation of this file.
1#ifndef TSCALER_H
2#define TSCALER_H
3
4/** \addtogroup Sorting
5 * @{
6 */
7
8/*
9 * Author: V. Bildstein, <vbildste@uoguelph.ca>
10 *
11 * Based on the TPPG class
12 *
13 * Please indicate changes with your initials.
14 *
15 */
16
17//////////////////////////////////////////////////////////////////////////
18///
19/// \class TScaler
20///
21/// The TScaler is designed to hold all of the information about the
22/// scaler status.
23///
24//////////////////////////////////////////////////////////////////////////
25
26#include <iostream>
27#include <map>
28
29#include "TObject.h"
30#include "Globals.h"
31#include "TCollection.h"
32#include "TTree.h"
33#include "TH1D.h"
34
35#include "TPPG.h"
36
37class TScalerData : public TObject {
38public:
41 TScalerData(TScalerData&&) noexcept = default;
42 TScalerData& operator=(const TScalerData&) = default;
43 TScalerData& operator=(TScalerData&&) noexcept = default;
44 ~TScalerData() = default;
45
46 void Copy(TObject& rhs) const override;
47
48 void SetAddress(UInt_t address) { fAddress = address; }
49 void SetNetworkPacketId(UInt_t networkId) { fNetworkPacketId = networkId; }
50 void SetLowTimeStamp(UInt_t lowTime) { fLowTimeStamp = lowTime; }
51 void SetHighTimeStamp(UInt_t highTime) { fHighTimeStamp = highTime; }
52 void SetScaler(size_t index, UInt_t scaler)
53 {
54 if(index < fScaler.size()) {
55 fScaler[index] = scaler;
56 } else {
57 std::cout << "Failed to set scaler " << scaler << ", index " << index << " is out of range 0 - "
58 << fScaler.size() << std::endl;
59 }
60 }
61 void SetScaler(UInt_t* data, int size)
62 {
63 fScaler = std::vector<uint32_t>(data, data + size);
64 }
65
66 UInt_t GetAddress() const { return fAddress; }
67 UInt_t GetNetworkPacketId() const { return fNetworkPacketId; }
68 UInt_t GetLowTimeStamp() const { return fLowTimeStamp; }
69 UInt_t GetHighTimeStamp() const { return fHighTimeStamp; }
70 std::vector<UInt_t> GetScaler() const { return fScaler; }
71 UInt_t GetScaler(size_t index) const
72 {
73 if(index < fScaler.size()) {
74 return fScaler[index];
75 }
76 return 0;
77 }
78
79 ULong64_t GetTimeStamp() const
80 {
81 ULong64_t time = GetHighTimeStamp();
82 time = time << 28;
83 time |= GetLowTimeStamp() & 0x0fffffff;
84 return 10 * time; // convert from raw 10 ns units to ns
85 }
86
87 void ResizeScaler(size_t newSize = 1) { fScaler.resize(newSize); }
88
89 void Print(Option_t* opt = "") const override;
90 void Clear(Option_t* opt = "") override;
91
92private:
94 UInt_t fAddress{0};
95 std::vector<UInt_t> fScaler;
96 UInt_t fLowTimeStamp{0};
97 UInt_t fHighTimeStamp{0};
98
99 /// \cond CLASSIMP
100 ClassDefOverride(TScalerData, 2) // NOLINT(readability-else-after-return)
101 /// \endcond
102};
103
104class TScaler : public TObject {
105public:
106 explicit TScaler(bool loadIntoMap = false);
107 explicit TScaler(TTree*, bool loadIntoMap = false);
108 TScaler(const TScaler&);
109 TScaler(TScaler&&) noexcept = default;
110 TScaler& operator=(const TScaler&) = default;
111 TScaler& operator=(TScaler&&) noexcept = default;
112 ~TScaler();
113
114 void Copy(TObject& obj) const override;
115
116 std::vector<UInt_t> GetScaler(UInt_t address, ULong64_t time) const;
117 UInt_t GetScaler(UInt_t address, ULong64_t time, size_t index) const;
118 UInt_t GetScalerDifference(UInt_t address, ULong64_t time, size_t index) const;
119 ULong64_t NumberOfScalerReadouts() const { return fEntries; };
120
121 ULong64_t GetTimePeriod(UInt_t address);
122
123 std::map<UInt_t, ULong64_t> GetTimePeriodMap() { return fTimePeriod; }
124 std::map<UInt_t, std::map<ULong64_t, int>> GetNumberOfTimePeriods() { return fNumberOfTimePeriods; }
125
126 void Clear(Option_t* opt = "") override;
127 using TObject::Draw; // This is to remove hidden overload
128 TH1D* Draw(UInt_t address, size_t index = 0, Option_t* option = "");
129 TH1D* Draw(UInt_t lowAddress, UInt_t highAddress, size_t index = 0, Option_t* option = "");
130 TH1D* DrawRawTimes(UInt_t address, Double_t lowtime, Double_t hightime, size_t index = 0, Option_t* option = "");
131
132 void ListHistograms();
133
134 static double GetLastScaler(TTree* tree = nullptr, UInt_t address = 0xffff, size_t nominator = 2, size_t denominator = 1)
135 {
136 /// This function returns the ratio of the two scalers nominator and denominator for the last entry with a matching address for a given tree.
137 /// If no tree is provided it tries to get the "RateScaler" tree from the current directory.
138 if(tree == nullptr) {
139 tree = static_cast<TTree*>(gDirectory->Get("RateScaler"));
140 if(tree == nullptr) {
141 std::cerr << __PRETTY_FUNCTION__ << ": no tree provided and failed to find \"RateScaler\" in " << gDirectory->GetName() << std::endl; // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
142 return -1.;
143 }
144 }
145 TScalerData* scalerData = nullptr;
146 tree->SetBranchAddress("ScalerData", &scalerData);
147
148 for(Long64_t entry = tree->GetEntries() - 1; entry >= 0; --entry) {
149 tree->GetEntry(entry);
150 if(scalerData->GetAddress() != address) { continue; }
151 auto scalers = scalerData->GetScaler();
152 if(nominator >= scalers.size() || denominator >= scalers.size()) {
153 std::cerr << __PRETTY_FUNCTION__ << ": trying to get nominator " << nominator << " and denominator " << denominator << " from vector of size " << scalers.size() << std::endl; // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
154 return -1.;
155 }
156 return static_cast<double>(scalers[nominator]) / scalers[denominator];
157 }
158 std::cerr << __PRETTY_FUNCTION__ << ": failed to find any entry for address " << hex(address, 4) << std::endl; // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
159 return -1.;
160 }
161
162private:
163 void ReadTree(bool loadIntoMap);
164
165 TTree* fTree;
167 Long64_t fEntries;
168 std::map<UInt_t, std::map<ULong64_t, std::vector<UInt_t>>> fScalerMap; //!<! an address-map of timestamp mapped scaler values
169 std::map<UInt_t, ULong64_t> fTimePeriod; //!<! a map between addresses and time differences (used to calculate the time period)
170 std::map<UInt_t, std::map<ULong64_t, int>> fNumberOfTimePeriods; //!<!
171 ULong64_t fTotalTimePeriod; //!<!
172 std::map<ULong64_t, int> fTotalNumberOfTimePeriods; //!<!
173 TPPG* fPPG; //!<!
174 std::map<UInt_t, TH1D*> fHist; //!<! map to store histograms that have already been drawn
175 std::map<std::pair<UInt_t, UInt_t>, TH1D*> fHistRange; //!<! map to store histograms for address-ranges
176
177 /// \cond CLASSIMP
178 ClassDefOverride(TScaler, 2) // NOLINT(readability-else-after-return)
179 /// \endcond
180};
181/*! @} */
182#endif
std::string hex(T val, int width=-1)
Definition Globals.h:129
Definition TPPG.h:132
void Clear(Option_t *opt="") override
Definition TScaler.cxx:27
std::vector< UInt_t > fScaler
Definition TScaler.h:95
UInt_t GetScaler(size_t index) const
Definition TScaler.h:71
ULong64_t GetTimeStamp() const
Definition TScaler.h:79
UInt_t fAddress
Definition TScaler.h:94
UInt_t fNetworkPacketId
Definition TScaler.h:93
void Copy(TObject &rhs) const override
Definition TScaler.cxx:18
UInt_t fLowTimeStamp
Definition TScaler.h:96
UInt_t GetNetworkPacketId() const
Definition TScaler.h:67
UInt_t fHighTimeStamp
Definition TScaler.h:97
std::vector< UInt_t > GetScaler() const
Definition TScaler.h:70
void Print(Option_t *opt="") const override
Definition TScaler.cxx:37
void SetScaler(size_t index, UInt_t scaler)
Definition TScaler.h:52
void SetAddress(UInt_t address)
Definition TScaler.h:48
UInt_t GetAddress() const
Definition TScaler.h:66
void SetScaler(UInt_t *data, int size)
Definition TScaler.h:61
void SetNetworkPacketId(UInt_t networkId)
Definition TScaler.h:49
void ResizeScaler(size_t newSize=1)
Definition TScaler.h:87
UInt_t GetLowTimeStamp() const
Definition TScaler.h:68
void SetLowTimeStamp(UInt_t lowTime)
Definition TScaler.h:50
UInt_t GetHighTimeStamp() const
Definition TScaler.h:69
TScalerData(TScalerData &&) noexcept=default
void SetHighTimeStamp(UInt_t highTime)
Definition TScaler.h:51
std::map< UInt_t, std::map< ULong64_t, int > > fNumberOfTimePeriods
!
Definition TScaler.h:170
std::map< UInt_t, std::map< ULong64_t, int > > GetNumberOfTimePeriods()
Definition TScaler.h:124
ULong64_t fTotalTimePeriod
!
Definition TScaler.h:171
std::map< UInt_t, ULong64_t > GetTimePeriodMap()
Definition TScaler.h:123
TTree * fTree
Definition TScaler.h:165
void Clear(Option_t *opt="") override
Definition TScaler.cxx:228
TH1D * DrawRawTimes(UInt_t address, Double_t lowtime, Double_t hightime, size_t index=0, Option_t *option="")
Definition TScaler.cxx:450
static double GetLastScaler(TTree *tree=nullptr, UInt_t address=0xffff, size_t nominator=2, size_t denominator=1)
Definition TScaler.h:134
void ListHistograms()
Definition TScaler.cxx:523
std::map< ULong64_t, int > fTotalNumberOfTimePeriods
!
Definition TScaler.h:172
std::map< UInt_t, ULong64_t > fTimePeriod
! a map between addresses and time differences (used to calculate the time period)
Definition TScaler.h:169
std::vector< UInt_t > GetScaler(UInt_t address, ULong64_t time) const
Definition TScaler.cxx:108
std::map< std::pair< UInt_t, UInt_t >, TH1D * > fHistRange
! map to store histograms for address-ranges
Definition TScaler.h:175
TScalerData * fScalerData
Definition TScaler.h:166
TScaler(bool loadIntoMap=false)
Definition TScaler.cxx:46
std::map< UInt_t, TH1D * > fHist
! map to store histograms that have already been drawn
Definition TScaler.h:174
UInt_t GetScalerDifference(UInt_t address, ULong64_t time, size_t index) const
Definition TScaler.cxx:163
Long64_t fEntries
Definition TScaler.h:167
std::map< UInt_t, std::map< ULong64_t, std::vector< UInt_t > > > fScalerMap
! an address-map of timestamp mapped scaler values
Definition TScaler.h:168
void Copy(TObject &obj) const override
Definition TScaler.cxx:95
ULong64_t GetTimePeriod(UInt_t address)
Definition TScaler.cxx:491
TScaler(TScaler &&) noexcept=default
TPPG * fPPG
!
Definition TScaler.h:173
void ReadTree(bool loadIntoMap)
Definition TScaler.cxx:60
TH1D * Draw(UInt_t address, size_t index=0, Option_t *option="")
Definition TScaler.cxx:255
ULong64_t NumberOfScalerReadouts() const
Definition TScaler.h:119