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

#include <DemoIntsCodec.h>

Inheritance diagram for AthRemoteExec::Example::DemoIntsCodec:
Collaboration diagram for AthRemoteExec::Example::DemoIntsCodec:

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::WriteHandleKeyArray< int64_t > m_decoded
SG::ReadHandleKeyArray< int64_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 21 of file DemoIntsCodec.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::DemoIntsCodec::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 43 of file DemoIntsCodec.cxx.

45 {
46 std::vector<DemoSchema::NamedInt> values;
47 std::string error;
48 if (!DemoSchema::decodeInts(payload.data, values, error)) {
49 ATH_MSG_ERROR("'{}': {}", key(), error);
50 return StatusCode::FAILURE;
51 }
52
53 for (SG::WriteHandle<int64_t>& handle : m_decoded.makeHandles(ctx)) {
54 const auto found =
55 std::find_if(values.begin(), values.end(),
56 [&handle](const DemoSchema::NamedInt& candidate) {
57 return candidate.name == handle.key();
58 });
59 if (found == values.end()) {
60 ATH_MSG_ERROR("'{}' carries no entry named '{}'", key(), handle.key());
61 return StatusCode::FAILURE;
62 }
63 ATH_CHECK(handle.record(std::make_unique<int64_t>(found->value)));
64 ATH_MSG_DEBUG("Unpacked {} = {}", handle.key(), found->value);
65 }
66 return StatusCode::SUCCESS;
67}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
SG::WriteHandleKeyArray< int64_t > m_decoded
virtual const std::string & key() const override final
bool decodeInts(std::string_view bytes, std::vector< NamedInt > &values, std::string &error)
virtual void handle(const Incident &inc)
Handle end of run incidents to save the metadata at that point.

◆ doEncode()

StatusCode AthRemoteExec::Example::DemoIntsCodec::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 69 of file DemoIntsCodec.cxx.

72 {
73 std::vector<DemoSchema::NamedInt> values;
74 for (SG::ReadHandle<int64_t>& handle : m_encoded.makeHandles(ctx)) {
75 if (!handle.isValid()) {
76 ATH_MSG_ERROR("'{}': nothing under '{}'", key(), handle.key());
77 return StatusCode::FAILURE;
78 }
79 values.push_back(DemoSchema::NamedInt{handle.key(), *handle});
80 }
81
82 std::string error;
83 if (!DemoSchema::encodeInts(values, payload.data, error)) {
84 ATH_MSG_ERROR("'{}': {}", key(), error);
85 return StatusCode::FAILURE;
86 }
87 ATH_MSG_DEBUG("Packed {} integer(s) into '{}'", values.size(), key());
88 return StatusCode::SUCCESS;
89}
SG::ReadHandleKeyArray< int64_t > m_encoded
bool encodeInts(const std::vector< NamedInt > &values, std::string &bytes, std::string &error)

◆ 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::DemoIntsCodec::encoding ( ) const
overridevirtual

Definition at line 17 of file DemoIntsCodec.cxx.

17 {
18 static const std::string tag = "protobuf";
19 return tag;
20}

◆ 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}
virtual StatusCode initializeBoundary()
Called from initialize().
Gaudi::Property< std::string > m_direction

◆ initializeBoundary()

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

Called from initialize().

Reimplemented from AthRemoteExec::PayloadCodecBase.

Definition at line 22 of file DemoIntsCodec.cxx.

22 {
23 if (schema() != DemoSchema::ints) {
24 ATH_MSG_ERROR("Schema is '{}'; this codec implements '{}'", schema(),
26 return StatusCode::FAILURE;
27 }
28
29 ATH_CHECK(m_decoded.initialize());
30 ATH_CHECK(m_encoded.initialize());
31
32 const bool haveKeys = writingToSG() ? !m_decoded.empty() : !m_encoded.empty();
33 if (!haveKeys) {
35 "Direction is '{}' but the matching key list is empty; this codec "
36 "would carry nothing",
37 writingToSG() ? "WriteToSG" : "ReadFromSG");
38 return StatusCode::FAILURE;
39 }
40 return StatusCode::SUCCESS;
41}
virtual const std::string & schema() const override final
bool writingToSG() const
Codec direction.
const char *const ints
athexremoteexec.demo.v1.Ints

◆ 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::WriteHandleKeyArray<int64_t> AthRemoteExec::Example::DemoIntsCodec::m_decoded
private
Initial value:
{
this, "Decoded", {}, "Decoded values key array"}

Definition at line 38 of file DemoIntsCodec.h.

38 {
39 this, "Decoded", {}, "Decoded values key array"};

◆ 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::ReadHandleKeyArray<int64_t> AthRemoteExec::Example::DemoIntsCodec::m_encoded
private
Initial value:
{
this, "Encoded", {}, "Encoded values key array"}

Definition at line 40 of file DemoIntsCodec.h.

40 {
41 this, "Encoded", {}, "Encoded values key array"};

◆ 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: