CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MCDBSource.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <utility>
3 #include <string>
4 
5 #include <boost/regex.hpp>
6 
7 #include "mcdb.hpp"
8 
15 
19 
20 #include "LHESource.h"
21 
22 using namespace lhef;
23 
24 class MCDBSource : public LHESource {
25  public:
26  explicit MCDBSource(const edm::ParameterSet &params,
27  const edm::InputSourceDescription &desc);
28  virtual ~MCDBSource();
29 };
30 
31 static std::pair<std::vector<std::string>, unsigned int>
33 {
34  unsigned int articleId = params.getParameter<unsigned int>("articleID");
35 
36  edm::LogInfo("Generator|LHEInterface")
37  << "Reading article id " << articleId << " from MCDB."
38  << std::endl;
39 
40  mcdb::MCDB mcdb;
41 
42  mcdb::Article article = mcdb.getArticle(articleId);
43 
44  edm::LogInfo("Generator|LHEInterface")
45  << "Title: " << article.title() << std::endl
46  << "First author: " << article.authors()[0].firstName() << " "
47  << article.authors()[0].lastName() << std::endl
48  << "Number of authors: " << article.authors().size() << std::endl
49  << "Abstract: " << article.abstract() << std::endl
50  << "Generator: " << article.generator().name()
51  << ", " << article.generator().version() << std::endl
52  << "Number of files: " << article.files().size() << std::endl
53  << "Files: " << std::endl;
54 
55  std::vector<std::string> supportedProtocols =
56  params.getUntrackedParameter< std::vector<std::string> >(
57  "supportedProtocols");
58 
59  boost::regex filter(params.getUntrackedParameter<std::string>(
60  "filter", "\\.lhef?$"),
61  boost::regex_constants::normal |
62  boost::regex_constants::icase);
63 
64  unsigned int firstEvent =
65  params.getUntrackedParameter<unsigned int>("skipEvents", 0);
66 
67  unsigned int fcount = 0;
68  std::vector<std::string> fileURLs;
69  for(std::vector<mcdb::File>::iterator file = article.files().begin();
70  file != article.files().end(); ++file) {
71  std::string fileURL;
72  for(std::vector<std::string>::const_iterator prot =
73  supportedProtocols.begin();
74  prot != supportedProtocols.end(); ++prot) {
75  for(std::vector<std::string>::const_iterator path =
76  file->paths().begin();
77  path != file->paths().end(); ++path) {
78  if (path->substr(0, prot->length() + 1) ==
79  *prot + ":") {
80  fileURL = *path;
81  break;
82  }
83  }
84  if (!fileURL.empty())
85  break;
86  }
87 
88  if (fileURL.empty())
89  throw cms::Exception("Generator|LHEInterface")
90  << "MCDB did not contain any URLs with"
91  " supported protocols for at least one"
92  " file." << std::endl;
93 
94  if (!boost::regex_search(fileURL, filter))
95  continue;
96 
97  int nEvents = file->eventsNumber();
98  if (nEvents > 0 && (int)firstEvent >= nEvents) {
99  firstEvent -= nEvents;
100  continue;
101  }
102 
103  fileURLs.push_back(fileURL);
104  fcount++;
105  edm::LogInfo("Generator|LHEInterface") << "Adding file n. " << fcount << " " << fileURL;
106  }
107 
108  return std::make_pair(fileURLs, firstEvent);
109 }
110 
112 {
113  // note that this is inherently ugly, but the only way to
114  // pass the file URLs to ExternalInputSource, as the MCDB client
115  // is nothing but an MCDB to URL converter
116  // all modified parameters are untracked, so the provenance is
117  // unchanged
118 
119  std::pair<std::vector<std::string>, unsigned int> result =
120  getFileURLs(params);
121 
122  edm::ParameterSet newParams = params;
123  newParams.addUntrackedParameter<std::vector<std::string> >(
124  "fileNames", result.first);
125  newParams.addUntrackedParameter<unsigned int>(
126  "skipEvents", result.second);
127 
128  return newParams;
129 }
130 
132  const edm::InputSourceDescription &desc) :
133  LHESource(augmentPSetFromMCDB(params), desc)
134 {
135 }
136 
138 {
139 }
140 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
MCDBSource(const edm::ParameterSet &params, const edm::InputSourceDescription &desc)
Definition: MCDBSource.cc:131
static std::pair< std::vector< std::string >, unsigned int > getFileURLs(const edm::ParameterSet &params)
Definition: MCDBSource.cc:32
virtual ~MCDBSource()
Definition: MCDBSource.cc:137
list path
Definition: scaleCards.py:51
#define DEFINE_FWK_INPUT_SOURCE(type)
tuple result
Definition: query.py:137
static edm::ParameterSet augmentPSetFromMCDB(const edm::ParameterSet &params)
Definition: MCDBSource.cc:111
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:209
UInt_t nEvents
Definition: hcalCalib.cc:43