FairRoot/PandaRoot
Functions
runExample1Sampler.cxx File Reference
#include <iostream>
#include "boost/program_options.hpp"
#include "FairMQLogger.h"
#include "FairMQParser.h"
#include "FairMQProgOptions.h"
#include "PndMQExample1Sampler.h"
#include "FairMQTransportFactoryZMQ.h"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 32 of file runExample1Sampler.cxx.

References filename, PndMQExample1Sampler::SetProperty(), and PndMQExample1Sampler::Text.

33 {
34  PndMQExample1Sampler sampler;
35  sampler.CatchSignals();
36 
37  FairMQProgOptions config;
38 
39  try
40  {
41  std::string text;
42 
43  options_description samplerOptions("Sampler options");
44  samplerOptions.add_options()
45  ("text", value<std::string>(&text)->default_value("Hello"), "Text to send out");
46 
47  config.AddToCmdLineOptions(samplerOptions);
48 
49  if (config.ParseAll(argc, argv))
50  {
51  return 0;
52  }
53 
54  std::string filename = config.GetValue<std::string>("config-json-file");
55  std::string id = config.GetValue<std::string>("id");
56 
57  config.UserParser<FairMQParser::JSON>(filename, id);
58 
59  sampler.fChannels = config.GetFairMQMap();
60 
61  LOG(INFO) << "PID: " << getpid();
62 
63 #ifdef NANOMSG
64  FairMQTransportFactory* transportFactory = new FairMQTransportFactoryNN();
65 #else
66  FairMQTransportFactory* transportFactory = new FairMQTransportFactoryZMQ();
67 #endif
68 
69  sampler.SetTransport(transportFactory);
70 
71  sampler.SetProperty(PndMQExample1Sampler::Id, id);
73 
74  sampler.ChangeState("INIT_DEVICE");
75  sampler.WaitForEndOfState("INIT_DEVICE");
76 
77  sampler.ChangeState("INIT_TASK");
78  sampler.WaitForEndOfState("INIT_TASK");
79 
80  sampler.ChangeState("RUN");
81  sampler.InteractiveStateLoop();
82  }
83  catch (std::exception& e)
84  {
85  LOG(ERROR) << e.what();
86  LOG(INFO) << "Command line options are the following: ";
87  config.PrintHelp();
88  return 1;
89  }
90 
91  return 0;
92 }
virtual void SetProperty(const int key, const std::string &value)
const string filename