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 int nmatch = sscanf(scalename,
"pt_clust_%d",&ipart);
217 <<
"invalid attribute in <scales> tag"
222 const char *scalevalstr =
XMLSimpleStr(attributes.getValue(iscale));
223 sscanf(scalevalstr,
"%e",&scaleval);
225 scales.push_back(scaleval);
235 <<
"LHE file has invalid format" << std::endl;
238 if (name ==
"header") {
240 impl = DOMImplementationRegistry::getDOMImplementation(
246 }
if (name ==
"init") {
248 }
else if (name ==
"event") {
250 impl = DOMImplementationRegistry::getDOMImplementation(
259 const XMLCh *npLOval = attributes.getValue(XMLString::transcode(
"npLO"));
262 sscanf(npLOs,
"%d",&
npLO);
264 const XMLCh *npNLOval = attributes.getValue(XMLString::transcode(
"npNLO"));
267 sscanf(npNLOs,
"%d",&
npNLO);
277 <<
"LHE file has invalid format" << std::endl;
283 const XMLCh *
const localname,
284 const XMLCh *
const qname)
290 if (
mode == kHeader && xmlNodes.size() > 1) {
291 xmlNodes.resize(xmlNodes.size() - 1);
293 }
else if (
mode == kHeader) {
294 std::auto_ptr<DOMWriter> writer(
295 static_cast<DOMImplementationLS*>(
296 impl)->createDOMWriter());
299 for(DOMNode *
node = xmlNodes[0]->getFirstChild();
307 switch(
node->getNodeType()) {
308 case DOMNode::ELEMENT_NODE:
309 elem =
static_cast<DOMElement*
>(
node);
312 p = std::strchr((
const char*)buffer,
314 q = std::strrchr(p,
'<');
316 case DOMNode::COMMENT_NODE:
319 q = buffer + strlen(buffer) - 3;
324 std::strspn(buffer,
" \t\r\n");
334 xmlHeader->release();
337 else if (name ==
"event" &&
339 xmlEventNodes.size() >= 1) {
340 for(DOMNode *
node = xmlEventNodes[0]->getFirstChild();
342 switch(
node->getNodeType() ) {
343 case DOMNode::ELEMENT_NODE:
344 for(DOMNode *rwgt = xmlEventNodes[1]->getFirstChild();
345 rwgt; rwgt = rwgt->getNextSibling()) {
346 DOMNode*
attr = rwgt->getAttributes()->item(0);
349 switch( rwgt->getNodeType() ) {
350 case DOMNode::ELEMENT_NODE:
351 weightsinevent.push_back(std::make_pair((
const char*)atname,
359 case DOMNode::TEXT_NODE:
370 else if (
mode == kEvent) {
375 if (gotObject !=
kNone)
377 <<
"Unexpected pileup in"
378 " LHEReader::XMLHandler::endElement"
387 const unsigned int length)
389 if (
mode == kHeader) {
390 DOMText *
text = xmlHeader->createTextNode(data_);
391 xmlNodes.back()->appendChild(text);
402 if(
mode == kEvent ) {
403 DOMText *
text = xmlEvent->createTextNode(data_+offset);
404 xmlEventNodes.back()->appendChild(text);
410 <<
"LHE file has invalid format" << std::endl;
417 const unsigned int length)
419 if (
mode == kHeader) {
420 DOMComment *
comment = xmlHeader->createComment(data_);
421 xmlNodes.back()->appendChild(comment);
433 fileURLs(params.getUntrackedParameter< std::vector<std::
string> >(
"fileNames")),
435 firstEvent(params.getUntrackedParameter<unsigned int>(
"skipEvents", 0)),
436 maxEvents(params.getUntrackedParameter<int>(
"limitEvents", -1)),
443 fileURLs(fileNames), strName(
""), firstEvent(firstEvent),
maxEvents(-1),
450 strName(inputs), firstEvent(firstEvent),
maxEvents(-1),
467 if ( newFileOpened !=
nullptr ) *newFileOpened =
true;
480 std::istringstream
data;
491 return boost::shared_ptr<LHEEvent>();
501 std::for_each(
handler->headers.begin(),
514 <<
"Got LHE event without"
515 " initialization." << std::endl;
523 return boost::shared_ptr<LHEEvent>();
527 boost::shared_ptr<LHEEvent> lheevent;
530 for(
size_t i=0;
i< info.size(); ++
i ) {
535 lheevent->setNpLO(
handler->npLO);
536 lheevent->setNpNLO(
handler->npNLO);
538 if (
handler->scales.size()>0) {
539 lheevent->setScales(
handler->scales);
545 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
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
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)