BOSS 7.1.0
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
26DECLARE_COMPONENT(JobInfoSvc)
27
28JobInfoSvc::JobInfoSvc(const std::string& name, ISvcLocator* pSvcLocator) :
29 base_class(name, pSvcLocator) {
30 declareProperty("xmlrpcServer", m_xmlrpcServer = "202.122.37.68");
31 declareProperty("xmlrpcPort", m_xmlrpcPort = 8080);
32 declareProperty("xmlrpcUrl", m_xmlrpcUrl = "/bemp/xmlrpc");
33 declareProperty("xmlrpcMethod", m_xmlrpcMethod = "SetJobInfo.setEvtNum");
34 }
35
37 MsgStream log( msgSvc(), name() );
38 log << MSG::INFO << "in initialize" << endreq;
39
40 StatusCode sc = Service::initialize();
41 if( sc.isFailure() ) return sc;
42
43 IIncidentSvc* incsvc;
44 sc = service("IncidentSvc", incsvc);
45 int priority = 100;
46 if( sc.isSuccess() ){
47 incsvc -> addListener(this, "BeginEvent", priority);
48 }
49
50 m_outputFileName = getJobOutputFile();
51 m_count = 0;
52
53 //Set initialize value of real event number
54 xmlrpc(-1);
55
56 return StatusCode::SUCCESS;
57}
58
59/*StatusCode JobInfoSvc::queryInterface(const InterfaceID& riid, void** ppvInterface)
60{
61 if ( IJobInfoSvc::interfaceID().versionMatch(riid) ) {
62 *ppvInterface = (IJobInfoSvc*)this;
63 }else{
64 return Service::queryInterface(riid, ppvInterface);
65 }
66 addRef();
67 return StatusCode::SUCCESS;
68}*/
69
70void JobInfoSvc::handle(const Incident& inc){
71 MsgStream log( messageService(), name() );
72
73 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
74 if ( inc.type() == "BeginEvent" ){
75 log << MSG::DEBUG << "Begin Event" << endreq;
76 //count execute time
77 m_count++;
78 }
79}
80
81
83 MsgStream log(msgSvc(), name());
84 log << MSG::INFO << "in finalize" << endreq;
85
86 //Keep this line for log file output please!
87 std::cout<< "JobInfoSvc: totle event number = "<< m_count << std::endl;
88
89 //Save event number to job manage database
90 xmlrpc(m_count);
91
92 return StatusCode::SUCCESS;
93}
94
95int JobInfoSvc::xmlrpc(int evtNum){
96 MsgStream log(msgSvc(), name());
97
98 XmlRpcClient c(m_xmlrpcServer.c_str(), m_xmlrpcPort, m_xmlrpcUrl.c_str());
99 XmlRpcValue args, result;
100
101 args[0] = m_outputFileName;
102 args[1] = evtNum;
103
104 if (args[0] != "" && c.execute(m_xmlrpcMethod.c_str(), args, result)){
105 log << MSG::INFO << " set evtNum = "<< evtNum << endreq;
106 }else{
107 log << MSG::ERROR<< " Error in execute "<< m_xmlrpcMethod << endreq;
108 return -1;
109 }
110
111 return 0;
112}
113
115 MsgStream log(msgSvc(), name());
116 std::string outputFileName = "";
117
118 IJobOptionsSvc* jobSvc;
119 Gaudi::svcLocator()->service("JobOptionsSvc", jobSvc);
120
121 const std::vector<const Property*>* properties_event = jobSvc->getProperties("EventCnvSvc");
122 if (properties_event != NULL) {
123 for (unsigned int i = 0; i < properties_event->size(); i++) {
124 if ((*properties_event)[i]->name() == "digiRootOutputFile") {
125 outputFileName = (*properties_event)[i]->toString();
126 break;
127 }
128 }
129 }
130
131 const std::vector<const Property*>* properties_root = jobSvc->getProperties("RootCnvSvc");
132 if (properties_root != NULL) {
133 for (unsigned int i = 0; i < properties_root->size(); i++) {
134 if ((*properties_root)[i]->name() == "digiRootOutputFile") {
135 outputFileName = (*properties_root)[i]->toString();
136 break;
137 }
138 }
139 }
140
141 //FIXME for RawDataCnvSvc
142
143 return outputFileName;
144}
IMessageSvc * msgSvc()
#define NULL
int xmlrpc(int evtNum)
Definition: JobInfoSvc.cxx:95
void handle(const Incident &)
Definition: JobInfoSvc.cxx:70
StatusCode initialize()
Definition: JobInfoSvc.cxx:36
std::string getJobOutputFile()
Definition: JobInfoSvc.cxx:114
StatusCode finalize()
Definition: JobInfoSvc.cxx:82
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