ATLAS Offline Software
Loading...
Searching...
No Matches
AthenaPoolTestAttrWriter.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
16
17// INCLUDE HEADER FILES:
18
20
21
22#include "EventInfo/EventInfo.h"
23#include "EventInfo/EventID.h"
24
25// AttributeList:
27#include "GaudiKernel/ThreadLocalContext.h"
28
30 ISvcLocator* pSvcLocator)
31 :
32 AthAlgorithm(name, pSvcLocator), m_attributes(nullptr)
33{}
34
37
39{
40
41 // Create AttrList
42 try {
43 ATH_MSG_DEBUG("Try new attlist" );
45 m_attributes->extend("Run", "unsigned int" );
46 m_attributes->extend("Event", "unsigned int" );
47 m_attributes->extend("IEvent", "unsigned int");
48 m_attributes->extend("MissingET", "float");
49 m_attributes->extend("electronPT", "float");
50 ATH_MSG_DEBUG("new attlist" );
51 } catch (const std::exception& e) {
52 ATH_MSG_ERROR("Caught exception from creation of AthenaAttributeList. Message: "
53 << e.what()
54 );
55 return (StatusCode::FAILURE);
56 }
57 m_attributes->addRef();
58
59 ATH_MSG_DEBUG("After new att list" );
60
61 return StatusCode::SUCCESS;
62}
63
65{
66 ATH_MSG_DEBUG("Executing AthenaPoolTestAttrWriter" );
67
68 const EventInfo* eventInfo = nullptr;
69 ATH_CHECK( evtStore()->retrieve(eventInfo) );
70 ATH_MSG_DEBUG( "Retrieved EventInfo" );
71
72 const EventID* myEventID=eventInfo->event_ID();
73
74 // Create AttrList
75 const EventContext& ctx = Gaudi::Hive::currentContext();
76 unsigned int iEvent = ctx.evt() + 1;
78
79 try {
80 (*attributes)["Run"].setValue(myEventID->run_number());
81 (*attributes)["Event"].setValue(myEventID->event_number());
82 ++iEvent;
83 (*attributes)["IEvent"].setValue(iEvent);
84 // Must cast double to float, otherwise exception!!
85 (*attributes)["MissingET"].setValue(7.0f*iEvent);
86 (*attributes)["electronPT"].setValue(5.0f*iEvent);
87 } catch (const std::exception& e) {
88 ATH_MSG_ERROR("Caught exception from setValue for attributes. Message: "
89 << e.what()
90 );
91 return (StatusCode::FAILURE);
92 }
93
94 ATH_MSG_DEBUG("After create att" );
95
96 coral::AttributeList::const_iterator first = attributes->begin();
97 coral::AttributeList::const_iterator last = attributes->end();
98 for (; first != last; ++first) {
99 std::stringstream str;
100 (*first).toOutputStream(str);
101 ATH_MSG_DEBUG(" name " << (*first).specification().name()
102 << " type " << (*first).specification().typeName()
103 << " value ");
104 }
105
106 ATH_MSG_DEBUG("After iteration" );
107
108 ATH_CHECK( evtStore()->record(attributes, "SimpleTag") );
109 ATH_MSG_DEBUG("End" );
110 return StatusCode::SUCCESS;
111
112}
113
115{
116 return StatusCode::SUCCESS;
117}
118
119
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Test Algorithm for testing creation of explicit collections, writes an AttributeList to the transient...
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
An AttributeList represents a logical row of attributes in a metadata table.
AthenaAttributeList * m_attributes
Create attr list at intitialize and use each event.
virtual StatusCode execute()
Algorithm execute once per event.
virtual StatusCode initialize()
Algorithm initialize at begin of job.
AthenaPoolTestAttrWriter(const std::string &name, ISvcLocator *pSvcLocator)
Algorithm constructor.
~AthenaPoolTestAttrWriter()
Algorithm destructor.
virtual StatusCode finalize()
Algorithm finalize at end of job.
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
Definition EventID.h:35
EventID * event_ID()
the unique identification of the event.