| # Gaudi Framework, version v21r6 |

Home |  | Generated: 11 Nov 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 extends1<Algorithm, 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   : base_class(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 initialize()   {
    00055     MsgStream log(msgSvc(), name());
    00056     SmartIF<IAlgTool> tool(m_actor);
    00057     STATUS sc = toolSvc()->retrieveTool(m_toolType,m_actor,this);
    00058     if ( sc.isFailure() ) {
    00059       log << MSG::ERROR << "Unable to load PartitionSwitchTool "
    00060           << m_toolType << endmsg;
    00061       return sc;
    00062     }
    00064     if ( tool ) toolSvc()->releaseTool(tool);
    00066     IInterface* partititon = 0;
    00067     sc = m_actor->get(m_partName, partititon);
    00068     if ( !sc.isSuccess() )  {
    00069       log << MSG::ERROR << "Cannot access partition \""
    00070           << m_partName << "\"" << endmsg;
    00071     }
    00072     return sc;
    00073   }
    00074
    00076   virtual STATUS finalize() {
    00077     SmartIF<IAlgTool> tool(m_actor);
    00078     if ( tool ) toolSvc()->releaseTool(tool);
    00079     m_actor = 0;
    00080     return STATUS::SUCCESS;
    00081   }
    00082
    00084   virtual STATUS execute()    {
    00085     if ( m_actor )  {
    00086       STATUS sc = m_actor->activate(m_partName);
    00087       if ( !sc.isSuccess() )  {
    00088         MsgStream log(msgSvc(), name());
    00089         log << MSG::ERROR << "Cannot activate partition \""
    00090             << m_partName << "\"!" << endmsg;
    00091       }
    00092       return sc;
    00093     }
    00094     MsgStream log(msgSvc(), name());
    00095     log << MSG::ERROR << "The partition control tool \"" << name()
    00096         << "." << m_toolType << "\" cannot be accessed!" << endmsg;
    00097     return STATUS::FAILURE;
    00098   }
    00099
    00100   void _check(STATUS sc, CSTR msg)  const {
    00101     MsgStream log(msgSvc(), name());
    00102     log << MSG::ERROR << msg << " Status=" << sc.getCode() << endmsg;
    00103   }
    00104 #define CHECK(x,y) if ( !x.isSuccess() ) _check(x, y); return x;
    00105
    00107   virtual STATUS create(CSTR nam, CSTR typ)  {
    00108     STATUS sc = m_actor ? m_actor->create(nam,typ) : NO_INTERFACE;
    00109     CHECK(sc, "Cannot create partition: "+nam+" of type "+typ);
    00110   }
    00112   virtual STATUS create(CSTR nam, CSTR typ, IInterface*& pPartition)  {
    00113     STATUS sc = m_actor ? m_actor->create(nam,typ,pPartition) : NO_INTERFACE;
    00114     CHECK(sc, "Cannot create partition: "+nam+" of type "+typ);
    00115   }
    00117   virtual STATUS drop(CSTR nam)  {
    00118     STATUS sc = m_actor ? m_actor->drop(nam) : NO_INTERFACE;
    00119     CHECK(sc, "Cannot drop partition: "+nam);
    00120   }
    00122   virtual STATUS drop(IInterface* pPartition)  {
    00123     STATUS sc = m_actor ? m_actor->drop(pPartition) : NO_INTERFACE;
    00124     CHECK(sc, "Cannot drop partition by Interface.");
    00125   }
    00127   virtual STATUS activate(CSTR nam)  {
    00128     STATUS sc = m_actor ? m_actor->activate(nam) : NO_INTERFACE;
    00129     CHECK(sc, "Cannot activate partition: "+nam);
    00130   }
    00132   virtual STATUS activate(IInterface* pPartition)  {
    00133     STATUS sc = m_actor ? m_actor->activate(pPartition) : NO_INTERFACE;
    00134     CHECK(sc, "Cannot activate partition by Interface.");
    00135   }
    00137   virtual STATUS get(CSTR nam, IInterface*& pPartition) const  {
    00138     STATUS sc = m_actor ? m_actor->get(nam, pPartition) : NO_INTERFACE;
    00139     CHECK(sc, "Cannot get partition "+nam);
    00140   }
    00142   virtual STATUS activePartition(std::string& nam, IInterface*& pPartition) const  {
    00143     STATUS sc = m_actor ? m_actor->activePartition(nam, pPartition) : NO_INTERFACE;
    00144     CHECK(sc, "Cannot determine active partition.");
    00145   }
    00146 };
    00147
    00148 DECLARE_ALGORITHM_FACTORY(PartitionSwitchAlg)