ATLAS Offline Software
Trigger/TrigT1/L1Topo/L1TopoRDO/src/Helpers.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <vector>
6 #include <bitset>
7 #include <algorithm>
8 #include <sstream>
9 #include <iostream>
10 #include <iomanip>
11 #include <cmath>
12 #include <cstdint>
13 #include <boost/io/ios_state.hpp>
14 #include "L1TopoRDO/L1TopoRDO.h"
16 #include "L1TopoRDO/Helpers.h"
17 #include "L1TopoRDO/Header.h"
18 #include "L1TopoRDO/Fibre.h"
19 #include "L1TopoRDO/Status.h"
20 #include "L1TopoRDO/L1TopoTOB.h"
21 #include "L1TopoRDO/BlockTypes.h"
22 
23 // Print function
24 std::ostream& operator<<(std::ostream& os, const L1TopoRDO& rdo) {
25  // save ostream state; destructor will restore state when it goes out of scope
26  boost::io::ios_all_saver ias(os);
27  os << "L1TopoRDO:\n";
28  os << " SourceID: " << L1Topo::formatHex8(rdo.getSourceID());
29  if (rdo.isDAQModule()){
30  os << " DAQ";
31  }
32  else if (rdo.isROIModule()){
33  os << " ROI";
34  }
35  os << "\n";
36  os << " Errors: " << rdo.getErrors() << "\n";
37  os << " Status words:\n";
38  std::vector<uint32_t> status = rdo.getStatusWords();
39  for(auto & word: status){
40  os << " " << L1Topo::formatHex8(word) << "\n";
41  }
42  os << " Data words:\n";
43  std::vector<uint32_t> data = rdo.getDataWords();
44  for(const uint32_t word: data){
45  os << " " << L1Topo::formatHex8(word) << " ";
46  switch (L1Topo::blockType(word)){
48  {
49  os << L1Topo::Header(word) << "\n";
50  break;
51  }
53  {
54  os << L1Topo::Fibre(word) << "\n";
55  break;
56  }
58  {
59  os << L1Topo::Status(word) << "\n";
60  break;
61  }
63  {
64  os << " EM TOB\n";
65  break;
66  }
68  {
69  os << " TAU TOB\n";
70  break;
71  }
73  {
74  os << " MUON TOB\n";
75  break;
76  }
78  {
79  os << " JET TOB crate 1\n";
80  break;
81  }
83  {
84  os << " JET TOB crate 2\n";
85  break;
86  }
88  {
89  os << " Energy TOB\n";
90  break;
91  }
93  {
94  os << L1Topo::L1TopoTOB(word);
95  break;
96  }
97  default:
98  os << "\n";
99  break;
100  }
101  }
102  return os;
103 }
104 
105 namespace L1Topo{
106 
107  uint32_t decode(const uint32_t &word, const uint32_t &offset, const uint32_t &size) {
108  return static_cast<uint32_t>((word >> offset) & size);
109  }
110 
111  std::string formatHex8(uint32_t word){
112  std::ostringstream s;
113  s << std::showbase << std::hex << std::internal << std::setfill ('0') << std::setw(10) << word << std::dec << std::noshowbase;
114  return s.str();
115  }
116 
117  std::string formatHex4(uint32_t word){
118  std::ostringstream s;
119  s << std::showbase << std::hex << std::internal << std::setfill ('0') << std::setw( 6 ) << word << std::dec << std::noshowbase;
120  return s.str();
121  }
122 
123 
124 const std::string formatVecHex8(const std::vector<uint32_t>& vec)
125 {
126  std::ostringstream s;
127  s<<"[ ";
128  for (auto elem: vec){
129  s<<std::hex<<std::showbase<<std::setfill('0')<<std::setw(10)
130  <<elem<<" "<<std::dec<<std::noshowbase;
131  }
132  s<<"]";
133  return s.str();
134 }
135 
136  // this is out of date and should not be used
137  unsigned int triggerBitIndex(uint32_t moduleId, const L1Topo::L1TopoTOB& c){
138  uint32_t module = (moduleId >>4) & 0x1;
139  uint32_t index = 64*module + 32*c.fpga() + 16*c.clock() + 8*c.index();
140  return index;
141  }
142 
143  // this reflects the actual CTP mapping and the CTP simulation with which L1Topo output is compared
144  unsigned int triggerBitIndexNew(uint32_t moduleId, const L1Topo::L1TopoTOB& c, unsigned int bitIdx){
145  uint32_t module = (moduleId >>4) & 0x1;
146  uint32_t index = 64*module + 32*c.fpga() + c.clock() + 2*(8*c.index() + bitIdx);
147  //std::cout << "L1Topo::triggerBitIndexNew DEBUG index=" << index << " for module=" << module << " fpga=" << c.fpga() << " clock=" << c.clock() << " index=" << c.index() << " bitIdx=" << bitIdx << std::endl;
148  return index;
149  }
150 
151  // this reflects the actual CTP mapping and the CTP simulation with which L1Topo output is compared
152  unsigned int triggerBitIndexPhase1(uint32_t topo, uint32_t fpga, size_t bitIdx){
153  uint32_t index = (topo==3 ? (fpga+2)*32:fpga*32);
154  index += bitIdx<16 ? 2*(bitIdx) : 2*(bitIdx-16)+1;
155  return index;
156  }
157 
158  // convenience wrapper for use with L1TopoResult - can't be included here as is creates dependency loop with TrigT1Result
159  /*
160  std::pair< std::bitset<128>,std::bitset<128> > getDecisionAndOverflowBits(const std::vector<L1TopoResult>& res){
161  L1TopoRDOCollection col;
162  for (auto & r : res){
163  col.push_back(new L1TopoRDO(r.rdo()));
164  }
165  return getDecisionAndOverflowBits(col);
166  }
167  */
168 
169  std::pair< std::bitset<128>,std::bitset<128> > getDecisionAndOverflowBits(const L1TopoRDOCollection& col){
170 
171  // There is no uint128_t so a bit-wise approach is needed.
172  std::bitset<128> decision;
173  std::bitset<128> overflow;
174 
175  //std::cout << "L1Topo::getDecisionAndOverflowBits: number of RDOs " << col.size() << std::endl;
176 
177  for (L1TopoRDOCollection::const_iterator pRDO = col.begin(); pRDO != col.end(); ++pRDO){
178  const std::vector<uint32_t> data = (*pRDO)->getDataWords();
179  //std::cout << "L1Topo::getDecisionAndOverflowBits: number of data words " << data.size() << std::endl;
180  for(const uint32_t word: data){
182  L1Topo::L1TopoTOB c(word);
183  const uint32_t triggerByte = c.trigger_bits();
184  const uint32_t overflowByte = c.overflow_bits();
185  // Take one bit at a time and set it in the bitset
186  //std::cout << "L1Topo::getDecisionAndOverflowBits: " << c;
187  for (unsigned int i=0; i<8; ++i){
188  const unsigned int index = L1Topo::triggerBitIndexNew((*pRDO)->getSourceID(),c,i);
189  decision[index]=( triggerByte >>i)&1;
190  overflow[index]=(overflowByte >>i)&1;
191  }
192  //std::cout << " index " << index << " updated decision " << decision << std::endl;
193  //std::cout << " index " << index << " updated overflow " << overflow << std::endl;
194  }
195  else{
196  //std::cout << "L1Topo::getDecisionAndOverflowBits: skipping block as not L1Topo_TOB " << L1Topo::formatHex8(word) << std::endl;
197  }
198  }
199  }
200  return std::pair< std::bitset<128>,std::bitset<128> >(decision,overflow);
201  }
202 
203 } // namespace L1Topo
L1TopoRDO
The class that represents the raw data received from an L1Topo board.
Definition: L1TopoRDO.h:29
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
L1Topo::triggerBitIndexNew
unsigned int triggerBitIndexNew(uint32_t moduleId, const L1Topo::L1TopoTOB &, unsigned int bitIdx)
Helper to calculate the index needed to pack trigger bits into the full 128-bit decision....
Definition: Trigger/TrigT1/L1Topo/L1TopoRDO/src/Helpers.cxx:144
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
L1TopoRDO::getDataWords
const std::vector< uint32_t > & getDataWords() const
get the data words
Definition: L1TopoRDO.cxx:15
L1TopoRDO.h
L1Topo::L1TopoTOB
Represents the L1Topo TOB word of the L1Topo ROI data, with decode and encoder.
Definition: L1TopoTOB.h:17
L1Topo::getDecisionAndOverflowBits
std::pair< std::bitset< 128 >, std::bitset< 128 > > getDecisionAndOverflowBits(const L1TopoRDOCollection &)
Get the trigger decision and overflow bits from the L1Topo ROI data block 'L1Topo TOB' and order them...
Definition: Trigger/TrigT1/L1Topo/L1TopoRDO/src/Helpers.cxx:169
Fibre.h
operator<<
std::ostream & operator<<(std::ostream &os, const L1TopoRDO &rdo)
This file contains some static helper functions to help users of L1TopoRDO.
Definition: Trigger/TrigT1/L1Topo/L1TopoRDO/src/Helpers.cxx:24
L1TopoRDO::isDAQModule
bool isDAQModule() const
check the module type, derived from the source ID and the L1Topo module
Definition: L1TopoRDO.cxx:67
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
L1Topo::formatVecHex8
const std::string formatVecHex8(const std::vector< uint32_t > &vec)
Helper function to format a vector of 32-bit integers as 8-digit hex numbers for printing.
Definition: Trigger/TrigT1/L1Topo/L1TopoRDO/src/Helpers.cxx:124
index
Definition: index.py:1
L1Topo::Status
Represents the L1Topo status word of the L1Topo DAQ header, with decoder and encoder.
Definition: Status.h:19
BlockTypes.h
L1Topo::blockType
L1Topo::BlockTypes blockType(const uint32_t word, uint32_t offset=28, uint32_t size=0x0f)
Function to return the block type of a data word from L1Topo
Definition: BlockTypes.cxx:9
L1Topo::BlockTypes::JET2_TOB
@ JET2_TOB
L1Topo::BlockTypes::JET1_TOB
@ JET1_TOB
L1Topo::BlockTypes::MUON_TOB
@ MUON_TOB
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
L1Topo::BlockTypes::FIBRE
@ FIBRE
L1Topo::BlockTypes::ENERGY_TOB
@ ENERGY_TOB
L1Topo::BlockTypes::STATUS
@ STATUS
L1Topo::Header
Represents the L1Topo header word of the L1Topo DAQ data, with decoder and encoder.
Definition: L1Topo/L1TopoRDO/L1TopoRDO/Header.h:18
Header.h
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
python.PyAthena.module
module
Definition: PyAthena.py:134
L1Topo::BlockTypes::EM_TOB
@ EM_TOB
L1TopoRDO::getSourceID
uint32_t getSourceID() const
get the source identifier, i.e. the word representing the subdet type and
Definition: L1TopoRDO.cxx:57
L1Topo::BlockTypes::TAU_TOB
@ TAU_TOB
lumiFormat.i
int i
Definition: lumiFormat.py:92
L1Topo::BlockTypes::L1TOPO_TOB
@ L1TOPO_TOB
L1TopoRDOCollection.h
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
L1TopoRDO::getStatusWords
const std::vector< uint32_t > & getStatusWords() const
get the status words
Definition: L1TopoRDO.cxx:25
L1TopoRDOCollection
Container of L1TopoRDOs (standard Athena boilerplate)
Definition: L1TopoRDOCollection.h:13
L1Topo::formatHex4
std::string formatHex4(uint32_t word)
Helper function to format a 32-bit integer as a 4-digit hex number for printing.
Definition: Trigger/TrigT1/L1Topo/L1TopoRDO/src/Helpers.cxx:117
L1Topo::formatHex8
std::string formatHex8(uint32_t word)
Helper function to format a 32-bit integer as an 8-digit hex number for printing.
Definition: Trigger/TrigT1/L1Topo/L1TopoRDO/src/Helpers.cxx:111
L1Topo::decode
uint32_t decode(const uint32_t &word, const uint32_t &offset, const uint32_t &size)
Helper function to decode word based on offset and size.
Definition: Trigger/TrigT1/L1Topo/L1TopoRDO/src/Helpers.cxx:107
L1Topo::triggerBitIndexPhase1
unsigned int triggerBitIndexPhase1(uint32_t topo, uint32_t fpga, size_t bitIdx)
Definition: Trigger/TrigT1/L1Topo/L1TopoRDO/src/Helpers.cxx:152
L1TopoRDO::isROIModule
bool isROIModule() const
check the module type, derived from the source ID and the L1Topo module
Definition: L1TopoRDO.cxx:72
query_example.col
col
Definition: query_example.py:7
L1Topo::Fibre
Represents the L1Topo fibre word of the L1Topo DAQ header, with decoder and encoder.
Definition: Fibre.h:22
L1TopoRDO::getErrors
std::vector< L1Topo::Error > getErrors() const
get a vector of Errors found during RAW to RDO conversion; see enum and
Definition: L1TopoRDO.cxx:35
DeMoScan.index
string index
Definition: DeMoScan.py:362
L1Topo::triggerBitIndex
unsigned int triggerBitIndex(uint32_t moduleId, const L1Topo::L1TopoTOB &)
OUT OF DATE DO NOT USE Helper to calculate the index needed to pack trigger bits into the full 128-bi...
Definition: Trigger/TrigT1/L1Topo/L1TopoRDO/src/Helpers.cxx:137
Status.h
L1Topo::BlockTypes::HEADER
@ HEADER
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
L1TopoTOB.h
merge.status
status
Definition: merge.py:17
L1Topo
Definition: BlockTypes.h:11
python.compressB64.c
def c
Definition: compressB64.py:93
Helpers.h