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  std::vector<std::string> fileURLs;
68  for(std::vector<mcdb::File>::iterator file = article.files().begin();
69  file != article.files().end(); ++file) {
70  std::string fileURL;
71  for(std::vector<std::string>::const_iterator prot =
72  supportedProtocols.begin();
73  prot != supportedProtocols.end(); ++prot) {
74  for(std::vector<std::string>::const_iterator path =
75  file->paths().begin();
76  path != file->paths().end(); ++path) {
77  if (path->substr(0, prot->length() + 1) ==
78  *prot + ":") {
79  fileURL = *path;
80  break;
81  }
82  }
83  if (!fileURL.empty())
84  break;
85  }
86 
87  if (fileURL.empty())
88  throw cms::Exception("Generator|LHEInterface")
89  << "MCDB did not contain any URLs with"
90  " supported protocols for at least one"
91  " file." << std::endl;
92 
93  if (!boost::regex_search(fileURL, filter))
94  continue;
95 
96  int nEvents = file->eventsNumber();
97  if (nEvents > 0 && (int)firstEvent >= nEvents) {
98  firstEvent -= nEvents;
99  continue;
100  }
101 
102  fileURLs.push_back(fileURL);
103  }
104 
105  return std::make_pair(fileURLs, firstEvent);
106 }
107 
109 {
110  // note that this is inherently ugly, but the only way to
111  // pass the file URLs to ExternalInputSource, as the MCDB client
112  // is nothing but an MCDB to URL converter
113  // all modified parameters are untracked, so the provenance is
114  // unchanged
115 
116  std::pair<std::vector<std::string>, unsigned int> result =
117  getFileURLs(params);
118 
119  edm::ParameterSet newParams = params;
120  newParams.addUntrackedParameter<std::vector<std::string> >(
121  "fileNames", result.first);
122  newParams.addUntrackedParameter<unsigned int>(
123  "skipEvents", result.second);
124 
125  return newParams;
126 }
127 
129  const edm::InputSourceDescription &desc) :
130  LHESource(augmentPSetFromMCDB(params), desc)
131 {
132 }
133 
135 {
136 }
137 
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:128
static std::pair< std::vector< std::string >, unsigned int > getFileURLs(const edm::ParameterSet &params)
Definition: MCDBSource.cc:32
virtual ~MCDBSource()
Definition: MCDBSource.cc:134
int path() const
Definition: HLTadd.h:3
#define DEFINE_FWK_INPUT_SOURCE(type)
tuple result
Definition: query.py:137
static edm::ParameterSet augmentPSetFromMCDB(const edm::ParameterSet &params)
Definition: MCDBSource.cc:108
tuple filter
USE THIS FOR SKIMMED TRACKS process.p = cms.Path(process.hltLevel1GTSeed*process.skimming*process.offlineBeamSpot*process.TrackRefitter2) OTHERWISE USE THIS.
Definition: align_tpl.py:86
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:203
UInt_t nEvents
Definition: hcalCalib.cc:43