ATLAS Offline Software
CTPResultUtils.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Includes
7 
8 // Local include
10 
11 // TDAQ include
12 #include "CTPfragment/CTPdataformatVersion.h"
13 
14 // Gaudi include(s):
15 #include "GaudiKernel/Bootstrap.h"
16 #include "GaudiKernel/ISvcLocator.h"
17 #include "GaudiKernel/IMessageSvc.h"
18 #include "GaudiKernel/MsgStream.h"
19 
20 namespace CTPResultUtils {
21 
22  // Initialise the object given the CTP version number, data words and the number of extra words
23  void initialize(xAOD::CTPResult& ctpRes, const uint32_t ctpVersionNumber, std::vector<uint32_t>& data, const uint32_t nExtraWords) {
24 
25  // CTP version number
26  CTPdataformatVersion ctpDataFormat(ctpVersionNumber);
27  ctpRes.setCtpVersionNumber(ctpVersionNumber);
28 
29  // Header words
30  ctpRes.setHeaderSize(8);
31  ctpRes.setL1ID(0);
32  ctpRes.setEventType(0);
33 
34  // Trailer words
35  ctpRes.setErrorStatus(0);
36  ctpRes.setInfoStatus(0);
37  ctpRes.setNumStatusWords(2);
38  ctpRes.setStatusPosition(1);
39 
40  // Number of bunches
41  if (!data.size()) {
42  ctpRes.setNumberOfBunches(0u);
43  } else {
44  uint32_t numberOfWords = static_cast<uint32_t>(data.size()) - ctpDataFormat.getNumberTimeWords() - nExtraWords;
45  ctpRes.setNumberOfBunches(numberOfWords / ctpDataFormat.getDAQwordsPerBunch());
46  }
47 
48  // Create vectors of vectors for the trigger words for all bunches
49  std::vector<std::vector<uint32_t>> tip(ctpRes.numberOfBunches());
50  std::vector<std::vector<uint32_t>> tbp(ctpRes.numberOfBunches());
51  std::vector<std::vector<uint32_t>> tap(ctpRes.numberOfBunches());
52  std::vector<std::vector<uint32_t>> tav(ctpRes.numberOfBunches());
53 
54  // Fill vectors
55  for( uint32_t bunch=0u; bunch != ctpRes.numberOfBunches(); ++bunch){
56 
57  // TIP words
58  for(unsigned int tipIdx = 0; tipIdx < ctpDataFormat.getTIPwords(); ++tipIdx) {
59  unsigned int index = ctpDataFormat.getTIPpos() + tipIdx + (bunch * ctpDataFormat.getDAQwordsPerBunch());
60  if( index < data.size() ) {
61  tip[bunch].push_back(data[index]);
62  }
63  }
64 
65  // TBP words
66  for(unsigned int tbpIdx = 0; tbpIdx < ctpDataFormat.getTBPwords(); ++tbpIdx) {
67  unsigned int index = ctpDataFormat.getTBPpos() + tbpIdx + (bunch * ctpDataFormat.getDAQwordsPerBunch());
68  if( index < data.size() ) {
69  tbp[bunch].push_back(data[index]);
70  }
71  }
72 
73  // TAP words
74  for(unsigned int tapIdx = 0; tapIdx < ctpDataFormat.getTAPwords(); ++tapIdx) {
75  unsigned int index = ctpDataFormat.getTAPpos() + tapIdx + (bunch * ctpDataFormat.getDAQwordsPerBunch());
76  if( index < data.size() ) {
77  tap[bunch].push_back(data[index]);
78  }
79  }
80 
81  // TAV words
82  for(unsigned int tavIdx = 0; tavIdx < ctpDataFormat.getTAVwords(); ++tavIdx) {
83  unsigned int index = ctpDataFormat.getTAVpos() + tavIdx + (bunch * ctpDataFormat.getDAQwordsPerBunch());
84  if( index < data.size() ) {
85  tav[bunch].push_back(data[index]);
86  }
87  }
88  }
89  ctpRes.setTIPWords(tip);
90  ctpRes.setTBPWords(tbp);
91  ctpRes.setTAPWords(tap);
92  ctpRes.setTAVWords(tav);
93 
94  // Additional words
95  std::vector<uint32_t> vec;
96  vec.assign(data.begin() + (data.size()-nExtraWords), data.end());
97  ctpRes.setAdditionalWords(vec);
98  }
99 
100  // Print object content to default message stream
101  void dumpData(xAOD::CTPResult& ctpRes) {
102  SmartIF<IMessageSvc> msgSvc{Gaudi::svcLocator()->service("MessageSvc")};
103  if ( !msgSvc ) {
104  return;
105  }
106  MsgStream log(msgSvc, "xAOD::CTPResult");
107  dumpData(ctpRes, log);
108  }
109 
110  // Print object content to given message stream
111  void dumpData(xAOD::CTPResult& ctpRes, MsgStream& log) {
112 
113  log << MSG::DEBUG << "*BEGIN* xAOD::CTPResult" << endmsg;
114 
115  // Check number of bunches
116  if(ctpRes.numberOfBunches() == 0) {
117  log << MSG::DEBUG << "xAOD::CTPResult empty" << endmsg;
118  log << MSG::DEBUG << "*END* xAOD::CTPResult" << endmsg;
119  return;
120  }
121 
122  // Check number of bunches size
123  if(ctpRes.numberOfBunches() != ctpRes.tipWords().size()) {
124  log << MSG::ERROR <<"Mismatch: " << ctpRes.numberOfBunches() << " bunches, but the size of tipWords is " << ctpRes.tipWords().size() << endmsg;
125  }
126 
127  log << MSG::DEBUG << "CTP version number: " << ctpRes.ctpVersionNumber() << endmsg;
128  log << MSG::DEBUG << "Number of bunches: " << ctpRes.numberOfBunches() << endmsg;
129  log << MSG::DEBUG << "L1A position: " << ctpRes.l1AcceptBunchPosition() << endmsg;
130 
131  // Print header info
132  log << MSG::DEBUG << "Header marker : " << MSG::hex << ctpRes.headerMarker() << MSG::dec << endmsg;
133  log << MSG::DEBUG << "Header size : " << ctpRes.headerSize() << endmsg;
134  log << MSG::DEBUG << "Header format version : " << ctpRes.headerFormatVersion() << endmsg;
135  log << MSG::DEBUG << "Source ID : 0x" << MSG::hex << ctpRes.sourceID() << MSG::dec << endmsg;
136  log << MSG::DEBUG << "Run number : " << ctpRes.runNumber() << endmsg;
137  log << MSG::DEBUG << "Ext. LVL1 ID : " << ctpRes.L1ID() << endmsg;
138  log << MSG::DEBUG << "BCID : " << ctpRes.BCID() << endmsg;
139  log << MSG::DEBUG << "Trigger type : " << ctpRes.triggerType() << endmsg;
140  log << MSG::DEBUG << "Det. event type : " << ctpRes.eventType() << endmsg;
141 
142  // Print payload info
143  log << MSG::DEBUG << "Time " << ctpRes.timeSec() << "s "
144  << std::setw(10) << std::setiosflags(std::ios_base::right) << std::setfill(' ')
145  << ctpRes.timeNanoSec() << std::resetiosflags(std::ios_base::right)
146  << "ns" << endmsg;
147 
148  // Print per-bunch information
149  for(unsigned int i = 0; i<ctpRes.numberOfBunches(); ++i) {
150 
151  auto bunch = ctpRes.getBC(i);
152  log << MSG::DEBUG << "BC dump for bunch " << i << endmsg;
153 
154  // TIP words
155  for(unsigned int j = 0; j<ctpRes.tipWords()[i].size(); ++j) {
156  log << MSG::DEBUG << "TIP word number " << j << ": " << ctpRes.tipWords()[i][j] << endmsg;
157  }
158  if (ctpRes.tipWords()[i].size() == 0) {
159  log << MSG::DEBUG << "No TIP words!" << endmsg;
160  }
161 
162  // TBP words
163  for(unsigned int j = 0; j<ctpRes.tbpWords()[i].size(); ++j) {
164  log << MSG::DEBUG << "TBP word number " << j << ": " << ctpRes.tbpWords()[i][j] << endmsg;
165  }
166  if (ctpRes.tbpWords()[i].size() == 0) {
167  log << MSG::DEBUG << "No TBP words!" << endmsg;
168  }
169 
170  // TAP words
171  for(unsigned int j = 0; j<ctpRes.tapWords()[i].size(); ++j) {
172  log << MSG::DEBUG << "TAP word number " << j << ": " << ctpRes.tapWords()[i][j] << endmsg;
173  }
174  if (ctpRes.tapWords()[i].size() == 0) {
175  log << MSG::DEBUG << "No TAP words!" << endmsg;
176  }
177 
178  // TAV words
179  for(unsigned int j = 0; j<ctpRes.tavWords()[i].size(); ++j) {
180  log << MSG::DEBUG << "TAV word number " << j << ": " << ctpRes.tavWords()[i][j] << endmsg;
181  }
182  if (ctpRes.tavWords()[i].size() == 0) {
183  log << MSG::DEBUG << "No TAV words!" << endmsg;
184  }
185  }
186 
187  // Additional words
188  for(unsigned int i = 0; i<ctpRes.additionalWords().size(); ++i) {
189  log << MSG::DEBUG << "Additional word number " << i << ": " << ctpRes.additionalWords()[i] << endmsg;
190  }
191  if (ctpRes.additionalWords().size() == 0) {
192  log << MSG::DEBUG << "No additional words!" << endmsg;
193  }
194 
195  // Print trailer info
196  log << MSG::DEBUG << "Error status : " << ctpRes.errorStatus() << endmsg;
197  log << MSG::DEBUG << "Status info : " << ctpRes.infoStatus() << endmsg;
198  log << MSG::DEBUG << "Number of status words : " << ctpRes.numStatusWords() << endmsg;
199  log << MSG::DEBUG << "Number of data words : " << ctpRes.numDataWords() << endmsg;
200  log << MSG::DEBUG << "Status information position : " << ctpRes.statusPosition() << endmsg;
201  log << MSG::DEBUG << "*END* xAOD::CTPResult" << endmsg;
202  }
203 
204 
205 } // namespace CTPResultUtils
xAOD::CTPResult_v1::setHeaderSize
void setHeaderSize(const uint32_t word)
Set the number of words in the header.
xAOD::CTPResult_v1::setInfoStatus
void setInfoStatus(const uint32_t word)
Set the info status word.
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
xAOD::CTPResult_v1::setL1ID
void setL1ID(const uint32_t word)
Set the extended LVL1 ID.
xAOD::CTPResult_v1::errorStatus
uint32_t errorStatus() const
Retrieve the error status word.
xAOD::CTPResult_v1::sourceID
uint32_t sourceID() const
Retrieve the sub-detector source ID.
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
xAOD::CTPResult_v1::L1ID
uint32_t L1ID() const
Retrieve the extended LVL1 ID.
index
Definition: index.py:1
xAOD::CTPResult_v1::statusPosition
uint32_t statusPosition() const
Retrieve the position of status information in the ROD.
CTPResultUtils.h
xAOD::CTPResult_v1::setAdditionalWords
void setAdditionalWords(const std::vector< uint32_t > &words)
Set the additional data words.
xAOD::CTPResult_v1::ctpVersionNumber
uint32_t ctpVersionNumber() const
Get the CTP version number.
xAOD::CTPResult_v1::eventType
uint32_t eventType() const
Retrieve the LVL1 event type.
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:9
xAOD::CTPResult_v1::setNumStatusWords
void setNumStatusWords(const uint32_t word)
Set the number of status words in the trailer.
xAOD::tap
setBGCode tap
Definition: TrigDecision_v1.cxx:43
xAOD::CTPResult_v1
This is the trigger result for each item before prescale, after prescale and after veto....
Definition: CTPResult_v1.h:23
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
xAOD::CTPResult_v1::headerFormatVersion
uint32_t headerFormatVersion() const
Retrieve the format version of the header.
xAOD::CTPResult_v1::setTIPWords
void setTIPWords(const std::vector< std::vector< uint32_t > > &words)
Set the TIP words for all bunch crossings.
CTPResultUtils::dumpData
void dumpData(xAOD::CTPResult &ctpRes)
Print object content to default message stream.
Definition: CTPResultUtils.cxx:101
xAOD::CTPResult_v1::setTAPWords
void setTAPWords(const std::vector< std::vector< uint32_t > > &words)
Set the TAP words for all bunch crossings.
xAOD::CTPResult_v1::setTBPWords
void setTBPWords(const std::vector< std::vector< uint32_t > > &words)
Set the TBP words for all bunch crossings.
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
xAOD::CTPResult_v1::setEventType
void setEventType(const uint32_t word)
Set the LVL1 event type.
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
xAOD::CTPResult_v1::BCID
uint32_t BCID() const
Retrieve the bunch crossing ID.
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
xAOD::CTPResult_v1::l1AcceptBunchPosition
uint32_t l1AcceptBunchPosition() const
Get the L1 accept bunch position.
xAOD::CTPResult_v1::tapWords
const std::vector< std::vector< uint32_t > > & tapWords() const
Get the TAP words for all bunch crossings.
xAOD::CTPResult_v1::numStatusWords
uint32_t numStatusWords() const
Retrieve the number of status words in the trailer.
xAOD::CTPResult_v1::numDataWords
uint32_t numDataWords() const
Retrieve the number of data words.
xAOD::CTPResult_v1::setStatusPosition
void setStatusPosition(const uint32_t word)
Set the position of status information in the ROD.
xAOD::CTPResult_v1::runNumber
uint32_t runNumber() const
Retrieve the run number.
xAOD::CTPResult_v1::tipWords
const std::vector< std::vector< uint32_t > > & tipWords() const
Get the TIP words for all bunch crossings.
xAOD::CTPResult_v1::tavWords
const std::vector< std::vector< uint32_t > > & tavWords() const
Get the TAV words for all bunch crossings.
CTPResultUtils::initialize
void initialize(xAOD::CTPResult &ctpRes, const uint32_t ctpVersionNumber, std::vector< uint32_t > &data, const uint32_t nExtraWords)
Initialize the object using xAOD::Header, xAOD::Trailer, and the payload data.
Definition: CTPResultUtils.cxx:23
xAOD::CTPResult_v1::tbpWords
const std::vector< std::vector< uint32_t > > & tbpWords() const
Get the TBP words for all bunch crossings.
xAOD::CTPResult_v1::headerSize
uint32_t headerSize() const
Retrieve the number of words in the header.
xAOD::CTPResult_v1::setErrorStatus
void setErrorStatus(const uint32_t word)
Set the error status word.
xAOD::CTPResult_v1::numberOfBunches
uint32_t numberOfBunches() const
Get the number of bunch crossings.
xAOD::CTPResult_v1::setTAVWords
void setTAVWords(const std::vector< std::vector< uint32_t > > &words)
Set the TAV words for all bunch crossings.
xAOD::CTPResult_v1::triggerType
uint32_t triggerType() const
Retrieve the LVL1 trigger type.
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
xAOD::CTPResult_v1::headerMarker
uint32_t headerMarker() const
Retrieve the header marker word.
xAOD::CTPResult_v1::infoStatus
uint32_t infoStatus() const
Retrieve the info status word.
xAOD::CTPResult_v1::getBC
const CTPResult_v1::CTPBunchCrossing getBC(const int bunch=-1) const
Get the CTPBunchCrossing object for a specific bunch in the readout window.
Definition: CTPResult_v1.cxx:94
xAOD::CTPResult_v1::additionalWords
const std::vector< uint32_t > & additionalWords() const
Get the additional data words.
CTPResultUtils
Utility functions for xAOD::CTPResult objects that rely on tdaq-common.
Definition: CTPResultUtils.cxx:20
xAOD::CTPResult_v1::timeNanoSec
uint32_t timeNanoSec() const
Get the time in nanoseconds.
xAOD::CTPResult_v1::setCtpVersionNumber
void setCtpVersionNumber(const uint32_t ctpNumber)
Set the CTP version number.
xAOD::CTPResult_v1::timeSec
uint32_t timeSec() const
Get the time in seconds.
AuxElement.h
Base class for elements of a container that can have aux data.
xAOD::CTPResult_v1::setNumberOfBunches
void setNumberOfBunches(const uint32_t nBCs)
Set the number of bunch crossings.
Definition: CTPResult_v1.cxx:110