Commit ce2a5320 authored by Lukas Alexander Heinrich's avatar Lukas Alexander Heinrich Committed by Graeme Stewart
Browse files

actually emit FAILURE when we fail to get the GUID (TrigSerializeCnvSvc-00-00-35-01)

parent ae32a3f0
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef ITRIGSERHELPERBASE_H
#define ITRIGSERHELPERBASE_H
#include "GaudiKernel/IAlgTool.h"
#include <string>
/** @author Jiri.Masik@cern.ch
@class ITrigSerConvHelper
Tool interface for serializer
*/
/** Declaration of the interface ID ( interface id, major version, minor version) */
static const InterfaceID IID_ITrigSerConvHelper("ITrigSerConvHelper", 1 , 0);
class IOpaqueAddress;
class ITrigSerConvHelperBase {
public:
/** @return StatusCode
*/
virtual StatusCode createObj(const std::string &clname, IOpaqueAddress* iAddr, void *&ptr, bool) = 0;
/** @return StatusCode
*/
virtual StatusCode createRep(const std::string &clname, void *ptr, std::vector<uint32_t> &out, bool) = 0;
/**
*/
virtual ~ITrigSerConvHelperBase(){};
};
/**
@class ITrigSerializeConvHelper
AlgTool interface of a helper for converter classes
*/
class ITrigSerializeConvHelper : virtual public ITrigSerConvHelperBase, virtual public IAlgTool
{
public:
// Retrieve interface ID
static const InterfaceID& interfaceID() { return IID_ITrigSerConvHelper; }
};
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef ITRIGSERGUIDHELPERBASE_H
#define ITRIGSERGUIDHELPERBASE_H
#include "GaudiKernel/IAlgTool.h"
#include <string>
/** @author Jiri.Masik@cern.ch
@class ITrigSerGuidHelper
interface for Guid operations
*/
/** Declaration of the interface ID ( interface id, major version, minor version) */
static const InterfaceID IID_ITrigSerGuidHelper("ITrigSerGuidHelper", 1 , 0);
class ITrigSerGuidHelperBase {
public:
/** @return StatusCode
*/
virtual StatusCode ClassNameToInts(const std::string &clname, uint32_t *iarr) = 0;
/** @return StatusCode
*/
virtual StatusCode IntsToClassName(const uint32_t *iarr, std::string &clname) = 0;
/**
*/
virtual ~ITrigSerGuidHelperBase(){};
};
/**
@class ITrigSerGuidHelper
AlgTool interface of a helper for guid operations
*/
class ITrigSerializeGuidHelper : virtual public ITrigSerGuidHelperBase, virtual public IAlgTool
{
public:
// Retrieve interface ID
static const InterfaceID& interfaceID() { return IID_ITrigSerGuidHelper; }
};
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TRIGSERIALIZECONVERSIONSVC_H
#define TRIGSERIALIZECONVERSIONSVC_H
#include "GaudiKernel/IService.h"
#include "GaudiKernel/ConversionSvc.h"
template <class TYPE> class SvcFactory;
static const InterfaceID IID_TrigSerializeCnvSvc("TrigSerializeCnvSvc", 0, 1);
class TrigSerializeCnvSvc : public ConversionSvc {
public:
static long int storageType();
virtual long int repSvcType() const;
static const InterfaceID& interfaceID() { return IID_TrigSerializeCnvSvc; }
virtual StatusCode initialize();
protected:
friend class SvcFactory<TrigSerializeCnvSvc>;
TrigSerializeCnvSvc(const std::string &name, ISvcLocator* svc) :
ConversionSvc(name,svc,storageType()) { }
/*
TrigSerializeCnvSvc(const std::string &name, ISvcLocator* svc) :
IConversionSvc() { }
*/
virtual ~TrigSerializeCnvSvc() {};
};
#endif //
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
/**
* @class TrigSerializeConvHelper
* it is the worker class for templated converters
* non templated code should be concentrated here
* to avoid massive recompilation of the templated code
* @author Jiri Masik <Jiri.Masik@cern.ch>
*/
#ifndef TRIGSERCONVHELPER_H
#define TRIGSERCONVHELPER_H
#include "AthenaBaseComps/AthAlgTool.h"
#include "GaudiKernel/ToolHandle.h"
#include "GaudiKernel/ServiceHandle.h"
#include "TrigSerializeCnvSvc/ITrigSerConvHelper.h"
//fwd
class MsgStream;
class ITrigSerializerToolBase;
class TrigSerTPTool;
class ITrigSerializeGuidHelper;
class StoreGateSvc;
class IClassIDSvc;
class TrigSerializeConvHelper : virtual public ITrigSerializeConvHelper, public AthAlgTool {
public:
TrigSerializeConvHelper(const std::string& name, const std::string& type,
const IInterface* parent);
virtual ~TrigSerializeConvHelper();
StatusCode createObj(const std::string &clname, IOpaqueAddress* iAddr, void *&ptr, bool isxAOD = false);
StatusCode createRep(const std::string &clname, void *ptr, std::vector<uint32_t> &out, bool isxAOD = false);
StatusCode initialize();
private:
ToolHandle< ITrigSerializerToolBase > m_serializerTool;
ToolHandle<TrigSerTPTool> m_TPTool;
ToolHandle<ITrigSerializeGuidHelper> m_guidTool;
bool m_doTP;
std::map<std::string,std::string> m_oldEDMmap;
};
#endif
// Dear emacs, this is -*- c++ -*-
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
// $Id$
#ifndef TRIGSERIALIZECONVERTER_H
#define TRIGSERIALIZECONVERTER_H
#include "GaudiKernel/Converter.h"
#include "GaudiKernel/ToolHandle.h"
#include "GaudiKernel/ServiceHandle.h"
#include "CLIDSvc/tools/ClassID_traits.h"
#include "SGTools/StorableConversions.h"
#include "StoreGate/StoreGateSvc.h"
#include "TrigSerializeCnvSvc/TrigStreamAddress.h"
#include "TrigSerializeCnvSvc/ITrigSerConvHelper.h"
#include "TrigSerializeCnvSvc/TrigSerializeCnvSvc.h"
#include <memory>
//fwd
template< class Cnv >
class CnvFactory;
/***
* @brief TrigSerializeConverter is a templated converter which implements
* conversions from transient to persistent representation (and back)
* used by TrigSerializeCnvSvc to serialize and deserialize Trigger objects
*
* @author Jiri Masik Jiri.Masik@cern.ch
* @author Lukas Heinrich lukas.heinrich@cern.ch
*/
namespace SG{struct AuxElement;}
namespace SG{struct IAuxStore;}
template<typename T>
struct isxAOD {
template<typename C>
constexpr static typename std::enable_if<std::is_base_of<SG::AuxElement,typename std::pointer_traits<typename C::value_type>::element_type>::value,bool>::type isxAODVector(C*){return true;}
template<typename C>
constexpr static bool isxAODVector(...){return false;}
template<typename C>
constexpr static typename std::enable_if<std::is_base_of<SG::IAuxStore,C>::value,bool>::type isAuxVector(C*){return true;}
template<typename C>
constexpr static bool isAuxVector(...){return false;}
static const bool value = isxAODVector<T>(0) || isAuxVector<T>(0);
};
template< typename DATA >
class TrigSerializeConverter : public Converter {
public:
static const bool typeIsxAOD = isxAOD<DATA>::value;
// per->tran
StatusCode createObj( IOpaqueAddress* iAddr, DataObject *& pO ) {
const std::string clname = ClassID_traits< DATA >::typeName();
void *ptr( 0 );
if( m_log->level() <= MSG::DEBUG ) {
*m_log << MSG::DEBUG << "In createObj for : " << clname << endreq;
}
StatusCode sc = m_convHelper->createObj( clname, iAddr, ptr, typeIsxAOD);
if( sc.isFailure() ){
*m_log << MSG::WARNING << "m_convHelper->createObj failed for "
<< clname << endreq;
}
DATA *nObj = ( DATA* ) ptr;
pO = SG::asStorable( nObj );
if( m_log->level() <= MSG::DEBUG ) {
*m_log << MSG::DEBUG << "IOpaq: " << iAddr
<< " created nObj: " << nObj << endreq;
}
if( m_sgsvc && nObj ){
TrigStreamAddress *addr = dynamic_cast< TrigStreamAddress* >( iAddr );
if( addr ) {
if( m_sgsvc->contains< DATA >( addr->sgkey() ) ) {
//std::cout << "NOT OVERWRITING! ptr " << nObj << " key: " << addr->sgkey() << std::endl;
sc = m_sgsvc->overwrite( nObj, addr->sgkey(), false );
} else {
sc = m_sgsvc->record( nObj, addr->sgkey() );
}
if( sc.isFailure() ) {
*m_log << MSG::ERROR << "SG::record failed for " << addr->sgkey()
<< endreq;
} else if( m_log->level() <= MSG::DEBUG ) {
*m_log << MSG::DEBUG << "SG::record key: "
<< addr->sgkey() << " class: " << clname << endreq;
}
} else {
*m_log << MSG::WARNING << "createObj cast failed" << endreq;
}
} else if( m_log->level() <= MSG::DEBUG ) {
*m_log << MSG::DEBUG << "did not put an object into SG" << endreq;
}
return sc;
}
// tran->per
StatusCode createRep( DataObject* pObj, IOpaqueAddress*& pAddr ) {
const std::string clname = ClassID_traits<DATA>::typeName();
DATA *d( 0 );
SG::fromStorable( pObj, d );
if( m_log->level() <= MSG::DEBUG ) {
*m_log << MSG::DEBUG << "My createRep for " << classID() << " "
<< clname << endreq;
}
void *serptr = d;
//
std::vector< uint32_t > ser;
StatusCode sc = m_convHelper->createRep( clname, serptr, ser, typeIsxAOD);
if( m_log->level() <= MSG::DEBUG ) {
*m_log << MSG::DEBUG << "convHelper " << ser.size() << endreq;
}
TrigStreamAddress *addr = new TrigStreamAddress( classID(), clname, "" );
addr->add( ser );
pAddr = addr;
return sc;
}
StatusCode initialize(){
if( m_log ) {
m_log->setLevel( msgSvc()->outputLevel( "TrigSerializeConverter" ) );
} else {
return StatusCode::FAILURE;
}
StatusCode sc = m_convHelper.retrieve();
if( ! sc.isSuccess() ) {
if( m_log->level() <= MSG::DEBUG ) {
*m_log << MSG::DEBUG << m_convHelper << "not retrieved" << endreq;
}
} else {
if( m_log->level() <= MSG::DEBUG ) {
*m_log << MSG::DEBUG << m_convHelper << "m_serializer retrieved"
<< endreq;
}
if( ! m_convHelper->initialize().isSuccess() ) {
if( m_log->level() <= MSG::DEBUG ) {
*m_log << MSG::DEBUG << m_convHelper << " not initialized"
<< endreq;
}
}
}
StatusCode scsg = m_sgHandle.retrieve();
if (scsg.isFailure())
*m_log << MSG::ERROR << "cannot access SG" << endreq;
else {
m_sgsvc = m_sgHandle.operator->();
}
return sc;
}
static const CLID& classID() { return ClassID_traits<DATA>::ID(); }
virtual long int repSvcType() const;
static long int storageType();
protected:
friend class CnvFactory< TrigSerializeConverter< DATA > >;
TrigSerializeConverter( ISvcLocator* svcloc )
: Converter( storageType(), classID(), svcloc ),
m_convHelper( "TrigSerializeConvHelper/TrigSerializeConvHelper" ),
m_sgHandle( "StoreGateSvc", "TrigSerializeConverter" ),
m_log( 0 ), m_sgsvc( 0 ) {
m_log = new MsgStream( msgSvc(), "TrigSerializeConverter" );
}
~TrigSerializeConverter(){
delete m_log;
}
private:
ToolHandle< ITrigSerializeConvHelper > m_convHelper;
ServiceHandle< StoreGateSvc > m_sgHandle;
MsgStream *m_log;
StoreGateSvc *m_sgsvc;
};
template <typename DATA>
long int TrigSerializeConverter<DATA>::storageType() {
return TrigSerializeCnvSvc::storageType();
}
template <typename DATA>
long int TrigSerializeConverter<DATA>::repSvcType() const {
return storageType();
}
#endif // TRIGSERIALIZECONVERTER_H
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TRIGSTREAMCNVSVCBASE_TRIGSTREAMADDRESS_H
#define TRIGSTREAMCNVSVCBASE_TRIGSTREAMADDRESS_H
// Framework include files
#include "GaudiKernel/Kernel.h"
#include "GaudiKernel/StatusCode.h"
#include "GaudiKernel/GenericAddress.h"
#include <stdint.h>
#include <vector>
#include <iostream>
#include <string>
/**
* @class TrigStreamAddress
* @brief IOpaqueAddress for TrigSerializenCnvSvc
*/
class TrigStreamAddress : public GenericAddress {
public:
virtual ~TrigStreamAddress() {};
TrigStreamAddress(const CLID& clid, const std::string& fname,
const std::string& cname, int p1=0,int p2=0 );
TrigStreamAddress(const CLID& clid ) ;
void add(const std::vector<uint32_t> &a);
const std::vector<uint32_t> & get() const;
const std::string sgkey() const { return m_key;}
private:
std::vector<uint32_t> m_rep;
std::string m_key;
};
#endif
package TrigSerializeCnvSvc
use AtlasPolicy AtlasPolicy-*
use GaudiInterface GaudiInterface-* External
use AthenaBaseComps AthenaBaseComps-* Control
use CLIDSvc CLIDSvc-* Control
use SGTools SGTools-* Control
use StoreGate StoreGate-* Control
apply_pattern dual_use_library files=*.cxx
private
use AtlasROOT AtlasROOT-* External
use AtlasPOOL AtlasPOOL-* External
use AtlasReflex AtlasReflex-* External
use AthenaKernel AthenaKernel-* Control
use PersistentDataModel PersistentDataModel-* Database
use TrigSerializeResult TrigSerializeResult-* Trigger/TrigDataAccess
use TrigSerializeTP TrigSerializeTP-* Trigger/TrigDataAccess
end_private
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "TrigSerializeCnvSvc/TrigSerializeCnvSvc.h"
//#include <GaudiKernel/ICnvManager.h>
#include "GaudiKernel/MsgStream.h"
StatusCode TrigSerializeCnvSvc::initialize(){
MsgStream log(msgSvc(), "TrigSerializeCnvSvc");
log << MSG::INFO << "initialize()" << endreq;
/*
ICnvManager::CnvIterator i, stop;
for ( i = cnvManager()->cnvBegin(), stop = cnvManager()->cnvEnd(); i != stop; i++ ) {
if ( repSvcType() == (*i)->repSvcType() ) {
//StatusCode iret = addConverter( *(*i) );
CLID obj = (i)->objType();
StatusCode iret = initializeConverter(storageType(), obj, *(*i) );
}
}
*/
return StatusCode::SUCCESS;
}
long int
TrigSerializeCnvSvc::storageType() {
static long _type(0x51);
return _type;
}
long int TrigSerializeCnvSvc::repSvcType() const {
return storageType();
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "TrigSerializeCnvSvc/TrigSerializeConvHelper.h"
#include "GaudiKernel/MsgStream.h"
#include "GaudiKernel/ClassID.h"
#include "AthenaKernel/getMessageSvc.h"
#include "StoreGate/StoreGateSvc.h"
#include "TrigSerializeCnvSvc/TrigStreamAddress.h"
#include "TrigSerializeResult/ITrigSerializerToolBase.h"
#include "TrigSerializeTP/TrigSerTPTool.h"
#include "TrigSerializeCnvSvc/ITrigSerGuidHelper.h"
//
#include "TROOT.h"
#include "TClass.h"
//
#include "Reflex/Reflex.h"
#include "StorageSvc/DbReflex.h"
using ROOT::Reflex::Type;
using ROOT::Reflex::PropertyList;
TrigSerializeConvHelper::TrigSerializeConvHelper(const std::string& toolname, const std::string& type, const IInterface* parent) :
AthAlgTool(toolname, type, parent),
m_serializerTool("TrigTSerializer/TrigTSerializer"),
m_TPTool("TrigSerTPTool/TrigSerTPTool"),
m_guidTool("TrigSerializeGuidHelper/TrigSerializeGuidHelper"),
m_doTP(true)
{
declareInterface<ITrigSerializeConvHelper>( this );
declareProperty("doTP", m_doTP, "allows to serialize/deserialize transient classes");
}
TrigSerializeConvHelper::~TrigSerializeConvHelper(){
}
StatusCode TrigSerializeConvHelper::initialize(){
StatusCode sc = m_serializerTool.retrieve();
if (!sc.isSuccess()){