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