FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairSimConfig.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 #include "FairSimConfig.h"
9 
10 #include "FairLogger.h"
11 
12 #include <iostream>
13 #include <vector>
14 
15 using namespace std;
16 
18  : fDescription("Options")
19  , fHelp(false)
20  , fnEvents(1)
21  , fEngine("TGeant3")
22  , fMultiThreaded(false)
23  , fOutputFile("sim.root")
24  , fParameterFile("par.root")
25  , fRandomSeed(0)
26 {
27  // clang-format off
28  fDescription.add_options()
29  ("help", "Print this message")
30  ("nevents", po::value<int>(), "Number of events to simulate")
31  ("engine", po::value<vector<string>>(), "Monte Carlo engine")
32  ("multi-threaded", "Geant4 multi threaded")
33  ("output-file", po::value<vector<string>>(), "Output file")
34  ("parameter-file", po::value<vector<string>>(), "Parameter file")
35  ("random-seed", po::value<int>(), "Seed for the random number generator");
36  // clang-format on
37 }
38 
40 
41 int FairSimConfig::ParseCommandLine(int argc, char* argv[])
42 {
43  try {
44  po::store(po::parse_command_line(argc, argv, fDescription), fMap);
45 
46  po::notify(fMap);
47  } catch (po::error& e) {
48  LOG(error) << e.what();
49  fHelp = true;
50  return 0;
51  }
52 
53  if (fMap.count("help")) {
54  fHelp = true;
55  return 0;
56  }
57  if (fMap.count("nevents")) {
58  fnEvents = fMap["nevents"].as<int>();
59  }
60  if (fMap.count("engine")) {
61  fEngine = fMap["engine"].as<vector<string>>().at(0);
62  if (!GetEngine().EqualTo("TGeant3") && !GetEngine().EqualTo("TGeant4")) {
63  LOG(error) << "Option engine can be either TGeant3 or TGeant4";
64  return 1;
65  }
66  }
67  if (fMap.count("output-file")) {
68  fOutputFile = fMap["output-file"].as<vector<string>>().at(0);
69  }
70  if (fMap.count("parameter-file")) {
71  fParameterFile = fMap["parameter-file"].as<vector<string>>().at(0);
72  }
73  if (fMap.count("random-seed")) {
74  fRandomSeed = fMap["random-seed"].as<int>();
75  }
76  if (fMap.count("multi-threaded")) {
77  LOG(info) << "YUPYUPYUP";
78  fMultiThreaded = true;
79  }
80  return 0;
81 }
82 
83 void FairSimConfig::PrintHelpMessage() { cout << fDescription << endl; }
84 
int ParseCommandLine(int argc, char *argv[])
ClassImp(FairEventBuilder)
TString GetEngine() const
Definition: FairSimConfig.h:31
virtual ~FairSimConfig()
void PrintHelpMessage()