Skip to content
Snippets Groups Projects
Commit 460b2275 authored by Tadej Novak's avatar Tadej Novak
Browse files

Cleanup EventInfoTagBuilder

parent 83904e48
No related branches found
No related tags found
No related merge requests found
......@@ -47,8 +47,9 @@ def createOutputStream( streamName, fileName = "", asAlg = False, noTag = False,
# Tell tool to pick it up
outputStream.WritingTool.AttributeListKey=key
# build eventinfo attribute list
from .OutputStreamAthenaPoolConf import EventInfoTagBuilder
EventInfoTagBuilder = EventInfoTagBuilder(AttributeList=key, EventInfoKey=eventInfoKey, FilterString=decisionFilter)
from .OutputStreamAthenaPoolConf import EventInfoAttListTool, EventInfoTagBuilder
EventInfoTagBuilder = EventInfoTagBuilder(AttributeList=key, EventInfoKey=eventInfoKey, FilterString=decisionFilter,
Tool=EventInfoAttListTool())
from AthenaCommon.GlobalFlags import globalflags
if globalflags.InputFormat() == 'bytestream':
#No event-tag input in bytestream
......
......@@ -56,8 +56,8 @@ def OutputStreamCfg(configFlags, streamName, ItemList=[], disableEventTag=False
outputStream.WritingTool.AttributeListKey=key
# build eventinfo attribute list
EventInfoAttListTool, EventInfoTagBuilder=CompFactory.getComps("EventInfoAttListTool","EventInfoTagBuilder",)
result.addPublicTool(EventInfoAttListTool())
tagBuilder = EventInfoTagBuilder(AttributeList=key)
tagBuilder = EventInfoTagBuilder(AttributeList=key,
Tool=EventInfoAttListTool())
result.addEventAlgo(tagBuilder)
# For xAOD output
......
......@@ -4,84 +4,77 @@
#include "EventInfoTagBuilder.h"
#include "StoreGate/ReadHandle.h"
#include "StoreGate/WriteHandle.h"
EventInfoTagBuilder::EventInfoTagBuilder( const std::string& name, ISvcLocator* pSvcLocator )
: AthAlgorithm(name, pSvcLocator),
m_tool("EventInfoAttListTool/EventInfoAttListTool",this) {
declareProperty("EventInfoKey", m_evtKey = "EventInfo");
declareProperty("InputList", m_inputAttList = "Input");
declareProperty("AttributeList", m_attributeListName);
declareProperty("PropagateInput", m_propInput = true);
declareProperty("FilterString", m_filter = "");
#include <StoreGate/ReadHandle.h>
#include <StoreGate/WriteHandle.h>
EventInfoTagBuilder::EventInfoTagBuilder( const std::string& name, ISvcLocator* pSvcLocator )
: AthAlgorithm(name, pSvcLocator)
{
}
EventInfoTagBuilder::~EventInfoTagBuilder()
{}
StatusCode EventInfoTagBuilder::initialize() {
StatusCode EventInfoTagBuilder::initialize()
{
ATH_MSG_DEBUG( "Initializing " << name() );
if (m_attributeListName.empty()) {
ATH_MSG_ERROR("Output attribute list name should not be empty.");
return StatusCode::FAILURE;
}
ATH_CHECK( m_tool.retrieve() );
ATH_CHECK( m_evtKey.initialize() );
ATH_CHECK( m_attributeListName.initialize() );
ATH_CHECK( m_inputAttList.initialize() );
ATH_CHECK( m_attributeListName.initialize() );
return StatusCode::SUCCESS;
}
StatusCode EventInfoTagBuilder::execute() {
StatusCode EventInfoTagBuilder::execute()
{
ATH_MSG_DEBUG( "Executing " << name() );
SG::ReadHandle<xAOD::EventInfo> h_evt(m_evtKey);
if (!h_evt.isValid()) {
ATH_MSG_ERROR("Did not find xAOD::EventInfo");
return StatusCode::FAILURE;
}
/** create a EventInfo Tag and ask the tool to fill it */
if (h_evt.isValid()) {
std::unique_ptr<AthenaAttributeList> attribList =
m_tool->getAttributeListPtr( *h_evt );
// Check whether to propagate
if (m_propInput) {
SG::ReadHandle<AthenaAttributeList> h_att(m_inputAttList);
// Check if there is an input to propagate
if (h_att.isValid()) {
for (auto it = h_att->specification().begin();
it!= h_att->specification().end(); ++it) {
// Only propagate bool properties
if (it->typeName()=="bool"&&!attribList->exists(it->name())) {
// Check if there is filtering on the name
if (m_filter != "") {
if (it->name().find(m_filter)!=std::string::npos) {
// Add those bools to the output attribute list
(*attribList).extend(it->name(),it->type());
(*attribList)[it->name()].data<bool>() = (*h_att)[it->name()].data<bool>();
}
/** create a EventInfo Tag and ask the tool to fill it */
std::unique_ptr<AthenaAttributeList> attribList =
m_tool->getAttributeListPtr( *h_evt );
// Check whether to propagate
if (m_propInput) {
SG::ReadHandle<AthenaAttributeList> h_att(m_inputAttList);
// Check if there is an input to propagate
if (h_att.isValid()) {
for (auto it = h_att->specification().begin();
it!= h_att->specification().end(); ++it) {
// Only propagate bool properties
if (it->typeName()=="bool"&&!attribList->exists(it->name())) {
// Check if there is filtering on the name
if (m_filter != "") {
if (it->name().find(m_filter)!=std::string::npos) {
// Add those bools to the output attribute list
(*attribList).extend(it->name(),it->type());
(*attribList)[it->name()].data<bool>() = (*h_att)[it->name()].data<bool>();
}
} // take only bools
} // loop
} else { // valid input
ATH_MSG_INFO("No input attribute list");
}
} // propagate
/** record attribute list to SG */
SG::WriteHandle<AthenaAttributeList> wh(m_attributeListName);
ATH_CHECK( wh.record(std::move(attribList)) );
} else {
ATH_MSG_WARNING("Did not find xAOD::EventInfo");
}
}
} // take only bools
} // loop
} else { // valid input
ATH_MSG_INFO("No input attribute list");
}
} // propagate
/** record attribute list to SG */
SG::WriteHandle<AthenaAttributeList> wh(m_attributeListName);
ATH_CHECK( wh.record(std::move(attribList)) );
ATH_MSG_DEBUG( "Finished " << name() );
return StatusCode::SUCCESS;
}
StatusCode EventInfoTagBuilder::finalize()
{
return StatusCode::SUCCESS;
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#ifndef EVENTTAGALGS_EVENTINFOTAGBUILDER_H
......@@ -14,8 +14,8 @@ Updated : February 2006
DESCRIPTION:
Retrieves event tag data from an AOD file, stores this data in an attribute
list object and records the attribute list object in the TDS for subsequent
Retrieves event tag data from an AOD file, stores this data in an attribute
list object and records the attribute list object in the TDS for subsequent
inclusion in an event tag database.
*****************************************************************************/
......@@ -27,37 +27,39 @@ inclusion in an event tag database.
*/
#include "AthenaBaseComps/AthAlgorithm.h"
#include <AthenaBaseComps/AthAlgorithm.h>
#include <GaudiKernel/ToolHandle.h>
#include <PersistentDataModel/AthenaAttributeList.h>
#include <StoreGate/ReadHandleKey.h>
#include <StoreGate/WriteHandleKey.h>
#include <xAODEventInfo/EventInfo.h>
#include "EventInfoAttListTool.h"
#include "StoreGate/ReadHandleKey.h"
#include "StoreGate/WriteHandleKey.h"
#include "xAODEventInfo/EventInfo.h"
#include "PersistentDataModel/AthenaAttributeList.h"
#include "GaudiKernel/ToolHandle.h"
class EventInfoTagBuilder : public AthAlgorithm {
class EventInfoTagBuilder : public AthAlgorithm
{
public:
/// Standard constructor.
EventInfoTagBuilder(const std::string& name, ISvcLocator* pSvcLocator);
/// Destructor.
~EventInfoTagBuilder();
StatusCode initialize();
StatusCode execute();
StatusCode finalize();
~EventInfoTagBuilder() = default;
virtual StatusCode initialize() override;
virtual StatusCode execute() override;
private:
/// Global Event Tag Tool
ToolHandle<EventInfoAttListTool> m_tool;
ToolHandle<EventInfoAttListTool> m_tool{this, "Tool", "EventInfoAttListTool/EventInfoAttListTool", "EventInfoAttListTool used"};
SG::ReadHandleKey<xAOD::EventInfo> m_evtKey{this, "EventInfoKey", "EventInfo", "xAOD::EventInfo ReadHandleKey"};
SG::ReadHandleKey<AthenaAttributeList> m_inputAttList{this, "InputList", "Input", "Input Athena attribute list ReadHandleKey"};
SG::WriteHandleKey<AthenaAttributeList> m_attributeListName{this, "AttributeList", "SimpleTag", "Output Athena attribute list WriteHandleKey"};
SG::ReadHandleKey<xAOD::EventInfo> m_evtKey;
SG::ReadHandleKey<AthenaAttributeList> m_inputAttList;
SG::WriteHandleKey<AthenaAttributeList> m_attributeListName;
bool m_propInput;
std::string m_filter;
Gaudi::Property<bool> m_propInput{this, "PropagateInput", true, "Propagate input attribute list to the output"};
Gaudi::Property<std::string> m_filter{this, "FilterString", "", "Filter input attribute list when propagating to the output"};
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment