ATLAS Offline Software
Loading...
Searching...
No Matches
AthRemoteExec::Example::DemoWordsCodec Class Reference

#include <DemoWordsCodec.h>

Inheritance diagram for AthRemoteExec::Example::DemoWordsCodec:
Collaboration diagram for AthRemoteExec::Example::DemoWordsCodec:

Public Member Functions

virtual const std::string & encoding () const override
virtual StatusCode initialize () override
virtual const std::string & key () const override final
virtual const std::string & schema () const override final
virtual StatusCode decode (const EventContext &ctx, const Payload &payload) const override final
virtual StatusCode encode (const EventContext &ctx, Payload &payload, const std::vector< const IPayloadCodec * > &alsoCrossing, std::vector< std::string > &dangling) const override final

Protected Member Functions

virtual StatusCode initializeBoundary () override
 Called from initialize().
virtual StatusCode doDecode (const EventContext &ctx, IProxyDict &store, const Payload &payload) const override
 Decode payload.data and record it onto a SG.
virtual StatusCode doEncode (const EventContext &ctx, IProxyDict &store, Payload &payload, const std::vector< const IPayloadCodec * > &alsoCrossing, std::vector< std::string > &dangling) const override
 Read input data (SG, RawEvent, etc.) and encode it into a payload.data.
bool writingToSG () const
 Codec direction.

Private Member Functions

IProxyDict * storeOf (const EventContext &ctx) const
 The store belonging to ctx. Errors and returns null if there is none.

Private Attributes

SG::WriteHandleKey< std::vector< uint32_t > > m_decoded
SG::ReadHandleKey< std::vector< uint32_t > > m_encoded
Gaudi::Property< std::string > m_key {this, "Key", "", "see BoundaryInfo::key"}
Gaudi::Property< std::string > m_schema
Gaudi::Property< std::string > m_direction
bool m_writing = false

Detailed Description

Definition at line 22 of file DemoWordsCodec.h.

Member Function Documentation

◆ decode()

StatusCode AthRemoteExec::PayloadCodecBase::decode ( const EventContext & ctx,
const Payload & payload ) const
finaloverridevirtualinherited

Definition at line 47 of file PayloadCodecBase.cxx.

48 {
49 if (payload.encoding != encoding()) {
51 "'{}' arrived with encoding '{}' but this boundary declares '{}'",
52 m_key.value(), payload.encoding, encoding());
53 return StatusCode::FAILURE;
54 }
55
56 if (payload.schema != m_schema) {
57 ATH_MSG_ERROR("''{}' arrived as '{}' but this boundary declares '{}'",
58 m_key.value(), payload.schema, m_schema.value());
59 return StatusCode::FAILURE;
60 }
61
62 IProxyDict* store = storeOf(ctx);
63 if (store == nullptr) {
64 return StatusCode::FAILURE;
65 }
66
67 return doDecode(ctx, *store, payload);
68}
#define ATH_MSG_ERROR(x,...)
Gaudi::Property< std::string > m_key
Gaudi::Property< std::string > m_schema
IProxyDict * storeOf(const EventContext &ctx) const
The store belonging to ctx. Errors and returns null if there is none.
virtual StatusCode doDecode(const EventContext &ctx, IProxyDict &store, const Payload &payload) const =0
Decode payload.data and record it onto a SG.
TestStore store
Definition TestStore.cxx:23
encoding
TODO - add here other trackAnalyses configurations depending of the use-case.

◆ doDecode()

StatusCode AthRemoteExec::Example::DemoWordsCodec::doDecode ( const EventContext & ctx,
IProxyDict & store,
const Payload & payload ) const
overrideprotectedvirtual

Decode payload.data and record it onto a SG.

Implements AthRemoteExec::PayloadCodecBase.

Definition at line 46 of file DemoWordsCodec.cxx.

48 {
49 // Check if received data makes sense, return failure otherwise
50 if (payload.data.size() % sizeof(uint32_t) != 0) {
51 ATH_MSG_ERROR("Received payload size ({} bytes) does not align to {} bytes",
52 payload.data.size(), sizeof(uint32_t));
53 return StatusCode::FAILURE;
54 }
55
56 // Calculate how many words we received
57 const size_t nWords = payload.data.size() / sizeof(uint32_t);
58
59 // Allocate memory to hold these numbers
60 std::vector<uint32_t> words(nWords);
61
62 // Copy bytes from payload as words to vector
63 std::memcpy(words.data(), payload.data.data(), nWords);
64
65 // Create handle and record data to StoreGate
66 SG::WriteHandle<std::vector<uint32_t>> wordsHandle(m_decoded, ctx);
67 ATH_CHECK(wordsHandle.record(
68 std::make_unique<std::vector<uint32_t>>(std::move(words))));
69
70 ATH_MSG_INFO("Unpacked {} bytes into {} word(s) as {}", payload.data.size(),
71 nWords, wordsHandle.key());
72
73 return StatusCode::SUCCESS;
74}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x,...)
SG::WriteHandleKey< std::vector< uint32_t > > m_decoded
setEventNumber uint32_t

◆ doEncode()

StatusCode AthRemoteExec::Example::DemoWordsCodec::doEncode ( const EventContext & ctx,
IProxyDict & store,
Payload & payload,
const std::vector< const IPayloadCodec * > & alsoCrossing,
std::vector< std::string > & dangling ) const
overrideprotectedvirtual

Read input data (SG, RawEvent, etc.) and encode it into a payload.data.

Implements AthRemoteExec::PayloadCodecBase.

Definition at line 76 of file DemoWordsCodec.cxx.

79 {
80 SG::ReadHandle<std::vector<uint32_t>> words(m_encoded, ctx);
81
82 // Calculate how many bytes we need to send
83 const size_t nBytes = words->size() * sizeof(uint32_t);
84
85 // Clear data and allocate needed space
86 payload.data.clear();
87 payload.data.resize(nBytes);
88
89 // Copy entire vector as bytes
90 std::memcpy(payload.data.data(), reinterpret_cast<const char*>(words->data()),
91 nBytes);
92
93 ATH_MSG_INFO("Packed {} word(s) as {} bytes into '{}'", words->size(), nBytes,
94 key());
95
96 return StatusCode::SUCCESS;
97}
SG::ReadHandleKey< std::vector< uint32_t > > m_encoded
virtual const std::string & key() const override final

◆ encode()

StatusCode AthRemoteExec::PayloadCodecBase::encode ( const EventContext & ctx,
Payload & payload,
const std::vector< const IPayloadCodec * > & alsoCrossing,
std::vector< std::string > & dangling ) const
finaloverridevirtualinherited

Definition at line 70 of file PayloadCodecBase.cxx.

73 {
74 IProxyDict* store = storeOf(ctx);
75 if (store == nullptr) {
76 return StatusCode::FAILURE;
77 }
78
79 payload.key = m_key;
80 payload.encoding = encoding();
81 payload.schema = m_schema;
82 return doEncode(ctx, *store, payload, alsoCrossing, dangling);
83}
virtual StatusCode doEncode(const EventContext &ctx, IProxyDict &store, Payload &payload, const std::vector< const IPayloadCodec * > &alsoCrossing, std::vector< std::string > &dangling) const =0
Read input data (SG, RawEvent, etc.) and encode it into a payload.data.

◆ encoding()

const std::string & AthRemoteExec::Example::DemoWordsCodec::encoding ( ) const
overridevirtual

Definition at line 14 of file DemoWordsCodec.cxx.

14 {
15 // Return which RPC protocol we support
16 static const std::string tag = "protobuf";
17 return tag;
18}

◆ initialize()

StatusCode AthRemoteExec::PayloadCodecBase::initialize ( )
overridevirtualinherited

Definition at line 19 of file PayloadCodecBase.cxx.

19 {
20 if (m_key.empty()) {
22 "Key is not set; this codec serves one boundary and would not know "
23 "which");
24 return StatusCode::FAILURE;
25 }
26
27 // Set direction
28 if (m_direction == "WriteToSG") {
29 m_writing = true;
30 } else if (m_direction == "ReadFromSG") {
31 m_writing = false;
32 } else {
33 ATH_MSG_ERROR("Direction is '{}'; it must be 'ReadFromSG' or 'WriteToSG'",
34 m_direction.value());
35 return StatusCode::FAILURE;
36 }
37
39
40 ATH_MSG_DEBUG("Boundary '{}' on {}({}), {}", m_key.value(), encoding(),
41 (m_schema.empty() ? "" : " as " + m_schema.value()),
42 m_direction.value());
43
44 return StatusCode::SUCCESS;
45}
#define ATH_MSG_DEBUG(x,...)
virtual StatusCode initializeBoundary()
Called from initialize().
Gaudi::Property< std::string > m_direction

◆ initializeBoundary()

StatusCode AthRemoteExec::Example::DemoWordsCodec::initializeBoundary ( )
overrideprotectedvirtual

Called from initialize().

Reimplemented from AthRemoteExec::PayloadCodecBase.

Definition at line 20 of file DemoWordsCodec.cxx.

20 {
21 // Fail if we are configured to handle messages the we do not expect
22 if (schema() != "athremoteexec.demo.v1.Words") {
24 "Schema is '{}'; this codec implements 'athremoteexec.demo.v1.Words'",
25 schema());
26 return StatusCode::FAILURE;
27 }
28
29 // Initialize handles
30 ATH_CHECK(m_decoded.initialize(writingToSG()));
31 ATH_CHECK(m_encoded.initialize(!writingToSG()));
32
33 // Fail if incorrect keys are set for de/encoding
34 const bool haveKeys = writingToSG() ? !m_decoded.empty() : !m_encoded.empty();
35 if (!haveKeys) {
37 "Direction is '{}' but the matching key list is empty; this codec "
38 "would carry nothing",
39 writingToSG() ? "WriteToSG" : "ReadFromSG");
40 return StatusCode::FAILURE;
41 }
42
43 return StatusCode::SUCCESS;
44}
virtual const std::string & schema() const override final
bool writingToSG() const
Codec direction.

◆ key()

virtual const std::string & AthRemoteExec::PayloadCodecBase::key ( ) const
inlinefinaloverridevirtualinherited

Definition at line 34 of file PayloadCodecBase.h.

34{ return m_key; }

◆ schema()

virtual const std::string & AthRemoteExec::PayloadCodecBase::schema ( ) const
inlinefinaloverridevirtualinherited

Definition at line 35 of file PayloadCodecBase.h.

35{ return m_schema; }

◆ storeOf()

IProxyDict * AthRemoteExec::PayloadCodecBase::storeOf ( const EventContext & ctx) const
privateinherited

The store belonging to ctx. Errors and returns null if there is none.

Definition at line 85 of file PayloadCodecBase.cxx.

85 {
86 // From the context rather than from evtStore(), so this does not depend on
87 // which slot happens to be selected on this thread.
88 IProxyDict* store = Atlas::getExtendedEventContext(ctx).proxy();
89 if (store == nullptr) {
90 ATH_MSG_ERROR("No proxy dictionary in the event context");
91 }
92 return store;
93}
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.

◆ writingToSG()

bool AthRemoteExec::PayloadCodecBase::writingToSG ( ) const
inlineprotectedinherited

Codec direction.

Definition at line 46 of file PayloadCodecBase.h.

46{ return m_writing; }

Member Data Documentation

◆ m_decoded

SG::WriteHandleKey<std::vector<uint32_t> > AthRemoteExec::Example::DemoWordsCodec::m_decoded
private
Initial value:
{this, "Decoded", "",
"Decoded words key"}

Definition at line 39 of file DemoWordsCodec.h.

39 {this, "Decoded", "",
40 "Decoded words key"};

◆ m_direction

Gaudi::Property<std::string> AthRemoteExec::PayloadCodecBase::m_direction
privateinherited
Initial value:
{
this, "Direction", "",
"Direction in which this Codec operates: 'ReadFromSG' -> encoding, "
"'WriteFromSG' -> decoding"}

Definition at line 65 of file PayloadCodecBase.h.

65 {
66 this, "Direction", "",
67 "Direction in which this Codec operates: 'ReadFromSG' -> encoding, "
68 "'WriteFromSG' -> decoding"};

◆ m_encoded

SG::ReadHandleKey<std::vector<uint32_t> > AthRemoteExec::Example::DemoWordsCodec::m_encoded
private
Initial value:
{this, "Encoded", "",
"Encoded words key"}

Definition at line 41 of file DemoWordsCodec.h.

41 {this, "Encoded", "",
42 "Encoded words key"};

◆ m_key

Gaudi::Property<std::string> AthRemoteExec::PayloadCodecBase::m_key {this, "Key", "", "see BoundaryInfo::key"}
privateinherited

Definition at line 62 of file PayloadCodecBase.h.

62{this, "Key", "", "see BoundaryInfo::key"};

◆ m_schema

Gaudi::Property<std::string> AthRemoteExec::PayloadCodecBase::m_schema
privateinherited
Initial value:
{this, "Schema", "",
"see BoundaryInfo::schema"}

Definition at line 63 of file PayloadCodecBase.h.

63 {this, "Schema", "",
64 "see BoundaryInfo::schema"};

◆ m_writing

bool AthRemoteExec::PayloadCodecBase::m_writing = false
privateinherited

Definition at line 73 of file PayloadCodecBase.h.


The documentation for this class was generated from the following files: