Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:06:54

0001 /**
0002 Marco A. Harrendorf
0003 Dominik Beutel
0004 **/
0005 
0006 #include "GeneratorInterface/Herwig7Interface/interface/HerwigUIProvider.h"
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "GeneratorInterface/Core/interface/ParameterCollector.h"
0010 #include "GeneratorInterface/Herwig7Interface/interface/RandomEngineGlue.h"
0011 
0012 #include <ThePEG/Utilities/DynamicLoader.h>
0013 #include <ThePEG/Utilities/Debug.h>
0014 #include <ThePEG/Repository/Repository.h>
0015 #include <ThePEG/Handlers/SamplerBase.h>
0016 
0017 namespace Herwig {
0018 
0019   void HerwigUIProvider::quitWithHelp() const {
0020     edm::LogError("Herwig7Interface") << "An error occured, interface quits now.";
0021     quit();
0022   }
0023 
0024   void HerwigUIProvider::quit() const {
0025     ThePEG::Repository::cleanup();
0026     edm::LogInfo("Herwig7Interface") << "Quitting HerwigUIProvider after ThePEG repository cleanup.";
0027   }
0028 
0029   HerwigUIProvider::~HerwigUIProvider() { ThePEG::Repository::cleanup(); }
0030 
0031   HerwigUIProvider::HerwigUIProvider(const edm::ParameterSet &pset, std::string inputFileName, RunMode::Mode runMode)
0032       : runMode_(runMode),
0033         resume_(false),
0034         tics_(true),
0035         tag_(),
0036         inputfile_(inputFileName),
0037         repository_(),
0038         setupfile_(),
0039         integrationList_(),
0040         nEvents_(-1),
0041         seed_(0),
0042         jobs_(1),
0043         jobsize_(0),
0044         maxjobs_(0) {
0045     // check runMode of program and terminate if error state
0046     if (runMode_ == RunMode::ERROR)
0047       edm::LogError("Herwig7Interface") << "Invalid run mode: RunMode::ERROR was passed to Herwig.\n";
0048 
0049     /*
0050   std::string tmpRunMode = pset.getUntrackedParameter<std::string>("runMode", "read");
0051   if      ( tmpRunMode == "init" )       { runMode_ = RunMode::INIT; }
0052   else if ( tmpRunMode == "read" )       { runMode_ = RunMode::READ; }
0053   else if ( tmpRunMode == "build" )      { runMode_ = RunMode::BUILD; }
0054   else if ( tmpRunMode == "integrate" )  { runMode_ = RunMode::INTEGRATE; }
0055   else if ( tmpRunMode == "mergegrids" ) { runMode_ = RunMode::MERGEGRIDS; }
0056   else if ( tmpRunMode == "run" )        { runMode_ = RunMode::RUN; }
0057   else {
0058     runMode_ = RunMode::ERROR;
0059     quitWithHelp();
0060   }
0061 */
0062 
0063     // File path to repository file
0064     repository_ = gen::ParameterCollector::resolve(pset.getParameter<std::string>("repository"));
0065     if (repository_.empty()) {
0066       repository_ = std::string("HerwigDefaults.rpo");
0067     }
0068 
0069     // Number of events
0070     if (pset.getUntrackedParameter<int>("numberEvents", -1) != -1)
0071       nEvents_ = pset.getUntrackedParameter<int>("numberEvents", 1);
0072 
0073     // run name tag (default given in ggo file)
0074     if (!pset.getUntrackedParameter<std::string>("runTag", "").empty())
0075       tag_ = pset.getUntrackedParameter<std::string>("runTag", "Tag1");
0076 
0077     // Debugging level
0078     if (pset.getUntrackedParameter<unsigned int>("debugOutput", 0))
0079       ThePEG::Debug::setDebug(pset.getUntrackedParameter<unsigned int>("debugOutput", 0));
0080 
0081     // Floating point exceptions
0082     if (pset.getUntrackedParameter<bool>("debugFPE", false))
0083       ThePEG::Debug::unmaskFpuErrors();
0084 
0085     // Exit-on-error flag
0086     if (pset.getUntrackedParameter<bool>("exitOnError", false))
0087       ThePEG::Repository::exitOnError() = 1;
0088 
0089     // Tics
0090     if (pset.getUntrackedParameter<bool>("hideTics", false))
0091       tics_ = false;
0092 
0093     // RNG seed
0094     if (pset.getUntrackedParameter<int>("seed", 0) != 0)
0095       seed_ = pset.getUntrackedParameter<int>("seed", 0);
0096 
0097     // run modification file
0098     if (!pset.getUntrackedParameter<std::string>("setupFile", "").empty())
0099       setupfile_ = pset.getUntrackedParameter<std::string>("setupFile", "");
0100 
0101     // parallel jobs
0102     if (pset.getUntrackedParameter<int>("jobs", 1) != 1)
0103       jobs_ = pset.getUntrackedParameter<int>("jobs", 1);
0104 
0105     // Directories from which Herwig reads filesystem
0106     std::vector<std::string> aReadDirectories =
0107         pset.getUntrackedParameter<std::vector<std::string> >("appendReadDirectories", std::vector<std::string>());
0108     std::vector<std::string> pReadDirectories =
0109         pset.getUntrackedParameter<std::vector<std::string> >("prependReadDirectories", std::vector<std::string>());
0110     appendReadDirectories_.insert(appendReadDirectories_.end(), aReadDirectories.begin(), aReadDirectories.end());
0111     prependReadDirectories_.insert(prependReadDirectories_.end(), pReadDirectories.begin(), pReadDirectories.end());
0112 
0113     // Library search path for dlopen()
0114     std::vector<std::string> aPath =
0115         pset.getUntrackedParameter<std::vector<std::string> >("appendPath", std::vector<std::string>());
0116     std::vector<std::string> pPath =
0117         pset.getUntrackedParameter<std::vector<std::string> >("prependPath", std::vector<std::string>());
0118     for (size_t i = 0; i < aPath.size(); ++i)
0119       ThePEG::DynamicLoader::appendPath(aPath[i]);
0120     for (size_t i = 0; i < pPath.size(); ++i)
0121       ThePEG::DynamicLoader::prependPath(pPath[i]);
0122 
0123     // integration list
0124     if (!pset.getUntrackedParameter<std::string>("integrationList", "").empty()) {
0125       integrationList_ = "integrationJob" + pset.getUntrackedParameter<std::string>("integrationList", "1");
0126     }
0127 
0128     // job size
0129     if (pset.getUntrackedParameter<unsigned int>("jobSize", 0) != 0) {
0130       if (runMode_ == RunMode::BUILD) {
0131         jobsize_ = pset.getUntrackedParameter<unsigned int>("jobSize", 1);
0132         ThePEG::SamplerBase::setIntegratePerJob(jobsize_);
0133       }
0134     }
0135 
0136     // max integration jobs
0137     if (pset.getUntrackedParameter<unsigned int>("maxJobs", 0) != 0) {
0138       if (runMode_ == RunMode::BUILD) {
0139         maxjobs_ = pset.getUntrackedParameter<unsigned int>("maxJobs", 1);
0140         ThePEG::SamplerBase::setIntegrationJobs(maxjobs_);
0141       }
0142     }
0143 
0144     // Resume
0145     if (pset.getUntrackedParameter<bool>("resume", false))
0146       resume_ = true;
0147   }
0148 
0149   void HerwigUIProvider::setRunMode(RunMode::Mode runMode, const edm::ParameterSet &pset, std::string inputFile) {
0150     runMode_ = runMode;
0151     if (!inputFile.empty())
0152       inputfile_ = inputFile;
0153 
0154     /* If build mode is chosen set these parameters accordingly, else unset them.*/
0155     if (runMode_ == RunMode::BUILD) {
0156       // job size
0157       if (pset.getUntrackedParameter<unsigned int>("jobSize", 0) != 0) {
0158         jobsize_ = pset.getUntrackedParameter<unsigned int>("jobSize", 1);
0159         ThePEG::SamplerBase::setIntegratePerJob(jobsize_);
0160       }
0161       // max integration jobs
0162       if (pset.getUntrackedParameter<unsigned int>("maxJobs", 0) != 0) {
0163         maxjobs_ = pset.getUntrackedParameter<unsigned int>("maxJobs", 1);
0164         ThePEG::SamplerBase::setIntegrationJobs(maxjobs_);
0165       }
0166     } else {
0167       jobsize_ = 0;
0168       ThePEG::SamplerBase::setIntegratePerJob(jobsize_);
0169       maxjobs_ = 0;
0170       ThePEG::SamplerBase::setIntegrationJobs(maxjobs_);
0171     }
0172   }
0173   // End Herwig namespace
0174 }  // namespace Herwig