GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions | Variables
gEvServ.cxx File Reference
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <TSystem.h>
#include <TServerSocket.h>
#include <TSocket.h>
#include <TMessage.h>
#include <TBits.h>
#include <TMath.h>
#include "Conventions/Units.h"
#include "EVGCore/EventRecord.h"
#include "EVGDrivers/GEVGDriver.h"
#include "EVGDrivers/GEVGPool.h"
#include "EVGDrivers/GMCJMonitor.h"
#include "GHEP/GHepFlags.h"
#include "GHEP/GHepParticle.h"
#include "GHEP/GHepRecord.h"
#include "Interaction/Interaction.h"
#include "Messenger/Messenger.h"
#include "Numerical/Spline.h"
#include "PDG/PDGCodeList.h"
#include "Utils/XSecSplineList.h"
#include "Utils/StringUtils.h"
#include "Utils/CmdLnArgParser.h"
Include dependency graph for gEvServ.cxx:

Go to the source code of this file.

Functions

void GetCommandLineArgs (int argc, char **argv)
 
void PrintSyntax (void)
 
void RunInitChecks (void)
 
void HandleMesg (string mesg)
 
void Handshake (void)
 
void Configure (string mesg)
 
void CalcTotalXSec (string mesg)
 
void GenerateEvent (string mesg)
 
void Shutdown (void)
 
int main (int argc, char **argv)
 

Variables

const int kDefPortNum = 9090
 
const string kHandshakeCmdRecv = "RUB GENIE LAMP"
 
const string kHandshakeMesgSent = "YOU HAVE 3 WISHES!"
 
const string kConfigCmdRecv = "CONFIG"
 
const string kConfigOkMesgSent = "CONFIG COMPLETED"
 
const string kConfigCmdLdSpl = "load-splines"
 
const string kConfigCmdNeuList = "neutrino-list"
 
const string kConfigCmdTgtList = "target-list"
 
const string kXSecCmdRecv = "XSEC"
 
const string kXSecCmdSent = "XSECSPL"
 
const string kXSecOkMesgSent = "XSEC SENT"
 
const string kEvgenCmdRecv = "EVTVTX"
 
const string kEvgenHdrCmdSent = "EVTREC"
 
const string kEvgenStdhepCmdSent = "STDHEP"
 
const string kEvgenOkMesgSent = "EVENT GENERATED"
 
const string kShutdownCmdRecv = "SHUTDOWN"
 
const string kShutdownOkMesgSent = "SHUTTING DOWN"
 
const string kErrNoConf = "*** NOT CONFIGURED! ***"
 
const string kErrNoDriver = "*** NO EVENT GENERATION DRIVER! ***"
 
const string kErrNoEvent = "*** NULL OR UNPHYSICAL EVENT! ***"
 
const string kErr = "FAILED"
 
int gOptPortNum
 
TSocket * gSock = 0
 
bool gShutDown = false
 
bool gConfigured = false
 
GEVGPool gGPool
 

Function Documentation

void CalcTotalXSec ( string  mesg)

Definition at line 315 of file gEvServ.cxx.

References genie::InitialState::AsString(), genie::units::cm2, genie::GEVGDriver::CreateXSecSumSpline(), genie::Spline::Evaluate(), genie::utils::str::FilterString(), genie::GEVGPool::FindDriver(), gConfigured, gGPool, gSock, kErr, kErrNoConf, kErrNoDriver, kXSecCmdRecv, kXSecCmdSent, kXSecOkMesgSent, LOG, pERROR, pINFO, pNOTICE, genie::utils::str::Split(), genie::utils::str::TrimSpaces(), and genie::GEVGDriver::XSecSumSpline().

Referenced by HandleMesg().

316 {
317  LOG("gevserv", pNOTICE)
318  << "Sending total xsec for enabled channels - Input info : " << mesg;
319 
320  if(!gConfigured) {
321  LOG("gevserv", pERROR)
322  << "Event server is not configured - Can not generate event";
323  gSock->Send(kErrNoConf.c_str());
324  gSock->Send(kErr.c_str());
325  return;
326  }
327 
328  // Extract info from the input mesg
329 
330  mesg = str::FilterString(kXSecCmdRecv, mesg);
331  mesg = str::FilterString(":", mesg);
332  mesg = str::TrimSpaces(mesg);
333 
334  vector<string> sv = str::Split(mesg," ");
335  assert(sv.size()==2);
336 
337  int ipdgnu = atoi(sv[0].c_str()); // neutrino code
338  int ipdgtgt = atoi(sv[1].c_str()); // target code
339 
340  // Find the appropriate event generation driver for the given initial state
341 
342  InitialState init_state(ipdgtgt, ipdgnu);
343  GEVGDriver * evg_driver = gGPool.FindDriver(init_state);
344  if(!evg_driver) {
345  LOG("gevserv", pERROR)
346  << "No GEVGDriver object for init state: " << init_state.AsString();
347  gSock->Send(kErrNoDriver.c_str());
348  gSock->Send(kErr.c_str());
349  return;
350  }
351 
352  // Ask the event generation driver to sum up the splines for all enabled
353  // channels
354 
355  LOG("gevserv", pNOTICE)
356  << "Requesting total cross section for init state: "
357  << init_state.AsString();
358 
359  evg_driver->CreateXSecSumSpline (
360  1000 /*nknots*/, 0.001 /*Emin*/, 300 /*Emax*/, true /*in-log*/);
361 
362  const Spline * total_xsec_spl = evg_driver->XSecSumSpline();
363  assert(total_xsec_spl);
364 
365  // Send back the cross section data (use 200 MeV bins from 0.010 -> 200.010 GeV)
366 
367  double dE = 0.200;
368  double Emin = 0.010;
369  double Emax = 200.010;
370  int np = (int) TMath::Ceil((Emax-Emin)/dE);
371 
372  ostringstream xsec_hdr;
373  xsec_hdr << kXSecCmdSent << ":" << np;
374  gSock->Send(xsec_hdr.str().c_str());
375 
376  for(int ip=0; ip<np; ip++) {
377  double E = Emin + ip*dE;
378  double xs = TMath::Max(0., total_xsec_spl->Evaluate(E) / (1E-38*units::cm2));
379 
380  ostringstream xsec_spl_knot;
381  xsec_spl_knot << ip << " " << E << " " << Form("%15.8e",xs);
382  gSock->Send(xsec_spl_knot.str().c_str());
383  }
384 
385  gSock->Send(kXSecOkMesgSent.c_str());
386 
387  LOG("gevserv", pINFO) << "...done!";
388 }
void CreateXSecSumSpline(int nk, double Emin, double Emax, bool inlogE=true)
Definition: GEVGDriver.cxx:440
const string kXSecCmdSent
Definition: gEvServ.cxx:85
#define pERROR
Definition: Messenger.h:59
A numeric analysis tool class for interpolating 1-D functions.
Definition: Spline.h:58
const Spline * XSecSumSpline(void) const
Definition: GEVGDriver.h:87
GEVGDriver * FindDriver(const InitialState &init) const
Definition: GEVGPool.cxx:44
double Evaluate(double x) const
Definition: Spline.cxx:363
const string kErr
Definition: gEvServ.cxx:96
const string kXSecCmdRecv
Definition: gEvServ.cxx:84
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
static constexpr double cm2
Definition: Units.h:69
bool gConfigured
Definition: gEvServ.cxx:106
TSocket * gSock
Definition: gEvServ.cxx:104
GENIE Event Generation Driver. A minimalist user interface object for generating neutrino interaction...
Definition: GEVGDriver.h:54
#define pINFO
Definition: Messenger.h:62
const string kErrNoConf
Definition: gEvServ.cxx:93
string TrimSpaces(string input)
Definition: StringUtils.cxx:18
string FilterString(string filt, string input)
Definition: StringUtils.cxx:79
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
const string kErrNoDriver
Definition: gEvServ.cxx:94
#define pNOTICE
Definition: Messenger.h:61
GEVGPool gGPool
Definition: gEvServ.cxx:107
const string kXSecOkMesgSent
Definition: gEvServ.cxx:86
Initial State information.
Definition: InitialState.h:48
void Configure ( string  mesg)

Definition at line 196 of file gEvServ.cxx.

References genie::InitialState::AsString(), genie::GEVGDriver::Configure(), genie::utils::str::FilterString(), gConfigured, gGPool, gSock, genie::XSecSplineList::Instance(), kConfigCmdLdSpl, kConfigCmdNeuList, kConfigCmdRecv, kConfigCmdTgtList, kConfigOkMesgSent, LOG, pINFO, pNOTICE, genie::PDGCodeList::push_back(), genie::utils::str::Split(), genie::utils::str::TrimSpaces(), and genie::GEVGDriver::UseSplines().

Referenced by genie::Algorithm::AdoptConfig(), genie::Algorithm::Configure(), genie::GEVGDriver::Configure(), and HandleMesg().

197 {
198 // Configure the GENIE event server
199 // ** Load splines
200 // - if the "load-splines" command is contained in the mesg
201 // - the splines are loaded from the the XML file specified in $GSPLOAD (server-side)
202 // the "load-splines" mesg is sent
203 // ** Specify the neutrino list
204 // - adding a "neutrino-list=<comma separated list of pdg codes>" in the mesg
205 // ** Specify the target list
206 // - adding a "target-list=<comma separated list of pdg codes>" in the mesg
207 //
208 // Note:
209 // - All nedded cross section splines for the specified neutrino/target lists must
210 // be available in the specified XML file. If not GENIE will attempt building the
211 // the missing ones which may increase start-up overheads.
212 // - You can further control GENIE (suppress modes, set messenger verbosity, ...)
213 // by setting all the std GENIE env vars at the server side.
214 // See the GENIE web site.
215 
216  LOG("gevserv", pNOTICE) << "Configuring GENIE event server";
217 
218  mesg = str::FilterString(kConfigCmdRecv, mesg);
219  mesg = str::FilterString(":", mesg);
220  mesg = str::TrimSpaces(mesg);
221 
222  LOG("gevserv", pNOTICE) << "Configure options: " << mesg;
223 
224  // Autoload splines from the XML file pointed at the $GSPLOAD env. var.
225  // (if set at the server side)
226  //
227  if(mesg.find(kConfigCmdLdSpl) != string::npos) {
228  XSecSplineList * xspl = XSecSplineList::Instance();
229  xspl->AutoLoad();
230 
231  mesg.erase(mesg.find(kConfigCmdLdSpl),12);
232  mesg = str::TrimSpaces(mesg);
233  }
234 
235  // Extract neutrino and target lists from the input mesg
236  //
237  bool allowdup = false;
238  PDGCodeList neutrinos(allowdup);
239  PDGCodeList targets(allowdup);
240 
241  vector<string> conf_opt_v = str::Split(mesg," ");
242  vector<string>::iterator conf_opt_iter = conf_opt_v.begin();
243 
244  for( ; conf_opt_iter != conf_opt_v.end(); ++conf_opt_iter) {
245  string conf_opt = *conf_opt_iter;
246  LOG("gevserv", pNOTICE)
247  << "Processing config option: " << conf_opt;
248 
249  vector<string> sv = str::Split(conf_opt, "=");
250  assert(sv.size()==2);
251  string list_name = sv[0];
252  string particle_list = sv[1];
253 
254  vector<string> particles = str::Split(particle_list, ",");
255  vector<string>::iterator particle_iter = particles.begin();
256 
257  for( ; particle_iter != particles.end(); ++particle_iter) {
258  string particle_code_str = *particle_iter;
259  int particle_code = atoi(particle_code_str.c_str());
260 
261  if(list_name.find(kConfigCmdNeuList) != string::npos)
262  {
263  neutrinos.push_back(particle_code);
264  } else
265  if(list_name.find(kConfigCmdTgtList) != string::npos)
266  {
267  targets.push_back(particle_code);
268  }
269  }
270  }
271 
272  LOG("gevserv", pNOTICE)
273  << "Specified neutrino list: " << neutrinos;
274  LOG("gevserv", pNOTICE)
275  << "Specified target list: " << targets;
276 
277 
278  // Loop over the specified neutrinos and targets and for each
279  // possible pair create / configure a GENIE event generation driver.
280  //
281  PDGCodeList::const_iterator nuiter;
282  PDGCodeList::const_iterator tgtiter;
283 
284  for(nuiter = neutrinos.begin(); nuiter != neutrinos.end(); ++nuiter) {
285  for(tgtiter = targets.begin(); tgtiter != targets.end(); ++tgtiter) {
286 
287  int target_code = *tgtiter;
288  int neutrino_code = *nuiter;
289 
290  InitialState init_state(target_code, neutrino_code);
291 
292  LOG("gevserv", pNOTICE)
293  << "\n\n ---- Creating a GEVGDriver object configured for init-state: "
294  << init_state.AsString() << " ----\n\n";
295 
296  GEVGDriver * evgdriver = new GEVGDriver;
297  evgdriver->Configure(init_state);
298  evgdriver->UseSplines(); // will also check if all splines needed are loaded
299 
300  gGPool.insert( GEVGPool::value_type(init_state.AsString(), evgdriver) );
301 
302  } // targets
303  } // neutrinos
304 
305  LOG("gevserv", pNOTICE)
306  << "All necessary GEVGDriver object were pushed into GEVGPool\n";
307 
308  gConfigured = true;
309 
310  gSock->Send(kConfigOkMesgSent.c_str());
311 
312  LOG("gevserv", pINFO) << "...done!";
313 }
const string kConfigCmdRecv
Definition: gEvServ.cxx:79
A list of PDG codes.
Definition: PDGCodeList.h:32
const string kConfigCmdTgtList
Definition: gEvServ.cxx:83
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
bool gConfigured
Definition: gEvServ.cxx:106
TSocket * gSock
Definition: gEvServ.cxx:104
GENIE Event Generation Driver. A minimalist user interface object for generating neutrino interaction...
Definition: GEVGDriver.h:54
#define pINFO
Definition: Messenger.h:62
const string kConfigCmdLdSpl
Definition: gEvServ.cxx:81
string TrimSpaces(string input)
Definition: StringUtils.cxx:18
const string kConfigOkMesgSent
Definition: gEvServ.cxx:80
string FilterString(string filt, string input)
Definition: StringUtils.cxx:79
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
void Configure(int nu_pdgc, int Z, int A)
Definition: GEVGDriver.cxx:137
void UseSplines(void)
Definition: GEVGDriver.cxx:508
#define pNOTICE
Definition: Messenger.h:61
const string kConfigCmdNeuList
Definition: gEvServ.cxx:82
List of cross section vs energy splines.
GEVGPool gGPool
Definition: gEvServ.cxx:107
Initial State information.
Definition: InitialState.h:48
void GenerateEvent ( string  mesg)

Definition at line 390 of file gEvServ.cxx.

References genie::InitialState::AsString(), genie::GHepParticle::E(), genie::utils::str::FilterString(), genie::GEVGPool::FindDriver(), genie::GHepParticle::FirstDaughter(), genie::GHepParticle::FirstMother(), gConfigured, genie::GEVGDriver::GenerateEvent(), gGPool, gSock, genie::Target::HitQrkPdg(), genie::Interaction::InitState(), genie::ProcessInfo::IsDeepInelastic(), genie::ProcessInfo::IsInverseMuDecay(), genie::ProcessInfo::IsNuElectronElastic(), genie::ProcessInfo::IsQuasiElastic(), genie::ProcessInfo::IsResonant(), genie::GHepRecord::IsUnphysical(), genie::ProcessInfo::IsWeakCC(), genie::ProcessInfo::IsWeakNC(), kErr, kErrNoConf, kErrNoDriver, kErrNoEvent, kEvgenCmdRecv, kEvgenHdrCmdSent, kEvgenOkMesgSent, kEvgenStdhepCmdSent, genie::Interaction::Kine(), genie::GHepParticle::LastDaughter(), genie::GHepParticle::LastMother(), LOG, genie::GHepParticle::Mass(), genie::GHepParticle::Pdg(), pERROR, pINFO, pNOTICE, genie::Interaction::ProcInfo(), pWARN, genie::GHepParticle::Px(), genie::GHepParticle::Py(), genie::GHepParticle::Pz(), genie::Kinematics::Q2(), genie::utils::str::Split(), genie::GHepParticle::Status(), genie::InitialState::Tgt(), genie::utils::str::TrimSpaces(), genie::GHepParticle::Vt(), genie::GHepParticle::Vx(), genie::GHepParticle::Vy(), genie::GHepParticle::Vz(), genie::Kinematics::W(), genie::Kinematics::x(), and genie::Kinematics::y().

Referenced by genie::GEVGDriver::GenerateEvent(), and HandleMesg().

391 {
392  LOG("gevserv", pNOTICE) << "Generating event - Input info : " << mesg;
393 
394  if(!gConfigured) {
395  LOG("gevserv", pERROR)
396  << "Event server is not configured - Can not generate event";
397  gSock->Send(kErrNoConf.c_str());
398  gSock->Send(kErr.c_str());
399  return;
400  }
401 
402  // Extract info from the input mesg
403 
404  mesg = str::FilterString(kEvgenCmdRecv, mesg);
405  mesg = str::FilterString(":", mesg);
406  mesg = str::TrimSpaces(mesg);
407 
408  vector<string> sv = str::Split(mesg," ");
409 
410  assert(sv.size()==11);
411  int irun = atoi(sv[0].c_str()); // just pass through
412  int ievt = atoi(sv[1].c_str()); // ...
413  int ipdgnunoosc = atoi(sv[2].c_str()); // ...
414  double vtxx = atof(sv[3].c_str()); // ...
415  double vtxy = atof(sv[4].c_str()); // ...
416  double vtxz = atof(sv[5].c_str()); // ...
417  int ipdgnu = atoi(sv[6].c_str()); // neutrino code
418  int ipdgtgt = atoi(sv[7].c_str()); // target code
419  double px = atof(sv[8].c_str()); // neutrino px
420  double py = atof(sv[9].c_str()); // neutrino py
421  double pz = atof(sv[10].c_str()); // neutrino pz
422  double E = TMath::Sqrt(px*px + py*py + pz*pz);
423 
424  TLorentzVector p4(px,py,pz,E);
425 
426  // Find the appropriate event generation driver for the given initial state
427 
428  InitialState init_state(ipdgtgt, ipdgnu);
429  GEVGDriver * evg_driver = gGPool.FindDriver(init_state);
430  if(!evg_driver) {
431  LOG("gevserv", pERROR)
432  << "No GEVGDriver object for init state: " << init_state.AsString();
433  gSock->Send(kErrNoDriver.c_str());
434  gSock->Send(kErr.c_str());
435  return;
436  }
437 
438  // Generate the requested event
439 
440  EventRecord * event = evg_driver->GenerateEvent(p4);
441 
442  // Check/print the generated event
443  bool failed = (event==0) || event->IsUnphysical();
444  if(failed) {
445  LOG("gevserv", pWARN)
446  << "Failed to generate the requested event";
447  gSock->Send(kErrNoEvent.c_str());
448  gSock->Send(kErr.c_str());
449  return;
450  }
451  LOG("gevserv", pINFO) << "Generated event: " << *event;
452 
453  // Extract some summary info & convert to what MINOS expects
454 
455  const Interaction * interaction = event->Summary();
456  const ProcessInfo & proc_info = interaction->ProcInfo();
457  const Kinematics & kine = interaction->Kine();
458 
459  int int_type = -1;
460  if (proc_info.IsQuasiElastic()) int_type = 1;
461  else if (proc_info.IsResonant()) int_type = 2;
462  else if (proc_info.IsDeepInelastic()) int_type = 3;
463  else if (proc_info.IsCoherent()) int_type = 4;
464  else if (proc_info.IsInverseMuDecay()) int_type = 5;
465  else if (proc_info.IsNuElectronElastic()) int_type = 6;
466 
467  int iaction = -1;
468  if (proc_info.IsWeakNC()) iaction = 0;
469  else if (proc_info.IsWeakCC()) iaction = 1;
470  else iaction = 2; // cc+nc interference
471 
472  int nucleon = -1;
473  GHepParticle * hitnucl = event->HitNucleon();
474  if(hitnucl) {
475  nucleon = hitnucl->Pdg();
476  }
477 
478  int hitquark = interaction->InitState().Tgt().HitQrkPdg();
479 
480  bool get_selected = true;
481  double xbj_sel = kine.x (get_selected);
482  double y_sel = kine.y (get_selected);
483  double W2_sel = TMath::Power(kine.W (get_selected), 2.);
484  double q2_sel = -1 * kine.Q2(get_selected);
485 
486  double tot_xsec = event->XSec();
487  double diff_xsec = event->DiffXSec();
488 
489  int ihadmode = 0; // need to fill
490 
491  // Send back the event through the tcp/ip socket
492 
493  ostringstream hdr1, hdr2, hdr3, hdr4, stdhep_hdr;
494 
495  hdr1
496  << kEvgenHdrCmdSent << ": "
497  << irun << " "
498  << ievt << " "
499  << ipdgnunoosc << " "
500  << vtxx << " "
501  << vtxy << " "
502  << vtxz;
503  hdr2
504  << ipdgnu << " "
505  << ipdgtgt << " "
506  << px << " "
507  << py << " "
508  << pz;
509  hdr3
510  << int_type << " "
511  << iaction << " "
512  << nucleon << " "
513  << hitquark << " "
514  << xbj_sel << " "
515  << y_sel << " "
516  << W2_sel << " "
517  << q2_sel;
518  hdr4
519  << tot_xsec << " "
520  << diff_xsec << " "
521  << ihadmode;
522 
523  stdhep_hdr
524  << kEvgenStdhepCmdSent << ": "
525  << event->GetEntriesFast();
526 
527  gSock->Send(hdr1.str().c_str());
528  gSock->Send(hdr2.str().c_str());
529  gSock->Send(hdr3.str().c_str());
530  gSock->Send(hdr4.str().c_str());
531  gSock->Send(stdhep_hdr.str().c_str());
532 
533  unsigned int i=0;
534  TIter event_iter(event);
535  GHepParticle * p = 0;
536  while ( (p = dynamic_cast<GHepParticle *>(event_iter.Next())) ) {
537 
538  ostringstream stdhep_entry;
539 
540  stdhep_entry
541  << i << " " << p->Status() << " " << p->Pdg() << " "
542  << p->FirstMother() << " " << p->LastMother() << " "
543  << p->FirstDaughter() << " " << p->LastDaughter() << " "
544  << p->Px() << " " << p->Py() << " " << p->Pz() << " " << p->E() << " "
545  << p->Mass() << " "
546  << p->Vx() << " " << p->Vy() << " " << p->Vz() << " " << p->Vt();
547 
548  gSock->Send(stdhep_entry.str().c_str());
549  i++;
550  }
551 
552  // Clean-up and report success
553 
554  delete event;
555 
556  gSock->Send(kEvgenOkMesgSent.c_str());
557 
558  LOG("gevserv", pINFO) << "...done!";
559 }
bool IsResonant(void) const
Definition: ProcessInfo.cxx:99
double W(bool selected=false) const
Definition: Kinematics.cxx:157
bool IsWeakCC(void) const
#define pERROR
Definition: Messenger.h:59
double E(void) const
Get energy.
Definition: GHepParticle.h:91
int FirstDaughter(void) const
Definition: GHepParticle.h:68
int HitQrkPdg(void) const
Definition: Target.cxx:242
bool IsInverseMuDecay(void) const
bool IsQuasiElastic(void) const
Definition: ProcessInfo.cxx:69
Generated/set kinematical variables for an event.
Definition: Kinematics.h:39
double x(bool selected=false) const
Definition: Kinematics.cxx:99
double Mass(void) const
Mass that corresponds to the PDG code.
GEVGDriver * FindDriver(const InitialState &init) const
Definition: GEVGPool.cxx:44
const string kEvgenHdrCmdSent
Definition: gEvServ.cxx:88
double Pz(void) const
Get Pz.
Definition: GHepParticle.h:90
GHepStatus_t Status(void) const
Definition: GHepParticle.h:64
double Px(void) const
Get Px.
Definition: GHepParticle.h:88
double y(bool selected=false) const
Definition: Kinematics.cxx:112
int LastMother(void) const
Definition: GHepParticle.h:67
double Vt(void) const
Get production time.
Definition: GHepParticle.h:97
int Pdg(void) const
Definition: GHepParticle.h:63
int FirstMother(void) const
Definition: GHepParticle.h:66
Summary information for an interaction.
Definition: Interaction.h:56
const string kErrNoEvent
Definition: gEvServ.cxx:95
const string kErr
Definition: gEvServ.cxx:96
int LastDaughter(void) const
Definition: GHepParticle.h:69
bool IsWeakNC(void) const
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
bool IsNuElectronElastic(void) const
A class encapsulating an enumeration of interaction types (EM, Weak-CC, Weak-NC) and scattering types...
Definition: ProcessInfo.h:46
const string kEvgenStdhepCmdSent
Definition: gEvServ.cxx:89
const Kinematics & Kine(void) const
Definition: Interaction.h:71
bool gConfigured
Definition: gEvServ.cxx:106
TSocket * gSock
Definition: gEvServ.cxx:104
GENIE Event Generation Driver. A minimalist user interface object for generating neutrino interaction...
Definition: GEVGDriver.h:54
#define pINFO
Definition: Messenger.h:62
const string kErrNoConf
Definition: gEvServ.cxx:93
#define pWARN
Definition: Messenger.h:60
string TrimSpaces(string input)
Definition: StringUtils.cxx:18
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:37
bool IsDeepInelastic(void) const
Definition: ProcessInfo.cxx:89
const string kEvgenCmdRecv
Definition: gEvServ.cxx:87
const string kEvgenOkMesgSent
Definition: gEvServ.cxx:90
string FilterString(string filt, string input)
Definition: StringUtils.cxx:79
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
virtual bool IsUnphysical(void) const
Definition: GHepRecord.h:119
double Vz(void) const
Get production z.
Definition: GHepParticle.h:96
const InitialState & InitState(void) const
Definition: Interaction.h:69
const string kErrNoDriver
Definition: gEvServ.cxx:94
const ProcessInfo & ProcInfo(void) const
Definition: Interaction.h:70
double Vy(void) const
Get production y.
Definition: GHepParticle.h:95
double Q2(bool selected=false) const
Definition: Kinematics.cxx:125
#define pNOTICE
Definition: Messenger.h:61
const Target & Tgt(void) const
Definition: InitialState.h:66
STDHEP-like event record entry that can fit a particle or a nucleus.
Definition: GHepParticle.h:39
GEVGPool gGPool
Definition: gEvServ.cxx:107
double Vx(void) const
Get production x.
Definition: GHepParticle.h:94
Initial State information.
Definition: InitialState.h:48
EventRecord * GenerateEvent(const TLorentzVector &nu4p)
Definition: GEVGDriver.cxx:228
double Py(void) const
Get Py.
Definition: GHepParticle.h:89
void GetCommandLineArgs ( int  argc,
char **  argv 
)
void HandleMesg ( string  mesg)

Definition at line 156 of file gEvServ.cxx.

References CalcTotalXSec(), Configure(), GenerateEvent(), Handshake(), kConfigCmdRecv, kEvgenCmdRecv, kHandshakeCmdRecv, kShutdownCmdRecv, kXSecCmdRecv, and Shutdown().

Referenced by main().

157 {
158  if(mesg.find(kHandshakeCmdRecv.c_str()) != string::npos)
159  {
160  Handshake();
161  }
162  else
163  if (mesg.find(kConfigCmdRecv.c_str()) != string::npos)
164  {
165  Configure(mesg);
166  }
167  else
168  if (mesg.find(kXSecCmdRecv.c_str()) != string::npos)
169  {
170  CalcTotalXSec(mesg);
171  }
172  else
173  if (mesg.find(kEvgenCmdRecv.c_str()) != string::npos)
174  {
175  GenerateEvent(mesg);
176  }
177  else
178  if (mesg.find(kShutdownCmdRecv.c_str()) != string::npos)
179  {
180  Shutdown();
181  }
182 }
const string kConfigCmdRecv
Definition: gEvServ.cxx:79
void Shutdown(void)
Definition: gEvServ.cxx:561
void GenerateEvent(string mesg)
Definition: gEvServ.cxx:390
const string kShutdownCmdRecv
Definition: gEvServ.cxx:91
const string kXSecCmdRecv
Definition: gEvServ.cxx:84
const string kEvgenCmdRecv
Definition: gEvServ.cxx:87
void CalcTotalXSec(string mesg)
Definition: gEvServ.cxx:315
void Configure(string mesg)
Definition: gEvServ.cxx:196
void Handshake(void)
Definition: gEvServ.cxx:184
const string kHandshakeCmdRecv
Definition: gEvServ.cxx:77
void Handshake ( void  )

Definition at line 184 of file gEvServ.cxx.

References gSock, kHandshakeMesgSent, LOG, pINFO, and pNOTICE.

Referenced by HandleMesg().

185 {
186 // Reply to client messages checking whether the event server is active
187 //
188  LOG("gevserv", pNOTICE)
189  << "GENIE was pinged by a client (lamp was rubbed)! Responding...";
190 
191  gSock->Send(kHandshakeMesgSent.c_str());
192 
193  LOG("gevserv", pINFO) << "...done!";
194 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
TSocket * gSock
Definition: gEvServ.cxx:104
#define pINFO
Definition: Messenger.h:62
const string kHandshakeMesgSent
Definition: gEvServ.cxx:78
#define pNOTICE
Definition: Messenger.h:61
int main ( int  argc,
char **  argv 
)

Definition at line 110 of file gEvServ.cxx.

References GetCommandLineArgs(), gOptPortNum, gShutDown, gSock, HandleMesg(), LOG, pNOTICE, and RunInitChecks().

111 {
112  // Parse command line arguments
113  GetCommandLineArgs(argc,argv);
114 
115  // Run some checks
116  RunInitChecks();
117 
118  // Open a server socket
119  TServerSocket * serv_sock = new TServerSocket(gOptPortNum, kTRUE);
120 
121  // Accept a connection
122  gSock = serv_sock->Accept();
123 
124  if(!gSock) exit(1);
125  LOG("gevserv", pNOTICE) << "Listening on port: " << gOptPortNum;
126 
127  // Set no TCP/IP NODELAY
128  int delay_ok = gSock->SetOption(kNoDelay,1);
129  LOG("gevserv", pNOTICE) << "TCP_NODELAY > " << delay_ok;
130 
131  // Start listening for messages & take the corresponding actions
132 
133  while(1) {
134 
135  if(gShutDown) break;
136 
137  TMessage * mesg = 0;
138 
139  gSock->Recv(mesg);
140 
141  if(!mesg) continue;
142  if(mesg->What() != kMESS_STRING) continue;
143 
144  char mesg_content[2048];
145  mesg->ReadString(mesg_content, 2048);
146 
147  LOG("gevserv", pNOTICE) << "Processing mesg > " << mesg_content;
148 
149  HandleMesg(mesg_content);
150 
151  } // while(1)
152 
153  return 0;
154 }
void RunInitChecks(void)
Definition: gEvServ.cxx:572
int gOptPortNum
Definition: gEvServ.cxx:100
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
TSocket * gSock
Definition: gEvServ.cxx:104
void HandleMesg(string mesg)
Definition: gEvServ.cxx:156
bool gShutDown
Definition: gEvServ.cxx:105
#define pNOTICE
Definition: Messenger.h:61
void GetCommandLineArgs(int argc, char **argv)
Definition: gAtmoEvGen.cxx:563
void PrintSyntax ( void  )
void RunInitChecks ( void  )

Definition at line 572 of file gEvServ.cxx.

References LOG, and pWARN.

Referenced by main().

573 {
574  if(gSystem->Getenv("GSPLOAD")) {
575  string splines_filename = gSystem->Getenv("GSPLOAD");
576  bool is_accessible = ! (gSystem->AccessPathName( splines_filename.c_str() ));
577  if (!is_accessible) {
578  LOG("gevserv", pWARN)
579  << "*** The file (" << splines_filename
580  << ") specified in $GSPLOAD doesn't seem to be available!";
581  LOG("gevserv", pWARN)
582  << "*** Expect a significant start-up overhead!";
583  }
584  } else {
585  LOG("gevserv", pWARN) << "*** $GSPLOAD was not set!";
586  LOG("gevserv", pWARN) << "*** Expect a significant start-up overhead!";
587  }
588 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pWARN
Definition: Messenger.h:60
void Shutdown ( void  )

Definition at line 561 of file gEvServ.cxx.

References gShutDown, gSock, kShutdownOkMesgSent, LOG, pINFO, and pNOTICE.

Referenced by HandleMesg().

562 {
563  LOG("gevserv", pNOTICE) << "Shutting GENIE event server down ...";
564 
565  gShutDown = true;
566 
567  gSock->Send(kShutdownOkMesgSent.c_str());
568 
569  LOG("gevserv", pINFO) << "...done!";
570 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
TSocket * gSock
Definition: gEvServ.cxx:104
#define pINFO
Definition: Messenger.h:62
const string kShutdownOkMesgSent
Definition: gEvServ.cxx:92
bool gShutDown
Definition: gEvServ.cxx:105
#define pNOTICE
Definition: Messenger.h:61

Variable Documentation

bool gConfigured = false

Definition at line 106 of file gEvServ.cxx.

Referenced by CalcTotalXSec(), Configure(), and GenerateEvent().

GEVGPool gGPool

Definition at line 107 of file gEvServ.cxx.

Referenced by CalcTotalXSec(), Configure(), and GenerateEvent().

int gOptPortNum

Definition at line 100 of file gEvServ.cxx.

Referenced by main().

bool gShutDown = false

Definition at line 105 of file gEvServ.cxx.

Referenced by main(), and Shutdown().

TSocket* gSock = 0

Definition at line 104 of file gEvServ.cxx.

Referenced by CalcTotalXSec(), Configure(), GenerateEvent(), Handshake(), main(), and Shutdown().

const string kConfigCmdLdSpl = "load-splines"

Definition at line 81 of file gEvServ.cxx.

Referenced by Configure().

const string kConfigCmdNeuList = "neutrino-list"

Definition at line 82 of file gEvServ.cxx.

Referenced by Configure().

const string kConfigCmdRecv = "CONFIG"

Definition at line 79 of file gEvServ.cxx.

Referenced by Configure(), and HandleMesg().

const string kConfigCmdTgtList = "target-list"

Definition at line 83 of file gEvServ.cxx.

Referenced by Configure().

const string kConfigOkMesgSent = "CONFIG COMPLETED"

Definition at line 80 of file gEvServ.cxx.

Referenced by Configure().

const int kDefPortNum = 9090

Definition at line 76 of file gEvServ.cxx.

const string kErr = "FAILED"

Definition at line 96 of file gEvServ.cxx.

Referenced by CalcTotalXSec(), and GenerateEvent().

const string kErrNoConf = "*** NOT CONFIGURED! ***"

Definition at line 93 of file gEvServ.cxx.

Referenced by CalcTotalXSec(), and GenerateEvent().

const string kErrNoDriver = "*** NO EVENT GENERATION DRIVER! ***"

Definition at line 94 of file gEvServ.cxx.

Referenced by CalcTotalXSec(), and GenerateEvent().

const string kErrNoEvent = "*** NULL OR UNPHYSICAL EVENT! ***"

Definition at line 95 of file gEvServ.cxx.

Referenced by GenerateEvent().

const string kEvgenCmdRecv = "EVTVTX"

Definition at line 87 of file gEvServ.cxx.

Referenced by GenerateEvent(), and HandleMesg().

const string kEvgenHdrCmdSent = "EVTREC"

Definition at line 88 of file gEvServ.cxx.

Referenced by GenerateEvent().

const string kEvgenOkMesgSent = "EVENT GENERATED"

Definition at line 90 of file gEvServ.cxx.

Referenced by GenerateEvent().

const string kEvgenStdhepCmdSent = "STDHEP"

Definition at line 89 of file gEvServ.cxx.

Referenced by GenerateEvent().

const string kHandshakeCmdRecv = "RUB GENIE LAMP"

Definition at line 77 of file gEvServ.cxx.

Referenced by HandleMesg().

const string kHandshakeMesgSent = "YOU HAVE 3 WISHES!"

Definition at line 78 of file gEvServ.cxx.

Referenced by Handshake().

const string kShutdownCmdRecv = "SHUTDOWN"

Definition at line 91 of file gEvServ.cxx.

Referenced by HandleMesg().

const string kShutdownOkMesgSent = "SHUTTING DOWN"

Definition at line 92 of file gEvServ.cxx.

Referenced by Shutdown().

const string kXSecCmdRecv = "XSEC"

Definition at line 84 of file gEvServ.cxx.

Referenced by CalcTotalXSec(), and HandleMesg().

const string kXSecCmdSent = "XSECSPL"

Definition at line 85 of file gEvServ.cxx.

Referenced by CalcTotalXSec().

const string kXSecOkMesgSent = "XSEC SENT"

Definition at line 86 of file gEvServ.cxx.

Referenced by CalcTotalXSec().