CMS 3D CMS Logo

Public Types | Public Member Functions | Protected Member Functions | Private Attributes | Friends

lhef::LHEReader::XMLHandler Class Reference

Inheritance diagram for lhef::LHEReader::XMLHandler:
lhef::XMLDocument::Handler

List of all members.

Public Types

enum  Object {
  kNone = 0, kHeader, kInit, kComment,
  kEvent
}

Public Member Functions

void reset ()
 XMLHandler ()
 ~XMLHandler ()

Protected Member Functions

void characters (const XMLCh *const data, const unsigned int length)
void comment (const XMLCh *const data, const unsigned int length)
void endElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
void startElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attributes)

Private Attributes

std::string buffer
Object gotObject
bool headerOk
std::vector< LHERunInfo::Headerheaders
DOMImplementation * impl
Object mode
DOMDocument * xmlHeader
std::vector< DOMElement * > xmlNodes

Friends

class LHEReader

Detailed Description

Definition at line 96 of file LHEReader.cc.


Member Enumeration Documentation

Enumerator:
kNone 
kHeader 
kInit 
kComment 
kEvent 

Definition at line 104 of file LHEReader.cc.

                     { headerOk = false; }

Constructor & Destructor Documentation

lhef::LHEReader::XMLHandler::XMLHandler ( ) [inline]

Definition at line 98 of file LHEReader.cc.

lhef::LHEReader::XMLHandler::~XMLHandler ( ) [inline]

Definition at line 101 of file LHEReader.cc.

References xmlHeader.

        { if (xmlHeader) xmlHeader->release(); }


Member Function Documentation

void lhef::LHEReader::XMLHandler::characters ( const XMLCh *const  data,
const unsigned int  length 
) [protected]

Definition at line 278 of file LHEReader.cc.

References AlCaHLTBitMon_QueryRunRegistry::data, Exception, lhef::XMLSimpleStr::isAllSpaces(), lhef::XMLSimpleStr::isSpace(), WDecay::kNone, mode, evf::evtn::offset(), and runonSM::text.

{
        if (mode == kHeader) {
                DOMText *text = xmlHeader->createTextNode(data_);
                xmlNodes.back()->appendChild(text);
                return;
        }

        if (XMLSimpleStr::isAllSpaces(data_, length))
                return;

        unsigned int offset = 0;
        while(offset < length && XMLSimpleStr::isSpace(data_[offset]))
                offset++;

        XMLSimpleStr data(data_ + offset);

        if (mode == kNone)
                throw cms::Exception("InvalidFormat")
                        << "LHE file has invalid format" << std::endl;

        buffer.append(data);
}

void lhef::LHEReader::XMLHandler::comment ( const XMLCh *const  data,
const unsigned int  length 
) [protected]

Definition at line 303 of file LHEReader.cc.

References comment, AlCaHLTBitMon_QueryRunRegistry::data, lhef::fillHeader(), and mode.

{
        if (mode == kHeader) {
                DOMComment *comment = xmlHeader->createComment(data_);
                xmlNodes.back()->appendChild(comment);
                return;
        }

        XMLSimpleStr data(data_);

        LHERunInfo::Header header;
        fillHeader(header, data);
        headers.push_back(header);
}

void lhef::LHEReader::XMLHandler::endElement ( const XMLCh *const  uri,
const XMLCh *const  localname,
const XMLCh *const  qname 
) [protected]

Definition at line 212 of file LHEReader.cc.

References python::HTMLExport::elem(), Exception, lhef::fillHeader(), WDecay::kNone, mode, python::Node::node, AlCaHLTBitMon_ParallelJobs::p, and lumiQueryAPI::q.

{
        if (mode) {
                if (mode == kHeader && xmlNodes.size() > 1) {
                        xmlNodes.resize(xmlNodes.size() - 1);
                        return;
                } else if (mode == kHeader) {
                        std::auto_ptr<DOMWriter> writer(
                                static_cast<DOMImplementationLS*>(
                                                impl)->createDOMWriter());
                        writer->setEncoding(XMLUniStr("UTF-8"));

                        for(DOMNode *node = xmlNodes[0]->getFirstChild();
                            node; node = node->getNextSibling()) {
                                XMLSimpleStr buffer(
                                        writer->writeToString(*node));

                                std::string type;
                                const char *p, *q;
                                DOMElement *elem;

                                switch(node->getNodeType()) {
                                    case DOMNode::ELEMENT_NODE:
                                        elem = static_cast<DOMElement*>(node);
                                        type = (const char*)XMLSimpleStr(
                                                        elem->getTagName());
                                        p = std::strchr((const char*)buffer,
                                                        '>') + 1;
                                        q = std::strrchr(p, '<');
                                        break;
                                    case DOMNode::COMMENT_NODE:
                                        type = "";
                                        p = buffer + 4;
                                        q = buffer + strlen(buffer) - 3;
                                        break;
                                    default:
                                        type = "<>";
                                        p = buffer +
                                            std::strspn(buffer, " \t\r\n");
                                        if (!*p)
                                                continue;
                                        q = p + strlen(p);
                                }

                                LHERunInfo::Header header(type);
                                fillHeader(header, p, q - p);
                                headers.push_back(header);
                        }

                        xmlHeader->release();
                        xmlHeader = 0;
                }

                if (gotObject != kNone)
                        throw cms::Exception("InvalidState")
                                << "Unexpected pileup in"
                                    " LHEReader::XMLHandler::endElement"
                                << std::endl;

                gotObject = mode;
                mode = kNone;
        }
}

void lhef::LHEReader::XMLHandler::reset ( void  ) [inline]

Definition at line 112 of file LHEReader.cc.

:
        void startElement(const XMLCh *const uri,
void lhef::LHEReader::XMLHandler::startElement ( const XMLCh *const  uri,
const XMLCh *const  localname,
const XMLCh *const  qname,
const Attributes &  attributes 
) [protected]

Definition at line 167 of file LHEReader.cc.

References lhef::attributesToDom(), buffer, python::HTMLExport::elem(), Exception, headerOk, impl, kEvent, kHeader, kInit, kNone, mode, mergeVDriftHistosByStation::name, xmlHeader, and xmlNodes.

{
        std::string name((const char*)XMLSimpleStr(qname));

        if (!headerOk) {
                if (name != "LesHouchesEvents")
                        throw cms::Exception("InvalidFormat")
                                << "LHE file has invalid header" << std::endl;
                headerOk = true;
                return;
        }

        if (mode == kHeader) {
                DOMElement *elem = xmlHeader->createElement(qname);
                attributesToDom(elem, attributes);
                xmlNodes.back()->appendChild(elem);
                xmlNodes.push_back(elem);
                return;
        } else if (mode != kNone)
                throw cms::Exception("InvalidFormat")
                        << "LHE file has invalid format" << std::endl;

        if (name == "header") {
                if (!impl)
                        impl = DOMImplementationRegistry::getDOMImplementation(
                                                        XMLUniStr("Core"));
                xmlHeader = impl->createDocument(0, qname, 0);
                xmlNodes.resize(1);
                xmlNodes[0] = xmlHeader->getDocumentElement();
                mode = kHeader;
        } if (name == "init")
                mode = kInit;
        else if (name == "event")
                mode = kEvent;

        if (mode == kNone)
                throw cms::Exception("InvalidFormat")
                        << "LHE file has invalid format" << std::endl;

        buffer.clear();
}


Friends And Related Function Documentation

friend class LHEReader [friend]

Definition at line 128 of file LHEReader.cc.


Member Data Documentation

std::string lhef::LHEReader::XMLHandler::buffer [private]

Definition at line 131 of file LHEReader.cc.

Referenced by startElement().

Definition at line 132 of file LHEReader.cc.

Definition at line 136 of file LHEReader.cc.

Referenced by startElement().

Definition at line 137 of file LHEReader.cc.

DOMImplementation* lhef::LHEReader::XMLHandler::impl [private]

Definition at line 130 of file LHEReader.cc.

Referenced by startElement().

Definition at line 133 of file LHEReader.cc.

Referenced by startElement().

Definition at line 134 of file LHEReader.cc.

Referenced by startElement(), and ~XMLHandler().

std::vector<DOMElement*> lhef::LHEReader::XMLHandler::xmlNodes [private]

Definition at line 135 of file LHEReader.cc.

Referenced by startElement().