ATLAS Offline Software
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 
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 
36 {}
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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
AthenaPoolTestAttrWriter.h
Test Algorithm for testing creation of explicit collections, writes an AttributeList to the transient...
AthenaAttributeList.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
EventID.h
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
AthenaPoolTestAttrWriter::finalize
virtual StatusCode finalize()
Algorithm finalize at end of job.
Definition: AthenaPoolTestAttrWriter.cxx:114
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AthenaPoolTestAttrWriter::~AthenaPoolTestAttrWriter
~AthenaPoolTestAttrWriter()
Algorithm destructor.
Definition: AthenaPoolTestAttrWriter.cxx:35
EventInfo::event_ID
EventID * event_ID()
the unique identification of the event.
Definition: EventInfo/EventInfo/EventInfo.h:210
AthenaPoolTestAttrWriter::m_attributes
AthenaAttributeList * m_attributes
Create attr list at intitialize and use each event.
Definition: AthenaPoolTestAttrWriter.h:57
calibdata.exception
exception
Definition: calibdata.py:496
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthenaAttributeList
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
Definition: PersistentDataModel/PersistentDataModel/AthenaAttributeList.h:45
AthenaPoolTestAttrWriter::execute
virtual StatusCode execute()
Algorithm execute once per event.
Definition: AthenaPoolTestAttrWriter.cxx:64
AthAlgorithm
Definition: AthAlgorithm.h:47
AthenaPoolTestAttrWriter::AthenaPoolTestAttrWriter
AthenaPoolTestAttrWriter(const std::string &name, ISvcLocator *pSvcLocator)
Algorithm constructor.
Definition: AthenaPoolTestAttrWriter.cxx:29
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
EventInfo
This class provides general information about an event. Event information is provided by the accessor...
Definition: EventInfo/EventInfo/EventInfo.h:42
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
DeMoScan.first
bool first
Definition: DeMoScan.py:534
EventID
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
Definition: EventID.h:35
collListGuids.attributes
attributes
Definition: collListGuids.py:46
str
Definition: BTagTrackIpAccessor.cxx:11
AthenaPoolTestAttrWriter::initialize
virtual StatusCode initialize()
Algorithm initialize at begin of job.
Definition: AthenaPoolTestAttrWriter.cxx:38