00001 #include <fstream>
00002
00003 #include "CaloOnlineTools/HcalOnlineDb/interface/LMapLoader.h"
00004 #include "CaloOnlineTools/HcalOnlineDb/interface/DBlmapWriter.h"
00005 #include "CalibCalorimetry/HcalTPGAlgos/interface/XMLProcessor.h"
00006
00007
00008 DBlmapWriter::DBlmapWriter(){
00009
00010 }
00011
00012 DBlmapWriter::~DBlmapWriter(){
00013
00014 }
00015
00016 XMLDOMBlock * DBlmapWriter::createLMapHBEFXMLBase( std::string templateFileName )
00017 {
00018 XMLDOMBlock * result = new XMLDOMBlock( templateFileName );
00019 DOMDocument * loader = result -> getDocument();
00020
00021
00022 loader -> getElementsByTagName( XMLProcessor::_toXMLCh( "NAME" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( "HCAL LMAP for HB, HE, HF" ) );
00023
00024
00025
00026 return result;
00027 }
00028
00029
00030
00031 int DBlmapWriter::addLMapHBEFDataset( XMLDOMBlock * doc, LMapRowHBEF * row, std::string templateFileName )
00032 {
00033 DOMDocument * loader = doc -> getDocument();
00034 DOMElement * root = loader -> getDocumentElement();
00035
00036 XMLDOMBlock dataSetDoc( templateFileName );
00037 DOMDocument * dataSet = dataSetDoc . getDocument();
00038
00039
00040 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "SIDE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> side ) );
00041 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "ETA" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> eta) );
00042 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "PHI" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> phi ) );
00043 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "DELTA_PHI" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> dphi ) );
00044
00045 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "DEPTH" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> depth ) );
00046 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "SUBDETECTOR" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> det ) );
00047 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "RBX_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> rbx ) );
00048 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "WEDGE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> wedge ) );
00049
00050 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "RM_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> rm ) );
00051 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "HPD_PIXEL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> pixel ) );
00052 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "QIE_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> qie ) );
00053 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "ADC" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> adc ) );
00054 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "RM_FIBER" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> rm_fi ) );
00055
00056 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "FIBER_CHANNEL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> fi_ch));
00057 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "CRATE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> crate ) );
00058 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "HTR_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> htr ) );
00059 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "HTR_FPGA" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> fpga ) );
00060
00061 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "HTR_FIBER" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> htr_fi ));
00062 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "DCC_SL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> dcc_sl ) );
00063 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "SPIGOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> spigo ) );
00064 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "DCC_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> dcc ) );
00065 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "SLB_SITE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> slb ) );
00066 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "SLB_CHANNEL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> slbin ));
00067 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "SLB_CHANNEL2" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> slbin2));
00068
00069 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "SLB_CABLE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> slnam ) );
00070 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "RCT_CRATE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> rctcra ) );
00071 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "RCT_CARD" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> rctcar ) );
00072 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "RCT_CONNECTOR" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row ->rctcon));
00073 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "RCT_NAME" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> rctnam ) );
00074 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "FED_ID" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> fedid ) );
00075
00076
00077
00078 DOMNode * cloneDataSet = loader -> importNode( dataSet -> getDocumentElement(), true );
00079 root -> appendChild( cloneDataSet );
00080
00081 return 0;
00082 }
00083
00084 XMLDOMBlock * DBlmapWriter::createLMapHOXMLBase( std::string templateFileName )
00085 {
00086 XMLDOMBlock * result = new XMLDOMBlock( templateFileName );
00087 DOMDocument * loader = result -> getDocument();
00088
00089
00090 loader -> getElementsByTagName( XMLProcessor::_toXMLCh( "NAME" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( "HCAL LMAP for HO" ) );
00091
00092
00093
00094 return result;
00095 }
00096
00097
00098 int DBlmapWriter::addLMapHODataset( XMLDOMBlock * doc, LMapRowHO * row, std::string templateFileName )
00099 {
00100 DOMDocument * loader = doc -> getDocument();
00101 DOMElement * root = loader -> getDocumentElement();
00102
00103 XMLDOMBlock dataSetDoc( templateFileName );
00104 DOMDocument * dataSet = dataSetDoc . getDocument();
00105
00106
00107 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "SIDE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> sideO ) );
00108 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "ETA" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> etaO ) );
00109 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "PHI" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> phiO ) );
00110 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "DELTA_PHI" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> dphiO ) );
00111
00112 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "DEPTH" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> depthO ) );
00113 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "SUBDETECTOR" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> detO ) );
00114 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "RBX_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> rbxO ) );
00115 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "SECTOR" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> sectorO ) );
00116
00117 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "RM_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> rmO ) );
00118 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "HPD_PIXEL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> pixelO ) );
00119 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "QIE_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> qieO ) );
00120 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "ADC" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> adcO ) );
00121 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "RM_FIBER" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> rm_fiO ) );
00122 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "FIBER_CHANNEL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row ->fi_chO));
00123
00124 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "LETTER_CODE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh(row ->let_codeO));
00125 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "CRATE" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> crateO ) );
00126 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "HTR_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> htrO ) );
00127 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "HTR_FPGA" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> fpgaO ) );
00128
00129 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "HTR_FIBER" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> htr_fiO ) );
00130 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "DCC_SL" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> dcc_slO ) );
00131 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "SPIGOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> spigoO ) );
00132 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "DCC_SLOT" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> dccO ) );
00133 dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "FED_ID" ) ) -> item(0) -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( row -> fedidO ) );
00134
00135
00136
00137 DOMNode * cloneDataSet = loader -> importNode( dataSet -> getDocumentElement(), true );
00138 root -> appendChild( cloneDataSet );
00139
00140 return 0;
00141 }
00142
00143
00144
00145 int DBlmapWriter::createLMap( void ){
00146 std::cout << "XML Test..." << std::endl;
00147
00148
00149
00150
00151 LMapLoader doc;
00152
00153 LMapLoader::LMapRowHBEF aRow;
00154 LMapLoader::LMapRowHO bRow;
00155
00156
00157 std::ifstream fcha("/afs/fnal.gov/files/home/room3/avetisya/public_html/HCAL/Maps/HCALmapHBEF_Feb.21.2008.txt");
00158 std::ifstream fcho("/afs/fnal.gov/files/home/room3/avetisya/public_html/HCAL/Maps/HCALmapHO_Feb.21.2008.txt");
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 const int NCHA = 6912;
00169 const int NCHO = 2160;
00170 int ncho = 0;
00171 int i, j;
00172 std::string ndump;
00173
00174 int sideC[NCHA], etaC[NCHA], phiC[NCHA], dphiC[NCHA], depthC[NCHA], wedgeC[NCHA], crateC[NCHA], rmC[NCHA], rm_fiC[NCHA], htrC[NCHA];
00175 int htr_fiC[NCHA], fi_chC[NCHA], spigoC[NCHA], dccC[NCHA], dcc_slC[NCHA], fedidC[NCHA], pixelC[NCHA], qieC[NCHA], adcC[NCHA];
00176 int slbC[NCHA], rctcraC[NCHA], rctcarC[NCHA], rctconC[NCHA];
00177 std::string detC[NCHA], rbxC[NCHA], fpgaC[NCHA], slbinC[NCHA], slbin2C[NCHA], slnamC[NCHA], rctnamC[NCHA];
00178
00179 int sideO[NCHO], etaO[NCHO], phiO[NCHO], dphiO[NCHO], depthO[NCHO], sectorO[NCHO], crateO[NCHO], rmO[NCHO], rm_fiO[NCHO], htrO[NCHO];
00180 int htr_fiO[NCHO], fi_chO[NCHO], spigoO[NCHO], dccO[NCHO], dcc_slO[NCHO], fedidO[NCHO], pixelO[NCHO], qieO[NCHO], adcO[NCHO];
00181 int geoO[NCHO], blockO[NCHO], lcO[NCHO];
00182 std::string detO[NCHO], rbxO[NCHO], fpgaO[NCHO], let_codeO[NCHO];
00183
00184 int counter = 0;
00185 for (i = 0; i < NCHA; i++){
00186 if(i == counter){
00187 for (j = 0; j < 31; j++){
00188 fcha>>ndump;
00189 ndump = "";
00190 }
00191 counter += 21;
00192 }
00193 fcha>>sideC[i];
00194 fcha>>etaC[i]>>phiC[i]>>dphiC[i]>>depthC[i]>>detC[i];
00195 fcha>>rbxC[i]>>wedgeC[i]>>rmC[i]>>pixelC[i]>>qieC[i];
00196 fcha>>adcC[i]>>rm_fiC[i]>>fi_chC[i]>>crateC[i]>>htrC[i];
00197 fcha>>fpgaC[i]>>htr_fiC[i]>>dcc_slC[i]>>spigoC[i]>>dccC[i];
00198 fcha>>slbC[i]>>slbinC[i]>>slbin2C[i]>>slnamC[i]>>rctcraC[i]>>rctcarC[i];
00199 fcha>>rctconC[i]>>rctnamC[i]>>fedidC[i];
00200 }
00201
00202 for(i = 0; i < NCHA; i++){
00203 aRow . side = sideC[i];
00204 aRow . eta = etaC[i];
00205 aRow . phi = phiC[i];
00206 aRow . dphi = dphiC[i];
00207 aRow . depth = depthC[i];
00208 aRow . det = detC[i];
00209 aRow . rbx = rbxC[i];
00210 aRow . wedge = wedgeC[i];
00211 aRow . rm = rmC[i];
00212 aRow . pixel = pixelC[i];
00213 aRow . qie = qieC[i];
00214 aRow . adc = adcC[i];
00215 aRow . rm_fi = rm_fiC[i];
00216 aRow . fi_ch = fi_chC[i];
00217 aRow . crate = crateC[i];
00218 aRow . htr = htrC[i];
00219 aRow . fpga = fpgaC[i];
00220 aRow . htr_fi = htr_fiC[i];
00221 aRow . dcc_sl = dcc_slC[i];
00222 aRow . spigo = spigoC[i];
00223 aRow . dcc = dccC[i];
00224 aRow . slb = slbC[i];
00225 aRow . slbin = slbinC[i];
00226 aRow . slbin2 = slbin2C[i];
00227 aRow . slnam = slnamC[i];
00228 aRow . rctcra = rctcraC[i];
00229 aRow . rctcar = rctcarC[i];
00230 aRow . rctcon = rctconC[i];
00231 aRow . rctnam = rctnamC[i];
00232 aRow . fedid = fedidC[i];
00233
00234 doc . addLMapHBEFDataset( &aRow, "FullHCALDataset.xml" );
00235 }
00236
00237 counter = 0;
00238 for (i = 0; i < NCHO; i++){
00239 if(i == counter){
00240 for (j = 0; j < 27; j++){
00241 fcho>>ndump;
00242 ndump = "";
00243 }
00244 counter += 21;
00245 }
00246 fcho>>sideO[i];
00247 if (sideO[i] != 1 && sideO[i] != -1){
00248 std::cerr<<ncho<<'\t'<<sideO[i]<<std::endl;
00249 break;
00250 }
00251 fcho>>etaO[i]>>phiO[i]>>dphiO[i]>>depthO[i]>>detO[i];
00252 fcho>>rbxO[i]>>sectorO[i]>>rmO[i]>>pixelO[i]>>qieO[i];
00253 fcho>>adcO[i]>>rm_fiO[i]>>fi_chO[i]>>let_codeO[i]>>crateO[i]>>htrO[i];
00254 fcho>>fpgaO[i]>>htr_fiO[i]>>dcc_slO[i]>>spigoO[i]>>dccO[i];
00255 fcho>>fedidO[i]>>geoO[i]>>blockO[i]>>lcO[i];
00256
00257 ncho++;
00258 }
00259
00260 for(i = 0; i < NCHO; i++){
00261 bRow . sideO = sideO[i];
00262 bRow . etaO = etaO[i];
00263 bRow . phiO = phiO[i];
00264 bRow . dphiO = dphiO[i];
00265 bRow . depthO = depthO[i];
00266
00267 bRow . detO = detO[i];
00268 bRow . rbxO = rbxO[i];
00269 bRow . sectorO = sectorO[i];
00270 bRow . rmO = rmO[i];
00271 bRow . pixelO = pixelO[i];
00272
00273 bRow . qieO = qieO[i];
00274 bRow . adcO = adcO[i];
00275 bRow . rm_fiO = rm_fiO[i];
00276 bRow . fi_chO = fi_chO[i];
00277 bRow . let_codeO = let_codeO[i];
00278
00279 bRow . crateO = crateO[i];
00280 bRow . htrO = htrO[i];
00281 bRow . fpgaO = fpgaO[i];
00282 bRow . htr_fiO = htr_fiO[i];
00283 bRow . dcc_slO = dcc_slO[i];
00284
00285 bRow . spigoO = spigoO[i];
00286 bRow . dccO = dccO[i];
00287 bRow . fedidO = fedidO[i];
00288
00289 doc . addLMapHODataset( &bRow, "FullHCALDataset.xml" );
00290
00291 }
00292
00293 doc . write( "FullHCALmap.xml" );
00294
00295
00296 std::cout << "XML Test...done" << std::endl;
00297
00298 return 0;
00299 }