Skip to content
Snippets Groups Projects
Commit 2762a708 authored by James Beacham's avatar James Beacham Committed by Atlas Nightlybuild
Browse files

Merge branch 'xAODEventInfoNonConstCnvAlg-21.0-20181109' into '21.0'

Adding EventInfoNonConstCnvAlg, 21.0 branch (2018.11.09.)

See merge request atlas/athena!15794

(cherry picked from commit 48f6fe74 [formerly c311c830a6c770d39e85c8eb16d226845949733a])

dc5c875e Introduced the xAODMaker::EventInfoNonConstCnvAlg algorithm.

Former-commit-id: 3bd0752518cc6ee915dc41473f737744dba6edf5
parent f5551669
No related branches found
No related tags found
No related merge requests found
package xAODEventInfoCnv
# $Id: requirements 769747 2016-08-24 08:07:58Z will $
author Attila Krasznahorkay
public
use AtlasPolicy AtlasPolicy-*
use xAODCnvInterfaces xAODCnvInterfaces-* Event/xAOD
private
use GaudiInterface GaudiInterface-* External
use AthenaBaseComps AthenaBaseComps-* Control
use AthenaKernel AthenaKernel-* Control
use AthenaPoolUtilities AthenaPoolUtilities-* Database/AthenaPOOL
#use InDetBeamSpotService InDetBeamSpotService-* InnerDetector/InDetConditions
use_ifndef pplist="XAOD_ANALYSIS" pkg="InnerDetector/InDetConditions/InDetBeamSpotService"
#use LumiBlockComps LumiBlockComps-* LumiBlock
use_ifndef pplist="XAOD_ANALYSIS" pkg="LumiBlock/LumiBlockComps"
use xAODEventInfo xAODEventInfo-* Event/xAOD
use EventInfo EventInfo-* Event
use xAODTruth xAODTruth-* Event/xAOD
end_private
# Declare the library:
library xAODEventInfoCnv *.cxx components/*.cxx
apply_pattern component_library
# Install the additional files:
apply_pattern declare_python_modules files="*.py"
apply_pattern declare_joboptions files="*.py"
#
# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
#
# Set up the reading of a file.
FNAME = '/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/CommonInputs/DAOD_PHYSVAL/mc16_13TeV.410501.PowhegPythia8EvtGen_A14_ttbar_hdamp258p75_nonallhad.DAOD_PHYSVAL.e5458_s3126_r9364_r9315_AthDerivation-21.2.1.0.root'
import AthenaPoolCnvSvc.ReadAthenaPool
ServiceMgr.EventSelector.InputCollections = [ FNAME ]
# Access the algorithm sequence.
from AthenaCommon.AlgSequence import AlgSequence
theJob = AlgSequence()
# Set up the algorithm making the xAOD::EventInfo object non-const.
from AthenaCommon import CfgMgr
theJob += CfgMgr.xAODMaker__EventInfoNonConstCnvAlg( 'EventInfoNonConstCnvAlg',
OutputLevel = VERBOSE )
# Set up the algorithm that tries to now modify the object.
theJob += CfgMgr.xAODReader__EventInfoModifierAlg( 'EventInfoModifierAlg',
OutputLevel = VERBOSE )
# Tweak the job a bit more.
from AthenaCommon.AppMgr import theApp
theApp.EvtMax = 10
ServiceMgr.MessageSvc.OutputLevel = INFO
ServiceMgr.MessageSvc.defaultLimit = 1000000
//
// Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
//
// Local include(s).
#include "EventInfoModifierAlg.h"
// EDM include(s).
#include "xAODEventInfo/EventInfo.h"
namespace xAODReader {
EventInfoModifierAlg::EventInfoModifierAlg( const std::string& name,
ISvcLocator* svcLoc )
: AthAlgorithm( name, svcLoc ) {
// Declare the algorithm's properties.
declareProperty( "EventInfoKey", m_key = "EventInfo",
"Event store key for the xAOD::EventInfo object to "
"modify" );
}
StatusCode EventInfoModifierAlg::execute() {
// Retrieve a non-const pointer to the event info.
xAOD::EventInfo* ei = nullptr;
ATH_CHECK( evtStore()->retrieve( ei, m_key ) );
ATH_MSG_VERBOSE( "Retrieved a non-const xAOD::EventInfo object "
"with key \"" << m_key << "\"" );
// Now try to modify the object.
ei->setRunNumber( ei->runNumber() + 1 );
ei->setEventNumber( ei->eventNumber() - 1 );
if( ei->isAvailable< uint32_t >( "mvEventNumber" ) ) {
ei->setMCEventNumber( ei->mcEventNumber() + 2 );
}
ATH_MSG_VERBOSE( "Modified some static and dynamic properties of \""
<< m_key << "\"" );
// Return gracefully.
return StatusCode::SUCCESS;
}
} // namespace xAODReader
// Dear emacs, this is -*- c++ -*-
//
// Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
//
#ifndef XAODEVENTINFOCNV_EVENTINFOMODIFIERALG_H
#define XAODEVENTINFOCNV_EVENTINFOMODIFIERALG_H
// System include(s).
#include <string>
// Gaudi/Athena include(s).
#include "AthenaBaseComps/AthAlgorithm.h"
namespace xAODReader {
/// Algorithm making modifications to a non-const @c xAOD::EventInfo
///
/// This algorithm is here to allow for some tests that modify an
/// @c xAOD::EventInfo object. That was created some "some way".
///
/// @author Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch>
///
class EventInfoModifierAlg final : public AthAlgorithm {
public:
/// Algorithm constructor
EventInfoModifierAlg( const std::string& name, ISvcLocator* svcLoc );
/// Function executing the algorithm
virtual StatusCode execute() override;
private:
/// Key for the xAOD::EventInfo object
std::string m_key;
}; // class EventInfoModifierAlg
} // namespace xAODReader
#endif // XAODEVENTINFOCNV_EVENTINFOMODIFIERALG_H
//
// Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
//
// Local include(s).
#include "EventInfoNonConstCnvAlg.h"
// EDM include(s).
#include "xAODEventInfo/EventInfo.h"
#include "xAODEventInfo/EventAuxInfo.h"
// System include(s).
#include <memory>
namespace xAODMaker {
EventInfoNonConstCnvAlg::EventInfoNonConstCnvAlg( const std::string& name,
ISvcLocator* svcLoc )
: AthAlgorithm( name, svcLoc ) {
// Declare the algorithm's properties.
declareProperty( "EventInfoKey", m_key = "EventInfo",
"Event store key for the xAOD::EventInfo object to "
"modify" );
}
StatusCode EventInfoNonConstCnvAlg::execute() {
// Check if xAOD::EventInfo is available.
if( ! evtStore()->contains< xAOD::EventInfo >( m_key ) ) {
// If not, then let's just stop right away.
ATH_MSG_VERBOSE( "No xAOD::EventInfo with key \"" << m_key << "\"" );
return StatusCode::SUCCESS;
}
// Retrieve the const object.
const xAOD::EventInfo* ei = nullptr;
ATH_CHECK( evtStore()->retrieve( ei, m_key ) );
// Check if it's already set up to be modifiable.
if( ei->getStore() ) {
// If so, let's assume that SG will also let the object be retrieved
// as a non-const pointer.
ATH_MSG_VERBOSE( "xAOD::EventInfo with key \"" << m_key
<< "\" seems to be modifiable -> not touching it" );
return StatusCode::SUCCESS;
}
// Access the aux container as well now.
const xAOD::EventAuxInfo* aux = nullptr;
ATH_CHECK( evtStore()->retrieve( aux, m_key + "Aux." ) );
// Make a deep copy of the object.
auto newei = std::make_unique< xAOD::EventInfo >();
auto newaux = std::make_unique< xAOD::EventAuxInfo >();
newei->setStore( newaux.get() );
*newei = *ei;
ATH_MSG_VERBOSE( "Made a deep copy of \"" << m_key << "\"" );
// Overwrite the original object with its deep copy.
static const bool ALLOW_MODS = true;
ATH_CHECK( evtStore()->overwrite( std::move( newei ), m_key,
ALLOW_MODS ) );
ATH_CHECK( evtStore()->overwrite( std::move( newaux ), m_key + "Aux.",
ALLOW_MODS ) );
ATH_MSG_VERBOSE( "Overwrote \"" << m_key << "\" with its deep copy" );
// Return gracefully.
return StatusCode::SUCCESS;
}
} // namespace xAODMaker
// Dear emacs, this is -*- c++ -*-
//
// Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
//
#ifndef XAODEVENTINFOCNV_EVENTINFONONCONSTCNVALG_H
#define XAODEVENTINFOCNV_EVENTINFONONCONSTCNVALG_H
// System include(s).
#include <string>
// Gaudi/Athena include(s).
#include "AthenaBaseComps/AthAlgorithm.h"
namespace xAODMaker {
/// Algorithm making a const @c xAOD::EventInfo object non-const
///
/// In jobs that process an input file which already has an
/// @c xAOD::EventInfo object in it, which itself has information that we
/// need to keep, but the job wants to further modify that object, we need
/// to make sure that algorithms are able to do those modifications.
///
/// This algorithm can be used to make the @c xAOD::EventInfo object in
/// StoreGate modifiable.
///
/// Note that this implementation is *only* meant for 21.X. For release
/// 22.X we will take care of this a bit differently.
///
/// @author Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch>
///
class EventInfoNonConstCnvAlg final : public AthAlgorithm {
public:
/// Algorithm constructor
EventInfoNonConstCnvAlg( const std::string& name, ISvcLocator* svcLoc );
/// Function executing the algorithm
virtual StatusCode execute() override;
private:
/// Key for the xAOD::EventInfo object
std::string m_key;
}; // class EventInfoNonConstCnvAlg
} // namespace xAODMaker
#endif // XAODEVENTINFOCNV_EVENTINFONONCONSTCNVALG_H
// $Id: xAODEventInfoCnv_entries.cxx 769747 2016-08-24 08:07:58Z will $
//
// Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
//
// Gaudi/Athena include(s):
#include "GaudiKernel/DeclareFactoryEntries.h"
......@@ -9,6 +11,8 @@
#include "../EventInfoCnvAlg.h"
#include "../EventInfoReaderAlg.h"
#include "../EventDuplicateFinderAlg.h"
#include "../EventInfoNonConstCnvAlg.h"
#include "../EventInfoModifierAlg.h"
#include "../EventInfoMCWeightFixAlg.h"
......@@ -17,6 +21,8 @@ DECLARE_NAMESPACE_TOOL_FACTORY( xAODMaker, EventInfoSelectorTool )
DECLARE_NAMESPACE_ALGORITHM_FACTORY( xAODMaker, EventInfoCnvAlg )
DECLARE_NAMESPACE_ALGORITHM_FACTORY( xAODReader, EventInfoReaderAlg )
DECLARE_NAMESPACE_ALGORITHM_FACTORY( xAODReader, EventDuplicateFinderAlg )
DECLARE_NAMESPACE_ALGORITHM_FACTORY( xAODMaker, EventInfoNonConstCnvAlg )
DECLARE_NAMESPACE_ALGORITHM_FACTORY( xAODReader, EventInfoModifierAlg )
DECLARE_ALGORITHM_FACTORY( EventInfoMCWeightFixAlg )
......@@ -27,6 +33,8 @@ DECLARE_FACTORY_ENTRIES( xAODEventInfoCnv ) {
DECLARE_NAMESPACE_ALGORITHM( xAODMaker, EventInfoCnvAlg )
DECLARE_NAMESPACE_ALGORITHM( xAODReader, EventInfoReaderAlg )
DECLARE_NAMESPACE_ALGORITHM( xAODReader, EventDuplicateFinderAlg )
DECLARE_NAMESPACE_ALGORITHM( xAODMaker, EventInfoNonConstCnvAlg )
DECLARE_NAMESPACE_ALGORITHM( xAODReader, EventInfoModifierAlg )
DECLARE_ALGORITHM( EventInfoMCWeightFixAlg )
......
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