ATLAS Offline Software
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 
19 class IL1TriggerByteStreamTool : virtual public IAlgTool {
20 public:
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 
57 protected:
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  }
81  inline void clearCache(const EventContext& eventContext) {
82  m_cache.get(eventContext)->clear();
83  }
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  }
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 
115 private:
123  struct Cache {
124  std::vector<std::unique_ptr<uint32_t[]>> rodData;
125  std::vector<std::unique_ptr<OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment>> robFragments;
126  ~Cache() {clear();}
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
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
IL1TriggerByteStreamTool::ConversionMode::Decoding
@ Decoding
= BS->xAOD
VarHandleKey.h
A property holding a SG store/key/clid from which a VarHandle is made.
IL1TriggerByteStreamTool::ConversionMode::Encoding
@ Encoding
= xAOD->BS
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
IL1TriggerByteStreamTool::Cache::robFragments
std::vector< std::unique_ptr< OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment > > robFragments
Definition: IL1TriggerByteStreamTool.h:125
IL1TriggerByteStreamTool::ConversionMode::Undefined
@ Undefined
VarHandleKeyArray.h
Base class for VarHandleKeyArray for reading from StoreGate.
IL1TriggerByteStreamTool::Cache::clear
void clear()
Definition: IL1TriggerByteStreamTool.h:127
IL1TriggerByteStreamTool::Cache::~Cache
~Cache()
Definition: IL1TriggerByteStreamTool.h:126
IL1TriggerByteStreamTool::newRobFragment
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.
Definition: IL1TriggerByteStreamTool.h:91
IL1TriggerByteStreamTool::~IL1TriggerByteStreamTool
virtual ~IL1TriggerByteStreamTool() override=default
IL1TriggerByteStreamTool::newRodData
uint32_t * newRodData(const EventContext &eventContext, const size_t size)
Allocate new array of raw ROD words for output ByteStream data.
Definition: IL1TriggerByteStreamTool.h:85
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
IL1TriggerByteStreamTool::DeclareInterfaceID
DeclareInterfaceID(IL1TriggerByteStreamTool, 1, 0)
SG::SlotSpecificObj
Maintain a set of objects, one per slot.
Definition: AthenaKernel/AthenaKernel/SlotSpecificObj.h:70
IL1TriggerByteStreamTool::robIds
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.
RawEvent.h
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
IL1TriggerByteStreamTool::convertFromBS
virtual StatusCode convertFromBS(const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &vrobf, const EventContext &eventContext) const =0
Convert BS -> xAOD.
IL1TriggerByteStreamTool::Cache
Cache which tracks memory allocated for ByteStream data representation in the convertToBS method.
Definition: IL1TriggerByteStreamTool.h:123
IL1TriggerByteStreamTool::convertToBS
virtual StatusCode convertToBS(std::vector< OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment * > &vrobf, const EventContext &eventContext)=0
Convert xAOD -> BS.
IL1TriggerByteStreamTool::m_cache
SG::SlotSpecificObj< Cache > m_cache
Definition: IL1TriggerByteStreamTool.h:132
IL1TriggerByteStreamTool::ConversionMode
ConversionMode
Enum defining conversion mode.
Definition: IL1TriggerByteStreamTool.h:59
IL1TriggerByteStreamTool::clearCache
void clearCache(const EventContext &eventContext)
Helper to clear the ByteStream data cache for a given event slot.
Definition: IL1TriggerByteStreamTool.h:81
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment
eformat::write::ROBFragment ROBFragment
Definition: RawEvent.h:33
IL1TriggerByteStreamTool::getConversionMode
ConversionMode getConversionMode(const RHK &readHandleKeys, const WHK &writeHandleKeys, MsgStream &msg)
Helper to find out the conversion mode based on configured data handles.
Definition: IL1TriggerByteStreamTool.h:62
SlotSpecificObj.h
Maintain a set of objects, one per slot.
IL1TriggerByteStreamTool::Cache::rodData
std::vector< std::unique_ptr< uint32_t[]> > rodData
Definition: IL1TriggerByteStreamTool.h:124
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
IL1TriggerByteStreamTool
Interface for AlgTools converting ByteStream to xAOD RoI objects and vice versa.
Definition: IL1TriggerByteStreamTool.h:19
toolFromAlgData.writeHandleKeys
writeHandleKeys
Definition: toolFromAlgData.py:27