Skip to content
Snippets Groups Projects
Commit 0d34eafb authored by Andrea Abba's avatar Andrea Abba Committed by Graeme Stewart
Browse files

Add a missing #include. (OverlayAlgBase-00-01-05)

parent d1b2612a
No related branches found
No related tags found
No related merge requests found
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
// Dear emacs, this is -*-c++-*-
/**
* @file
*
* A resource-acquisition-in-initialization class, which can be used
* in a code that manipulates active store to guarantee that
* ActiveStoreSvc is set back to the state expected by the rest of the
* program.
*
* @author Andrei Gaponenko, 2006
*/
#ifndef ACTIVE_STORE_SWITCHER_H
#define ACTIVE_STORE_SWITCHER_H
#include "StoreGate/ActiveStoreSvc.h"
class StoreGateSvc;
class ActiveStoreSwitcher {
ActiveStoreSvc *m_aSvc;
StoreGateSvc *m_oldStore;
public:
ActiveStoreSwitcher(ActiveStoreSvc *aSvc, StoreGateSvc *newStore)
: m_aSvc(aSvc), m_oldStore( aSvc->operator->() )
{
m_aSvc->setStore(newStore);
}
~ActiveStoreSwitcher()
{
m_aSvc->setStore(m_oldStore);
}
};
#endif/*ACTIVE_STORE_SWITCHER_H*/
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
// Dear emacs, this is -*-c++-*-
/**
* @file
*
* Code to set up access to two StoreGate-s for overlaying algorithms.
* Factored out from InDetOverlay.
*
* @author Andrei Gaponenko, 2006-2009
*/
#ifndef OVERLAYALGBASE_H
#define OVERLAYALGBASE_H
#include <string>
#include "GaudiKernel/Algorithm.h"
#include "GaudiKernel/ServiceHandle.h"
#include "AthenaBaseComps/AthMessaging.h"
class StoreGateSvc;
/**
* This class sets up acces to the two event stores and makes sure
* they are syncronized. It also handles McEventCollection.
*
* Algorithms inheriting from OverlayAlgBase should not redefine
* initialize(), execute() and finalize() but provide
* overlayInitialize() etc. instead.
*/
class OverlayAlgBase : public Algorithm,
public AthMessaging
{
public:
OverlayAlgBase(const std::string &name,ISvcLocator *pSvcLocator);
virtual StatusCode initialize();
virtual StatusCode execute();
virtual StatusCode finalize();
//----------------
virtual StatusCode overlayInitialize() = 0;
virtual StatusCode overlayExecute() = 0;
virtual StatusCode overlayFinalize() = 0;
protected:
// ----------------------------------------------------------------
ServiceHandle<StoreGateSvc> m_storeGateData;
ServiceHandle<StoreGateSvc> m_storeGateMC;
ServiceHandle<StoreGateSvc> m_storeGateOutput;
template<class TypeToBeRemoved> void removeAllObjectsOfType(StoreGateSvc *sg);
template<class TypeToBeCopied> void copyAllObjectsOfType(StoreGateSvc *to, StoreGateSvc *from);
};
#include "OverlayAlgBase/OverlayAlgBase.icc"
#endif/*OVERLAYALGBASE_H*/
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "StoreGate/DataHandle.h"
#include "StoreGate/StoreGateSvc.h"
#include "AthenaBaseComps/AthMsgStreamMacros.h"
#include <typeinfo>
//================================================================
template <class TypeToBeRemoved>
void OverlayAlgBase::removeAllObjectsOfType(StoreGateSvc* sg) {
// could use: templateClassName = abi::__cxa_demangle(typeid(TypeToBeRemoved).name(), 0, 0, &status);
// but this would be gcc-specific. So templateClassName is mangled on the output.
const std::string templateClassName = typeid(TypeToBeRemoved).name();
const DataHandle<TypeToBeRemoved> data;
const DataHandle<TypeToBeRemoved> dataEnd;
if(sg->retrieve(data, dataEnd).isSuccess()) {
ATH_MSG_DEBUG("removeAllObjectsOfType<"<<templateClassName<<">(): retrieved data for removal");
for( ; data != dataEnd; data++ ) {
ATH_MSG_DEBUG("removeAllObjectsOfType<"<<templateClassName<<">(): Working on p="<<data.cptr()<<", key="<<sg->proxy(data.cptr())->name());
if(!sg->removeDataAndProxy(data.cptr()).isSuccess()) {
ATH_MSG_WARNING("removeAllObjectsOfType<"<<templateClassName<<">(): problem removing object p="<<data.cptr()<<", key="<<sg->proxy(data.cptr())->name());
}
}
}
else {
ATH_MSG_WARNING("removeAllObjectsOfType<"<<templateClassName<<">(): Problem retrieving data for removal");
}
}
//================================================================
template <class TypeToBeCopied>
void OverlayAlgBase::copyAllObjectsOfType(StoreGateSvc* to, StoreGateSvc *from) {
// could use: templateClassName = abi::__cxa_demangle(typeid(TypeToBeCopied).name(), 0, 0, &status);
// but this would be gcc-specific. So templateClassName is mangled on the output.
const std::string templateClassName = typeid(TypeToBeCopied).name();
typedef std::vector<std::string> KeyList;
KeyList keys = from->keys<TypeToBeCopied>();
if(keys.empty()) {
ATH_MSG_WARNING("copyAllObjectsOfType<"<<templateClassName<<">(): no keys found");
}
for(KeyList::const_iterator k=keys.begin(); k!=keys.end(); ++k) {
std::auto_ptr<TypeToBeCopied> ap(from->retrievePrivateCopy<TypeToBeCopied>(*k));
ATH_MSG_DEBUG("copyAllObjectsOfType<"<<templateClassName<<">(): Working on p="<<ap.get()<<", key="<<*k);
if(!to->record(ap, *k).isSuccess()) {
ATH_MSG_WARNING("copyAllObjectsOfType<"<<templateClassName<<">(): problem recording object p="<<ap.get()<<", key="<<*k);
}
}
}
//================================================================
package OverlayAlgBase
author Andrei Gaponenko <agaponenko@lbl.gov>
use AtlasPolicy AtlasPolicy-*
use GaudiInterface GaudiInterface-* External
use StoreGate StoreGate-* Control
use AthenaBaseComps AthenaBaseComps-* Control
apply_pattern installed_library
library OverlayAlgBase *.cxx
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
// Andrei Gaponenko, 2006-2009
#include "OverlayAlgBase/OverlayAlgBase.h"
#include "AthenaBaseComps/AthMsgStreamMacros.h"
#include "StoreGate/StoreGateSvc.h"
//================================================================
OverlayAlgBase::OverlayAlgBase(const std::string &name, ISvcLocator *pSvcLocator) :
Algorithm(name, pSvcLocator),
AthMessaging( msgSvc(), name),
m_storeGateData("StoreGateSvc/OriginalEvent_SG", name),
m_storeGateMC("StoreGateSvc/BkgEvent_0_SG", name),
m_storeGateOutput("StoreGateSvc/StoreGateSvc", name)
{
declareProperty("DataStore", m_storeGateData, "help");
declareProperty("MCStore", m_storeGateMC, "help");
declareProperty("OutputStore", m_storeGateOutput, "help");
}
//================================================================
StatusCode OverlayAlgBase::initialize()
{
ATH_MSG_DEBUG("OverlayAlgBase::initialize()");
if (m_storeGateData.retrieve().isFailure()) {
ATH_MSG_FATAL("OverlayAlgBase::initialize): StoreGate[data] service not found !");
return StatusCode::FAILURE;
}
if (m_storeGateMC.retrieve().isFailure()) {
ATH_MSG_FATAL("OverlayAlgBase::initialize): StoreGate[MC] service not found !");
return StatusCode::FAILURE;
}
if (m_storeGateOutput.retrieve().isFailure()) {
ATH_MSG_FATAL("OverlayAlgBase::initialize): StoreGate[output] service not found !");
return StatusCode::FAILURE;
}
// Call initialization() of a derived class.
return overlayInitialize();
}
//================================================================
StatusCode OverlayAlgBase::execute() {
ATH_MSG_DEBUG("OverlayAlgBase::execute() begin. Calling derived class execute()");
StatusCode ret = overlayExecute();
ATH_MSG_DEBUG("OverlayAlgBase::execute() end");
return ret;
}
//================================================================
StatusCode OverlayAlgBase::finalize() {
return overlayFinalize();
}
//================================================================
//EOF
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