FairRoot/PandaRoot
runHitSampler.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * PndMQSdsHitLoaderhis software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
15 #include <iostream>
16 
17 #include "boost/program_options.hpp"
18 
19 #include "FairMQLogger.h"
20 #include "FairMQSampler.h"
21 #include "FairMQParser.h"
22 
23 #ifdef NANOMSG
24 #include "FairMQTransportFactoryNN.h"
25 #else
26 #include "FairMQTransportFactoryZMQ.h"
27 #endif
28 
29 
30 // data format for the task
31 #include "PndMQSdsHitLoader.h"
32 #include "PndSdsHit.h"
33 #include "FairMQProgOptions.h"
34 #include "FairMQSampler.h"
35 
36 // boost data format
37 #include <boost/archive/text_oarchive.hpp>
38 #include <boost/archive/binary_oarchive.hpp>
39 
40 
41 
42 using namespace std;
43 using namespace boost::program_options;
44 
45 
46 int main(int argc, char** argv)
47 {
48 
49  FairMQProgOptions config;
50 
51  FairMQSampler<PndMQSdsHitLoader> sampler;
52  sampler.CatchSignals();
53 
54  try
55  {
56  std::string InputFile, ParFile, Branch;
57 
58  options_description samplerOptions("Sampler options");
59  samplerOptions.add_options()
60  ("InputFile", value<std::string>(&InputFile)->default_value(""))
61  ("ParameterFile", value<std::string>(&ParFile)->default_value(""))
62  ("Branch", value<std::string>(&Branch)->default_value(""));
63 
64  config.AddToCmdLineOptions(samplerOptions);
65 
66  config.ParseAll(argc, argv);
67 
68  std::string filename = config.GetValue<std::string>("config-json-file");
69  std::string id = config.GetValue<std::string>("id");
70 
71 
72 
73  config.UserParser<FairMQParser::JSON>(filename, id);
74  sampler.fChannels = config.GetFairMQMap();
75 
76  LOG(INFO) << "PID: " << getpid();
77 
78  #ifdef NANOMSG
79  FairMQTransportFactory* transportFactory = new FairMQTransportFactoryNN();
80  #else
81  FairMQTransportFactory* transportFactory = new FairMQTransportFactoryZMQ();
82  #endif
83 
84  sampler.SetTransport(transportFactory);
85 
86  sampler.SetProperty(FairMQDevice::Id, id);
87  sampler.SetProperty(FairMQSampler<PndMQSdsHitLoader>::InputFile, config.GetValue<string>("InputFile"));
88  sampler.SetProperty(FairMQSampler<PndMQSdsHitLoader>::ParFile, config.GetValue<string>("ParameterFile"));
89  sampler.SetProperty(FairMQSampler<PndMQSdsHitLoader>::Branch, config.GetValue<string>("Branch"));
90  //sampler.SetProperty(FairMQSampler::EventRate, options.eventRate);
91 
92  sampler.ChangeState("INIT_DEVICE");
93  sampler.WaitForEndOfState("INIT_DEVICE");
94 
95  sampler.ChangeState("INIT_TASK");
96  sampler.WaitForEndOfState("INIT_TASK");
97 
98  sampler.ChangeState("RUN");
99  sampler.InteractiveStateLoop();
100  }
101  catch (std::exception& e)
102  {
103  LOG(ERROR) << e.what();
104  LOG(INFO) << "Command line options are the following: ";
105  config.PrintHelp();
106  return 1;
107  }
108 
109  return 0;
110 }
int main(int argc, char **argv)
const string filename