BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
JobInfoSvc.cxx
Go to the documentation of this file.
2#include "GaudiKernel/MsgStream.h"
4#include "GaudiKernel/ISvcLocator.h"
5#include "GaudiKernel/IJobOptionsSvc.h"
6#include "GaudiKernel/PropertyMgr.h"
7#include "GaudiKernel/SvcFactory.h"
8#include "GaudiKernel/Bootstrap.h"
9#include "GaudiKernel/Kernel.h"
10#include "GaudiKernel/IInterface.h"
11#include "GaudiKernel/IIncidentSvc.h"
12#include "GaudiKernel/Incident.h"
13#include "GaudiKernel/IIncidentListener.h"
14#include "GaudiKernel/StatusCode.h"
15#include "GaudiKernel/SvcFactory.h"
16
17
18#include <sys/types.h>
19#include <sys/stat.h>
20#include <fcntl.h>
21#include <time.h>
22
23
24using namespace XmlRpc;
25
26
27JobInfoSvc::JobInfoSvc(const std::string& name, ISvcLocator* pSvcLocator) :
28 Service(name, pSvcLocator) {
29 declareProperty("xmlrpcServer", m_xmlrpcServer = "202.122.37.68");
30 declareProperty("xmlrpcPort", m_xmlrpcPort = 8080);
31 declareProperty("xmlrpcUrl", m_xmlrpcUrl = "/bemp/xmlrpc");
32 declareProperty("xmlrpcMethod", m_xmlrpcMethod = "SetJobInfo.setEvtNum");
33 }
34
36 MsgStream log( msgSvc(), name() );
37 log << MSG::INFO << "in initialize" << endreq;
38
39 StatusCode sc = Service::initialize();
40 if( sc.isFailure() ) return sc;
41
42 IIncidentSvc* incsvc;
43 sc = service("IncidentSvc", incsvc);
44 int priority = 100;
45 if( sc.isSuccess() ){
46 incsvc -> addListener(this, "BeginEvent", priority);
47 }
48
49 m_outputFileName = getJobOutputFile();
50 m_count = 0;
51
52 //Set initialize value of real event number
53 xmlrpc(-1);
54
55 return StatusCode::SUCCESS;
56}
57
58StatusCode JobInfoSvc::queryInterface(const InterfaceID& riid, void** ppvInterface)
59{
60 if ( IJobInfoSvc::interfaceID().versionMatch(riid) ) {
61 *ppvInterface = (IJobInfoSvc*)this;
62 }else{
63 return Service::queryInterface(riid, ppvInterface);
64 }
65 addRef();
66 return StatusCode::SUCCESS;
67}
68
69void JobInfoSvc::handle(const Incident& inc){
70 MsgStream log( messageService(), name() );
71
72 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
73 if ( inc.type() == "BeginEvent" ){
74 log << MSG::DEBUG << "Begin Event" << endreq;
75 //count execute time
76 m_count++;
77 }
78}
79
80
82 MsgStream log(msgSvc(), name());
83 log << MSG::INFO << "in finalize" << endreq;
84
85 //Keep this line for log file output please!
86 std::cout<< "JobInfoSvc: totle event number = "<< m_count << std::endl;
87
88 //Save event number to job manage database
89 xmlrpc(m_count);
90
91 return StatusCode::SUCCESS;
92}
93
94int JobInfoSvc::xmlrpc(int evtNum){
95 MsgStream log(msgSvc(), name());
96
97 XmlRpcClient c(m_xmlrpcServer.c_str(), m_xmlrpcPort, m_xmlrpcUrl.c_str());
98 XmlRpcValue args, result;
99
100 args[0] = m_outputFileName;
101 args[1] = evtNum;
102
103 if (args[0] != "" && c.execute(m_xmlrpcMethod.c_str(), args, result)){
104 log << MSG::INFO << " set evtNum = "<< evtNum << endreq;
105 }else{
106 log << MSG::ERROR<< " Error in execute "<< m_xmlrpcMethod << endreq;
107 return -1;
108 }
109
110 return 0;
111}
112
114 MsgStream log(msgSvc(), name());
115 std::string outputFileName = "";
116
117 IJobOptionsSvc* jobSvc;
118 Gaudi::svcLocator()->service("JobOptionsSvc", jobSvc);
119
120 const std::vector<const Property*>* properties_event = jobSvc->getProperties("EventCnvSvc");
121 if (properties_event != NULL) {
122 for (unsigned int i = 0; i < properties_event->size(); i++) {
123 if ((*properties_event)[i]->name() == "digiRootOutputFile") {
124 outputFileName = (*properties_event)[i]->toString();
125 break;
126 }
127 }
128 }
129
130 const std::vector<const Property*>* properties_root = jobSvc->getProperties("RootCnvSvc");
131 if (properties_root != NULL) {
132 for (unsigned int i = 0; i < properties_root->size(); i++) {
133 if ((*properties_root)[i]->name() == "digiRootOutputFile") {
134 outputFileName = (*properties_root)[i]->toString();
135 break;
136 }
137 }
138 }
139
140 //FIXME for RawDataCnvSvc
141
142 return outputFileName;
143}
IMessageSvc * msgSvc()
#define NULL
static const InterfaceID & interfaceID()
Definition: IJobInfoSvc.h:16
StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
Definition: JobInfoSvc.cxx:58
int xmlrpc(int evtNum)
Definition: JobInfoSvc.cxx:94
void handle(const Incident &)
Definition: JobInfoSvc.cxx:69
StatusCode initialize()
Definition: JobInfoSvc.cxx:35
std::string getJobOutputFile()
Definition: JobInfoSvc.cxx:113
JobInfoSvc(const std::string &name, ISvcLocator *pSvcLocator)
Definition: JobInfoSvc.cxx:27
StatusCode finalize()
Definition: JobInfoSvc.cxx:81
A class to send XML RPC requests to a server and return the results.
Definition: XmlRpcClient.h:25
bool execute(const char *method, XmlRpcValue const &params, XmlRpcValue &result)
RPC method arguments and results are represented by Values.
Definition: XmlRpcValue.h:22
Definition: XmlRpc.h:35