00001 #include "JobInfoSvc/JobInfoSvc.h"
00002 #include "GaudiKernel/MsgStream.h"
00003 #include "xmlrpc++0.7/src/XmlRpc.h"
00004 #include "GaudiKernel/ISvcLocator.h"
00005 #include "GaudiKernel/IJobOptionsSvc.h"
00006 #include "GaudiKernel/PropertyMgr.h"
00007 #include "GaudiKernel/SvcFactory.h"
00008 #include "GaudiKernel/Bootstrap.h"
00009 #include "GaudiKernel/Kernel.h"
00010 #include "GaudiKernel/IInterface.h"
00011 #include "GaudiKernel/IIncidentSvc.h"
00012 #include "GaudiKernel/Incident.h"
00013 #include "GaudiKernel/IIncidentListener.h"
00014 #include "GaudiKernel/StatusCode.h"
00015 #include "GaudiKernel/SvcFactory.h"
00016
00017
00018 #include <sys/types.h>
00019 #include <sys/stat.h>
00020 #include <fcntl.h>
00021 #include <time.h>
00022
00023
00024 using namespace XmlRpc;
00025
00026
00027 JobInfoSvc::JobInfoSvc(const std::string& name, ISvcLocator* pSvcLocator) :
00028 Service(name, pSvcLocator) {
00029 declareProperty("xmlrpcServer", m_xmlrpcServer = "202.122.37.68");
00030 declareProperty("xmlrpcPort", m_xmlrpcPort = 8080);
00031 declareProperty("xmlrpcUrl", m_xmlrpcUrl = "/bemp/xmlrpc");
00032 declareProperty("xmlrpcMethod", m_xmlrpcMethod = "SetJobInfo.setEvtNum");
00033 }
00034
00035 StatusCode JobInfoSvc::initialize(){
00036 MsgStream log( msgSvc(), name() );
00037 log << MSG::INFO << "in initialize" << endreq;
00038
00039 StatusCode sc = Service::initialize();
00040 if( sc.isFailure() ) return sc;
00041
00042 IIncidentSvc* incsvc;
00043 sc = service("IncidentSvc", incsvc);
00044 int priority = 100;
00045 if( sc.isSuccess() ){
00046 incsvc -> addListener(this, "BeginEvent", priority);
00047 }
00048
00049 m_outputFileName = getJobOutputFile();
00050 m_count = 0;
00051
00052
00053 xmlrpc(-1);
00054
00055 return StatusCode::SUCCESS;
00056 }
00057
00058 StatusCode JobInfoSvc::queryInterface(const InterfaceID& riid, void** ppvInterface)
00059 {
00060 if ( IJobInfoSvc::interfaceID().versionMatch(riid) ) {
00061 *ppvInterface = (IJobInfoSvc*)this;
00062 }else{
00063 return Service::queryInterface(riid, ppvInterface);
00064 }
00065 addRef();
00066 return StatusCode::SUCCESS;
00067 }
00068
00069 void JobInfoSvc::handle(const Incident& inc){
00070 MsgStream log( messageService(), name() );
00071
00072 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
00073 if ( inc.type() == "BeginEvent" ){
00074 log << MSG::DEBUG << "Begin Event" << endreq;
00075
00076 m_count++;
00077 }
00078 }
00079
00080
00081 StatusCode JobInfoSvc::finalize() {
00082 MsgStream log(msgSvc(), name());
00083 log << MSG::INFO << "in finalize" << endreq;
00084
00085
00086 std::cout<< "JobInfoSvc: totle event number = "<< m_count << std::endl;
00087
00088
00089 xmlrpc(m_count);
00090
00091 return StatusCode::SUCCESS;
00092 }
00093
00094 int JobInfoSvc::xmlrpc(int evtNum){
00095 MsgStream log(msgSvc(), name());
00096
00097 XmlRpcClient c(m_xmlrpcServer.c_str(), m_xmlrpcPort, m_xmlrpcUrl.c_str());
00098 XmlRpcValue args, result;
00099
00100 args[0] = m_outputFileName;
00101 args[1] = evtNum;
00102
00103 if (args[0] != "" && c.execute(m_xmlrpcMethod.c_str(), args, result)){
00104 log << MSG::INFO << " set evtNum = "<< evtNum << endreq;
00105 }else{
00106 log << MSG::ERROR<< " Error in execute "<< m_xmlrpcMethod << endreq;
00107 return -1;
00108 }
00109
00110 return 0;
00111 }
00112
00113 std::string JobInfoSvc::getJobOutputFile(){
00114 MsgStream log(msgSvc(), name());
00115 std::string outputFileName = "";
00116
00117 IJobOptionsSvc* jobSvc;
00118 Gaudi::svcLocator()->service("JobOptionsSvc", jobSvc);
00119
00120 const std::vector<const Property*>* properties_event = jobSvc->getProperties("EventCnvSvc");
00121 if (properties_event != NULL) {
00122 for (unsigned int i = 0; i < properties_event->size(); i++) {
00123 if ((*properties_event)[i]->name() == "digiRootOutputFile") {
00124 outputFileName = (*properties_event)[i]->toString();
00125 break;
00126 }
00127 }
00128 }
00129
00130 const std::vector<const Property*>* properties_root = jobSvc->getProperties("RootCnvSvc");
00131 if (properties_root != NULL) {
00132 for (unsigned int i = 0; i < properties_root->size(); i++) {
00133 if ((*properties_root)[i]->name() == "digiRootOutputFile") {
00134 outputFileName = (*properties_root)[i]->toString();
00135 break;
00136 }
00137 }
00138 }
00139
00140
00141
00142 return outputFileName;
00143 }