| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PartitionSwitchAlg.cpp
Go to the documentation of this file.
1 // ====================================================================
2 // PartitionSwitchAlg.cpp
3 // --------------------------------------------------------------------
4 //
5 // Author : Markus Frank
6 //
7 // ====================================================================
8 #include "GaudiKernel/IPartitionControl.h"
9 #include "GaudiKernel/Algorithm.h"
10 #include "GaudiKernel/MsgStream.h"
11 #include "GaudiKernel/IToolSvc.h"
12 #include "GaudiKernel/IAlgTool.h"
13 #include "GaudiKernel/SmartIF.h"
14
24 class PartitionSwitchAlg : public extends1<Algorithm, IPartitionControl> {
25
26 typedef StatusCode STATUS;
27 typedef const std::string& CSTR;
28
29 private:
30
32 std::string m_partName;
34 std::string m_toolType;
36 IPartitionControl* m_actor;
37
38 public:
39
41 PartitionSwitchAlg(CSTR name, ISvcLocator* pSvcLocator)
42 : base_class(name, pSvcLocator), m_actor(0)
43 {
44 declareProperty("Partition", m_partName);
45 declareProperty("Tool", m_toolType="PartitionSwitchTool");
46 }
48 virtual ~PartitionSwitchAlg() {
49 }
50
52 virtual STATUS initialize() {
53 MsgStream log(msgSvc(), name());
54 SmartIF<IAlgTool> tool(m_actor);
55 STATUS sc = toolSvc()->retrieveTool(m_toolType,m_actor,this);
56 if ( sc.isFailure() ) {
57 log << MSG::ERROR << "Unable to load PartitionSwitchTool "
58 << m_toolType << endmsg;
59 return sc;
60 }
62 if ( tool ) toolSvc()->releaseTool(tool);
64 IInterface* partititon = 0;
65 sc = m_actor->get(m_partName, partititon);
66 if ( !sc.isSuccess() ) {
67 log << MSG::ERROR << "Cannot access partition \""
68 << m_partName << "\"" << endmsg;
69 }
70 return sc;
71 }
72
74 virtual STATUS finalize() {
75 SmartIF<IAlgTool> tool(m_actor);
76 if ( tool ) toolSvc()->releaseTool(tool);
77 m_actor = 0;
78 return STATUS::SUCCESS;
79 }
80
82 virtual STATUS execute() {
83 if ( m_actor ) {
84 STATUS sc = m_actor->activate(m_partName);
85 if ( !sc.isSuccess() ) {
86 MsgStream log(msgSvc(), name());
87 log << MSG::ERROR << "Cannot activate partition \""
88 << m_partName << "\"!" << endmsg;
89 }
90 return sc;
91 }
92 MsgStream log(msgSvc(), name());
93 log << MSG::ERROR << "The partition control tool \"" << name()
94 << "." << m_toolType << "\" cannot be accessed!" << endmsg;
95 return STATUS::FAILURE;
96 }
97
98 void _check(STATUS sc, CSTR msg) const {
99 MsgStream log(msgSvc(), name());
100 log << MSG::ERROR << msg << " Status=" << sc.getCode() << endmsg;
101 }
102 #define CHECK(x,y) if ( !x.isSuccess() ) _check(x, y); return x;
103
105 virtual STATUS create(CSTR nam, CSTR typ) {
106 STATUS sc = m_actor ? m_actor->create(nam,typ) : NO_INTERFACE;
107 CHECK(sc, "Cannot create partition: "+nam+" of type "+typ);
108 }
110 virtual STATUS create(CSTR nam, CSTR typ, IInterface*& pPartition) {
111 STATUS sc = m_actor ? m_actor->create(nam,typ,pPartition) : NO_INTERFACE;
112 CHECK(sc, "Cannot create partition: "+nam+" of type "+typ);
113 }
115 virtual STATUS drop(CSTR nam) {
116 STATUS sc = m_actor ? m_actor->drop(nam) : NO_INTERFACE;
117 CHECK(sc, "Cannot drop partition: "+nam);
118 }
120 virtual STATUS drop(IInterface* pPartition) {
121 STATUS sc = m_actor ? m_actor->drop(pPartition) : NO_INTERFACE;
122 CHECK(sc, "Cannot drop partition by Interface.");
123 }
125 virtual STATUS activate(CSTR nam) {
126 STATUS sc = m_actor ? m_actor->activate(nam) : NO_INTERFACE;
127 CHECK(sc, "Cannot activate partition: "+nam);
128 }
130 virtual STATUS activate(IInterface* pPartition) {
131 STATUS sc = m_actor ? m_actor->activate(pPartition) : NO_INTERFACE;
132 CHECK(sc, "Cannot activate partition by Interface.");
133 }
135 virtual STATUS get(CSTR nam, IInterface*& pPartition) const {
136 STATUS sc = m_actor ? m_actor->get(nam, pPartition) : NO_INTERFACE;
137 CHECK(sc, "Cannot get partition "+nam);
138 }
140 virtual STATUS activePartition(std::string& nam, IInterface*& pPartition) const {
141 STATUS sc = m_actor ? m_actor->activePartition(nam, pPartition) : NO_INTERFACE;
142 CHECK(sc, "Cannot determine active partition.");
143 }
144 };
145
146 DECLARE_COMPONENT(PartitionSwitchAlg)