ATLAS Offline Software
WriteTag.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
11 #include "WriteTag.h"
12 
16 #include "StoreGate/WriteHandle.h"
17 
18 using namespace AthPoolEx;
19 
20 //___________________________________________________________________________
21 WriteTag::WriteTag(const std::string& name, ISvcLocator* pSvcLocator)
22  : AthReentrantAlgorithm(name, pSvcLocator), m_attribListSpec(0)
23 {
24  declareProperty("Magic", m_magic = 0);
25 }
26 //___________________________________________________________________________
28  if (m_attribListSpec != 0) {
30  }
31 }
32 //___________________________________________________________________________
34  ATH_MSG_INFO("in initialize()");
35 
36  ATH_MSG_DEBUG("Defining the attribute list specification.");
38  m_attribListSpec->extend("RunNumber", "unsigned int");
39  m_attribListSpec->extend("EventNumber", "unsigned int");
40  if (m_magic > 0) {
41  m_attribListSpec->extend("MagicNumber", "unsigned int");
42  }
43  ATH_MSG_DEBUG("Printing out attribute list specification:");
45  ATH_MSG_DEBUG(" name " << (*first).name() << " type " << (*first).typeName());
46  }
47 
50  return StatusCode::SUCCESS;
51 }
52 //___________________________________________________________________________
53 StatusCode WriteTag::execute (const EventContext& ctx) const {
54  ATH_MSG_DEBUG("in execute()");
55 
56  unsigned int eventNumber = ctx.eventID().event_number();
57  unsigned int runNumber = ctx.eventID().run_number();
58  ATH_MSG_INFO("EventInfo event: " << eventNumber << " run: " << runNumber);
59 
60  const AthenaAttributeListSpecification* attribListSpec = m_attribListSpec;
61  auto tagAttribList = std::make_unique<TagAthenaAttributeList>(*attribListSpec);
62  (*tagAttribList)["RunNumber"].data<unsigned int>() = runNumber;
63  (*tagAttribList)["EventNumber"].data<unsigned int>() = eventNumber;
64  if (m_magic > 0) {
65  (*tagAttribList)["MagicNumber"].data<unsigned int>() = m_magic.value();
66  }
67 
68  coral::AttributeListSpecification* cspec = new coral::AttributeListSpecification;
69  m_attribListSpec->coralSpec (*cspec);
70  auto attribList = std::make_unique<AthenaAttributeList>(*cspec);
71  cspec->release();
72  (*attribList)["RunNumber"].data<unsigned int>() = runNumber;
73  (*attribList)["EventNumber"].data<unsigned int>() = eventNumber;
74  if (m_magic > 0) {
75  (*attribList)["MagicNumber"].data<unsigned int>() = m_magic.value();
76  }
77 
80  ATH_CHECK( attribListH.record (std::move(attribList)) );
81  ATH_CHECK( tagAttribListH.record (std::move(tagAttribList)) );
82 
83  ATH_MSG_INFO("registered all data");
84  return StatusCode::SUCCESS;
85 }
86 //___________________________________________________________________________
88  ATH_MSG_INFO("in finalize()");
89  return StatusCode::SUCCESS;
90 }
AthenaAttributeListSpecification
Definition: AthenaAttributeListSpecification.h:42
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthenaAttributeListSpecification.h
AthenaAttributeListSpecification::const_iterator
The iterator class.
Definition: AthenaAttributeListSpecification.h:94
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
AthPoolEx::WriteTag::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: WriteTag.cxx:53
AthPoolEx::WriteTag::WriteTag
WriteTag(const std::string &name, ISvcLocator *pSvcLocator)
Standard Service Constructor.
Definition: WriteTag.cxx:21
AthenaAttributeListSpecification::begin
const_iterator begin() const
Returns a forward iterator.
Definition: AthenaAttributeListSpecification.h:163
AthPoolEx::WriteTag::m_magic
IntegerProperty m_magic
Definition: WriteTag.h:42
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
AthenaAttributeListSpecification::extend
void extend(const std::string &name, const std::string &unitName="UNKNOWN", const std::string &groupName="UNKNOWN")
Appends a new specification.
Definition: AthenaAttributeListSpecification.h:149
WriteHandle.h
Handle class for recording to StoreGate.
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
WriteTag.h
This file contains the class definition for the WriteTag class.
AthenaAttributeListSpecification::end
const_iterator end() const
Definition: AthenaAttributeListSpecification.h:170
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
AthPoolEx::WriteTag::m_key
SG::WriteHandleKey< AthenaAttributeList > m_key
Definition: WriteTag.h:40
AthenaAttributeListSpecification::release
void release() const
Decrements the reference counter.
Definition: AthenaAttributeListSpecification.h:285
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
AthPoolEx::WriteTag::~WriteTag
virtual ~WriteTag()
Destructor.
Definition: WriteTag.cxx:27
AthenaAttributeList.h
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
TagAthenaAttributeList.h
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
DeMoScan.first
bool first
Definition: DeMoScan.py:534
AthPoolEx::WriteTag::m_attribListSpec
AthenaAttributeListSpecification * m_attribListSpec
Specification of the event tag metadata schema.
Definition: WriteTag.h:44
AthPoolEx
Definition: PassNoneFilter.h:16
AthPoolEx::WriteTag::finalize
virtual StatusCode finalize() override
Definition: WriteTag.cxx:87
AthPoolEx::WriteTag::m_tagKey
SG::WriteHandleKey< TagAthenaAttributeList > m_tagKey
Definition: WriteTag.h:41
AthenaAttributeListSpecification::coralSpec
void coralSpec(coral::AttributeListSpecification &) const
Fills a coral Specification.
Definition: AthenaAttributeListSpecification.h:362
AthPoolEx::WriteTag::initialize
virtual StatusCode initialize() override
Gaudi Service Interface method implementations:
Definition: WriteTag.cxx:33