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);
130 void characters(
const XMLCh *
const data,
const unsigned int length);
131 void comment(
const XMLCh *
const data,
const unsigned int length);
150 for(
unsigned int i = 0;
i < attributes.getLength();
i++) {
151 const XMLCh *
name = attributes.getQName(
i);
152 const XMLCh *
value = attributes.getValue(
i);
154 dom->setAttribute(name, value);
161 const char *
end = len >= 0 ? (data + len) : 0;
162 while(*data && (!end || data < end)) {
163 std::size_t len = std::strcspn(data,
"\r\n");
164 if (end && data + len > end)
166 if (data[len] ==
'\r' && data[len + 1] ==
'\n')
176 const XMLCh *
const localname,
177 const XMLCh *
const qname,
183 if (name !=
"LesHouchesEvents")
185 <<
"LHE file has invalid header" << std::endl;
200 if( name ==
"rwgt" ) {
202 }
else if (name ==
"wgt") {
209 <<
"LHE file has invalid format" << std::endl;
212 if (name ==
"header") {
214 impl = DOMImplementationRegistry::getDOMImplementation(
220 }
if (name ==
"init") {
222 }
else if (name ==
"event") {
224 impl = DOMImplementationRegistry::getDOMImplementation(
236 <<
"LHE file has invalid format" << std::endl;
242 const XMLCh *
const localname,
243 const XMLCh *
const qname)
249 if (
mode == kHeader && xmlNodes.size() > 1) {
250 xmlNodes.resize(xmlNodes.size() - 1);
252 }
else if (
mode == kHeader) {
253 std::auto_ptr<DOMWriter> writer(
254 static_cast<DOMImplementationLS*>(
255 impl)->createDOMWriter());
258 for(DOMNode *
node = xmlNodes[0]->getFirstChild();
266 switch(
node->getNodeType()) {
267 case DOMNode::ELEMENT_NODE:
268 elem =
static_cast<DOMElement*
>(
node);
271 p = std::strchr((
const char*)buffer,
273 q = std::strrchr(p,
'<');
275 case DOMNode::COMMENT_NODE:
278 q = buffer + strlen(buffer) - 3;
283 std::strspn(buffer,
" \t\r\n");
290 headers.push_back(header);
293 xmlHeader->release();
297 if( name ==
"rwgt" &&
mode == kEvent )
return;
298 if( name ==
"wgt" &&
mode == kEvent )
return;
300 if (name ==
"event" &&
302 xmlEventNodes.size() >= 1) {
303 for(DOMNode *
node = xmlEventNodes[0]->getFirstChild();
305 switch(
node->getNodeType() ) {
306 case DOMNode::ELEMENT_NODE:
307 for(DOMNode *rwgt = xmlEventNodes[1]->getFirstChild();
308 rwgt; rwgt = rwgt->getNextSibling()) {
309 DOMNode*
attr = rwgt->getAttributes()->item(0);
312 switch( rwgt->getNodeType() ) {
313 case DOMNode::ELEMENT_NODE:
314 weightsinevent.push_back(std::make_pair((
const char*)atname,
322 case DOMNode::TEXT_NODE:
334 if (gotObject !=
kNone)
336 <<
"Unexpected pileup in"
337 " LHEReader::XMLHandler::endElement"
346 const unsigned int length)
348 if (
mode == kHeader) {
349 DOMText *
text = xmlHeader->createTextNode(data_);
350 xmlNodes.back()->appendChild(text);
361 if(
mode == kEvent ) {
362 DOMText *
text = xmlEvent->createTextNode(data_+offset);
363 xmlEventNodes.back()->appendChild(text);
369 <<
"LHE file has invalid format" << std::endl;
376 const unsigned int length)
378 if (
mode == kHeader) {
379 DOMComment *
comment = xmlHeader->createComment(data_);
380 xmlNodes.back()->appendChild(comment);
388 headers.push_back(header);
392 fileURLs(params.getUntrackedParameter< std::vector<std::
string> >(
"fileNames")),
394 firstEvent(params.getUntrackedParameter<unsigned int>(
"skipEvents", 0)),
395 maxEvents(params.getUntrackedParameter<int>(
"limitEvents", -1)),
402 fileURLs(fileNames), strName(
""), firstEvent(firstEvent),
maxEvents(-1),
409 strName(inputs), firstEvent(firstEvent),
maxEvents(-1),
426 if ( newFileOpened !=
nullptr ) *newFileOpened =
true;
439 std::istringstream
data;
459 std::for_each(
handler->headers.begin(),
472 <<
"Got LHE event without"
473 " initialization." << std::endl;
481 return boost::shared_ptr<LHEEvent>();
485 boost::shared_ptr<LHEEvent> lheevent;
488 for(
size_t i=0;
i< info.size(); ++
i ) {
491 sscanf(snum.c_str(),
"%le",&
num);
498 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)