11 #include <boost/bind.hpp>
13 #include <xercesc/sax2/Attributes.hpp>
14 #include <xercesc/dom/DOM.hpp>
31 #include "boost/lexical_cast.hpp"
33 XERCES_CPP_NAMESPACE_USE
60 <<
"Could not open LHE file \""
61 << fileURL <<
"\" for reading"
82 <<
"Empty LHE file string name \""
85 std::stringstream * tmpis =
new std::stringstream(inputs);
100 typedef std::vector<std::pair<std::string,std::string> >
wgt_info;
122 const XMLCh *
const localname,
123 const XMLCh *
const qname,
127 const XMLCh *
const localname,
128 const XMLCh *
const qname)
override;
130 void characters(
const XMLCh *
const data,
const unsigned int length)
override;
131 void comment(
const XMLCh *
const data,
const unsigned int length)
override;
153 for(
unsigned int i = 0;
i < attributes.getLength();
i++) {
154 const XMLCh *
name = attributes.getQName(
i);
155 const XMLCh *
value = attributes.getValue(
i);
157 dom->setAttribute(name, value);
164 const char *
end = len >= 0 ? (data + len) : 0;
165 while(*data && (!end || data < end)) {
166 std::size_t len = std::strcspn(data,
"\r\n");
167 if (end && data + len > end)
169 if (data[len] ==
'\r' && data[len + 1] ==
'\n')
179 const XMLCh *
const localname,
180 const XMLCh *
const qname,
186 if (name !=
"LesHouchesEvents")
188 <<
"LHE file has invalid header" << std::endl;
204 if( name ==
"rwgt" ) {
206 }
else if (name ==
"wgt") {
209 else if (name ==
"scales") {
210 for (XMLSize_t iscale=0; iscale<attributes.getLength(); ++iscale) {
212 const char *scalename =
XMLSimpleStr(attributes.getQName(iscale));
213 sscanf(scalename,
"pt_clust_%d",&ipart);
216 const char *scalevalstr =
XMLSimpleStr(attributes.getValue(iscale));
217 sscanf(scalevalstr,
"%e",&scaleval);
229 <<
"LHE file has invalid format" << std::endl;
232 if (name ==
"header") {
234 impl = DOMImplementationRegistry::getDOMImplementation(
240 }
if (name ==
"init") {
242 }
else if (name ==
"event") {
244 impl = DOMImplementationRegistry::getDOMImplementation(
253 const XMLCh *npLOval = attributes.getValue(XMLString::transcode(
"npLO"));
256 sscanf(npLOs,
"%d",&
npLO);
258 const XMLCh *npNLOval = attributes.getValue(XMLString::transcode(
"npNLO"));
261 sscanf(npNLOs,
"%d",&
npNLO);
271 <<
"LHE file has invalid format" << std::endl;
277 const XMLCh *
const localname,
278 const XMLCh *
const qname)
284 if (
mode == kHeader && xmlNodes.size() > 1) {
285 xmlNodes.resize(xmlNodes.size() - 1);
287 }
else if (
mode == kHeader) {
288 std::auto_ptr<DOMWriter> writer(
289 static_cast<DOMImplementationLS*>(
290 impl)->createDOMWriter());
293 for(DOMNode *
node = xmlNodes[0]->getFirstChild();
301 switch(
node->getNodeType()) {
302 case DOMNode::ELEMENT_NODE:
303 elem =
static_cast<DOMElement*
>(
node);
306 p = std::strchr((
const char*)buffer,
308 q = std::strrchr(p,
'<');
310 case DOMNode::COMMENT_NODE:
313 q = buffer + strlen(buffer) - 3;
318 std::strspn(buffer,
" \t\r\n");
328 xmlHeader->release();
331 else if (name ==
"event" &&
333 xmlEventNodes.size() >= 1) {
334 for(DOMNode *
node = xmlEventNodes[0]->getFirstChild();
336 switch(
node->getNodeType() ) {
337 case DOMNode::ELEMENT_NODE:
338 for(DOMNode *rwgt = xmlEventNodes[1]->getFirstChild();
339 rwgt; rwgt = rwgt->getNextSibling()) {
340 DOMNode*
attr = rwgt->getAttributes()->item(0);
343 switch( rwgt->getNodeType() ) {
344 case DOMNode::ELEMENT_NODE:
345 weightsinevent.push_back(std::make_pair((
const char*)atname,
353 case DOMNode::TEXT_NODE:
364 else if (
mode == kEvent) {
369 if (gotObject !=
kNone)
371 <<
"Unexpected pileup in"
372 " LHEReader::XMLHandler::endElement"
381 const unsigned int length)
383 if (
mode == kHeader) {
384 DOMText *
text = xmlHeader->createTextNode(data_);
385 xmlNodes.back()->appendChild(text);
396 if(
mode == kEvent ) {
397 DOMText *
text = xmlEvent->createTextNode(data_+offset);
398 xmlEventNodes.back()->appendChild(text);
404 <<
"LHE file has invalid format" << std::endl;
411 const unsigned int length)
413 if (
mode == kHeader) {
414 DOMComment *
comment = xmlHeader->createComment(data_);
415 xmlNodes.back()->appendChild(comment);
427 fileURLs(params.getUntrackedParameter< std::vector<std::
string> >(
"fileNames")),
429 firstEvent(params.getUntrackedParameter<unsigned int>(
"skipEvents", 0)),
430 maxEvents(params.getUntrackedParameter<int>(
"limitEvents", -1)),
437 fileURLs(fileNames), strName(
""), firstEvent(firstEvent),
maxEvents(-1),
444 strName(inputs), firstEvent(firstEvent),
maxEvents(-1),
461 if ( newFileOpened !=
nullptr ) *newFileOpened =
true;
474 std::istringstream
data;
485 return boost::shared_ptr<LHEEvent>();
495 std::for_each(
handler->headers.begin(),
508 <<
"Got LHE event without"
509 " initialization." << std::endl;
517 return boost::shared_ptr<LHEEvent>();
521 boost::shared_ptr<LHEEvent> lheevent;
524 for(
size_t i=0;
i< info.size(); ++
i ) {
527 sscanf(snum.c_str(),
"%le",&
num);
530 lheevent->setNpLO(
handler->npLO);
531 lheevent->setNpNLO(
handler->npNLO);
533 if (
handler->scalesmap.size()>0) {
534 std::vector<float> &scales = lheevent->scales();
535 scales = std::vector<float>(lheevent->getHEPEUP()->NUP, -1.);
536 for (
const std::pair<int,float> &
scale :
handler->scalesmap) {
538 scales[scale.first-1] = scale.second;
545 return boost::shared_ptr<LHEEvent>();
XMLDocument * createReader(XMLDocument::Handler &handler) override
std::map< int, float > scalesmap
LHEReader(const edm::ParameterSet ¶ms)
static void logFileAction(char const *msg, std::string const &fileName)
static void fillHeader(LHERunInfo::Header &header, const char *data, int len=-1)
StringSource(const std::string &inputs)
void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname) override
const wgt_info & weightInfo() const
Storage * open(const std::string &url, int mode=IOFlags::OpenRead)
const std::vector< std::string > fileURLs
static bool isSpace(XMLCh ch)
void comment(const XMLCh *const data, const unsigned int length) override
void characters(const XMLCh *const data, const unsigned int length) override
std::vector< LHERunInfo::Header > headers
U second(std::pair< T, U > const &p)
static StorageFactory * get(void)
boost::shared_ptr< LHERunInfo > curRunInfo
std::vector< DOMElement * > xmlEventNodes
void addHeader(const Header &header)
std::auto_ptr< XMLHandler > handler
static bool isAllSpaces(const XMLCh *str, unsigned int length)
const std::string strName
std::vector< std::pair< std::string, std::string > > wgt_info
unsigned int offset(bool)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
std::vector< DOMElement * > xmlNodes
void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attributes) override
boost::shared_ptr< LHEEvent > next(bool *newFileOpened=nullptr)
XMLDocument * createReader(XMLDocument::Handler &handler) override
std::auto_ptr< XMLDocument > curDoc
std::auto_ptr< StorageWrap > fileStream
char data[epos_bytes_allocation]
virtual XMLDocument * createReader(XMLDocument::Handler &handler)=0
volatile std::atomic< bool > shutdown_flag false
std::auto_ptr< Source > curSource
std::auto_ptr< std::istream > fileStream
FileSource(const std::string &fileURL)
static void attributesToDom(DOMElement *dom, const Attributes &attributes)