Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 144 of file ExternalONCRPCServerSvc.cxx.

144  {
145 
146  ATH_MSG_VERBOSE( "Finalize()" );
147 
151  ReleaseClient().ignore();
152 
153  return StatusCode::SUCCESS;
154  }

◆ 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 #if defined(__clang__) && __clang_major__ >= 19
83 # pragma clang diagnostic push
84 # pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
85 #endif
86  //Now try pinging the server
87  clnt_stat ret = clnt_call(m_client, NULLPROC, (xdrproc_t)xdr_void, NULL,
88  (xdrproc_t)xdr_void, NULL, GetTimeout());
89 #if defined(__clang__) && __clang_major__ >= 19
90 # pragma clang diagnostic pop
91 #endif
92 #if __GNUC__ >= 8
93 # pragma GCC diagnostic pop
94 #endif
95 
96  //And check for the result
97  if (ret != RPC_SUCCESS){
98  ATH_MSG_WARNING( "Failed calling the server on host " << m_hostName << " : " << clnt_sperrno(ret) );
99  //Also destroy the client in this case - otherwise we might be stranded
100  //with an invalid client object
101  ReleaseClient().ignore();
102  //and return failure
103  return StatusCode::FAILURE;
104  }
105 
106  //Be verbose on success
107  ATH_MSG_VERBOSE( "Successfully connected to server on host " << m_hostName );
108 
109  return StatusCode::SUCCESS;
110  }

◆ GetTimeout()

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

Convert timeout double in seconds to struct timeval.

Definition at line 60 of file ExternalONCRPCServerSvc.cxx.

115  {
116  //Declare return value
117  struct timeval timeout = { 0, 0 };
118  //Catch for negatives
119  if (m_timeOut < 0) return timeout;
120  //Get seconds as integer part
121  timeout.tv_sec = static_cast<long>(m_timeOut);
122  //Get microseconds as fractional part
123  timeout.tv_usec = static_cast<long>((m_timeOut - timeout.tv_sec)*1e6);
124  //Finally return it
125  return timeout;
126  }

◆ 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 131 of file ExternalONCRPCServerSvc.cxx.

131  {
132  //Destroy the client
133  if (m_client) clnt_destroy(m_client);
134  //And set pointer to NULL
135  m_client=NULL;
136  //For now always return success
137  return StatusCode::SUCCESS;
138  }

◆ 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 160 of file ExternalONCRPCServerSvc.cxx.

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

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:115
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:240
JiveXML::ExternalONCRPCServerSvc::ReleaseClient
StatusCode ReleaseClient()
Destroy the private client handle.
Definition: ExternalONCRPCServerSvc.cxx:131
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:36
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
JiveXML::ExternalONCRPCServerSvc::m_hostName
std::string m_hostName
Definition: ExternalONCRPCServerSvc.h:53