11 #include <boost/bind.hpp>
13 #include <xercesc/sax2/Attributes.hpp>
14 #include <xercesc/dom/DOM.hpp>
32 #include "boost/lexical_cast.hpp"
34 XERCES_CPP_NAMESPACE_USE
61 <<
"Could not open LHE file \""
62 << fileURL <<
"\" for reading"
83 <<
"Empty LHE file string name \""
86 std::stringstream * tmpis =
new std::stringstream(inputs);
101 typedef std::vector<std::pair<std::string,std::string> >
wgt_info;
123 const XMLCh *
const localname,
124 const XMLCh *
const qname,
128 const XMLCh *
const localname,
129 const XMLCh *
const qname);
131 void characters(
const XMLCh *
const data,
const unsigned int length);
132 void comment(
const XMLCh *
const data,
const unsigned int length);
151 for(
unsigned int i = 0;
i < attributes.getLength();
i++) {
152 const XMLCh *
name = attributes.getQName(
i);
153 const XMLCh *
value = attributes.getValue(
i);
155 dom->setAttribute(name, value);
162 const char *
end = len >= 0 ? (data + len) : 0;
163 while(*data && (!end || data < end)) {
164 std::size_t len = std::strcspn(data,
"\r\n");
165 if (end && data + len > end)
167 if (data[len] ==
'\r' && data[len + 1] ==
'\n')
171 header.
addLine(std::string(data, len));
177 const XMLCh *
const localname,
178 const XMLCh *
const qname,
184 if (name !=
"LesHouchesEvents")
186 <<
"LHE file has invalid header" << std::endl;
201 if( name ==
"rwgt" ) {
203 }
else if (name ==
"wgt") {
210 <<
"LHE file has invalid format" << std::endl;
213 if (name ==
"header") {
215 impl = DOMImplementationRegistry::getDOMImplementation(
221 }
if (name ==
"init") {
223 }
else if (name ==
"event") {
225 impl = DOMImplementationRegistry::getDOMImplementation(
237 <<
"LHE file has invalid format" << std::endl;
243 const XMLCh *
const localname,
244 const XMLCh *
const qname)
250 if (
mode == kHeader && xmlNodes.size() > 1) {
251 xmlNodes.resize(xmlNodes.size() - 1);
253 }
else if (
mode == kHeader) {
254 std::auto_ptr<DOMWriter> writer(
255 static_cast<DOMImplementationLS*>(
256 impl)->createDOMWriter());
259 for(DOMNode *
node = xmlNodes[0]->getFirstChild();
267 switch(
node->getNodeType()) {
268 case DOMNode::ELEMENT_NODE:
269 elem =
static_cast<DOMElement*
>(
node);
272 p = std::strchr((
const char*)buffer,
274 q = std::strrchr(p,
'<');
276 case DOMNode::COMMENT_NODE:
279 q = buffer + strlen(buffer) - 3;
284 std::strspn(buffer,
" \t\r\n");
291 headers.push_back(header);
294 xmlHeader->release();
298 if( name ==
"rwgt" &&
mode == kEvent )
return;
299 if( name ==
"wgt" &&
mode == kEvent )
return;
301 if (name ==
"event" &&
303 xmlEventNodes.size() >= 1) {
304 for(DOMNode *
node = xmlEventNodes[0]->getFirstChild();
306 switch(
node->getNodeType() ) {
307 case DOMNode::ELEMENT_NODE:
308 for(DOMNode *rwgt = xmlEventNodes[1]->getFirstChild();
309 rwgt; rwgt = rwgt->getNextSibling()) {
310 DOMNode*
attr = rwgt->getAttributes()->item(0);
313 switch( rwgt->getNodeType() ) {
314 case DOMNode::ELEMENT_NODE:
315 weightsinevent.push_back(std::make_pair((
const char*)atname,
323 case DOMNode::TEXT_NODE:
335 if (gotObject !=
kNone)
337 <<
"Unexpected pileup in"
338 " LHEReader::XMLHandler::endElement"
347 const unsigned int length)
349 if (
mode == kHeader) {
350 DOMText *
text = xmlHeader->createTextNode(data_);
351 xmlNodes.back()->appendChild(text);
362 if(
mode == kEvent ) {
363 DOMText *
text = xmlEvent->createTextNode(data_+offset);
364 xmlEventNodes.back()->appendChild(text);
370 <<
"LHE file has invalid format" << std::endl;
377 const unsigned int length)
379 if (
mode == kHeader) {
380 DOMComment *
comment = xmlHeader->createComment(data_);
381 xmlNodes.back()->appendChild(comment);
389 headers.push_back(header);
393 fileURLs(params.getUntrackedParameter< std::vector<std::string> >(
"fileNames")),
395 firstEvent(params.getUntrackedParameter<unsigned int>(
"skipEvents", 0)),
396 maxEvents(params.getUntrackedParameter<int>(
"limitEvents", -1)),
403 fileURLs(fileNames), strName(
""), firstEvent(firstEvent),
maxEvents(-1),
410 strName(inputs), firstEvent(firstEvent),
maxEvents(-1),
427 if ( newFileOpened !=
nullptr ) *newFileOpened =
true;
440 std::istringstream
data;
460 std::for_each(
handler->headers.begin(),
473 <<
"Got LHE event without"
474 " initialization." << std::endl;
482 return boost::shared_ptr<LHEEvent>();
486 boost::shared_ptr<LHEEvent> lheevent;
489 for(
size_t i=0;
i< info.size(); ++
i ) {
490 std::string snum = info[
i].second.substr(0,info[
i].
second.size()-1);
492 sscanf(snum.c_str(),
"%le",&
num);
499 return boost::shared_ptr<LHEEvent>();
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)
const wgt_info & weightInfo() const
Storage * open(const std::string &url, int mode=IOFlags::OpenRead)
void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attributes)
const std::vector< std::string > fileURLs
static bool isSpace(XMLCh ch)
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
void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
std::vector< DOMElement * > xmlNodes
boost::shared_ptr< LHEEvent > next(bool *newFileOpened=nullptr)
void characters(const XMLCh *const data, const unsigned int length)
std::auto_ptr< XMLDocument > curDoc
std::auto_ptr< StorageWrap > fileStream
char data[epos_bytes_allocation]
virtual XMLDocument * createReader(XMLDocument::Handler &handler)=0
void comment(const XMLCh *const data, const unsigned int length)
std::auto_ptr< Source > curSource
std::auto_ptr< std::istream > fileStream
FileSource(const std::string &fileURL)
XMLDocument * createReader(XMLDocument::Handler &handler)
static void attributesToDom(DOMElement *dom, const Attributes &attributes)
XMLDocument * createReader(XMLDocument::Handler &handler)