CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/DQM/HcalMonitorClient/src/HcalDQMDbInterface.cc

Go to the documentation of this file.
00001 #include "DQM/HcalMonitorClient/interface/HcalDQMDbInterface.h"
00002 
00003 namespace {
00004   template <class T> XMLCh* transcode (const T& fInput) {
00005     std::ostringstream ost;
00006     ost << fInput;
00007     return XMLString::transcode(ost.str().c_str());
00008   } 
00009 }
00010 
00011 DOMElement* HcalDQMDbInterface::createElement(DOMDocument* doc, DOMElement* parent, const char* name){
00012   DOMElement*  elem = doc->createElement(XML(name));
00013   parent->appendChild(elem);
00014   return elem;
00015 }
00016 
00017 DOMElement* HcalDQMDbInterface::createElement(DOMDocument* doc, DOMElement* parent, const char* name, const char* value){
00018   DOMElement*  elem = createElement(doc,parent,name);
00019   elem->appendChild(doc->createTextNode(XML(value)));
00020   return elem;
00021 }
00022 
00023 DOMDocument* HcalDQMDbInterface::createDocument(){
00024   DOMImplementation* impl =  DOMImplementationRegistry::getDOMImplementation(XML("Core"));
00025   return impl->createDocument(0,XML("ROOT"),0);
00026 }
00027 
00028 void HcalDQMDbInterface::writeDocument(DOMDocument* doc, const char* xmlFile){
00029   DOMImplementation* impl =  DOMImplementationRegistry::getDOMImplementation(XML("Core"));
00030   DOMWriter *theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter();
00031   if (theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
00032     theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
00033   if (theSerializer->canSetFeature(XMLUni::fgDOMWRTBOM, true))
00034     theSerializer->setFeature(XMLUni::fgDOMWRTBOM, true);
00035   XMLFormatTarget *myFormTarget = new LocalFileFormatTarget(xmlFile);
00036   theSerializer->writeNode(myFormTarget, *doc);
00037   delete theSerializer;
00038   delete myFormTarget;
00039 }
00040 
00041 DOMElement* HcalDQMDbInterface::createFooter(DOMDocument* doc,
00042                                              unsigned long long fIovBegin, unsigned long long fIovEnd,
00043                                              const char* fTagName, const char* fDetectorName, const char* fComment){
00044   
00045   DOMElement* parent = doc->getDocumentElement();
00046   DOMElement* elems = createElement(doc,parent,"ELEMENTS");
00047   DOMElement* dataset = createElement(doc, elems, "DATA_SET");
00048   dataset->setAttribute(transcode("id"), transcode("-1"));
00049   createIOV(doc,elems,fIovBegin,fIovEnd);
00050   createTag(doc,elems,fTagName,fDetectorName,fComment);
00051 
00052   DOMElement* maps = createElement(doc,parent, "MAPS");
00053   DOMElement* mapTag = makeMapTag(doc,maps);
00054   DOMElement* mapIov = makeMapIOV(doc,mapTag);
00055   makeMapDataset(doc,mapIov);
00056 
00057   return elems;
00058 }
00059 
00060 DOMElement* HcalDQMDbInterface::makeMapTag(DOMDocument* doc,DOMElement* fMap) {
00061   DOMElement* tag = createElement(doc, fMap, "TAG");
00062   tag->setAttribute(transcode("idref"), transcode("TAG_ID"));
00063   return tag;
00064 }
00065 
00066 DOMElement* HcalDQMDbInterface::makeMapIOV(DOMDocument* doc,DOMElement* fTag) {
00067   DOMElement* iov = createElement(doc,fTag, "IOV");
00068   iov->setAttribute(transcode("idref"), transcode("IOV_ID"));
00069   return iov;
00070 }
00071 
00072 DOMElement* HcalDQMDbInterface::makeMapDataset(DOMDocument* doc,DOMElement* fIov) {
00073   DOMElement* element = createElement(doc,fIov, "DATA_SET");
00074   element->setAttribute(transcode("idref"), transcode("-1"));
00075   return element;
00076 }
00077 
00078 DOMElement* HcalDQMDbInterface::createIOV(DOMDocument* doc,DOMElement*  parent, 
00079                                           unsigned long long fIovBegin, unsigned long long fIovEnd) {
00080   DOMElement* iov = createElement(doc,parent,"IOV");
00081   iov->setAttribute(transcode("id"), transcode("IOV_ID"));
00082   
00083   createElement(doc,iov,"INTERVAL_OF_VALIDITY_BEGIN", itoa(fIovBegin));
00084   if(fIovEnd) {
00085     createElement(doc,iov,"INTERVAL_OF_VALIDITY_END", itoa(fIovEnd));
00086   }
00087   return iov;
00088 }
00089 
00090 DOMElement* HcalDQMDbInterface::createTag(DOMDocument* doc,DOMElement*  parent, 
00091                                            const char* fTagName, const char* fDetectorName, const char* fComment) {
00092   DOMElement* tag = createElement(doc,parent,"TAG");
00093   tag->setAttribute(transcode("id"), transcode ("TAG_ID"));
00094   tag->setAttribute(transcode("mode"), transcode ("auto"));
00095 
00096   createElement(doc,tag,"TAG_NAME", fTagName);
00097   createElement(doc,tag,"DETECTOR_NAME", fDetectorName);
00098   createElement(doc,tag,"COMMENT_DESCRIPTION", fComment);
00099 
00100   return tag;
00101 }
00102 
00103 
00104 void HcalHotCellDbInterface::createHeader(DOMDocument* doc, unsigned int runno, const char* startTime){
00105   DOMElement*  parent = doc->getDocumentElement();
00106   DOMElement*  headerElem = createElement(doc,parent,"HEADER");
00107   DOMElement*  typeElem = createElement(doc,headerElem,"TYPE");
00108   createElement(doc,typeElem,"EXTENSION_TABLE_NAME","HCAL_CHANNEL_ON_OFF_STATES");
00109   createElement(doc,typeElem,"NAME","HCAL channel on off states");
00110   DOMElement*  runElem = createElement(doc,headerElem,"RUN");
00111   createElement(doc,runElem,"RUN_TYPE","hcal-dqm-onoff-test");
00112   createElement(doc,runElem,"RUN_NUMBER",itoa(runno));
00113   createElement(doc,runElem,"RUN_BEGIN_TIMESTAMP",startTime);
00114   createElement(doc,runElem,"COMMENT_DESCRIPTION","dqm data");
00115 }
00116 
00117 DOMElement* HcalDQMDbInterface::createChannel(DOMDocument* doc,DOMElement* parent, HcalDetId id){
00118   HcalText2DetIdConverter converter(id);
00119   DOMElement*  chanElem = createElement(doc,parent,"CHANNEL");
00120   createElement(doc,chanElem,"EXTENSION_TABLE_NAME","HCAL_CHANNELS");
00121   createElement(doc,chanElem,"ETA",itoa(id.ietaAbs()));
00122   createElement(doc,chanElem,"PHI",itoa(id.iphi()));
00123   createElement(doc,chanElem,"DEPTH",itoa(id.depth()));
00124   createElement(doc,chanElem,"Z",itoa(id.zside()));
00125   createElement(doc,chanElem,"DETECTOR_NAME",converter.getFlavor().c_str());
00126   createElement(doc,chanElem,"HCAL_CHANNEL_ID",itoa(id.rawId()));
00127   return chanElem;
00128 }
00129 
00130 DOMElement* HcalHotCellDbInterface::createData(DOMDocument* doc,DOMElement* parent, HcalDQMChannelQuality::Item item){
00131   DOMElement*  dataElem = createElement(doc,parent,"DATA");
00132   createElement(doc,dataElem,"CHANNEL_ON_OFF_STATE",itoa(item.mMasked));
00133   createElement(doc,dataElem,"CHANNEL_STATUS_WORD",itoa(item. mQuality));
00134   createElement(doc,dataElem,"COMMENT_DESCRIPTION",item.mComment.c_str());
00135   return dataElem;
00136 }
00137 
00138 
00139 void HcalHotCellDbInterface::createDataset(DOMDocument* doc,
00140                                            HcalDQMChannelQuality::Item item,
00141                                            const char* gmtime,
00142                                            const char* version){
00143 
00144   DOMElement*  parent = doc->getDocumentElement();
00145   DOMElement*  dataSetElem = createElement(doc,parent,"DATA_SET");
00146   createElement(doc,dataSetElem,"VERSION",version);
00147   createElement(doc,dataSetElem,"CREATION_TIMESTAMP",gmtime);
00148   createElement(doc,dataSetElem,"CREATED_BY","wfisher");
00149 
00150   HcalDetId id(item.mId);
00151   createChannel(doc, dataSetElem, id);
00152   createData(doc, dataSetElem,item);
00153 }
00154 
00155 void HcalHLXMaskDbInterface::createHeader(DOMDocument* doc){
00156   DOMElement*  parent = doc->getDocumentElement();
00157   DOMElement*  headerElem = createElement(doc,parent,"HEADER");
00158   DOMElement*  typeElem = createElement(doc,headerElem,"TYPE");
00159   createElement(doc,typeElem,"EXTENSION_TABLE_NAME","HCAL_HLX_MASKS_TYPE01");
00160   createElement(doc,typeElem,"NAME","HCAL HLX masks [type 1]");
00161   DOMElement* element= createElement(doc,headerElem,"RUN");
00162   element->setAttribute(transcode("mode"), transcode("no-run"));
00163 }
00164 
00165 void HcalHLXMaskDbInterface::createData(DOMDocument* doc,DOMElement* parent, HcalHLXMask masks){
00166   DOMElement*  dataElem = createElement(doc,parent,"DATA");
00167   createElement(doc, dataElem, "FPGA", masks.position);
00168   char tmp[5] = "fooo";
00169   sprintf(tmp,"%i",masks.occMask);
00170   createElement(doc, dataElem, "OCC_MASK", tmp);
00171   sprintf(tmp,"%i",masks.lhcMask);
00172   createElement(doc, dataElem, "LHC_MASK", tmp);
00173   sprintf(tmp,"%i",masks.sumEtMask);
00174   createElement(doc, dataElem, "SUM_ET_MASK", tmp);
00175 }
00176 
00177 DOMElement* HcalHLXMaskDbInterface::createDataset(DOMDocument* doc,
00178                                                   const HcalHLXMask masks,
00179                                                   const char* gmtime,
00180                                                   const char* version, const char* subversion){
00181 
00182   DOMElement*  parent = doc->getDocumentElement();
00183   DOMElement*  dataSetElem = createElement(doc,parent,"DATA_SET");
00184   createElement(doc,dataSetElem,"VERSION",version);
00185   createElement(doc,dataSetElem,"SUBVERSION",subversion);
00186   createElement(doc,dataSetElem,"CREATION_TIMESTAMP",gmtime);
00187   createElement(doc,dataSetElem,"CREATED_BY","jwerner");
00188 
00189   DOMElement*  partAssElem = createElement(doc,dataSetElem,"PART_ASSEMBLY");
00190   DOMElement* parentPartAssElem = createElement(doc,partAssElem,"PARENT_PART");
00191   createElement(doc, parentPartAssElem, "KIND_OF_PART", "HCAL HTR Crate");
00192   char tmp[5];
00193   if(masks.crateId <10){ sprintf(tmp,"CRATE0%i",masks.crateId);}
00194   else{ sprintf(tmp,"CRATE%i",masks.crateId);}
00195   createElement(doc, parentPartAssElem, "NAME_LABEL",tmp);
00196   //end PARENT_PART 
00197   DOMElement* childUniqueIdByElem = createElement(doc,partAssElem,"CHILD_UNIQUELY_IDENTIFIED_BY");
00198   createElement(doc, childUniqueIdByElem, "KIND_OF_PART", "HCAL HTR Crate Slot");
00199   DOMElement* attributeElem = createElement(doc,childUniqueIdByElem,"ATTRIBUTE");
00200   createElement(doc, attributeElem, "NAME", "HCAL HTR Slot Number");
00201   createElement(doc, attributeElem, "VALUE", itoa(masks.slotId));
00202   //end attribute                                                                                                                  
00203   //end child uni...                                                                                                               
00204   //end part assembly                                                                                                              
00205 
00206   return dataSetElem;
00207 }