ATLAS Offline Software
Loading...
Searching...
No Matches
IL1TriggerByteStreamTool.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef TRIGT1RESULTBYTESTREAM_IL1TRIGGERBYTESTREAMTOOL_H
5#define TRIGT1RESULTBYTESTREAM_IL1TRIGGERBYTESTREAMTOOL_H
6
8#include "ByteStreamData/RawEvent.h" //OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment typedef
11#include "GaudiKernel/IAlgTool.h"
12#include "GaudiKernel/EventContext.h"
13#include "eformat/Status.h" //eformat::STATUS_BACK enum
14
15#include <vector>
16#include <type_traits>
17#include <cstdint>
18#include <memory>
19
21
26class IL1TriggerByteStreamTool : virtual public IAlgTool {
27public:
29 virtual ~IL1TriggerByteStreamTool() override = default;
30
37 virtual StatusCode convertFromBS(const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& vrobf,
38 const EventContext& eventContext) const = 0;
39
54 virtual StatusCode convertToBS(std::vector<OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment*>& vrobf,
56 const EventContext& eventContext) = 0;
57
65 virtual const std::vector<uint32_t>& robIds() const = 0;
66
67protected:
71 template<typename RHK, typename WHK>
72 inline ConversionMode getConversionMode(const RHK& readHandleKeys, const WHK& writeHandleKeys, MsgStream& msg) {
73 if (readHandleKeys.empty() and not writeHandleKeys.empty()) {
75 }
76 if (writeHandleKeys.empty() and not readHandleKeys.empty()) {
78 }
79 if constexpr (std::is_base_of_v<SG::VarHandleKeyArray, RHK>) {
80 msg << MSG::ERROR << "Exactly one of the read / write handle key arrays has to be set and the other has to"
81 << " be empty, but they have " << readHandleKeys.size() << " / " << writeHandleKeys.size() << " elements"
82 << endmsg;
83 } else if constexpr (std::is_base_of_v<SG::VarHandleKey, RHK>) {
84 msg << MSG::ERROR << "Exactly one of the read / write handle keys has to be set and the other has to"
85 << " be empty, but they are \"" << readHandleKeys.key() << "\" / \"" << writeHandleKeys.key() << "\""
86 << endmsg;
87 }
89 }
90
91 inline void clearCache(const EventContext& eventContext) {
92 m_cache.get(eventContext)->clear();
93 }
94
95 inline uint32_t* newRodData(const EventContext& eventContext, const size_t size) {
96 Cache* cache = m_cache.get(eventContext);
97 cache->rodData.push_back(std::make_unique<uint32_t[]>(size));
98 return cache->rodData.back().get();
99 }
100
102 const EventContext& eventContext,
103 uint32_t source_id,
104 uint32_t ndata,
105 const uint32_t* data,
106 uint32_t detev_type = 0,
107 uint32_t status_position = eformat::STATUS_BACK) {
108
109 Cache* cache = m_cache.get(eventContext);
110 const EventIDBase& eid = eventContext.eventID();
111 cache->robFragments.push_back(std::make_unique<OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment>(
112 source_id,
113 eid.run_number(),
114 0, // lvl1_id will be overwritten downstream from full event fragment
115 eid.bunch_crossing_id(),
116 0, // lvl1_type will be overwritten downstream from full event fragment
117 detev_type,
118 ndata,
119 data,
120 status_position
121 ));
122 return cache->robFragments.back().get();
123 }
124
125private:
133 struct Cache {
134 std::vector<std::unique_ptr<uint32_t[]>> rodData;
135 std::vector<std::unique_ptr<OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment>> robFragments;
137 void clear() {
138 rodData.clear();
139 robFragments.clear();
140 }
141 };
142 SG::SlotSpecificObj<Cache> m_cache; // one cache per event slot
143};
144
145#endif // TRIGT1RESULTBYTESTREAM_IL1TRIGGERBYTESTREAMTOOL_H
#define endmsg
Maintain a set of objects, one per slot.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static Double_t tc
@ Undefined
Base class for VarHandleKeyArray for reading from StoreGate.
A property holding a SG store/key/clid from which a VarHandle is made.
size_t size() const
Number of registered mappings.
Interface for AlgTools converting ByteStream to xAOD RoI objects and vice versa.
uint32_t * newRodData(const EventContext &eventContext, const size_t size)
Allocate new array of raw ROD words for output ByteStream data.
DeclareInterfaceID(IL1TriggerByteStreamTool, 1, 0)
ConversionMode getConversionMode(const RHK &readHandleKeys, const WHK &writeHandleKeys, MsgStream &msg)
Helper to find out the conversion mode based on configured data handles.
virtual ~IL1TriggerByteStreamTool() override=default
virtual StatusCode convertFromBS(const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &vrobf, const EventContext &eventContext) const =0
Convert BS -> xAOD.
virtual StatusCode convertToBS(std::vector< OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment * > &vrobf, const xAOD::TrigCompositeContainer *tc, const EventContext &eventContext)=0
Convert xAOD -> BS.
SG::SlotSpecificObj< Cache > m_cache
void clearCache(const EventContext &eventContext)
Helper to clear the ByteStream data cache for a given event slot.
ConversionMode
Enum defining conversion mode.
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment * newRobFragment(const EventContext &eventContext, uint32_t source_id, uint32_t ndata, const uint32_t *data, uint32_t detev_type=0, uint32_t status_position=eformat::STATUS_BACK)
Allocate new ROBFragment for output ByteStream data.
virtual const std::vector< uint32_t > & robIds() const =0
List of IDs of ROBs which the convert methods expect in the vrobf input/output parameter.
Maintain a set of objects, one per slot.
eformat::write::ROBFragment ROBFragment
Definition RawEvent.h:33
TrigCompositeContainer_v1 TrigCompositeContainer
Declare the latest version of the container.
Cache which tracks memory allocated for ByteStream data representation in the convertToBS method.
std::vector< std::unique_ptr< uint32_t[]> > rodData
std::vector< std::unique_ptr< OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment > > robFragments
MsgStream & msg
Definition testRead.cxx:32