CMS 3D CMS Logo

Static Public Member Functions

EcalWeightGroupXMLTranslator Class Reference

#include <EcalWeightGroupXMLTranslator.h>

List of all members.

Static Public Member Functions

static std::string dumpXML (const EcalCondHeader &header, const EcalWeightXtalGroups &record)
static int readXML (const std::string &filename, EcalCondHeader &header, EcalWeightXtalGroups &record)
static int writeXML (const std::string &filename, const EcalCondHeader &header, const EcalWeightXtalGroups &record)

Detailed Description

Definition at line 26 of file EcalWeightGroupXMLTranslator.h.


Member Function Documentation

std::string EcalWeightGroupXMLTranslator::dumpXML ( const EcalCondHeader header,
const EcalWeightXtalGroups record 
) [static]

Definition at line 98 of file EcalWeightGroupXMLTranslator.cc.

References asciidump::doc, hcal_timing_source_file_cfg::dump, xuti::fromNative(), EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, EBDetId::MIN_HASH, dbtoconf::root, xuti::toNative(), EBDetId::unhashIndex(), EEDetId::unhashIndex(), EEDetId::validHashIndex(), xuti::WeightGroup_tag(), xuti::WeightGroups_tag(), xuti::writeCell(), xuti::writeHeader(), and xuti::WriteNodeWithValue().

                                                                         {

  XMLPlatformUtils::Initialize();
  
  DOMImplementation*  impl =
    DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
  
  DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
  
  DOMDocumentType* doctype = impl->createDocumentType( fromNative("XML").c_str(), 0, 0 );
  DOMDocument *    doc = 
    impl->createDocument( 0, fromNative(WeightGroups_tag).c_str(), doctype );
  
  
  doc->setEncoding(fromNative("UTF-8").c_str() );
  doc->setStandalone(true);
  doc->setVersion(fromNative("1.0").c_str() );
  
  
  DOMElement* root = doc->getDocumentElement();
 
  xuti::writeHeader(root,header);

  for (int cellid = EBDetId::MIN_HASH; 
       cellid < EBDetId::kSizeForDenseIndexing; 
       ++cellid){// loop on EB cells
    
    uint32_t rawid= EBDetId::unhashIndex(cellid);

    //if (!record[rawid]) continue; // cell absent from original record
    
    DOMElement* cellnode=writeCell(root,rawid);

    WriteNodeWithValue(cellnode,WeightGroup_tag,record[rawid].id());
  

  } // loop on EB cells
  
  
  
  for (int cellid = 0; 
       cellid < EEDetId::kSizeForDenseIndexing; 
       ++cellid){// loop on EE cells
    
    if (!EEDetId::validHashIndex(cellid)) continue;

    uint32_t rawid= EEDetId::unhashIndex(cellid);
    //xif (!record[rawid]) continue; // cell absent from original record

        
    DOMElement* cellnode=writeCell(root,rawid);
    WriteNodeWithValue(cellnode,WeightGroup_tag,record[rawid].id());
    
  } // loop on EE cells
  
  
  std::string dump= toNative(writer->writeToString(*root));
  doc->release();
  //   XMLPlatformUtils::Terminate();
  
  return dump;

}
int EcalWeightGroupXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalWeightXtalGroups record 
) [static]

Definition at line 24 of file EcalWeightGroupXMLTranslator.cc.

References xuti::Cell_tag(), gather_cfg::cout, cond::rpcobgas::detid, xuti::getChildNode(), xuti::GetNodeData(), geometryXMLtoCSV::parser, xuti::readCellId(), xuti::readHeader(), and xuti::WeightGroup_tag().

                                                                        {

  XMLPlatformUtils::Initialize();

  XercesDOMParser* parser = new XercesDOMParser;
  parser->setValidationScheme( XercesDOMParser::Val_Never );
  parser->setDoNamespaces( false );
  parser->setDoSchema( false );
  
  parser->parse(filename.c_str());

  DOMDocument* xmlDoc = parser->getDocument();
  if (!xmlDoc) {
    std::cout << "EcalWeightGroupXMLTranslator::Error parsing document" << std::endl;
    return -1;
  }

  DOMElement* elementRoot = xmlDoc->getDocumentElement();

  xuti::readHeader(elementRoot,header);
  // get the first cell node
  DOMNode * cellnode=getChildNode(elementRoot,Cell_tag);
  
  // loop on cell nodes
  while  (cellnode){

    unsigned int  group=0;

    // read id
    DetId detid= readCellId(dynamic_cast<DOMElement*> (cellnode));
       
    // read constant
    DOMNode * c_node = getChildNode(cellnode,WeightGroup_tag);
    GetNodeData(c_node,group);


    // fill record
    record[detid]=EcalXtalGroupId(group);
   

    // get next cell
    cellnode= cellnode->getNextSibling();
    
    while (cellnode&& cellnode->getNodeType( ) != DOMNode::ELEMENT_NODE)      
      cellnode= cellnode->getNextSibling();
    
    
  }


  delete parser;
  XMLPlatformUtils::Terminate();
  return 0;
    
}
int EcalWeightGroupXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalWeightXtalGroups record 
) [static]

Definition at line 86 of file EcalWeightGroupXMLTranslator.cc.

References EcalCondTools::dumpXML(), and dbtoconf::out.

                                                                              {
  std::fstream fs(filename.c_str(),ios::out);
  fs<< dumpXML(header,record);
  return 0; 
  
}