BmnRoot
Loading...
Searching...
No Matches
BmnMSCMatrix.h
Go to the documentation of this file.
1#ifndef BMNMSCMATRIX_H
2#define BMNMSCMATRIX_H
3
4#include <chrono>
5#include <map>
6#include <vector>
7// Boost
8#include <boost/dynamic_bitset.hpp>
9// #include <boost/numeric/ublas/matrix_sparse.hpp>
10// ROOT
11// #include <TMatrixTSparse.h>
12#include <TObject.h>
13// BmnRoot
14#include "BmnFunctionSet.h"
15
16using SysClock = std::chrono::system_clock;
17using SysPoint = std::chrono::time_point<SysClock>;
18
19using std::string;
20using std::vector;
21
22// namespace ublas = boost::numeric::ublas;
23
24// template class TMatrixTSparse<uint8_t>;
25// template class ublas::compressed_matrix<uint8_t>;
26
32template<typename IntType = uint8_t>
33class BmnMSCMatrix : public TObject
34{
35 typedef map<SysPoint, IntType> TimeLine;
36 typedef map<SysPoint, size_t> Time2Pos;
37 typedef map<string, TimeLine> Scaler2TimeDist;
38
39 typedef std::map<uint8_t, TimeLine> ScalerIdx2TimeDist;
40
41 public:
42 BmnMSCMatrix(size_t times_count = 0,
43 // uint16_t scaler_count = 0,
44 NameChMap scalerName2Index = NameChMap{})
45 : fNRecords{times_count}
46 // , fNScalers{scalerName2Index.size()} // , fVector(fNRecords * fNScalers, 0)
47 // , fMatrix{fNRecords, fNScalers, false}
48 // , fMatrix{(int32_t)fNRecords, fNScalers}
49 , fScalerName2index{scalerName2Index}
50 , fMapVector(GetNScalers())
51 , fTimes(fNRecords, SysPoint::min())
52 , fBitVecSpill(fNRecords, false)
53 , fBitVecBusy(fNRecords, false)
54 {}
55
56 // IntType& Counts(size_t i_record, uint16_t i_scaler) { return fVector[i_record * fNScalers + i_scaler]; }
57 // auto& Counts() { return fMatrix; }
58 IntType GetCount(size_t record_id, string scaler_name)
59 {
60 if (record_id >= GetNRecords())
61 return 0;
62 TimeLine& row = ScalerTimeLine(scaler_name);
63 SysPoint& time = fTimes[record_id];
64 return GetCntByTime(row, time);
65 }
66 IntType GetCount(size_t record_id, uint16_t scaler_id)
67 {
68 if (record_id >= GetNRecords())
69 return 0;
70 TimeLine& row = ScalerTimeLine(scaler_id);
71 SysPoint& time = fTimes[record_id];
72 return GetCntByTime(row, time);
73 // return fMatrix(record_id, scaler_id);
74 }
75 IntType GetCount(SysPoint& time, string scaler_name)
76 {
77 auto it = fScalerName2index.find(scaler_name);
78 if (it == fScalerName2index.end()) {
79 throw out_of_range("Scaler not found");
80 }
81 return GetCount(time, it->second);
82 }
83 IntType GetCount(SysPoint& time, uint16_t scaler_id)
84 {
85 TimeLine& row = ScalerTimeLine(scaler_id);
86 return GetCntByTime(row, time);
87 }
88
89 void SetCount(size_t record_id, uint16_t scaler_id, IntType val)
90 {
91 TimeLine& row = ScalerTimeLine(scaler_id);
92 SysPoint& time = fTimes[record_id];
93 row[time] = val;
94 // fMatrix(record_id, scaler_id) = val;
95 }
96
97 void SetCount(size_t record_id, string scaler_name, IntType val)
98 {
99 TimeLine& row = ScalerTimeLine(scaler_name);
100 SysPoint& time = fTimes[record_id];
101 row[time] = val;
102 }
103
104 SysPoint& Time(size_t record_id) { return fTimes[record_id]; }
105 TTimeStamp GetTS(size_t record_id) { return BmnFunctionSet::TimePoint2TS(fTimes[record_id]); }
106 void SetTS(size_t record_id, TTimeStamp ts) { fTimes[record_id] = BmnFunctionSet::TimeStamp2TP(ts); }
107
108 NameChMap& GetScalerName2indexMap() { return fScalerName2index; }
109 // NameChMap& ScalerName2indexMap() { return fScalerName2index; }
110
111 TimeLine& ScalerTimeLine(string scaler_name)
112 {
113 auto it = fScalerName2index.find(scaler_name);
114 if (it == fScalerName2index.end()) {
115 throw out_of_range("Scaler name not found");
116 }
117 return ScalerTimeLine(it->second);
118 }
119 TimeLine& ScalerTimeLine(uint16_t scaler_id)
120 {
121 if (scaler_id >= fScalerName2index.size())
122 throw out_of_range("Scaler index not found");
123 return fMapVector[scaler_id];
124 }
125 static IntType GetCntByTime(TimeLine& row, SysPoint& time)
126 {
127 auto it = row.find(time);
128 if (it == row.end())
129 return 0;
130 return it->second;
131 }
132
133 auto& IsSpillBitVec() { return fBitVecSpill; }
134
135 auto& IsBusyBitVec() { return fBitVecBusy; }
136
137 const size_t GetNRecords() { return fNRecords; }
138
139 const uint16_t GetNScalers() { return fScalerName2index.size(); }
140 // const uint16_t GetNScalers() { return fNScalers; }
142 virtual ~BmnMSCMatrix() {}
143
144 private:
145 const size_t fNRecords;
146 // const uint16_t fNScalers;
147 NameChMap fScalerName2index;
148 vector<TimeLine> fMapVector;
149 // std::map<IntType> fVector;
150 // std::vector<IntType> fVector;
151 // Time2Pos fTimeMap;
152 // ublas::compressed_matrix<IntType> fMatrix; // WTF ROOT cannot work with it in a macro
153 // TMatrixTSparse<uint8_t> fMatrix; // "template" only supports a couple of prebuilt types
154 vector<SysPoint> fTimes;
155 // std::vector<bool> fBitVecSpill;
156 // std::vector<bool> fBitVecBusy;
157 boost::dynamic_bitset<> fBitVecSpill;
158 boost::dynamic_bitset<> fBitVecBusy;
159
160 // Scaler2TimeDist scalers;
161 // TimeDist ext_cond;
162
163 ClassDef(BmnMSCMatrix, 2);
164};
165
166#endif /* BMNMSCMATRIX_H */
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition P4_F32vec4.h:30
std::chrono::system_clock SysClock
std::chrono::time_point< SysClock > SysPoint
std::unordered_map< std::string, uint16_t > NameChMap
Definition BmnAliases.h:7
static SysPoint TimeStamp2TP(TTimeStamp p)
static TTimeStamp TimePoint2TS(SysPoint p)
virtual ~BmnMSCMatrix()
static IntType GetCntByTime(TimeLine &row, SysPoint &time)
BmnMSCMatrix(size_t times_count=0, NameChMap scalerName2Index=NameChMap{})
TimeLine & ScalerTimeLine(uint16_t scaler_id)
SysPoint & Time(size_t record_id)
IntType GetCount(size_t record_id, uint16_t scaler_id)
const size_t GetNRecords()
auto & IsBusyBitVec()
NameChMap & GetScalerName2indexMap()
void SetCount(size_t record_id, string scaler_name, IntType val)
TTimeStamp GetTS(size_t record_id)
void SetCount(size_t record_id, uint16_t scaler_id, IntType val)
void SetTS(size_t record_id, TTimeStamp ts)
const uint16_t GetNScalers()
TimeLine & ScalerTimeLine(string scaler_name)
auto & IsSpillBitVec()
IntType GetCount(SysPoint &time, string scaler_name)
IntType GetCount(SysPoint &time, uint16_t scaler_id)
IntType GetCount(size_t record_id, string scaler_name)
@ IntType
std::chrono::time_point< SysClock > SysPoint