Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:58

0001 #include "GeneratorInterface/Pythia8Interface/interface/SLHAReaderBase.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 
0004 #include <sstream>
0005 
0006 #include "TFile.h"
0007 #include "TTree.h"
0008 
0009 SLHAReaderBase::SLHAReaderBase(const edm::ParameterSet& conf) {
0010   auto filename = conf.getParameter<std::string>("file");
0011   file_ = TFile::Open(filename.c_str());
0012   if (!file_)
0013     throw cms::Exception("MissingFile") << "Could not open file " << filename;
0014 
0015   auto treename = conf.getParameter<std::string>("tree");
0016   tree_ = (TTree*)file_->Get(treename.c_str());
0017   if (!tree_)
0018     throw cms::Exception("MissingTree") << "Could not get tree " << treename << " from file " << filename;
0019 }
0020 
0021 SLHAReaderBase::~SLHAReaderBase() { file_->Close(); }
0022 
0023 std::vector<std::string> SLHAReaderBase::splitline(const std::string& line, char delim) {
0024   std::stringstream ss(line);
0025   std::string field;
0026   std::vector<std::string> fields;
0027   while (getline(ss, field, delim)) {
0028     fields.push_back(field);
0029   }
0030   return fields;
0031 }
0032 
0033 EDM_REGISTER_PLUGINFACTORY(SLHAReaderFactory, "SLHAReaderFactory");