ATLAS Offline Software
Loading...
Searching...
No Matches
CTP_RDO.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6// this header file
8
9// STL includes:
10#include <iostream>
11#include <iomanip>
12#include <sstream>
13
14#include "GaudiKernel/MsgStream.h"
17
18
19CTP_RDO::CTP_RDO(unsigned int ctpVersionNumber, const uint32_t nBCs, uint32_t nExtraWords)
20 : m_ctpVersionNumber(ctpVersionNumber),
21 m_ctpDataFormat(ctpVersionNumber),
22 m_numberOfBunches(nBCs),
23 m_numberOfAdditionalWords(nExtraWords)
24{
25
26 // create correct length, zero filled data member
27 m_dataWords.resize(m_ctpDataFormat.getNumberTimeWords()+(nBCs*m_ctpDataFormat.getDAQwordsPerBunch() )+nExtraWords);
28}
29
30CTP_RDO::CTP_RDO(unsigned int ctpVersionNumber, std::vector<uint32_t>&& data, uint32_t nExtraWords)
31 : m_ctpVersionNumber(ctpVersionNumber),
32 m_ctpDataFormat(ctpVersionNumber),
33 m_dataWords(std::move(data))
34{
35
36 m_numberOfAdditionalWords=nExtraWords;
37 if(!m_dataWords.size()) {
38 m_numberOfBunches = 0u;
39 } else {
40 uint32_t dataWords = static_cast<uint32_t>(m_dataWords.size()) - m_ctpDataFormat.getNumberTimeWords() - nExtraWords;
41 m_numberOfBunches = dataWords / m_ctpDataFormat.getDAQwordsPerBunch();
42 }
43}
44
46
47const CTPdataformatVersion &
49 if(m_ctpVersionNumber==0) {
50 MsgStream log(Athena::getMessageSvc(), "CTP_RDO");
51 log << MSG::WARNING << "CTPVersion has not been set, no information about data format available, please fix your code" << endmsg;
52 }
53 return m_ctpDataFormat;
54}
55
56
57void
58CTP_RDO::setCTPVersionNumber( unsigned int ctpVersion ) {
59 m_ctpVersionNumber = ctpVersion;
60}
61
62void CTP_RDO::setTimeSec(const uint32_t sec)
63{
64 if(getCTPVersion().getTimeSecondsPos() < m_dataWords.size()) {
65 m_dataWords[getCTPVersion().getTimeSecondsPos()] = sec;
66 }
67}
68
69void CTP_RDO::setTimeNanoSec(const uint32_t nano)
70{
71 if(getCTPVersion().getTimeNanosecondsPos() < m_dataWords.size()) {
72 m_dataWords[getCTPVersion().getTimeNanosecondsPos()] =
73 (nano/getCTPVersion().getTimeNanosecondsTicks()) << getCTPVersion().getTimeNanosecondsOffset();
74 }
75}
76
77uint32_t CTP_RDO::getTimeSec() const
78{
79 if(m_dataWords.size() <= getCTPVersion().getTimeSecondsPos()) return 0;
80 return m_dataWords.at(getCTPVersion().getTimeSecondsPos() );
81}
82
83uint32_t CTP_RDO::getTimeNanoSec() const
84{
85 if(m_dataWords.size() <= getCTPVersion().getTimeNanosecondsPos()) return 0;
86 return (m_dataWords.at(getCTPVersion().getTimeNanosecondsPos() ) >> getCTPVersion().getTimeNanosecondsOffset() ) * getCTPVersion().getTimeNanosecondsTicks();
87}
88
90{
91 return m_numberOfBunches;
92}
93
95{
96 return m_l1AcceptPosition;
97}
98
100{
101 if(getEXTRAWords().size())
102 return getEXTRAWords().at(0);
103 return -999;
104}
105
107{
108 return m_turnCounter;
109}
110
111
112
117
118void CTP_RDO::selectBunch(const uint32_t iBC)
119{
120 if (iBC < m_numberOfBunches) {
121 m_activeBunch = iBC;
122 } else {
123 m_activeBunch = 0u;
124 }
125}
126
132
133void CTP_RDO::setNumberOfBunches(const uint32_t nBCs)
134{
135 if (nBCs > m_numberOfBunches) {
136 m_numberOfBunches = nBCs;
137 m_dataWords.resize(getCTPVersion().getNumberTimeWords()+(nBCs*getCTPVersion().getDAQwordsPerBunch() )+m_numberOfAdditionalWords);
138 }
139}
140
142{
143 if (pos < m_numberOfBunches) {
144 m_l1AcceptPosition = pos;
145 }
146}
147
148void CTP_RDO::setTurnCounter(const uint32_t tc)
149{
151}
152
153void CTP_RDO::setNumberOfAdditionalWords(const uint32_t nExtraWords)
154{
155 if(nExtraWords > m_numberOfAdditionalWords) {
156 m_dataWords.resize(m_dataWords.size()+nExtraWords-m_numberOfAdditionalWords);//Add the difference
157 }
158 m_numberOfAdditionalWords = nExtraWords;
159}
160
161//void CTP_RDO::setPITWord(const unsigned int i, const uint32_t word)
162//{
163// setWord(i + (m_activeBunch*getCTPVersion().getDAQwordsPerBunch()) + getCTPVersion().getPITpos(), word);
164//}
165
166//void CTP_RDO::setFPIWord(const unsigned int i, const uint32_t word)
167//{
168// setWord(i + (m_activeBunch*getCTPVersion().getDAQwordsPerBunch()) + getCTPVersion().getFPIpos(), word);
169//}
170
171void CTP_RDO::setTIPWord(const unsigned int i, const uint32_t word)
172{
173 setWord(i + (m_activeBunch*getCTPVersion().getDAQwordsPerBunch()) + getCTPVersion().getTIPpos(), word);
174}
175
176void CTP_RDO::setTBPWord(const unsigned int i, const uint32_t word)
177{
178 setWord(i + (m_activeBunch*getCTPVersion().getDAQwordsPerBunch() ) + getCTPVersion().getTBPpos(), word);
179}
180
181void CTP_RDO::setTAPWord(const unsigned int i, const uint32_t word)
182{
183 setWord(i + (m_activeBunch*getCTPVersion().getDAQwordsPerBunch() ) + getCTPVersion().getTAPpos(), word);
184}
185
186void CTP_RDO::setTAVWord(const unsigned int i, const uint32_t word)
187{
188 setWord(i + (m_activeBunch*getCTPVersion().getDAQwordsPerBunch()) + getCTPVersion().getTAVpos(), word);
189}
190
191//std::vector<uint32_t> CTP_RDO::getPITWords() const
192//{
193// return getWords(PIT);
194//}
195//
196//std::vector<uint32_t> CTP_RDO::getFPIWords() const
197//{
198// return getWords(FPI);
199//}
200
201std::vector<uint32_t> CTP_RDO::getTIPWords() const
202{
203 return getWords(TIP);
204}
205
206std::vector<uint32_t> CTP_RDO::getTBPWords() const
207{
208 return getWords(TBP);
209}
210
211std::vector<uint32_t> CTP_RDO::getTAPWords() const
212{
213 return getWords(TAP);
214}
215
216std::vector<uint32_t> CTP_RDO::getTAVWords() const
217{
218 return getWords(TAV);
219}
220
221std::vector<uint32_t> CTP_RDO::getEXTRAWords() const
222{
223 return getWords(EXTRA);
224}
225
226void CTP_RDO::setWord(const unsigned int i, const uint32_t word)
227{
228 if (i < m_dataWords.size()) {
229 m_dataWords[i] = word;
230 } else {
231 MsgStream log(Athena::getMessageSvc(), "CTP_RDO");
232 log << MSG::WARNING << "ignoring word " << word << " for position " << i << endmsg;
233 }
234
235 return;
236}
237
238std::vector<uint32_t> CTP_RDO::getWords(WordType type) const
239{
240 unsigned int nWords = 0;
241 unsigned int offset = 0;
242 std::vector<uint32_t> vec;
243 vec.clear();
244
245 switch (type) {
246 //case PIT:
247// nWords = getCTPVersion().getPITwords();
248// offset = getCTPVersion().getPITpos();
249// break;
250// case FPI:
251// nWords = getCTPVersion().getFPIwords();
252// offset = getCTPVersion().getFPIpos();
253// break;
254 case TIP:
255 nWords = getCTPVersion().getTIPwords();
256 offset = getCTPVersion().getTIPpos();
257 break;
258 case TBP:
259 nWords = getCTPVersion().getTBPwords();
260 offset = getCTPVersion().getTBPpos();
261 break;
262 case TAP:
263 nWords = getCTPVersion().getTAPwords();
264 offset = getCTPVersion().getTAPpos();
265 break;
266 case TAV:
267 nWords = getCTPVersion().getTAVwords();
268 offset = getCTPVersion().getTAVpos();
269 break;
270 case EXTRA:
271 vec.assign(m_dataWords.begin() + (m_dataWords.size()-m_numberOfAdditionalWords), m_dataWords.end());
272 return vec;
273 break;
274
275 default:
276 // error
277 break;
278 }
279
280 for(unsigned int bunch = 0 ; bunch < m_numberOfBunches ; ++bunch) {
281 for(unsigned int tbp = 0; tbp < nWords; ++tbp) {
282 // take offset of TBPwords into account
283 unsigned int index = offset + tbp;
284 // go to the correct bunch
285 index += (bunch * getCTPVersion().getDAQwordsPerBunch());
286 if( index < m_dataWords.size() ) vec.push_back(m_dataWords[index]);
287 }
288 }
289 // this is now a list of consecutive data words for all bunches
290 return vec;
291}
292
293const std::string CTP_RDO::dump() const
294{
295 std::ostringstream s;
296
298
299 return s.str();
300}
301
302const std::string CTP_RDO::print(const bool longFormat) const
303{
304 std::ostringstream s;
305
306 // lvl1 accept position
307 s << "\n L1APos:" << std::setw(3) << getL1AcceptBunchPosition();
308 if (longFormat) s << std::endl;
309 s << "\n Turn counter:" << std::setw(3) << getTurnCounter();
310 if (longFormat) s << std::endl;
311
312 // time is only stored once for the whole fragment
313 for (size_t i(0); (i < getCTPVersion().getNumberTimeWords() ) && (i < m_dataWords.size()); ++i) {
314 if (i == 0 || longFormat) s << "\n Time";
315 if (longFormat) s << std::setw(1) << i;
316 s << " " << std::setw(8) << m_dataWords[i];
317 if (longFormat) s << std::endl;
318 }
319
320 // return if data content is too short
321 if (m_dataWords.size() < 2) return s.str();
322
323
324 // loop over the rest of the data fragment
325 for (unsigned int k(0); k < (m_dataWords.size()-2)/getCTPVersion().getDAQwordsPerBunch(); ++k) {
326
327 // print single fragment
328
329 // TIP
330 for (size_t i(0), p(k*getCTPVersion().getDAQwordsPerBunch() + getCTPVersion().getTIPpos());
331 (i < getCTPVersion().getTIPwords()) && (p < m_dataWords.size());
332 ++i, ++p) {
333 if (i == 0 || longFormat) s << "\n TIP";
334 if (longFormat) s << std::setw(1) << i;
336 if (longFormat) s << std::endl;
337 }
338
339
340 // TBP
341 for (size_t i(0), p(k*getCTPVersion().getDAQwordsPerBunch() + getCTPVersion().getTBPpos());
342 (i < getCTPVersion().getTBPwords()) && (p < m_dataWords.size());
343 ++i, ++p) {
344 if (i == 0 || longFormat) s << "\n TBP";
345 if (longFormat) s << std::setw(1) << i;
347 if (longFormat) s << std::endl;
348 }
349
350 // TAP
351 for (size_t i(0), p(k*getCTPVersion().getDAQwordsPerBunch() + getCTPVersion().getTAPpos());
352 (i < getCTPVersion().getTAPwords()) && (p < m_dataWords.size());
353 ++i, ++p) {
354 if (i == 0 || longFormat) s << "\n TAP";
355 if (longFormat) s << std::setw(1) << i;
357 if (longFormat) s << std::endl;
358 }
359
360 // TAV
361 for (size_t i(0), p(k*getCTPVersion().getDAQwordsPerBunch() + getCTPVersion().getTAVpos() );
362 (i < getCTPVersion().getTAVwords()) && (p < m_dataWords.size());
363 ++i, ++p) {
364 if (i == 0 || longFormat) s << "\n TAV";
365 if (longFormat) s << std::setw(1) << i;
367 if (longFormat) s << std::endl;
368 }
369
370 }
371
372 //EXTRA WORDS
373 for (size_t i(m_dataWords.size()-m_numberOfAdditionalWords); i < m_dataWords.size(); ++i) {
374 if (i == m_dataWords.size()-m_numberOfAdditionalWords || longFormat ) s << "\n EXTRA";
375 if (longFormat) s << std::setw(1) << i;
377 if (longFormat) s << std::endl;
378 }
379
380 return s.str();
381}
#define endmsg
std::vector< size_t > vec
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static Double_t tc
@ EXTRA
Definition CTP_RDO.h:22
@ TAP
Definition CTP_RDO.h:22
@ TAV
Definition CTP_RDO.h:22
@ TBP
Definition CTP_RDO.h:22
@ TIP
Definition CTP_RDO.h:22
void setNumberOfBunches(const uint32_t nBCs)
Definition CTP_RDO.cxx:133
void selectBunch(const uint32_t iBC)
Definition CTP_RDO.cxx:118
std::vector< uint32_t > getTBPWords() const
Definition CTP_RDO.cxx:206
void setCTPVersionNumber(unsigned int ctpVersion)
Definition CTP_RDO.cxx:58
const std::string print(const bool longFormat=false) const
print object content in a human readable format to string
Definition CTP_RDO.cxx:302
const std::vector< uint32_t > & getDataWords() const
Definition CTP_RDO.h:39
uint32_t m_turnCounter
turn counter
Definition CTP_RDO.h:100
void setTimeNanoSec(const uint32_t nano)
Definition CTP_RDO.cxx:69
void selectNextBunch()
Definition CTP_RDO.cxx:127
uint32_t getTimeSec() const
Definition CTP_RDO.cxx:77
uint32_t m_numberOfAdditionalWords
number of configurable extra words in the fragment
Definition CTP_RDO.h:103
std::vector< uint32_t > getWords(WordType type) const
Definition CTP_RDO.cxx:238
void setTIPWord(const unsigned int i, const uint32_t word)
Definition CTP_RDO.cxx:171
std::vector< uint32_t > getTAPWords() const
Definition CTP_RDO.cxx:211
uint32_t getTimeNanoSec() const
Definition CTP_RDO.cxx:83
void setTimeSec(const uint32_t sec)
Definition CTP_RDO.cxx:62
void setNumberOfAdditionalWords(const uint32_t nExtraWords)
Definition CTP_RDO.cxx:153
uint8_t m_l1AcceptPosition
bunch position, from which the level1 accept was calculated
Definition CTP_RDO.h:99
uint32_t getTimeSinceLastL1A() const
Definition CTP_RDO.cxx:99
uint32_t m_numberOfBunches
number of bunches in raw data (transient)
Definition CTP_RDO.h:101
std::vector< uint32_t > getEXTRAWords() const
Definition CTP_RDO.cxx:221
void setTAVWord(const unsigned int i, const uint32_t word)
Definition CTP_RDO.cxx:186
void setTBPWord(const unsigned int i, const uint32_t word)
Definition CTP_RDO.cxx:176
unsigned int m_ctpVersionNumber
number of the CTP version to be used
Definition CTP_RDO.h:96
void setTAPWord(const unsigned int i, const uint32_t word)
Definition CTP_RDO.cxx:181
uint32_t m_activeBunch
active bunch, for book keepting (transient)
Definition CTP_RDO.h:102
uint32_t getTurnCounter() const
Definition CTP_RDO.cxx:106
uint32_t getNumberOfBunches() const
Definition CTP_RDO.cxx:89
void setL1AcceptBunchPosition(const uint8_t)
Definition CTP_RDO.cxx:141
const CTPdataformatVersion & getCTPVersion() const
Definition CTP_RDO.cxx:48
CTPdataformatVersion m_ctpDataFormat
CTP data format for a specified version.
Definition CTP_RDO.h:97
std::vector< uint32_t > getTIPWords() const
Definition CTP_RDO.cxx:201
std::vector< uint32_t > m_dataWords
raw data words
Definition CTP_RDO.h:98
void setWord(const unsigned int i, const uint32_t word)
Definition CTP_RDO.cxx:226
CTP_RDO()=default
Default constructor needed for pool converters.
~CTP_RDO()
empty default destructor
Definition CTP_RDO.cxx:45
uint32_t getL1AcceptBunchPosition() const
Definition CTP_RDO.cxx:94
const std::string dump() const
dump raw object content to string
Definition CTP_RDO.cxx:293
uint32_t getNumberOfAdditionalWords() const
Definition CTP_RDO.cxx:113
std::vector< uint32_t > getTAVWords() const
Definition CTP_RDO.cxx:216
void setTurnCounter(const uint32_t)
Definition CTP_RDO.cxx:148
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
const std::string convertToHex(const uint32_t word)
helper function to dump a number in hex format
Definition index.py:1
STL namespace.