diff --git a/Event/xAOD/xAODEventInfoCnv/cmt/requirements b/Event/xAOD/xAODEventInfoCnv/cmt/requirements deleted file mode 100644 index 7e236e7a942b1112766deacf45b8a1ac68786f5d..0000000000000000000000000000000000000000 --- a/Event/xAOD/xAODEventInfoCnv/cmt/requirements +++ /dev/null @@ -1,40 +0,0 @@ -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" diff --git a/Event/xAOD/xAODEventInfoCnv/share/xAODEventInfoNonConstCnv_jobOptions.py b/Event/xAOD/xAODEventInfoCnv/share/xAODEventInfoNonConstCnv_jobOptions.py new file mode 100644 index 0000000000000000000000000000000000000000..d6facddef0263843e9963acd442162da4176b38c --- /dev/null +++ b/Event/xAOD/xAODEventInfoCnv/share/xAODEventInfoNonConstCnv_jobOptions.py @@ -0,0 +1,27 @@ +# +# 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 diff --git a/Event/xAOD/xAODEventInfoCnv/src/EventInfoModifierAlg.cxx b/Event/xAOD/xAODEventInfoCnv/src/EventInfoModifierAlg.cxx new file mode 100644 index 0000000000000000000000000000000000000000..114b18dc543c07c429b13b3d040c3844f67e2768 --- /dev/null +++ b/Event/xAOD/xAODEventInfoCnv/src/EventInfoModifierAlg.cxx @@ -0,0 +1,44 @@ +// +// 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 diff --git a/Event/xAOD/xAODEventInfoCnv/src/EventInfoModifierAlg.h b/Event/xAOD/xAODEventInfoCnv/src/EventInfoModifierAlg.h new file mode 100644 index 0000000000000000000000000000000000000000..9168d7a299f2bc57721c5e80332b215ac899086c --- /dev/null +++ b/Event/xAOD/xAODEventInfoCnv/src/EventInfoModifierAlg.h @@ -0,0 +1,40 @@ +// 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 diff --git a/Event/xAOD/xAODEventInfoCnv/src/EventInfoNonConstCnvAlg.cxx b/Event/xAOD/xAODEventInfoCnv/src/EventInfoNonConstCnvAlg.cxx new file mode 100644 index 0000000000000000000000000000000000000000..1f65fe1702bc7735c2049ff17f1e1853a05375c4 --- /dev/null +++ b/Event/xAOD/xAODEventInfoCnv/src/EventInfoNonConstCnvAlg.cxx @@ -0,0 +1,72 @@ +// +// 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 diff --git a/Event/xAOD/xAODEventInfoCnv/src/EventInfoNonConstCnvAlg.h b/Event/xAOD/xAODEventInfoCnv/src/EventInfoNonConstCnvAlg.h new file mode 100644 index 0000000000000000000000000000000000000000..a5c292bbfe2f1b6c901e6555feea5bc471ac61ab --- /dev/null +++ b/Event/xAOD/xAODEventInfoCnv/src/EventInfoNonConstCnvAlg.h @@ -0,0 +1,48 @@ +// 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 diff --git a/Event/xAOD/xAODEventInfoCnv/src/components/xAODEventInfoCnv_entries.cxx b/Event/xAOD/xAODEventInfoCnv/src/components/xAODEventInfoCnv_entries.cxx index aadcfe84b7b923f3a9260dfd93896346eeabbda8..6af48e19f67f8eff5ab0c70e1db36eec57427d1b 100644 --- a/Event/xAOD/xAODEventInfoCnv/src/components/xAODEventInfoCnv_entries.cxx +++ b/Event/xAOD/xAODEventInfoCnv/src/components/xAODEventInfoCnv_entries.cxx @@ -1,4 +1,6 @@ -// $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 )