BmnRoot
Loading...
Searching...
No Matches
BmnDaqBuffer.cxx
Go to the documentation of this file.
1
8#include <cassert>
9#include <iostream>
10#include <iomanip>
11#include <sstream>
12
13#include "TString.h"
14
15#include "FairLogger.h"
16
17#include "BmnDaqBuffer.h"
18#include "BmnModuleList.h"
19
20using std::setprecision;
21using std::stringstream;
22using std::fixed;
23using std::string;
24using std::pair;
25using std::multimap;
26
27// ----- Initialisation of static variables ------------------------------
28BmnDaqBuffer* BmnDaqBuffer::fgInstance = NULL;
29// ---------------------------------------------------------------------------
30
31
32
33// ----- Constructor -----------------------------------------------------
34BmnDaqBuffer::BmnDaqBuffer() {
35}
36// ---------------------------------------------------------------------------
37
38
39// ----- Destructor ------------------------------------------------------
42// ---------------------------------------------------------------------------
43
44
45
46// ----- Time of first raw data ------------------------------------------
48 Double_t time = -1.;
49 Bool_t firstDetector = kTRUE;
50 for (Int_t iDet = kREF; iDet < kNOFDETS; iDet++) {
51 if ( GetSize(iDet) ) {
52 if ( firstDetector ) {
53 time = GetFirstTime(iDet);
54 firstDetector = kFALSE;
55 } //? first detector with data
56 else time = ( time < GetFirstTime(iDet) ? time : GetFirstTime(iDet) );
57 } //? detector has data
58 } //# detectors
59 return time;
60}
61// ---------------------------------------------------------------------------
62
63
64
65// ----- Time of first raw data for detector ------------------------------
66Double_t BmnDaqBuffer::GetFirstTime(Int_t iDet) const {
67 if ( iDet < kREF || iDet >= kNOFDETS ) return -1.;
68 if ( ! GetSize(iDet) ) return -1.;
69 assert ( (fData[iDet].begin())->second );
70 return (fData[iDet].begin())->second->GetTime();
71}
72// ---------------------------------------------------------------------------
73
74
75
76// ----- Time of last raw data -------------------------------------------
77Double_t BmnDaqBuffer::GetLastTime() const {
78 Double_t time = -1.;
79 Bool_t firstDetector = kTRUE;
80 for (Int_t iDet = kREF; iDet < kNOFDETS; iDet++) {
81 if ( GetSize(iDet) ) {
82 if ( firstDetector ) {
83 time = GetLastTime(iDet);
84 firstDetector = kFALSE;
85 } //? first detector
86 else time = ( time > GetLastTime(iDet) ? time : GetLastTime(iDet) );
87 } //? detector has data
88 } //# detectors
89 return time;
90}
91// ---------------------------------------------------------------------------
92
93
94
95// ----- Time of last raw data for detector -------------------------------
96Double_t BmnDaqBuffer::GetLastTime(Int_t iDet) const {
97 if ( iDet < kREF || iDet >= kNOFDETS ) return -1.;
98 if ( ! GetSize(iDet) ) return -1.;
99 assert ( (--fData[iDet].end())->second );
100 return (--fData[iDet].end())->second->GetTime();
101}
102// ---------------------------------------------------------------------------
103
104
105
106// ----- Access to next data ---------------------------------------------
108
109 // --- Check for system ID
110 if ( iDet >= kNOFDETS ) {
111 LOG(WARNING) << "DaqBuffer: Illegal system ID " << iDet;
112 return NULL;
113 }
114
115 // --- Check for empty buffer
116 if ( ! fData[iDet].size() ) return NULL;
117
118 // --- Get data from buffer
119 BmnDigi* digi = NULL;
120 multimap<Double_t, BmnDigi*>::iterator it = fData[iDet].begin();
121 BmnDigi* test = it->second;
122 digi = test;
123 fData[iDet].erase(it);
124
125 return digi;
126}
127// ---------------------------------------------------------------------------
128
129
130
131// ----- Access to next data with time limit ------------------------------
132BmnDigi* BmnDaqBuffer::GetNextData(Int_t iDet, Double_t time) {
133
134
135 // --- Check for system ID
136 if ( iDet >= kNOFDETS ) {
137 LOG(WARNING) << "DaqBuffer: Illegal system ID " << iDet;
138 return NULL;
139 }
140
141 // --- Check for empty buffer
142 if ( ! fData[iDet].size() ) return NULL;
143
144 // --- Get data from buffer
145 BmnDigi* digi = NULL;
146 multimap<Double_t, BmnDigi*>::iterator it = fData[iDet].begin();
147 BmnDigi* test = it->second;
148 if ( test->GetTime() < time ) {
149 digi = test;
150 fData[iDet].erase(it);
151 }
152 return digi;
153
154}
155// ---------------------------------------------------------------------------
156
157
158
159// ----- Number of objects in buffer -------------------------------------
161
162 Int_t size = 0;
163 for (Int_t iDet = kREF; iDet < kNOFDETS; iDet++)
164 size += fData[iDet].size();
165 return size;
166
167}
168// ---------------------------------------------------------------------------
169
170
171
172// ----- Number of objects in buffer for given detector ------------------
173Int_t BmnDaqBuffer::GetSize(Int_t det) const {
174 if ( det < kREF || det > kNOFDETS) return 0;
175 return fData[det].size();
176}
177// ---------------------------------------------------------------------------
178
179
180
181// ----- Insert data into buffer -----------------------------------------
183
184 if ( ! digi ) LOG(fatal) << "DaqBuffer: invalid digi pointer";
185
186 Int_t iDet = digi->GetSystemId();
187 if ( iDet >= kNOFDETS) {
188 LOG(WARNING) << "DaqBuffer: Illegal system ID " << iDet;
189 return;
190 }
191
192 pair<Double_t, BmnDigi*> value (digi->GetTime(), digi);
193 fData[iDet].insert(value);
194
195 LOG(debug2) << "DaqBuffer: Inserting digi, detectorID "
196 << digi->GetAddress() << ", time " << digi->GetTime();
197
198}
199// ---------------------------------------------------------------------------
200
201
202
203// ----- Instance --------------------------------------------------------
205 if ( ! fgInstance ) fgInstance = new BmnDaqBuffer();
206 return fgInstance;
207}
208// ---------------------------------------------------------------------------
209
210
211
212// ----- Print status ----------------------------------------------------
214 TString sysName;
215 Int_t size = GetSize();
216 LOG(info) << "DaqBuffer: Status ";
217 if ( ! size ) {
218 LOG(info) << "empty";
219 return;
220 }
221 for (Int_t det = kREF; det < kNOFDETS; det++) {
222 if ( GetSize(det) ) {
224 LOG(info) << sysName << " " << GetSize(det) << " ";
225 }
226 }
227 LOG(info) << "\t " << "Total: " << GetSize() << " from "
228 << fixed << setprecision(3) << GetFirstTime() << " ns to "
229 << GetLastTime() << " ns";
230}
231// ---------------------------------------------------------------------------
232
233
234
235// ----- Status to string ------------------------------------------------
237 stringstream ss;
238 ss << "DaqBuffer: ";
239 Int_t size = GetSize();
240 if ( ! size ) {
241 ss << "empty";
242 return ss.str();
243 }
244 TString sysName;
245 for (Int_t det = kREF; det < kNOFDETS; det++) {
246 if ( GetSize(det) ) {
248 ss << sysName << " " << GetSize(det) << " ";
249 }
250 }
251 ss << "Total: " << size << " from " << fixed << setprecision(3)
252 << GetFirstTime() << " ns to " << GetLastTime() << " ns";
253
254 return ss.str();
255}
256// ---------------------------------------------------------------------------
257
@ kREF
@ kNOFDETS
Singleton buffer class for BMN raw data.
BmnDigi * GetNextData(Int_t iDet)
Pointer to next raw data object for a given detector.
Double_t GetFirstTime() const
Double_t GetLastTime() const
std::string ToString() const
static BmnDaqBuffer * Instance()
void InsertData(BmnDigi *digi)
Int_t GetSize() const
void PrintStatus() const
Base class for persistent representation of digital information.
Definition BmnDigi.h:44
virtual Int_t GetSystemId() const =0
Definition BmnDigi.cxx:116
virtual Double_t GetTime() const =0
Definition BmnDigi.cxx:121
virtual Int_t GetAddress() const =0
Definition BmnDigi.cxx:111
static TString GetModuleNameCaps(Int_t moduleId)