Gaudi Framework, version v20r4

Generated: 8 Jan 2009

PartitionSwitchAlg.cpp

Go to the documentation of this file.
00001 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiSvc/src/DataSvc/PartitionSwitchAlg.cpp,v 1.2 2006/01/19 07:27:21 mato Exp $
00002 //      ====================================================================
00003 //  PartitionSwitchAlg.cpp
00004 //      --------------------------------------------------------------------
00005 //
00006 //      Author    : Markus Frank
00007 //
00008 //      ====================================================================
00009 #include "GaudiKernel/IPartitionControl.h"
00010 #include "GaudiKernel/AlgFactory.h"
00011 #include "GaudiKernel/Algorithm.h"
00012 #include "GaudiKernel/MsgStream.h"
00013 #include "GaudiKernel/IToolSvc.h"
00014 #include "GaudiKernel/IAlgTool.h"
00015 #include "GaudiKernel/SmartIF.h"
00016 
00026 class PartitionSwitchAlg : public Algorithm, virtual public IPartitionControl {
00027 
00028   typedef StatusCode         STATUS;
00029   typedef const std::string& CSTR;
00030 
00031 private:
00032 
00034   std::string        m_partName;
00036   std::string        m_toolType;
00038   IPartitionControl* m_actor;
00039 
00040 public:
00041 
00043   PartitionSwitchAlg(CSTR name, ISvcLocator* pSvcLocator)
00044   :     Algorithm(name, pSvcLocator), m_actor(0)
00045   {
00046     declareProperty("Partition",  m_partName);
00047     declareProperty("Tool",       m_toolType="PartitionSwitchTool");
00048   }
00050   virtual ~PartitionSwitchAlg()     {
00051   }
00052   
00054   virtual STATUS queryInterface(const InterfaceID& riid, void** ppvUnknown) {
00055     if ( IPartitionControl::interfaceID().versionMatch(riid) )
00056       *ppvUnknown = (IPartitionControl*)this;
00057     else 
00058       return Algorithm::queryInterface(riid, ppvUnknown);
00059     addRef();
00060     return SUCCESS;
00061   }
00062 
00064   virtual STATUS initialize()   {
00065     MsgStream log(msgSvc(), name());
00066     SmartIF<IAlgTool> tool(m_actor);
00067     STATUS sc = toolSvc()->retrieveTool(m_toolType,m_actor,this);
00068     if ( sc.isFailure() ) {
00069       log << MSG::ERROR << "Unable to load PartitionSwitchTool " 
00070           << m_toolType << endmsg;
00071       return sc;
00072     }
00074     if ( tool ) toolSvc()->releaseTool(tool);
00076     IInterface* partititon = 0;
00077     sc = m_actor->get(m_partName, partititon);
00078     if ( !sc.isSuccess() )  {
00079       log << MSG::ERROR << "Cannot access partition \""
00080           << m_partName << "\"" << endmsg;
00081     }
00082     return sc;
00083   }
00084 
00086   virtual STATUS finalize() {
00087     SmartIF<IAlgTool> tool(m_actor);
00088     if ( tool ) toolSvc()->releaseTool(tool);
00089     m_actor = 0;
00090     return STATUS::SUCCESS;
00091   }
00092 
00094   virtual STATUS execute()    {
00095     if ( m_actor )  {
00096       STATUS sc = m_actor->activate(m_partName);
00097       if ( !sc.isSuccess() )  {
00098         MsgStream log(msgSvc(), name());
00099         log << MSG::ERROR << "Cannot activate partition \""
00100             << m_partName << "\"!" << endmsg;
00101       }
00102       return sc;
00103     }
00104     MsgStream log(msgSvc(), name());
00105     log << MSG::ERROR << "The partition control tool \"" << name()
00106         << "." << m_toolType << "\" cannot be accessed!" << endmsg;
00107     return STATUS::FAILURE;
00108   }
00109 
00110   void _check(STATUS sc, CSTR msg)  const {
00111     MsgStream log(msgSvc(), name());
00112     log << MSG::ERROR << msg << " Status=" << sc.getCode() << endmsg;
00113   }
00114 #define CHECK(x,y) if ( !x.isSuccess() ) _check(x, y); return x;
00115     
00117   virtual STATUS create(CSTR nam, CSTR typ)  {
00118     STATUS sc = m_actor ? m_actor->create(nam,typ) : NO_INTERFACE;
00119     CHECK(sc, "Cannot create partition: "+nam+" of type "+typ);
00120   }
00122   virtual STATUS create(CSTR nam, CSTR typ, IInterface*& pPartition)  {
00123     STATUS sc = m_actor ? m_actor->create(nam,typ,pPartition) : NO_INTERFACE;
00124     CHECK(sc, "Cannot create partition: "+nam+" of type "+typ);
00125   }
00127   virtual STATUS drop(CSTR nam)  {
00128     STATUS sc = m_actor ? m_actor->drop(nam) : NO_INTERFACE;
00129     CHECK(sc, "Cannot drop partition: "+nam);
00130   }
00132   virtual STATUS drop(IInterface* pPartition)  {
00133     STATUS sc = m_actor ? m_actor->drop(pPartition) : NO_INTERFACE;
00134     CHECK(sc, "Cannot drop partition by Interface.");
00135   }
00137   virtual STATUS activate(CSTR nam)  {
00138     STATUS sc = m_actor ? m_actor->activate(nam) : NO_INTERFACE;
00139     CHECK(sc, "Cannot activate partition: "+nam);
00140   }
00142   virtual STATUS activate(IInterface* pPartition)  {
00143     STATUS sc = m_actor ? m_actor->activate(pPartition) : NO_INTERFACE;
00144     CHECK(sc, "Cannot activate partition by Interface.");
00145   }
00147   virtual STATUS get(CSTR nam, IInterface*& pPartition) const  {
00148     STATUS sc = m_actor ? m_actor->get(nam, pPartition) : NO_INTERFACE;
00149     CHECK(sc, "Cannot get partition "+nam);
00150   }
00152   virtual STATUS activePartition(std::string& nam, IInterface*& pPartition) const  {
00153     STATUS sc = m_actor ? m_actor->activePartition(nam, pPartition) : NO_INTERFACE;
00154     CHECK(sc, "Cannot determine active partition.");
00155   }
00156 };
00157 
00158 DECLARE_ALGORITHM_FACTORY(PartitionSwitchAlg)

Generated at Thu Jan 8 17:44:23 2009 for Gaudi Framework, version v20r4 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004