| # Gaudi Framework, version v20r3
Generated: 24 Nov 2008

# PartitionSwitchTool.cpp

Go to the documentation of this file.

    00001 // $Id: PartitionSwitchTool.cpp,v 1.2 2006/01/10 20:09:25 hmd Exp $
    00002
    00003 // Framework include files
    00004 #include "GaudiKernel/AlgTool.h"
    00005 #include "GaudiKernel/SmartIF.h"
    00006 #include "GaudiKernel/MsgStream.h"
    00007 #include "GaudiKernel/Tokenizer.h"
    00008 #include "GaudiKernel/ToolFactory.h"
    00009 #include "GaudiKernel/IPartitionControl.h"
    00010
    00016 class PartitionSwitchTool
    00017   : public AlgTool, virtual public IPartitionControl
    00018 {
    00019
    00020   typedef const std::string& CSTR;
    00021   typedef StatusCode         STATUS;
    00022
    00023 private:
    00024
    00026   std::string                m_actorName;
    00028   SmartIF<IPartitionControl> m_actor;
    00029
    00030 public:
    00031
    00033   PartitionSwitchTool(CSTR typ, CSTR nam, const IInterface* parent)
    00034   : AlgTool(typ, nam , parent)
    00035   {
    00036     // Declaring implemented interfaces
    00037     declareInterface<IPartitionControl>(this);
    00038     declareProperty("Actor", m_actorName = "EventDataService");
    00039   }
    00041   virtual ~PartitionSwitchTool()   {
    00042     m_actor = 0;
    00043   }
    00044
    00046   virtual STATUS queryInterface(const InterfaceID& riid, void** ppvUnknown) {
    00047     if ( IPartitionControl::interfaceID().versionMatch(riid) )
    00048       *ppvUnknown = (IPartitionControl*)this;
    00049     else
    00050       return AlgTool::queryInterface(riid, ppvUnknown);
    00051     addRef();
    00052     return SUCCESS;
    00053   }
    00054
    00056   virtual STATUS initialize()  {
    00058     STATUS sc = AlgTool::initialize();
    00059     MsgStream log(msgSvc(), name());
    00060     if ( !sc.isSuccess() )  {
    00061       log << MSG::ERROR << "Cannot initialize base class!" << endmsg;
    00062       return sc;
    00063     }
    00064     m_actor = 0;
    00065     sc = service(m_actorName, m_actor.pRef());
    00066     if ( !sc.isSuccess() )  {
    00067       log << MSG::ERROR << "Cannot retrieve partition controller \""
    00068           << m_actorName << "\"!" << endmsg;
    00069       return sc;
    00070     }
    00071     return sc;
    00072   }
    00074   virtual STATUS finalize()   {
    00075     m_actor = 0;
    00076     return AlgTool::finalize();
    00077   }
    00078
    00079   void _check(STATUS sc, CSTR msg)  const {
    00080     MsgStream log(msgSvc(), name());
    00081     log << MSG::ERROR << msg << " Status=" << sc.getCode() << endmsg;
    00082   }
    00083 #define CHECK(x,y) if ( !x.isSuccess() ) _check(x, y); return x;
    00084
    00086   virtual STATUS create(CSTR nam, CSTR typ)  {
    00087     STATUS sc = m_actor ? m_actor->create(nam,typ) : NO_INTERFACE;
    00088     CHECK(sc, "Cannot create partition: "+nam+" of type "+typ);
    00089   }
    00091   virtual STATUS create(CSTR nam, CSTR typ, IInterface*& pPartition)  {
    00092     STATUS sc = m_actor ? m_actor->create(nam,typ,pPartition) : NO_INTERFACE;
    00093     CHECK(sc, "Cannot create partition: "+nam+" of type "+typ);
    00094   }
    00096   virtual STATUS drop(CSTR nam)  {
    00097     STATUS sc = m_actor ? m_actor->drop(nam) : NO_INTERFACE;
    00098     CHECK(sc, "Cannot drop partition: "+nam);
    00099   }
    00101   virtual STATUS drop(IInterface* pPartition)  {
    00102     STATUS sc = m_actor ? m_actor->drop(pPartition) : NO_INTERFACE;
    00103     CHECK(sc, "Cannot drop partition by Interface.");
    00104   }
    00106   virtual STATUS activate(CSTR nam)  {
    00107     STATUS sc = m_actor ? m_actor->activate(nam) : NO_INTERFACE;
    00108     CHECK(sc, "Cannot activate partition: "+nam);
    00109   }
    00111   virtual STATUS activate(IInterface* pPartition)  {
    00112     STATUS sc = m_actor ? m_actor->activate(pPartition) : NO_INTERFACE;
    00113     CHECK(sc, "Cannot activate partition by Interface.");
    00114   }
    00116   virtual STATUS get(CSTR nam, IInterface*& pPartition) const  {
    00117     STATUS sc = m_actor ? m_actor->get(nam, pPartition) : NO_INTERFACE;
    00118     CHECK(sc, "Cannot get partition "+nam);
    00119   }
    00121   virtual STATUS activePartition(std::string& nam, IInterface*& pPartition) const  {
    00122     STATUS sc = m_actor ? m_actor->activePartition(nam, pPartition) : NO_INTERFACE;
    00123     CHECK(sc, "Cannot determine active partition.");
    00124   }
    00125 };
    00126
    00127 // Declaration of the Tool Factory
    00128 DECLARE_TOOL_FACTORY(PartitionSwitchTool)