CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions
MCDBSource.cc File Reference
#include <iostream>
#include <utility>
#include <string>
#include <boost/regex.hpp>
#include "mcdb.hpp"
#include "FWCore/Framework/interface/InputSourceMacros.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "SimDataFormats/GeneratorProducts/interface/LesHouches.h"
#include "GeneratorInterface/LHEInterface/interface/LHEEvent.h"
#include "GeneratorInterface/LHEInterface/interface/LHEReader.h"
#include "LHESource.h"

Go to the source code of this file.

Classes

class  MCDBSource
 

Functions

static edm::ParameterSet augmentPSetFromMCDB (const edm::ParameterSet &params)
 
 DEFINE_FWK_INPUT_SOURCE (MCDBSource)
 
static std::pair< std::vector
< std::string >, unsigned int > 
getFileURLs (const edm::ParameterSet &params)
 

Function Documentation

static edm::ParameterSet augmentPSetFromMCDB ( const edm::ParameterSet params)
static

Definition at line 111 of file MCDBSource.cc.

References edm::ParameterSet::addUntrackedParameter(), getFileURLs(), and query::result.

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 }
static std::pair< std::vector< std::string >, unsigned int > getFileURLs(const edm::ParameterSet &params)
Definition: MCDBSource.cc:32
tuple result
Definition: query.py:137
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:209
DEFINE_FWK_INPUT_SOURCE ( MCDBSource  )
static std::pair<std::vector<std::string>, unsigned int> getFileURLs ( const edm::ParameterSet params)
static

Definition at line 32 of file MCDBSource.cc.

References mergeVDriftHistosByStation::file, alcazmumu_cfi::filter, create_complex_test_file0_cfg::firstEvent, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), nEvents, and scaleCards::path.

Referenced by augmentPSetFromMCDB().

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 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
list path
Definition: scaleCards.py:51
UInt_t nEvents
Definition: hcalCalib.cc:43