ATLAS Offline Software
Loading...
Searching...
No Matches
IL1TriggerByteStreamTool.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef TRIGT1RESULTBYTESTREAM_IL1TRIGGERBYTESTREAMTOOL_H
5#define TRIGT1RESULTBYTESTREAM_IL1TRIGGERBYTESTREAMTOOL_H
6
11#include "GaudiKernel/IAlgTool.h"
12#include "GaudiKernel/EventContext.h"
13#include "eformat/Status.h"
14
19class IL1TriggerByteStreamTool : virtual public IAlgTool {
20public:
22 virtual ~IL1TriggerByteStreamTool() override = default;
23
30 virtual StatusCode convertFromBS(const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& vrobf,
31 const EventContext& eventContext) const = 0;
32
45 virtual StatusCode convertToBS(std::vector<OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment*>& vrobf,
46 const EventContext& eventContext) = 0;
47
55 virtual const std::vector<uint32_t>& robIds() const = 0;
56
57protected:
61 template<typename RHK, typename WHK>
62 inline ConversionMode getConversionMode(const RHK& readHandleKeys, const WHK& writeHandleKeys, MsgStream& msg) {
63 if (readHandleKeys.empty() and not writeHandleKeys.empty()) {
65 }
66 if (writeHandleKeys.empty() and not readHandleKeys.empty()) {
68 }
69 if constexpr (std::is_base_of_v<SG::VarHandleKeyArray, RHK>) {
70 msg << MSG::ERROR << "Exactly one of the read / write handle key arrays has to be set and the other has to"
71 << " be empty, but they have " << readHandleKeys.size() << " / " << writeHandleKeys.size() << " elements"
72 << endmsg;
73 } else if constexpr (std::is_base_of_v<SG::VarHandleKey, RHK>) {
74 msg << MSG::ERROR << "Exactly one of the read / write handle keys has to be set and the other has to"
75 << " be empty, but they are \"" << readHandleKeys.key() << "\" / \"" << writeHandleKeys.key() << "\""
76 << endmsg;
77 }
79 }
80
81 inline void clearCache(const EventContext& eventContext) {
82 m_cache.get(eventContext)->clear();
83 }
84
85 inline uint32_t* newRodData(const EventContext& eventContext, const size_t size) {
86 Cache* cache = m_cache.get(eventContext);
87 cache->rodData.push_back(std::make_unique<uint32_t[]>(size));
88 return cache->rodData.back().get();
89 }
90
92 const EventContext& eventContext,
93 uint32_t source_id,
94 uint32_t ndata,
95 const uint32_t* data,
96 uint32_t detev_type = 0,
97 uint32_t status_position = eformat::STATUS_BACK) {
98
99 Cache* cache = m_cache.get(eventContext);
100 const EventIDBase& eid = eventContext.eventID();
101 cache->robFragments.push_back(std::make_unique<OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment>(
102 source_id,
103 eid.run_number(),
104 0, // lvl1_id will be overwritten downstream from full event fragment
105 eid.bunch_crossing_id(),
106 0, // lvl1_type will be overwritten downstream from full event fragment
107 detev_type,
108 ndata,
109 data,
110 status_position
111 ));
112 return cache->robFragments.back().get();
113 }
114
115private:
123 struct Cache {
124 std::vector<std::unique_ptr<uint32_t[]>> rodData;
125 std::vector<std::unique_ptr<OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment>> robFragments;
127 void clear() {
128 rodData.clear();
129 robFragments.clear();
130 }
131 };
132 SG::SlotSpecificObj<Cache> m_cache; // one cache per event slot
133};
134
135#endif // TRIGT1RESULTBYTESTREAM_IL1TRIGGERBYTESTREAMTOOL_H
#define endmsg
Maintain a set of objects, one per slot.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Base class for VarHandleKeyArray for reading from StoreGate.
A property holding a SG store/key/clid from which a VarHandle is made.
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.
virtual StatusCode convertToBS(std::vector< OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment * > &vrobf, const EventContext &eventContext)=0
Convert xAOD -> BS.
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.
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
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