CbmRoot
Loading...
Searching...
No Matches
CbmTimeSlice.cxx
Go to the documentation of this file.
1/* Copyright (C) 2012-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer], Florian Uhlig */
4
5/*
6 * CbmTimeSlice.cxx
7 *
8 * Created on: 17.07.2012
9 * Author: friese
10 */
11#include "CbmTimeSlice.h"
12
13#include "CbmLink.h" // for CbmLink
14#include "CbmModuleList.h" // for CbmModuleList
15
16#include <Logger.h> // for Logger, LOG
17
18#include <TNamed.h> // for TNamed
19
20#include <cassert> // for assert
21#include <iomanip> // for operator<<, setprecision
22#include <sstream> // for operator<<, basic_ostream, stringstream
23#include <string> // for char_traits
24#include <utility> // for pair
25
26using std::fixed;
27using std::setprecision;
28using std::string;
29using std::stringstream;
30
31
32// ----- Constructor for flexible time-slice ----------------------------
34 : TNamed()
35 , fType(type)
36 , fStartTime(-1.)
37 , fLength(-1.)
38 , fIsEmpty(true)
39 , fNofData()
40 , fTimeDataFirst(0.)
41 , fTimeDataLast(0.)
42 , fMatch()
43{
44}
45// ---------------------------------------------------------------------------
46
47
48// ----- Constructor for fixed-length time-slice -------------------------
49CbmTimeSlice::CbmTimeSlice(double start, double duration)
50 : TNamed()
51 , fType(kRegular)
52 , fStartTime(start)
53 , fLength(duration)
54 , fIsEmpty(true)
55 , fNofData()
56 , fTimeDataFirst(0.)
57 , fTimeDataLast(0.)
58 , fMatch()
59{
60}
61// ---------------------------------------------------------------------------
62
63
64// ----- Destructor ------------------------------------------------------
66// ---------------------------------------------------------------------------
67
68
69// ----- Add data with time stamp ----------------------------------------
70bool CbmTimeSlice::AddData(ECbmModuleId detector, double time)
71{
72
73 // Check for out of bounds
74 if (fType == kRegular) {
75 if (time < fStartTime || time > GetEndTime()) {
76 LOG(error) << "Trying to add data at t = " << time << " ns to "
77 << "time slice [ " << fStartTime << ", " << GetEndTime() << " ] ns !";
78 return false;
79 } //? out of bounds
80 } //? fixed-length
81
82 // Update bookkeeping
83 if (fIsEmpty) {
84 fTimeDataFirst = time;
85 fTimeDataLast = time;
86 } //? time-slice empty
87 else {
88 if (time < fTimeDataFirst) fTimeDataFirst = time;
89 if (time > fTimeDataLast) fTimeDataLast = time;
90 } //? time-slice not empty
91
92 fNofData[detector]++;
93 fIsEmpty = false;
94
95 return true;
96}
97// ---------------------------------------------------------------------------
98
99
100// ----- End time of time slice ------------------------------------------
102{
103 double value = -1.;
104 switch (fType) {
105 case kRegular: value = fStartTime + fLength; break;
106 case kFlexible: value = -1.; break;
107 case kEvent: value = fStartTime; break;
108 default: value = -1.; break;
109 }
110 return value;
111}
112// ---------------------------------------------------------------------------
113
114
115// ----- Get data array size ---------------------------------------------
117{
118 auto it = fNofData.find(detector);
119 if (it == fNofData.end()) return 0;
120 return it->second;
121}
122// ---------------------------------------------------------------------------
123
124
125// ----- Register data ---------------------------------------------------
127{
128
129 // Check for out of bounds
130 if (fType == kRegular) {
131 if (time < fStartTime || time > GetEndTime()) {
132 LOG(error) << "Trying to add data at t = " << time << " ns to "
133 << "time slice [ " << fStartTime << ", " << GetEndTime() << " ] ns !";
134 return false;
135 } //? out of bounds
136 } //? fixed-length
137
138 // Update bookkeeping
139 if (fIsEmpty) {
140 fTimeDataFirst = time;
141 fTimeDataLast = time;
142 } //? time-slice empty
143 else {
144 if (time < fTimeDataFirst) fTimeDataFirst = time;
145 if (time > fTimeDataLast) fTimeDataLast = time;
146 } //? time-slice not empty
147 fNofData[system]++;
148 fIsEmpty = false;
149
150 return true;
151}
152// ---------------------------------------------------------------------------
153
154
155// ----- Register data ---------------------------------------------------
156bool CbmTimeSlice::RegisterData(ECbmModuleId system, double time, const CbmMatch& match)
157{
158
159 // Update match object
160 CbmLink link;
161 for (int32_t iLink = 0; iLink < match.GetNofLinks(); iLink++) {
162 int32_t input = match.GetLink(iLink).GetFile();
163 int32_t event = match.GetLink(iLink).GetEntry();
164 double weight = match.GetLink(iLink).GetWeight();
165 fMatch.AddLink(weight, -1, event, input);
166 }
167
168 return RegisterData(system, time);
169}
170// ---------------------------------------------------------------------------
171
172
173// ----- Reset time slice --------------------------------------------------
175{
176 assert(fType != kRegular);
179}
180// ---------------------------------------------------------------------------
181
182
183// ----- Reset time slice --------------------------------------------------
184void CbmTimeSlice::Reset(double start, double length)
185{
186 fStartTime = start;
187 fLength = length;
190}
191// ---------------------------------------------------------------------------
192
193
194// ----- Reset time slice bookkeeping --------------------------------------
196{
197 fNofData.clear();
198 fIsEmpty = true;
199 fTimeDataFirst = 0.;
200 fTimeDataLast = 0.;
202}
203// ---------------------------------------------------------------------------
204
205
206// ----- Status info -----------------------------------------------------
208{
209 stringstream ss;
210 ss << "Time slice [";
211 switch (fType) {
212 case kRegular: ss << fixed << setprecision(0) << fStartTime << ", " << GetEndTime() << "] ns, data: "; break;
213 case kFlexible: ss << "flexible], data: "; break;
214 case kEvent: ss << "event], data: "; break;
215 default: ss << "], data: "; break;
216 }
217 if (IsEmpty()) ss << "empty";
218 else {
219 ss << "[" << fixed << setprecision(3) << fTimeDataFirst << ", " << fTimeDataLast << "] ns, ";
220 for (auto it = fNofData.begin(); it != fNofData.end(); it++) {
221 if (it->second) ss << CbmModuleList::GetModuleNameCaps(it->first) << " " << it->second << " ";
222 } //# detectors
223 ss << ", MC events " << fMatch.GetNofLinks();
224 } //? time-slice not empty
225 return ss.str();
226}
227// ---------------------------------------------------------------------------
228
229
ClassImp(CbmConverterManager)
ECbmModuleId
Definition CbmDefs.h:39
const CbmLink & GetLink(int32_t i) const
Definition CbmMatch.h:39
int32_t GetNofLinks() const
Definition CbmMatch.h:42
void AddLink(const CbmLink &newLink)
Definition CbmMatch.cxx:47
void ClearLinks()
Definition CbmMatch.cxx:78
static TString GetModuleNameCaps(ECbmModuleId moduleId)
Bookkeeping of time-slice content.
EType
Time-slice type enumerator.
@ kEvent
Flexible time slice; no fixed time limits.
@ kFlexible
Regular time slice with fixed-size time interval.
void ResetCounters()
Reset the time slice bookkeeping.
std::string ToString() const
bool fIsEmpty
Flag for containing no data.
CbmTimeSlice(EType type=kFlexible)
Constructor without time interval.
double fStartTime
Start time [ns].
double fTimeDataLast
Time of last data object.
double GetEndTime() const
void Reset()
Reset the time slice.
bool RegisterData(ECbmModuleId system, double time)
Register data to time-slice header.
void AddData(ECbmModuleId detector)
Add data to time-slice.
CbmMatch fMatch
Link time slice to events.
double fTimeDataFirst
Time of first data object.
double fLength
Length of time-slice [ns].
std::map< ECbmModuleId, int32_t > fNofData
SystemId -> Number of digis.
EType fType
Time-slice type.
bool IsEmpty() const
int32_t GetNofData(ECbmModuleId detector) const
Get size of raw data container for given detector.