CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/CondTools/Ecal/src/EcalDAQTowerStatusXMLTranslator.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <sstream>
00003 #include <fstream>
00004 #include <xercesc/dom/DOMNode.hpp>
00005 #include <xercesc/dom/DOM.hpp>
00006 #include <xercesc/parsers/XercesDOMParser.hpp>
00007 #include <xercesc/util/PlatformUtils.hpp>
00008 #include <xercesc/util/XMLString.hpp>
00009 #include <xercesc/sax/SAXException.hpp>
00010 #include <xercesc/framework/LocalFileFormatTarget.hpp>
00011 
00012 #include "CondTools/Ecal/interface/EcalDAQTowerStatusXMLTranslator.h"
00013 #include "CondTools/Ecal/interface/DOMHelperFunctions.h"
00014 #include "CondTools/Ecal/interface/XMLTags.h"
00015 
00016 using namespace XERCES_CPP_NAMESPACE;
00017 using namespace xuti;
00018 using namespace std;
00019 
00020 int  EcalDAQTowerStatusXMLTranslator::readXML(const std::string& filename, 
00021                                           EcalCondHeader& header,
00022                                           EcalDAQTowerStatus& record){
00023 
00024   std::cout << " DAQTowerStatus should not be filled out from an xml file ..." << std::endl;
00025   XMLPlatformUtils::Initialize();
00026 
00027   XercesDOMParser* parser = new XercesDOMParser;
00028   parser->setValidationScheme( XercesDOMParser::Val_Never );
00029   parser->setDoNamespaces( false );
00030   parser->setDoSchema( false );
00031   
00032   parser->parse(filename.c_str());
00033 
00034   DOMDocument* xmlDoc = parser->getDocument();
00035   if (!xmlDoc) {
00036     std::cout << "EcalDAQTowerStatusXMLTranslator::Error parsing document" << std::endl;
00037     return -1;
00038   }
00039 
00040   DOMElement* elementRoot = xmlDoc->getDocumentElement();
00041 
00042   xuti::readHeader(elementRoot,header);
00043 
00044   DOMNode * cellnode = getChildNode(elementRoot,Cell_tag);
00045 
00046   int chan = 0;
00047   while(cellnode) {
00048     int status = -1;
00049     DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
00050 
00051     DOMNode* my_node = getChildNode(cellnode,DAQStatusCode_tag);
00052     GetNodeData(my_node, status);
00053 
00054     record[detid] = status;
00055 
00056     cellnode = cellnode->getNextSibling();
00057 
00058     while(cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
00059       cellnode = cellnode->getNextSibling();
00060     chan++;
00061   } 
00062 
00063   delete parser;
00064   XMLPlatformUtils::Terminate();
00065   return 0;
00066  }
00067 
00068 int EcalDAQTowerStatusXMLTranslator::writeXML(const std::string& filename, 
00069                                           const EcalCondHeader& header,
00070                                           const EcalDAQTowerStatus& record){
00071   std::fstream fs(filename.c_str(),ios::out);
00072   fs<< dumpXML(header,record);
00073   return 0;  
00074 }
00075 
00076 
00077 std::string EcalDAQTowerStatusXMLTranslator::dumpXML(const EcalCondHeader& header,const EcalDAQTowerStatus& record){
00078 
00079   XMLPlatformUtils::Initialize();
00080   DOMImplementation*  impl =
00081     DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
00082 
00083   DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
00084   writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
00085 
00086   DOMDocumentType* doctype = impl->createDocumentType(fromNative("XML").c_str(), 0, 0 );
00087   DOMDocument *    doc = 
00088     impl->createDocument( 0, fromNative(DAQTowerStatus_tag).c_str(), doctype );
00089 
00090   doc->setEncoding(fromNative("UTF-8").c_str() );
00091   doc->setStandalone(true);
00092   doc->setVersion(fromNative("1.0").c_str() );
00093 
00094   DOMElement* root = doc->getDocumentElement();
00095 
00096   xuti::writeHeader(root,header);
00097   std::cout << " barrel size " << record.barrelItems().size() << std::endl;
00098   if (!record.barrelItems().size()) return std::string();
00099   for(uint cellid = 0;
00100       cellid < EcalTrigTowerDetId::kEBTotalTowers;
00101       ++cellid) {
00102     uint32_t rawid = EcalTrigTowerDetId::detIdFromDenseIndex(cellid);
00103     if (record.find(rawid) == record.end()) continue;
00104     DOMElement* cellnode=writeCell(root,rawid);
00105 
00106     WriteNodeWithValue(cellnode, DAQStatusCode_tag, record[rawid].getStatusCode());
00107   } 
00108 
00109   std::cout << " endcap size " << record.endcapItems().size() << std::endl;
00110   if (!record.endcapItems().size()) return std::string();
00111   for(uint cellid = 0;
00112       cellid < EcalTrigTowerDetId::kEETotalTowers;
00113       ++cellid) {
00114     if(!EcalScDetId::validHashIndex(cellid)) continue;
00115     uint32_t rawid = EcalScDetId::unhashIndex(cellid); 
00116 
00117     if (record.find(rawid) == record.end()) continue;
00118     DOMElement* cellnode=writeCell(root,rawid);
00119 
00120     WriteNodeWithValue(cellnode, DAQStatusCode_tag, record[rawid].getStatusCode());
00121   }
00122 
00123   std::string dump = toNative(writer->writeToString(*root)); 
00124   doc->release(); 
00125   return dump;
00126 }
00127 
00128 void EcalDAQTowerStatusXMLTranslator::plot(std::string fn, const EcalDAQTowerStatus& record){
00129   std::ofstream fout(fn.c_str());
00130   int valEB[34][72];
00131   std::cout << " barrel size " << record.barrelItems().size() << std::endl;
00132   if (!record.barrelItems().size()) return;
00133   for(uint cellid = 0;
00134       cellid < EcalTrigTowerDetId::kEBTotalTowers;
00135       ++cellid) {
00136     EcalTrigTowerDetId rawid = EcalTrigTowerDetId::detIdFromDenseIndex(cellid);
00137     if (record.find(rawid) == record.end()) continue;
00138     int ieta = rawid.ieta();
00139     int line = 17 - ieta;
00140     if(ieta < 0) line--;
00141     int iphi = rawid.iphi() - 1;  // 0 to 71
00142     valEB[line][iphi] = record[rawid].getStatusCode();
00143   }
00144   for(int line = 0; line < 34; line++) {
00145     for(int iphi = 0; iphi < 72; iphi++)
00146       fout << valEB[line][iphi] << " ";
00147     fout << std::endl;
00148     if(line == 16) fout << std::endl;
00149   }
00150 
00151   std::cout << " endcap size " << record.endcapItems().size() << std::endl;
00152   if (!record.endcapItems().size()) return;
00153   int valEE[2][20][20];
00154   for(int k = 0 ; k < 2; k++ ) 
00155     for(int ix = 0 ; ix < 20; ix++) 
00156       for(int iy = 0 ; iy < 20; iy++) 
00157         valEE[k][ix][iy] = -1;
00158   for(uint cellid = 0;
00159       cellid < EcalTrigTowerDetId::kEETotalTowers;
00160       ++cellid) {
00161     if(EcalScDetId::validHashIndex(cellid)) {
00162       EcalScDetId rawid = EcalScDetId::unhashIndex(cellid); 
00163       int ix = rawid.ix() - 1;  // 0 to 19
00164       int iy = 20 -  rawid.iy();  // 0 to 19
00165       int side = rawid.zside();
00166       int iz = side;
00167       if(side == -1) iz = 0;
00168       if(ix < 0 || ix > 19) std::cout << " Pb in ix " << ix << std::endl;
00169       if(iy < 0 || iy > 19) std::cout << " Pb in iy " << iy << std::endl;
00170       valEE[iz][ix][iy] = record[rawid].getStatusCode();
00171     }
00172   }
00173   for(int k = 0 ; k < 2; k++ ) {
00174     int iz = -1;
00175     if(k == 1) iz = 1;
00176     fout << " Side : " << iz << std::endl;
00177     for(int line = 0; line < 20; line++) {
00178       for(int ix = 0 ; ix < 20; ix++) {
00179         if(valEE[k][ix][line] < 0) fout << ". ";
00180         else fout << valEE[k][ix][line] << " ";
00181       }
00182       fout << std::endl;
00183     }
00184     fout << std::endl;
00185   }
00186 
00187   return;
00188 }