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