ATLAS Offline Software
Public Member Functions | List of all members
JiveXML::ExternalONCRPCServerSvc Class Reference

This athena service will provide a link to an external ONCRPC server, e.g running as standalone application or in another athena application. More...

#include <ExternalONCRPCServerSvc.h>

Inheritance diagram for JiveXML::ExternalONCRPCServerSvc:
Collaboration diagram for JiveXML::ExternalONCRPCServerSvc:

Public Member Functions

 ExternalONCRPCServerSvc (const std::string &name, ISvcLocator *sl)
 Default constructor. More...
 
virtual ~ExternalONCRPCServerSvc ()
 Destructor. More...
 
virtual StatusCode initialize () override
 Gaudi default methods. More...
 
virtual StatusCode finalize () override
 Finalize - called once at the end. More...
 

Server methods

std::string m_hostName
 
double m_timeOut
 
CLIENT * m_client
 
virtual StatusCode UpdateEventForStream (const EventStreamID &evtStreamID, const std::string &event) override
 Put this event as new current event for stream given by name. More...
 
StatusCode GetClient ()
 Obtain a client handle by. More...
 
StatusCode ReleaseClient ()
 Destroy the private client handle. More...
 
struct timeval GetTimeout ()
 Convert timeout double in seconds to struct timeval. More...
 

Detailed Description

This athena service will provide a link to an external ONCRPC server, e.g running as standalone application or in another athena application.

It only provides means for streaming events to that server.

Definition at line 23 of file ExternalONCRPCServerSvc.h.

Constructor & Destructor Documentation

◆ ExternalONCRPCServerSvc()

JiveXML::ExternalONCRPCServerSvc::ExternalONCRPCServerSvc ( const std::string &  name,
ISvcLocator *  sl 
)

Default constructor.

Constructor.

Definition at line 17 of file ExternalONCRPCServerSvc.cxx.

17  :
18  base_class ( name, sl ),
19  m_client(NULL)
20  {
21  //declare properties
22  declareProperty("Hostname",m_hostName="localhost","The name of the host the external server is running on [ default: \"localhost\" ]");
23  declareProperty("Timeout",m_timeOut=10,"Timeout when calling the server in seconds [ default: 10 ]");
24  }

◆ ~ExternalONCRPCServerSvc()

JiveXML::ExternalONCRPCServerSvc::~ExternalONCRPCServerSvc ( )
virtual

Destructor.

Definition at line 29 of file ExternalONCRPCServerSvc.cxx.

29  {
30  ATH_MSG_VERBOSE( "Destructor() " );
31  }

Member Function Documentation

◆ finalize()

StatusCode JiveXML::ExternalONCRPCServerSvc::finalize ( )
overridevirtual

Finalize - called once at the end.

  • shut down server

Release the client

Definition at line 137 of file ExternalONCRPCServerSvc.cxx.

137  {
138 
139  ATH_MSG_VERBOSE( "Finalize()" );
140 
144  ReleaseClient().ignore();
145 
146  return StatusCode::SUCCESS;
147  }

◆ GetClient()

StatusCode JiveXML::ExternalONCRPCServerSvc::GetClient ( )
private

Obtain a client handle by.

  • creating a CLIENT object
  • pinging the server using NULLPROC

Definition at line 60 of file ExternalONCRPCServerSvc.cxx.

60  {
61 
62  ATH_MSG_VERBOSE( "GetClient()" );
63 
64  //Try to create client if not there yet
65 #ifndef __APPLE__
66  if (!m_client) m_client = clnt_create(m_hostName.c_str(), ONCRPCSERVERPROG,ONCRPCSERVERVERS, "tcp");
67 #else
68  char proto[] = "tcp";
69  if (!m_client) m_client = clnt_create((char*)m_hostName.c_str(), ONCRPCSERVERPROG,ONCRPCSERVERVERS, proto);
70 #endif
71  //Fail if we still don't have a client
72  if (!m_client){
73  ATH_MSG_WARNING( "Unable to create client for server on host " << m_hostName << " using TCP/IP " );
74  return StatusCode::FAILURE;
75  }
76 
77 // xdr_void is defined inconsistently in xdr.h and gets a warning from gcc8.
78 #if __GNUC__ >= 8
79 # pragma GCC diagnostic push
80 # pragma GCC diagnostic ignored "-Wcast-function-type"
81 #endif
82  //Now try pinging the server
83  clnt_stat ret = clnt_call(m_client, NULLPROC, (xdrproc_t)xdr_void, NULL,
84  (xdrproc_t)xdr_void, NULL, GetTimeout());
85 #if __GNUC__ >= 8
86 # pragma GCC diagnostic pop
87 #endif
88 
89  //And check for the result
90  if (ret != RPC_SUCCESS){
91  ATH_MSG_WARNING( "Failed calling the server on host " << m_hostName << " : " << clnt_sperrno(ret) );
92  //Also destroy the client in this case - otherwise we might be stranded
93  //with an invalid client object
94  ReleaseClient().ignore();
95  //and return failure
96  return StatusCode::FAILURE;
97  }
98 
99  //Be verbose on success
100  ATH_MSG_VERBOSE( "Successfully connected to server on host " << m_hostName );
101 
102  return StatusCode::SUCCESS;
103  }

◆ GetTimeout()

struct timeval JiveXML::ExternalONCRPCServerSvc::GetTimeout ( )
private

Convert timeout double in seconds to struct timeval.

Definition at line 60 of file ExternalONCRPCServerSvc.cxx.

108  {
109  //Declare return value
110  struct timeval timeout = { 0, 0 };
111  //Catch for negatives
112  if (m_timeOut < 0) return timeout;
113  //Get seconds as integer part
114  timeout.tv_sec = static_cast<long>(m_timeOut);
115  //Get microseconds as fractional part
116  timeout.tv_usec = static_cast<long>((m_timeOut - timeout.tv_sec)*1e6);
117  //Finally return it
118  return timeout;
119  }

◆ initialize()

StatusCode JiveXML::ExternalONCRPCServerSvc::initialize ( )
overridevirtual

Gaudi default methods.

Initialize - called once in beginning.

  • create server

Try preemtivly creating a client right here - but ignore the result

Definition at line 37 of file ExternalONCRPCServerSvc.cxx.

37  {
38  ATH_MSG_VERBOSE( "Initialize()" );
39 
40  //Initialize Service base
41  if (Service::initialize().isFailure()) return StatusCode::FAILURE;
42 
43  //Initialize message stream level
44  msg().setLevel(outputLevel());
45  ATH_MSG_VERBOSE( "Output level is set to " << (int)msg().level() );
46 
50  GetClient().ignore();
51 
52  return StatusCode::SUCCESS;
53  }

◆ ReleaseClient()

StatusCode JiveXML::ExternalONCRPCServerSvc::ReleaseClient ( )
private

Destroy the private client handle.

Definition at line 124 of file ExternalONCRPCServerSvc.cxx.

124  {
125  //Destroy the client
126  if (m_client) clnt_destroy(m_client);
127  //And set pointer to NULL
128  m_client=NULL;
129  //For now always return success
130  return StatusCode::SUCCESS;
131  }

◆ UpdateEventForStream()

StatusCode JiveXML::ExternalONCRPCServerSvc::UpdateEventForStream ( const EventStreamID evtStreamID,
const std::string &  eventStr 
)
overridevirtual

Put this event as new current event for stream given by name.

Implementation of IServerSvc method.

Get one event and put it as the new event for the this stream, which is identified by EventStreamID

Definition at line 153 of file ExternalONCRPCServerSvc.cxx.

153  {
154 
155  ATH_MSG_VERBOSE( "UpdateEventForStream()" );
156 
157  //Check that the event stream id is valid
158  if (!evtStreamID.isValid()){
159  ATH_MSG_ERROR( "Invalid event stream identifier - cannot add event" );
160  return StatusCode::FAILURE;
161  }
162 
163  //Now create an event C-struct that we can send to the server
164  //NOTE: the struct has to be properly initialized
165  Event event;
166  event.isAvailable = false ; event.isIdentical = false ; event.isCompressed = false ;
167  event.RunNumber = evtStreamID.RunNumber();
168  event.EventNumber=evtStreamID.EventNumber();
169  event.StreamName=strdup(evtStreamID.StreamName().c_str());
170  event.NBytes = strlen(eventStr.c_str())+1;
171  event.EventData = strdup(eventStr.c_str());
172 
173  ATH_MSG_VERBOSE( "Created event structure for event " << event.EventNumber
174  << " from run " << event.RunNumber
175  << " to be put in stream " << event.StreamName
176  << " with " << event.NBytes << " bytes" );
177 
178  //Try to get a client
179  if (GetClient().isFailure()) {
180  ATH_MSG_WARNING( "Failed obtaining a client for sever on host " << m_hostName );
181  ATH_MSG_WARNING( " while updating stream " << evtStreamID.StreamName()
182  << " with event " << evtStreamID.EventNumber()
183  << " from run " << evtStreamID.RunNumber() );
184  return StatusCode::FAILURE;
185  }
186 
187  //Call the client to update the event
188  bool isSuccess = false;
189  clnt_stat ret = clnt_call(m_client, ONCRPC_SETEVENT_PROC, (xdrproc_t)xdr_event, (caddr_t)&event,
190  (xdrproc_t)xdr_bool,(caddr_t)&isSuccess, GetTimeout());
191 
192  //And check for the result
193  if (ret != RPC_SUCCESS){
194  ATH_MSG_WARNING( "Failed calling the server on host " << m_hostName << " : " << clnt_sperrno(ret) );
195  ATH_MSG_WARNING( " while updating stream " << evtStreamID.StreamName()
196  << " with event " << evtStreamID.EventNumber()
197  << " from run " << evtStreamID.RunNumber() );
198  return StatusCode::FAILURE;
199  }
200 
201  //Check if the server managed to update the event from return value
202  if (!isSuccess){
203  ATH_MSG_WARNING( "Server on host " << m_hostName << " returned failure " );
204  ATH_MSG_WARNING( " while updating stream " << evtStreamID.StreamName()
205  << " with event " << evtStreamID.EventNumber()
206  << " from run " << evtStreamID.RunNumber() );
207  return StatusCode::FAILURE;
208  }
209 
210  //Be verbose on success
211  ATH_MSG_DEBUG( "Server on host " << m_hostName << " returned success " );
212  ATH_MSG_DEBUG( " while updating stream " << evtStreamID.StreamName()
213  << " with event " << evtStreamID.EventNumber()
214  << " from run " << evtStreamID.RunNumber() );
215 
216  //Finally free the memory allocated for the event structure
217  xdr_free((xdrproc_t)xdr_event,(caddr_t)&event);
218 
219  return StatusCode::SUCCESS;
220  }

Member Data Documentation

◆ m_client

CLIENT* JiveXML::ExternalONCRPCServerSvc::m_client
private

Definition at line 59 of file ExternalONCRPCServerSvc.h.

◆ m_hostName

std::string JiveXML::ExternalONCRPCServerSvc::m_hostName
private

Definition at line 53 of file ExternalONCRPCServerSvc.h.

◆ m_timeOut

double JiveXML::ExternalONCRPCServerSvc::m_timeOut
private

Definition at line 56 of file ExternalONCRPCServerSvc.h.


The documentation for this class was generated from the following files:
JiveXML::ExternalONCRPCServerSvc::GetClient
StatusCode GetClient()
Obtain a client handle by.
Definition: ExternalONCRPCServerSvc.cxx:60
Event
Definition: trigbs_orderedMerge.cxx:42
initialize
void initialize()
Definition: run_EoverP.cxx:894
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
JiveXML::ExternalONCRPCServerSvc::m_client
CLIENT * m_client
Definition: ExternalONCRPCServerSvc.h:59
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
JiveXML::xdr_event
bool_t xdr_event(XDR *xdrsp, Event *event)
De-/Encoding of Event_t.
Definition: ONCRPCXDRProcs.cxx:51
JiveXML::ExternalONCRPCServerSvc::GetTimeout
struct timeval GetTimeout()
Convert timeout double in seconds to struct timeval.
Definition: ExternalONCRPCServerSvc.cxx:108
ONCRPCSERVERPROG
#define ONCRPCSERVERPROG
Definition: ONCRPCServer.h:30
ONCRPC_SETEVENT_PROC
#define ONCRPC_SETEVENT_PROC
Definition: ONCRPCServer.h:35
JiveXML::ExternalONCRPCServerSvc::m_timeOut
double m_timeOut
Definition: ExternalONCRPCServerSvc.h:56
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
JiveXML::ExternalONCRPCServerSvc::ReleaseClient
StatusCode ReleaseClient()
Destroy the private client handle.
Definition: ExternalONCRPCServerSvc.cxx:124
python.TrigPSCPythonDbSetup.outputLevel
outputLevel
Definition: TrigPSCPythonDbSetup.py:30
ONCRPCSERVERVERS
#define ONCRPCSERVERVERS
Definition: ONCRPCServer.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.TrigInDetArtSteps.timeout
timeout
Definition: TrigInDetArtSteps.py:35
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
JiveXML::ExternalONCRPCServerSvc::m_hostName
std::string m_hostName
Definition: ExternalONCRPCServerSvc.h:53