CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HerwigUIProvider.cc
Go to the documentation of this file.
1 
7 
11 
12 #include <ThePEG/Utilities/DynamicLoader.h>
13 #include <ThePEG/Utilities/Debug.h>
14 #include <ThePEG/Repository/Repository.h>
15 #include <ThePEG/Handlers/SamplerBase.h>
16 
17 namespace Herwig {
18 
20  edm::LogError("Herwig7Interface") << "An error occured, interface quits now.";
21  quit();
22  }
23 
24  void HerwigUIProvider::quit() const {
26  edm::LogInfo("Herwig7Interface") << "Quitting HerwigUIProvider after ThePEG repository cleanup.";
27  }
28 
30 
32  : runMode_(runMode),
33  resume_(false),
34  tics_(true),
35  tag_(),
36  inputfile_(inputFileName),
37  repository_(),
38  setupfile_(),
39  integrationList_(),
40  nEvents_(-1),
41  seed_(0),
42  jobs_(1),
43  jobsize_(0),
44  maxjobs_(0) {
45  // check runMode of program and terminate if error state
46  if (runMode_ == RunMode::ERROR)
47  edm::LogError("Herwig7Interface") << "Invalid run mode: RunMode::ERROR was passed to Herwig.\n";
48 
49  /*
50  std::string tmpRunMode = pset.getUntrackedParameter<std::string>("runMode", "read");
51  if ( tmpRunMode == "init" ) { runMode_ = RunMode::INIT; }
52  else if ( tmpRunMode == "read" ) { runMode_ = RunMode::READ; }
53  else if ( tmpRunMode == "build" ) { runMode_ = RunMode::BUILD; }
54  else if ( tmpRunMode == "integrate" ) { runMode_ = RunMode::INTEGRATE; }
55  else if ( tmpRunMode == "mergegrids" ) { runMode_ = RunMode::MERGEGRIDS; }
56  else if ( tmpRunMode == "run" ) { runMode_ = RunMode::RUN; }
57  else {
58  runMode_ = RunMode::ERROR;
59  quitWithHelp();
60  }
61 */
62 
63  // File path to repository file
65  if (repository_.empty()) {
66  repository_ = std::string("HerwigDefaults.rpo");
67  }
68 
69  // Number of events
70  if (pset.getUntrackedParameter<int>("numberEvents", -1) != -1)
71  nEvents_ = pset.getUntrackedParameter<int>("numberEvents", 1);
72 
73  // run name tag (default given in ggo file)
74  if (!pset.getUntrackedParameter<std::string>("runTag", "").empty())
75  tag_ = pset.getUntrackedParameter<std::string>("runTag", "Tag1");
76 
77  // Debugging level
78  if (pset.getUntrackedParameter<unsigned int>("debugOutput", 0))
79  ThePEG::Debug::setDebug(pset.getUntrackedParameter<unsigned int>("debugOutput", 0));
80 
81  // Floating point exceptions
82  if (pset.getUntrackedParameter<bool>("debugFPE", false))
83  ThePEG::Debug::unmaskFpuErrors();
84 
85  // Exit-on-error flag
86  if (pset.getUntrackedParameter<bool>("exitOnError", false))
87  ThePEG::Repository::exitOnError() = 1;
88 
89  // Tics
90  if (pset.getUntrackedParameter<bool>("hideTics", false))
91  tics_ = false;
92 
93  // RNG seed
94  if (pset.getUntrackedParameter<int>("seed", 0) != 0)
95  seed_ = pset.getUntrackedParameter<int>("seed", 0);
96 
97  // run modification file
98  if (!pset.getUntrackedParameter<std::string>("setupFile", "").empty())
99  setupfile_ = pset.getUntrackedParameter<std::string>("setupFile", "");
100 
101  // parallel jobs
102  if (pset.getUntrackedParameter<int>("jobs", 1) != 1)
103  jobs_ = pset.getUntrackedParameter<int>("jobs", 1);
104 
105  // Directories from which Herwig reads filesystem
106  std::vector<std::string> aReadDirectories =
107  pset.getUntrackedParameter<std::vector<std::string> >("appendReadDirectories", std::vector<std::string>());
108  std::vector<std::string> pReadDirectories =
109  pset.getUntrackedParameter<std::vector<std::string> >("prependReadDirectories", std::vector<std::string>());
110  appendReadDirectories_.insert(appendReadDirectories_.end(), aReadDirectories.begin(), aReadDirectories.end());
111  prependReadDirectories_.insert(prependReadDirectories_.end(), pReadDirectories.begin(), pReadDirectories.end());
112 
113  // Library search path for dlopen()
114  std::vector<std::string> aPath =
115  pset.getUntrackedParameter<std::vector<std::string> >("appendPath", std::vector<std::string>());
116  std::vector<std::string> pPath =
117  pset.getUntrackedParameter<std::vector<std::string> >("prependPath", std::vector<std::string>());
118  for (size_t i = 0; i < aPath.size(); ++i)
119  ThePEG::DynamicLoader::appendPath(aPath[i]);
120  for (size_t i = 0; i < pPath.size(); ++i)
121  ThePEG::DynamicLoader::prependPath(pPath[i]);
122 
123  // integration list
124  if (!pset.getUntrackedParameter<std::string>("integrationList", "").empty()) {
125  integrationList_ = "integrationJob" + pset.getUntrackedParameter<std::string>("integrationList", "1");
126  }
127 
128  // job size
129  if (pset.getUntrackedParameter<unsigned int>("jobSize", 0) != 0) {
130  if (runMode_ == RunMode::BUILD) {
131  jobsize_ = pset.getUntrackedParameter<unsigned int>("jobSize", 1);
132  ThePEG::SamplerBase::setIntegratePerJob(jobsize_);
133  }
134  }
135 
136  // max integration jobs
137  if (pset.getUntrackedParameter<unsigned int>("maxJobs", 0) != 0) {
138  if (runMode_ == RunMode::BUILD) {
139  maxjobs_ = pset.getUntrackedParameter<unsigned int>("maxJobs", 1);
140  ThePEG::SamplerBase::setIntegrationJobs(maxjobs_);
141  }
142  }
143 
144  // Resume
145  if (pset.getUntrackedParameter<bool>("resume", false))
146  resume_ = true;
147  }
148 
150  runMode_ = runMode;
151  if (!inputFile.empty())
152  inputfile_ = inputFile;
153 
154  /* If build mode is chosen set these parameters accordingly, else unset them.*/
155  if (runMode_ == RunMode::BUILD) {
156  // job size
157  if (pset.getUntrackedParameter<unsigned int>("jobSize", 0) != 0) {
158  jobsize_ = pset.getUntrackedParameter<unsigned int>("jobSize", 1);
159  ThePEG::SamplerBase::setIntegratePerJob(jobsize_);
160  }
161  // max integration jobs
162  if (pset.getUntrackedParameter<unsigned int>("maxJobs", 0) != 0) {
163  maxjobs_ = pset.getUntrackedParameter<unsigned int>("maxJobs", 1);
164  ThePEG::SamplerBase::setIntegrationJobs(maxjobs_);
165  }
166  } else {
167  jobsize_ = 0;
168  ThePEG::SamplerBase::setIntegratePerJob(jobsize_);
169  maxjobs_ = 0;
170  ThePEG::SamplerBase::setIntegrationJobs(maxjobs_);
171  }
172  }
173  // End Herwig namespace
174 } // namespace Herwig
T getUntrackedParameter(std::string const &, T const &) const
std::vector< std::string > appendReadDirectories_
static std::string resolve(const std::string &line)
void quitWithHelp() const override
static void cleanup(const Factory::MakerMap::value_type &v)
Definition: Factory.cc:13
Log< level::Error, false > LogError
HerwigUIProvider(const edm::ParameterSet &pset, std::string inputFileName, RunMode::Mode)
Constructor from the arguments provided by CMSSW.
void setRunMode(RunMode::Mode runMode, const edm::ParameterSet &pset, std::string inputFile="")
void quit() const override
RunMode::Mode runMode() const override
Requested Herwig run mode.
~HerwigUIProvider() override
Destructor to leave a clean ThePEG::Repository behind.
std::vector< std::string > prependReadDirectories_
Log< level::Info, false > LogInfo
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
static const int ERROR