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