ATLAS Offline Software
gFexInputByteStreamTool.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //***************************************************************************
6 // gFexInputByteStreamTool - This tool decodes Run3 gFEX input data!
7 // -------------------
8 // begin : 10 08 2022
9 // email : cecilia.tosciri@cern.ch
10 // ***************************************************************************/
11 
12 #ifndef GFEXINPUTBYTESTREAMTOOL_H
13 #define GFEXINPUTBYTESTREAMTOOL_H
14 
15 // Trigger includes
19 
20 // Athena includes
23 
24 // Gaudi includes
25 #include "Gaudi/Property.h"
26 
29 #include <array>
30 #include <vector>
31 #include <cstdint>
32 namespace gPos = LVL1::gFEXPos;
33 
40 class gFexInputByteStreamTool : public extends<AthAlgTool, IL1TriggerByteStreamTool> {
41  public:
42  typedef std::array<std::array<uint32_t, 7>, 100> gfiber;
43  typedef std::array<std::array<int, 6>, 32> gEngines;
44  typedef std::array<std::array<int, 12>, 32> gtFPGA;
45  typedef std::array<std::array<int, 20>, 100> gFields;
46  typedef std::array<std::array<int, 16>, 100> gCaloTwr;
47  typedef std::array<std::array<int, 8>, 100> gSatur;
48  typedef std::array<std::array<char, 20>, 100> gFieldsChar;
49  typedef std::array<std::array<int, 20>, 4> gType;
50  typedef std::array<std::array<char, 20>, 4> gTypeChar;
51  gFexInputByteStreamTool(const std::string& type, const std::string& name, const IInterface* parent);
52  virtual ~gFexInputByteStreamTool() override = default;
53 
54  // ------------------------- IAlgTool methods --------------------------------
55  virtual StatusCode initialize() override;
56 
57  // ------------------------- IL1TriggerByteStreamTool methods ----------------------
59  virtual StatusCode convertFromBS(const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& vrobf, const EventContext& eventContext)const override;
60 
62  virtual StatusCode convertToBS(std::vector<OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment*>& vrobf, const EventContext& eventContext) override;
63 
65  virtual const std::vector<uint32_t>& robIds() const override {
66  return m_robIds.value();
67  }
68 
69 
70  private:
71  // ------------------------- Properties --------------------------------------
72  ToolHandle<GenericMonitoringTool> m_monTool{this,"MonTool","","Monitoring tool"};
73  bool m_UseMonitoring = false;
74 
75  // FiberMapping property required by the interface
76  Gaudi::Property<std::string> m_FiberMapping{
77  this, "gFexFiberTowerMapping",
78  "Run3L1CaloSimulation/L1CaloFEXAlgos/gFEX/gFex_gCaloTowerMap_weighted_v1.txt",
79  "Text file to convert from hardware fiber to eta-phi location"};
80 
81  std::unordered_map<unsigned int, std::array<float, 4> > m_Firm2Tower_map;
82 
83  // ROBIDs property required by the interface
84  Gaudi::Property<std::vector<uint32_t>> m_robIds {this, "ROBIDs", {}, "List of ROB IDs required for conversion to/from xAOD RoI"};
85 
86  //Write handle keys for the L1Calo EDMs for BS->xAOD mode of operation
87  SG::WriteHandleKey< xAOD::gFexTowerContainer> m_gTowersWriteKey {this,"gTowersWriteKey" ,"L1_gFexDataTowers", "Name of the gFEX Input Data Towers"}; // TODO: This will be the only output of this class in the future
88  SG::WriteHandleKey< xAOD::gFexTowerContainer> m_gTowers50WriteKey {this,"gTowers50WriteKey" ,"", "Write gFexEDM Trigger Tower container with 50 MeV resolution"};
89  SG::WriteHandleKey< xAOD::gFexTowerContainer> m_gTowers200WriteKey {this,"gTowers200WriteKey" ,"", "Write gFexEDM Trigger Tower container with 200 MeV resolution (default)"};
90 
91  // Read handle keys for the L1Calo EDMs for xAOD->BS mode of operation
92  SG::ReadHandleKey < xAOD::gFexTowerContainer> m_gTowersReadKey {this,"gTowersReadKey" ,"L1_gFexDataTowers","Read gFexEDM Trigger Tower container"};
93 
94  virtual void a_gtrx_map( const gfiber &inputData, gfiber &jf_lar_rx_data) const;
95  virtual void b_gtrx_map( const gfiber &inputData, gfiber &jf_lar_rx_data) const;
96  virtual void c_gtrx_map( const gfiber &inputData, gfiber &outputData) const;
97 
98  virtual void gtReconstructABC( int XFPGA,
99  const gfiber & Xfiber,
100  int Xin,
101  gtFPGA &XgtF,
102  gtFPGA &Xgt,
103  int *BCIDptr,
104  int do_lconv,
105  const std::array<int, gPos::MAX_FIBERS> &XMPD_NFI,
106  const std::array<int, gPos::MAX_FIBERS> &XCALO_TYPE,
107  const gCaloTwr & XMPD_GTRN_ARR,
108  const gType & XMPD_DSTRT_ARR,
109  gTypeChar XMPD_DTYP_ARR,
110  const std::array<int, gPos::MAX_FIBERS> &XMSK,
111  gtFPGA &Xsatur,
112  std::array<int, (gPos::AB_FIBERS*gPos::MAX_E_FIELDS)> &FiberTower,
113  std::array<int, (gPos::AB_FIBERS*gPos::MAX_E_FIELDS)> &FiberTowerSatur) const;
114 
115  virtual int crc9d32(const std::array<uint32_t, 6> &inWords,int numWords,int reverse) const;
116  uint32_t crc9d23(uint32_t inword, uint32_t in_crc, int reverse ) const;
117 
118  virtual void undoMLE(int &datumPtr ) const;
119 
120  virtual void getEtaPhi(float &Eta, float &Phi, int iEta, int iPhi, int gFEXtowerID) const;
121 
122  virtual void signExtend(int *xptr, int upto) const;
123 
124  virtual void gtCalib(gtFPGA &gtf, int towerLSB, int fpga, unsigned int offset) const;
125 
126  StatusCode ReadFibersfromFile(const std::string&);
127 
128  void printError(const std::string& location, const std::string& title, MSG::Level type, const std::string& detail) const;
129 
130 };
131 
132 #endif // GFEXINPUTBYTESTREAMTOOL_H
gFexInputByteStreamTool::m_robIds
Gaudi::Property< std::vector< uint32_t > > m_robIds
{map index(towerid), {fpga, eta, phi, source}}
Definition: gFexInputByteStreamTool.h:84
gFexTowerContainer.h
gFexInputByteStreamTool::convertFromBS
virtual StatusCode convertFromBS(const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &vrobf, const EventContext &eventContext) const override
BS->xAOD conversion.
Definition: gFexInputByteStreamTool.cxx:55
gFexInputByteStreamTool::gType
std::array< std::array< int, 20 >, 4 > gType
Definition: gFexInputByteStreamTool.h:49
gFexInputByteStreamTool::m_gTowers50WriteKey
SG::WriteHandleKey< xAOD::gFexTowerContainer > m_gTowers50WriteKey
Definition: gFexInputByteStreamTool.h:88
gFexInputByteStreamTool::gtCalib
virtual void gtCalib(gtFPGA &gtf, int towerLSB, int fpga, unsigned int offset) const
Definition: gFexInputByteStreamTool.cxx:1717
gFexInputByteStreamTool::gtReconstructABC
virtual void gtReconstructABC(int XFPGA, const gfiber &Xfiber, int Xin, gtFPGA &XgtF, gtFPGA &Xgt, int *BCIDptr, int do_lconv, const std::array< int, gPos::MAX_FIBERS > &XMPD_NFI, const std::array< int, gPos::MAX_FIBERS > &XCALO_TYPE, const gCaloTwr &XMPD_GTRN_ARR, const gType &XMPD_DSTRT_ARR, gTypeChar XMPD_DTYP_ARR, const std::array< int, gPos::MAX_FIBERS > &XMSK, gtFPGA &Xsatur, std::array< int,(gPos::AB_FIBERS *gPos::MAX_E_FIELDS)> &FiberTower, std::array< int,(gPos::AB_FIBERS *gPos::MAX_E_FIELDS)> &FiberTowerSatur) const
Definition: gFexInputByteStreamTool.cxx:468
gFexInputByteStreamTool::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: gFexInputByteStreamTool.h:72
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
gFexInputByteStreamTool::signExtend
virtual void signExtend(int *xptr, int upto) const
Definition: gFexInputByteStreamTool.cxx:1699
LVL1::gFEXPos::MAX_E_FIELDS
constexpr int MAX_E_FIELDS
Definition: gFexPos.h:59
gFexInputByteStreamTool::~gFexInputByteStreamTool
virtual ~gFexInputByteStreamTool() override=default
gFexInputByteStreamTool::m_UseMonitoring
bool m_UseMonitoring
Definition: gFexInputByteStreamTool.h:73
gFexPos.h
detail
Definition: extract_histogram_tag.cxx:14
IL1TriggerByteStreamTool.h
gFexInputByteStreamTool::gtFPGA
std::array< std::array< int, 12 >, 32 > gtFPGA
Definition: gFexInputByteStreamTool.h:44
gFexInputByteStreamTool::undoMLE
virtual void undoMLE(int &datumPtr) const
Definition: gFexInputByteStreamTool.cxx:1471
Phi
@ Phi
Definition: RPCdef.h:8
gFexInputByteStreamTool::a_gtrx_map
virtual void a_gtrx_map(const gfiber &inputData, gfiber &jf_lar_rx_data) const
Definition: gFexInputByteStreamTool.cxx:405
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
LVL1::gFEXPos::AB_FIBERS
constexpr int AB_FIBERS
Definition: gFexPos.h:57
DeMoUpdate.reverse
reverse
Definition: DeMoUpdate.py:563
gFexInputByteStreamTool::crc9d23
uint32_t crc9d23(uint32_t inword, uint32_t in_crc, int reverse) const
Definition: gFexInputByteStreamTool.cxx:1410
gFexInputByteStreamTool::printError
void printError(const std::string &location, const std::string &title, MSG::Level type, const std::string &detail) const
Definition: gFexInputByteStreamTool.cxx:1810
gFexInputByteStreamTool::crc9d32
virtual int crc9d32(const std::array< uint32_t, 6 > &inWords, int numWords, int reverse) const
Definition: gFexInputByteStreamTool.cxx:1346
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
gFexInputByteStreamTool::initialize
virtual StatusCode initialize() override
Definition: gFexInputByteStreamTool.cxx:30
SG::WriteHandleKey
Property holding a SG store/key/clid from which a WriteHandle is made.
Definition: StoreGate/StoreGate/WriteHandleKey.h:40
gFexInputByteStreamTool::gEngines
std::array< std::array< int, 6 >, 32 > gEngines
Definition: gFexInputByteStreamTool.h:43
gFexInputByteStreamTool::m_gTowersReadKey
SG::ReadHandleKey< xAOD::gFexTowerContainer > m_gTowersReadKey
Definition: gFexInputByteStreamTool.h:92
gFexInputByteStreamTool::gSatur
std::array< std::array< int, 8 >, 100 > gSatur
Definition: gFexInputByteStreamTool.h:47
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
covarianceTool.title
title
Definition: covarianceTool.py:542
gFexInputByteStreamTool
Implementation of a tool for L1 input data conversion from BS to xAOD and from xAOD to BS (IL1Trigger...
Definition: gFexInputByteStreamTool.h:40
AthAlgTool.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
gFexInputByteStreamTool::gCaloTwr
std::array< std::array< int, 16 >, 100 > gCaloTwr
Definition: gFexInputByteStreamTool.h:46
gFexInputByteStreamTool::ReadFibersfromFile
StatusCode ReadFibersfromFile(const std::string &)
Definition: gFexInputByteStreamTool.cxx:1759
gFexInputByteStreamTool::gfiber
std::array< std::array< uint32_t, 7 >, 100 > gfiber
Definition: gFexInputByteStreamTool.h:42
gFexInputByteStreamTool::m_gTowersWriteKey
SG::WriteHandleKey< xAOD::gFexTowerContainer > m_gTowersWriteKey
Definition: gFexInputByteStreamTool.h:87
gFexInputByteStreamTool::m_FiberMapping
Gaudi::Property< std::string > m_FiberMapping
Definition: gFexInputByteStreamTool.h:76
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
lumiFormat.array
array
Definition: lumiFormat.py:91
PathResolver.h
gFexTowerAuxContainer.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
gFexInputByteStreamTool::gFexInputByteStreamTool
gFexInputByteStreamTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: gFexInputByteStreamTool.cxx:25
gFexInputByteStreamTool::getEtaPhi
virtual void getEtaPhi(float &Eta, float &Phi, int iEta, int iPhi, int gFEXtowerID) const
Definition: gFexInputByteStreamTool.cxx:1611
gFexInputByteStreamTool::gFields
std::array< std::array< int, 20 >, 100 > gFields
Definition: gFexInputByteStreamTool.h:45
Trk::iPhi
@ iPhi
Definition: ParamDefs.h:47
gFexInputByteStreamTool::m_gTowers200WriteKey
SG::WriteHandleKey< xAOD::gFexTowerContainer > m_gTowers200WriteKey
Definition: gFexInputByteStreamTool.h:89
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
gFexInputByteStreamTool::m_Firm2Tower_map
std::unordered_map< unsigned int, std::array< float, 4 > > m_Firm2Tower_map
Definition: gFexInputByteStreamTool.h:81
LVL1::gFEXPos
Definition: gFexPos.h:11
gFexInputByteStreamTool::b_gtrx_map
virtual void b_gtrx_map(const gfiber &inputData, gfiber &jf_lar_rx_data) const
Definition: gFexInputByteStreamTool.cxx:426
gFexInputByteStreamTool::gTypeChar
std::array< std::array< char, 20 >, 4 > gTypeChar
Definition: gFexInputByteStreamTool.h:50
gFexInputByteStreamTool::convertToBS
virtual StatusCode convertToBS(std::vector< OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment * > &vrobf, const EventContext &eventContext) override
xAOD->BS conversion
Definition: gFexInputByteStreamTool.cxx:1805
xAOD::iEta
setScale setgFexType iEta
Definition: gFexJetRoI_v1.cxx:77
Eta
@ Eta
Definition: RPCdef.h:8
gFexInputByteStreamTool::robIds
virtual const std::vector< uint32_t > & robIds() const override
Declare ROB IDs for conversion.
Definition: gFexInputByteStreamTool.h:65
gFexInputByteStreamTool::c_gtrx_map
virtual void c_gtrx_map(const gfiber &inputData, gfiber &outputData) const
Definition: gFexInputByteStreamTool.cxx:447
gFexInputByteStreamTool::gFieldsChar
std::array< std::array< char, 20 >, 100 > gFieldsChar
Definition: gFexInputByteStreamTool.h:48