CMS 3D CMS Logo

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