// OutNetProc.cc // Contact person: P G Jones // See OutNetProc.hh for more details. //—————————————————————---------------------------------------------——// #include using namespace CLHEP; #include #include #include #include #include using namespace RAT; #include using namespace std; OutNetProc::OutNetProc() : Processor("OutNetProc") { } OutNetProc::~OutNetProc() { vector::iterator iSocket; for( iSocket = fSockets.begin(); iSocket != fSockets.end(); ++iSocket ) delete *iSocket; } void OutNetProc::SetS( const std::string& param, const std::string& value ) { if( param == "host" ) { vector parts = split(value, ":"); if (parts.size() != 2) throw ParamInvalid(param, "host needs two parts - host:port"); string host = parts[0]; int port = to_int(parts[1]); if( !Connect(host, port) ) throw ParamInvalid( param, dformat("Could not connect to %s:%d", host.c_str(), port ) ); } else throw ParamUnknown( param ); } void OutNetProc::BeginOfRun( DS::Run& run ) { // Find available socket for writing TSocket* socket = fMonitor.Select(); if( socket->SendObject( &run ) == -1) warn << "OutNetProc::BeginOfRun: Cannot send run to " << socket->GetInetAddress().GetHostName() << ":" << socket->GetPort() << newline; } Processor::Result OutNetProc::DSEvent( DS::Run&, DS::Entry& ds ) { // Find available socket for writing TSocket* socket = fMonitor.Select(); if( socket->SendObject(&ds) == -1) { warn << "OutNetProc::DSEvent: Cannot send event to " << socket->GetInetAddress().GetHostName() << ":" << socket->GetPort() << newline; return Processor::ABORT; } return Processor::OK; } void OutNetProc::EndOfRun( DS::Run& run ) { // Find available socket for writing TSocket* socket = fMonitor.Select(); if( socket->SendObject( &run ) == -1) warn << "OutNetProc::EndOfRun: Cannot send run to " << socket->GetInetAddress().GetHostName() << ":" << socket->GetPort() << newline; } bool OutNetProc::Connect( const std::string& host, const int port ) { TSocket *s = new TSocket( host.c_str(), port ); if( s->IsValid() ) { fSockets.push_back( s ); fMonitor.Add( s, TMonitor::kWrite ); return true; } else return false; }