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

#include <DemoDoublesCodec.h>

Inheritance diagram for AthRemoteExec::Example::DemoDoublesCodec:
Collaboration diagram for AthRemoteExec::Example::DemoDoublesCodec:

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< double > > m_decoded
SG::ReadHandleKey< std::vector< double > > 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 DemoDoublesCodec.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::DemoDoublesCodec::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 DemoDoublesCodec.cxx.

45 {
46 auto values = std::make_unique<std::vector<double>>();
47 std::string name;
48 std::string error;
49 if (!DemoSchema::decodeDoubles(payload.data, name, *values, error)) {
50 ATH_MSG_ERROR("'{}': {}", key(), error);
51 return StatusCode::FAILURE;
52 }
53
54 SG::WriteHandle<std::vector<double>> handle(m_decoded, ctx);
55 ATH_MSG_DEBUG("Unpacked {} value(s) named '{}' into '{}'", values->size(),
56 name, handle.key());
57 ATH_CHECK(handle.record(std::move(values)));
58 return StatusCode::SUCCESS;
59}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
SG::WriteHandleKey< std::vector< double > > m_decoded
virtual const std::string & key() const override final
bool decodeDoubles(std::string_view bytes, std::string &name, std::vector< double > &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::DemoDoublesCodec::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 61 of file DemoDoublesCodec.cxx.

64 {
65 SG::ReadHandle<std::vector<double>> values(m_encoded, ctx);
66 if (!values.isValid()) {
67 ATH_MSG_ERROR("'{}': nothing under '{}'", key(), m_encoded.key());
68 return StatusCode::FAILURE;
69 }
70
71 std::string error;
72 if (!DemoSchema::encodeDoubles(m_encoded.key(), *values, payload.data,
73 error)) {
74 ATH_MSG_ERROR("'{}': {}", key(), error);
75 return StatusCode::FAILURE;
76 }
77 ATH_MSG_DEBUG("Packed {} value(s) into '{}'", values->size(), key());
78 return StatusCode::SUCCESS;
79}
SG::ReadHandleKey< std::vector< double > > m_encoded
bool encodeDoubles(const std::string &name, const std::vector< double > &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::DemoDoublesCodec::encoding ( ) const
overridevirtual

Definition at line 16 of file DemoDoublesCodec.cxx.

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

◆ 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::DemoDoublesCodec::initializeBoundary ( )
overrideprotectedvirtual

Called from initialize().

Reimplemented from AthRemoteExec::PayloadCodecBase.

Definition at line 21 of file DemoDoublesCodec.cxx.

21 {
22 if (schema() != DemoSchema::doubles) {
23 ATH_MSG_ERROR("Schema is '{}'; this codec implements '{}'", schema(),
25 return StatusCode::FAILURE;
26 }
27
28 ATH_CHECK(m_decoded.initialize(writingToSG()));
29 ATH_CHECK(m_encoded.initialize(!writingToSG()));
30
31 const bool haveKey =
32 writingToSG() ? !m_decoded.key().empty() : !m_encoded.key().empty();
33 if (!haveKey) {
35 "Direction is '{}' but the matching key is not set; this codec would "
36 "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 doubles
athexremoteexec.demo.v1.Doubles

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

Definition at line 38 of file DemoDoublesCodec.h.

38 {this, "Decoded", "",
39 "Decoded values 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<double> > AthRemoteExec::Example::DemoDoublesCodec::m_encoded
private
Initial value:
{this, "Encoded", "",
"Encoded values key"}

Definition at line 40 of file DemoDoublesCodec.h.

40 {this, "Encoded", "",
41 "Encoded values 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: