LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
evd::LandedSocket Class Reference

#include "LandedSocket.h"

Public Member Functions

 LandedSocket (fhicl::ParameterSet const &, art::ActivityRegistry &reg)
 
bool connect (void)
 
void sendGeometry (std::string)
 
void sendEvent (int, int, int, int, int)
 
void sendHit (double, double, double, double, double, int)
 
void sendVertex (double, double, double, double, int, int)
 

Private Member Functions

void postBeginJob ()
 
void postBeginJobWorkers (art::InputSource *, std::vector< art::Worker * > const &)
 
void preProcessEvent (art::Event const &)
 
void postProcessEvent (art::Event const &)
 

Private Attributes

art::InputSourceinputSource_
 
boost::asio::local::stream_protocol::endpoint * endpoint_
 
boost::asio::local::stream_protocol::socket * socket_
 
boost::asio::io_service service_
 
unsigned long record_
 

Detailed Description

Definition at line 20 of file LandedSocket.h.

Constructor & Destructor Documentation

evd::LandedSocket::LandedSocket ( fhicl::ParameterSet const &  pset,
art::ActivityRegistry reg 
)

Definition at line 20 of file LandedSocket_service.cc.

References postBeginJob(), postBeginJobWorkers(), postProcessEvent(), preProcessEvent(), art::ActivityRegistry::sPostBeginJob, art::ActivityRegistry::sPostBeginJobWorkers, art::ActivityRegistry::sPostProcessEvent, and art::ActivityRegistry::sPreProcessEvent.

21  :
22  endpoint_(nullptr),
23  socket_(nullptr),
24  service_()
25  {
26 
27  reg.sPostBeginJob.watch (this, &LandedSocket::postBeginJob);
31 
32  }
GlobalSignal< detail::SignalResponseType::FIFO, void()> sPostBeginJob
void postBeginJobWorkers(art::InputSource *, std::vector< art::Worker * > const &)
GlobalSignal< detail::SignalResponseType::LIFO, void(InputSource *, std::vector< Worker * > const &)> sPostBeginJobWorkers
void preProcessEvent(art::Event const &)
void postProcessEvent(art::Event const &)
boost::asio::local::stream_protocol::endpoint * endpoint_
Definition: LandedSocket.h:34
boost::asio::io_service service_
Definition: LandedSocket.h:36
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &)> sPreProcessEvent
GlobalSignal< detail::SignalResponseType::LIFO, void(Event const &)> sPostProcessEvent
boost::asio::local::stream_protocol::socket * socket_
Definition: LandedSocket.h:35

Member Function Documentation

bool evd::LandedSocket::connect ( void  )

Definition at line 95 of file LandedSocket_service.cc.

References endpoint_, sendGeometry(), service_, and socket_.

Referenced by postProcessEvent().

96  {
97  //connect to landed app
98  std::ostringstream sockfile;
99  sockfile << getenv("HOME") << "/.landed.sock";
100  endpoint_=new boost::asio::local::stream_protocol::endpoint(sockfile.str());
101  if (!endpoint_)
102  {
103  mf::LogError("Landed") << "failed to create socket for connection to LANDED app\n";
104  return false;
105  }
106  socket_=new boost::asio::local::stream_protocol::socket(service_);
107  if (socket_!=nullptr)
108  socket_->connect(*endpoint_);
109  return socket_!=nullptr;
110  }
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
boost::asio::local::stream_protocol::endpoint * endpoint_
Definition: LandedSocket.h:34
boost::asio::io_service service_
Definition: LandedSocket.h:36
boost::asio::local::stream_protocol::socket * socket_
Definition: LandedSocket.h:35
void evd::LandedSocket::postBeginJob ( )
private

Definition at line 35 of file LandedSocket_service.cc.

References postBeginJobWorkers().

Referenced by LandedSocket().

36  {
37 
38  }
void evd::LandedSocket::postBeginJobWorkers ( art::InputSource inputsource,
std::vector< art::Worker * > const &  workers 
)
private

Definition at line 40 of file LandedSocket_service.cc.

References inputSource_, preProcessEvent(), and record_.

Referenced by LandedSocket(), and postBeginJob().

42  {
43  inputSource_=inputsource;
44  record_=0;
45  }
art::InputSource * inputSource_
Definition: LandedSocket.h:33
unsigned long record_
Definition: LandedSocket.h:37
void evd::LandedSocket::postProcessEvent ( art::Event const &  event)
private

Definition at line 52 of file LandedSocket_service.cc.

References connect(), art::Event::id(), inputSource_, LOG_DEBUG, record_, art::RootInput::seekToEvent(), and socket_.

Referenced by LandedSocket(), and preProcessEvent().

53  {
54  if (socket_!=nullptr)
55  {
56  art::RootInput* rootinput = dynamic_cast<art::RootInput*>(inputSource_);
57  if (!rootinput)
58  {
59  throw cet::exception("Landed") << "input is not root file, therefore not seekable and therefore unsuitable for EventViewer\n";
60  }
61  boost::array<char, 128> instr;
62  size_t len=socket_->receive(boost::asio::buffer(instr));
63  if (len>0)
64  {
65  long newrec=atol(instr.data());
66  long diff=newrec-record_;
67  diff--;
68  // std::cout << "seek: " << diff << std::endl;
69  if (rootinput->seekToEvent(diff, true))
70  {
71  LOG_DEBUG("Landed") << "seek succeeded\n";
72  socket_->send(boost::asio::buffer("OK\n", 3));
73  record_=newrec;
74  }
75  else
76  {
77  // std::cout << "no such event, reloading\n";
78  if (!rootinput->seekToEvent(event.id(), true))
79  throw cet::exception("Landed") << "problem performing seek on input, lost track of input event\n";
80  socket_->send(boost::asio::buffer("NO\n", 3));
81  // std::cout << "reload performed\n";
82  }
83  //wait for message confirmation
84  boost::array<char, 2> conf;
85  if (socket_->receive(boost::asio::buffer(conf))!=1)
86  throw cet::exception("Landed") << "LANDED app did not confirm instruction result\n";
87 
88  }
89  else
90  throw cet::exception("Landed") << "bad instruction from LANDED app\n";
91  }
92  }
art::InputSource * inputSource_
Definition: LandedSocket.h:33
bool seekToEvent(T eventSpec, bool exact=false)
Definition: RootInput.h:145
unsigned long record_
Definition: LandedSocket.h:37
#define LOG_DEBUG(id)
boost::asio::local::stream_protocol::socket * socket_
Definition: LandedSocket.h:35
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Event finding and building.
void evd::LandedSocket::preProcessEvent ( art::Event const &  )
private

Definition at line 47 of file LandedSocket_service.cc.

References postProcessEvent().

Referenced by LandedSocket(), and postBeginJobWorkers().

48  {
49 
50  }
void evd::LandedSocket::sendEvent ( int  nhits,
int  nvertex,
int  run,
int  subrun,
int  event 
)

Definition at line 130 of file LandedSocket_service.cc.

References record_, sendHit(), socket_, and ss.

Referenced by sendGeometry().

131  {
132  std::ostringstream ss;
133  ss << "EVT:" << record_ << "," << nhits << "," << nvertex << ", " << run << "," << subrun << "," << event << "\n";
134  // std::cout << ss.str();
135  if (socket_->send(boost::asio::buffer(ss.str().c_str(), ss.str().length()))!=ss.str().length())
136  throw cet::exception("Landed") << "failed to send event introduction to LANDED app\n";
137  boost::array<char, 2> conf;
138  if (socket_->receive(boost::asio::buffer(conf))!=1)
139  throw cet::exception("Landed") << "LANDED app did not confirm event\n";
140  }
Float_t ss
Definition: plot.C:23
unsigned long record_
Definition: LandedSocket.h:37
boost::asio::local::stream_protocol::socket * socket_
Definition: LandedSocket.h:35
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void evd::LandedSocket::sendGeometry ( std::string  vrml)

Definition at line 113 of file LandedSocket_service.cc.

References LOG_DEBUG, sendEvent(), socket_, and ss.

Referenced by connect().

114  {
115  std::ostringstream ss;
116  ss << "GEO:"<< vrml.length() << "\n";
117  if (socket_->send(boost::asio::buffer(ss.str().c_str(), ss.str().length()))!=ss.str().length() ||
118  socket_->send(boost::asio::buffer(vrml.c_str(), vrml.length()))!=vrml.length())
119  {
120  throw cet::exception("Landed") << "failed to send detector geometry to LANDED app\n";
121  }
122  boost::array<char, 2> conf;
123  if (socket_->receive(boost::asio::buffer(conf))!=1)
124  throw cet::exception("Landed") << "LANDED app did not confirm detector geometry\n";
125  else
126  LOG_DEBUG("Landed") << "LANDED app has confirmed detector geometry\n";
127 
128  }
Float_t ss
Definition: plot.C:23
#define LOG_DEBUG(id)
boost::asio::local::stream_protocol::socket * socket_
Definition: LandedSocket.h:35
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void evd::LandedSocket::sendHit ( double  x,
double  y,
double  z,
double  e,
double  ne,
int  track 
)

Definition at line 142 of file LandedSocket_service.cc.

References sendVertex(), socket_, and ss.

Referenced by sendEvent().

143  {
144  std::ostringstream ss;
145  ss << "HIT:" << x << "," << y << "," << z << "," << e << "," << ne << "," << track << "\n";
146  // std::cout << ss.str();
147  if (socket_->send(boost::asio::buffer(ss.str().c_str(), ss.str().length()))!=ss.str().length())
148  throw cet::exception("Landed") << "failed to send hit to LANDED app\n";
149  boost::array<char, 2> conf;
150  if (socket_->receive(boost::asio::buffer(conf))!=1)
151  throw cet::exception("Landed") << "LANDED app did not confirm hit\n";
152 
153  }
Float_t x
Definition: compare.C:6
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:279
Float_t ss
Definition: plot.C:23
Float_t e
Definition: plot.C:34
Float_t track
Definition: plot.C:34
boost::asio::local::stream_protocol::socket * socket_
Definition: LandedSocket.h:35
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void evd::LandedSocket::sendVertex ( double  x,
double  y,
double  z,
double  e,
int  id,
int  pdgcode 
)

Definition at line 155 of file LandedSocket_service.cc.

References DEFINE_ART_SERVICE, socket_, and ss.

Referenced by sendHit().

156  {
157  std::ostringstream ss;
158  ss << "VTX:" << x << "," << y << "," << z << "," << e << "," << id << "," << pdgcode << "\n";
159  if (socket_->send(boost::asio::buffer(ss.str().c_str(), ss.str().length()))!=ss.str().length())
160  throw cet::exception("Landed") << "failed to send vertex to LANDED app\n";
161  boost::array<char, 2> conf;
162  if (socket_->receive(boost::asio::buffer(conf))!=1)
163  throw cet::exception("Landed") << "LANDED app did not confirm vertex\n";
164  }
Float_t x
Definition: compare.C:6
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:279
Float_t ss
Definition: plot.C:23
Float_t e
Definition: plot.C:34
boost::asio::local::stream_protocol::socket * socket_
Definition: LandedSocket.h:35
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33

Member Data Documentation

boost::asio::local::stream_protocol::endpoint* evd::LandedSocket::endpoint_
private

Definition at line 34 of file LandedSocket.h.

Referenced by connect().

art::InputSource* evd::LandedSocket::inputSource_
private

Definition at line 33 of file LandedSocket.h.

Referenced by postBeginJobWorkers(), and postProcessEvent().

unsigned long evd::LandedSocket::record_
private

Definition at line 37 of file LandedSocket.h.

Referenced by postBeginJobWorkers(), postProcessEvent(), and sendEvent().

boost::asio::io_service evd::LandedSocket::service_
private

Definition at line 36 of file LandedSocket.h.

Referenced by connect().

boost::asio::local::stream_protocol::socket* evd::LandedSocket::socket_
private

Definition at line 35 of file LandedSocket.h.

Referenced by connect(), postProcessEvent(), sendEvent(), sendGeometry(), sendHit(), and sendVertex().


The documentation for this class was generated from the following files: