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,
124 const Attributes &attributes)
override;
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;
154 for(
unsigned int i = 0;
i < attributes.getLength();
i++) {
155 const XMLCh *
name = attributes.getQName(
i);
156 const XMLCh *
value = attributes.getValue(
i);
158 dom->setAttribute(name, value);
165 const char *
end = len >= 0 ? (data + len) : 0;
166 while(*data && (!end || data < end)) {
167 std::size_t len = std::strcspn(data,
"\r\n");
168 if (end && data + len > end)
170 if (data[len] ==
'\r' && data[len + 1] ==
'\n')
180 const XMLCh *
const localname,
181 const XMLCh *
const qname,
182 const Attributes &attributes)
187 if (name !=
"LesHouchesEvents")
189 <<
"LHE file has invalid header" << std::endl;
208 if( name ==
"rwgt" ) {
210 }
else if (name ==
"wgt") {
213 else if (name ==
"scales") {
214 for (XMLSize_t iscale=0; iscale<attributes.getLength(); ++iscale) {
216 const char *scalename =
XMLSimpleStr(attributes.getQName(iscale));
217 int nmatch = sscanf(scalename,
"pt_clust_%d",&ipart);
221 <<
"invalid attribute in <scales> tag"
226 const char *scalevalstr =
XMLSimpleStr(attributes.getValue(iscale));
227 sscanf(scalevalstr,
"%e",&scaleval);
229 scales.push_back(scaleval);
239 <<
"LHE file has invalid format" << std::endl;
242 if (name ==
"header") {
244 impl = DOMImplementationRegistry::getDOMImplementation(
250 }
if (name ==
"init") {
252 }
else if (name ==
"event") {
256 impl = DOMImplementationRegistry::getDOMImplementation(
268 sscanf(npLOs,
"%d",&
npLO);
273 sscanf(npNLOs,
"%d",&
npNLO);
284 <<
"LHE file has invalid format" << std::endl;
290 const XMLCh *
const localname,
291 const XMLCh *
const qname)
297 if (
mode == kHeader && xmlNodes.size() > 1) {
298 xmlNodes.resize(xmlNodes.size() - 1);
300 }
else if (
mode == kHeader) {
301 std::auto_ptr<DOMWriter> writer(
302 static_cast<DOMImplementationLS*>(
303 impl)->createDOMWriter());
306 for(DOMNode *
node = xmlNodes[0]->getFirstChild();
314 switch(
node->getNodeType()) {
315 case DOMNode::ELEMENT_NODE:
316 elem =
static_cast<DOMElement*
>(
node);
319 p = std::strchr((
const char*)buffer,
321 q = std::strrchr(p,
'<');
323 case DOMNode::COMMENT_NODE:
326 q = buffer + strlen(buffer) - 3;
331 std::strspn(buffer,
" \t\r\n");
341 xmlHeader->release();
344 else if (name ==
"event" &&
346 (skipEvent || (xmlEventNodes.size() >= 1))) {
355 for(DOMNode *
node = xmlEventNodes[0]->getFirstChild();
357 switch(
node->getNodeType() ) {
358 case DOMNode::ELEMENT_NODE:
359 for(DOMNode *rwgt = xmlEventNodes[1]->getFirstChild();
360 rwgt; rwgt = rwgt->getNextSibling()) {
361 DOMNode* attr = rwgt->getAttributes()->item(0);
364 switch( rwgt->getNodeType() ) {
365 case DOMNode::ELEMENT_NODE:
366 weightsinevent.push_back(std::make_pair((
const char*)atname,
374 case DOMNode::TEXT_NODE:
385 else if (
mode == kEvent) {
390 if (gotObject !=
kNone)
392 <<
"Unexpected pileup in"
393 " LHEReader::XMLHandler::endElement"
402 const unsigned int length)
404 if (
mode == kHeader) {
405 DOMText *
text = xmlHeader->createTextNode(data_);
406 xmlNodes.back()->appendChild(text);
417 if(
mode == kEvent ) {
420 DOMText *
text = xmlEvent->createTextNode(data_+offset);
421 xmlEventNodes.back()->appendChild(text);
428 <<
"LHE file has invalid format" << std::endl;
435 const unsigned int length)
437 if (
mode == kHeader) {
438 DOMComment *
comment = xmlHeader->createComment(data_);
439 xmlNodes.back()->appendChild(comment);
451 fileURLs(params.getUntrackedParameter< std::vector<std::
string> >(
"fileNames")),
453 firstEvent(params.getUntrackedParameter<unsigned int>(
"skipEvents", 0)),
454 maxEvents(params.getUntrackedParameter<int>(
"limitEvents", -1)),
461 fileURLs(fileNames), strName(
""), firstEvent(firstEvent),
maxEvents(-1),
468 strName(inputs), firstEvent(firstEvent),
maxEvents(-1),
485 if ( newFileOpened !=
nullptr ) *newFileOpened =
true;
505 return boost::shared_ptr<LHEEvent>();
514 std::istringstream
data;
520 std::for_each(
handler->headers.begin(),
535 <<
"Got LHE event without"
536 " initialization." << std::endl;
544 return boost::shared_ptr<LHEEvent>();
548 std::istringstream
data;
552 boost::shared_ptr<LHEEvent> lheevent;
555 for(
size_t i=0;
i< info.size(); ++
i ) {
560 lheevent->setNpLO(
handler->npLO);
561 lheevent->setNpNLO(
handler->npNLO);
563 if (
handler->scales.size()>0) {
564 lheevent->setScales(
handler->scales);
571 return boost::shared_ptr<LHEEvent>();
XMLDocument * createReader(XMLDocument::Handler &handler) override
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
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)
boost::shared_ptr< LHERunInfo > curRunInfo
std::vector< DOMElement * > xmlEventNodes
static const StorageFactory * get(void)
void addHeader(const Header &header)
std::auto_ptr< XMLHandler > handler
XMLCh * transcode(const T &fInput)
static bool isAllSpaces(const XMLCh *str, unsigned int length)
const std::string strName
std::vector< std::pair< std::string, std::string > > wgt_info
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
std::vector< float > scales
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)
std::unique_ptr< Storage > open(const std::string &url, int mode=IOFlags::OpenRead) const