00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <xercesc/parsers/XercesDOMParser.hpp>
00016 #include <xercesc/sax/HandlerBase.hpp>
00017 #include <xercesc/dom/DOM.hpp>
00018
00019 XERCES_CPP_NAMESPACE_USE
00020
00021
00022 #include "CaloOnlineTools/HcalOnlineDb/interface/XMLHTRPatterns.h"
00023 #include "CaloOnlineTools/HcalOnlineDb/interface/XMLProcessor.h"
00024
00025 #include <stdio.h>
00026 #include <string.h>
00027 #include <iostream>
00028 #include <fstream>
00029 #include <sstream>
00030
00031 using namespace std;
00032
00033
00034 #define NHBHECR 9 //HB HE crates
00035 #define NHFCR 3 //HF crates
00036 #define NHOCR 4 //HO crates
00037 #define NFBR 8 //Fibers for htrs
00038 #define NFCH 3 //3 Fiber channels ranging 0-2
00039 #define NTOPBOT 2
00040 #define NHTRS 3 //Htrs 0, 1, 2 for HB HE
00041 #define NHSETS 4 //4 sets of HB/HE htrs
00042 #define NHTRSHO 4 //Htrs 0-3 for HO
00043 #define NHSETSHO 3 //3 sets of H0 htrs
00044 #define NRMFIBR 6 //6 rm fibers ranging 2-7
00045 #define NRMSLOT 4 //4 rm slots ranging 1-4
00046 #define NHOETA 15
00047 #define NHOPHI 72
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 XMLHTRPatterns::HTRPatternConfig::_HTRPatternConfig()
00063 {
00064 CFGBrickSet = "example";
00065 crate = 0;
00066 slot = 13;
00067 topbottom = 0;
00068 fiber = 1;
00069 generalizedindex = slot*100 + topbottom*10 + fiber;
00070 creationtag = "example";
00071
00072 char timebuf[50];
00073
00074 time_t _time = 1193697120;
00075
00076 strftime( timebuf, 50, "%Y-%m-%d %H:%M:%S.0", gmtime( &_time ) );
00077 creationstamp = timebuf;
00078
00079 pattern_spec_name = "example";
00080 }
00081
00082 XMLHTRPatterns::XMLHTRPatterns() : XMLDOMBlock( "HCAL_HTR_DATA_PATTERNS.crate.template" )
00083 {
00084 }
00085
00086 XMLHTRPatterns::XMLHTRPatterns( string templateBase ) : XMLDOMBlock( templateBase )
00087 {
00088 }
00089
00090
00091
00092
00093
00094
00095 XMLHTRPatterns::~XMLHTRPatterns()
00096 {
00097 }
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 int XMLHTRPatterns::addPattern( HTRPatternConfig * config, string templateFileName )
00115 {
00116 DOMElement * root = document -> getDocumentElement();
00117
00118 XMLDOMBlock dataSetDoc( templateFileName );
00119 DOMDocument * dataSet = dataSetDoc . getDocument();
00120
00121 DOMNodeList * _list = dataSet -> getElementsByTagName( XMLProcessor::_toXMLCh( "Parameter" ) );
00122 for ( int i = 0; i < _list -> getLength(); i++ )
00123 {
00124 DOMElement * _tag = (DOMElement *)( _list -> item( i ));
00125 string parameterName = XMLString::transcode( _tag -> getAttribute( XMLProcessor::_toXMLCh( "name" ) ) );
00126
00127 if ( parameterName == "CRATE" ) setTagValue( "Parameter", config -> crate, i, dataSet );
00128 if ( parameterName == "SLOT" ) setTagValue( "Parameter", config -> slot, i, dataSet );
00129 if ( parameterName == "TOPBOTTOM" ) setTagValue( "Parameter", config -> topbottom, i, dataSet );
00130 if ( parameterName == "FIBER" ) setTagValue( "Parameter", config -> fiber, i, dataSet );
00131 if ( parameterName == "GENERALIZEDINDEX" ) setTagValue( "Parameter", config -> generalizedindex, i, dataSet );
00132 if ( parameterName == "CREATIONTAG" ) setTagValue( "Parameter", config -> creationtag, i, dataSet );
00133 if ( parameterName == "CREATIONSTAMP" ) setTagValue( "Parameter", config -> creationstamp, i, dataSet );
00134 if ( parameterName == "PATTERN_SPEC_NAME" ) setTagValue( "Parameter", config -> pattern_spec_name, i, dataSet );
00135 }
00136
00137 setTagValue( "Data", data_elements, 0, dataSet );
00138
00139
00140
00141
00142
00143 DOMNode * cloneDataSet = document -> importNode( dataSet -> getDocumentElement(), true );
00144 root -> appendChild( cloneDataSet );
00145
00146 return 0;
00147 }
00148
00149 int XMLHTRPatterns::fillPatternInfo( const HTRPatternConfig & _conf )
00150 {
00151 HTRPatternID id_;
00152 id_ . crate = _conf . crate;
00153 id_ . slot = _conf . slot;
00154 id_ . topbottom = _conf . topbottom;
00155 id_ . fiber = _conf . fiber;
00156
00157 configByCrate[ id_ ] = _conf . crate;
00158
00159 return 0;
00160 }
00161
00162 int XMLHTRPatterns::createByCrate( void )
00163 {
00164
00165 for ( int i = 0; i < 1024; i++ ) data_elements . append( " 10803" );
00166
00167
00168 int i, j;
00169
00170
00171
00172 stringstream mystream;
00173
00174
00175 void printHBHEHF();
00176 void printHO();
00177
00178 void writeXMLFooter (std::ostream& fOutput);
00179 void writeXMLHeader (std::ostream& fOutput, int swi);
00180 void writeXML (std::ostream& fOutput);
00181 void writeXMLHO (std::ostream& fOutput);
00182
00183
00184
00185 int irm, irm_fi, iwedge, ipixel, iqie, iadc, isector;
00186 int islb, irctcra, irctcar, irctcon, irctnam, idphi;
00187 int iside, ieta, iphi, idepth, icrate, ihtr;
00188 int ihtr_fi, ifi_ch, ispigot, idcc, idcc_sl, ifed;
00189
00190 string rbx, slbin, slbin2, slnam;
00191 string det, fpga, rctnam, letter;
00192 char tempbuff[30];
00193
00194
00195 int titlecounter = 0;
00196
00197 FILE* HOmap;
00198 FILE* HBEFmap;
00199
00200
00201 HOmap = fopen ("../Maps/HCALmapHO_9.14.2007.txt","w");
00202 HBEFmap = fopen ("../Maps/HCALmapHBEF_9.14.2007.txt","w");
00203
00204
00205 int hbhecrate[NHBHECR]={0,1,4,5,10,11,14,15,17};
00206
00207 int hfcrate[NHFCR]={2,9,12};
00208
00209 int hocrate[NHOCR]={3,7,6,13};
00210
00211 int fedhbhenum[NHBHECR][2]={{702,703},{704,705},{700,701},
00212 {706,707},{716,717},{708,709},
00213 {714,715},{710,711},{712,713}};
00214
00215 int fedhfnum[NHFCR][2]={{718,719},{720,721},{722,723}};
00216
00217 int fedhonum[NHOCR][2]={{724,725},{726,727},{728,729},{730,731}};
00218
00219 int ihslot[NHSETS]={2,5,13,16};
00220
00221 int ihslotho[NHSETSHO][NHTRSHO]={{2,3,4,5},{6,7,13,14},{15,16,17,18}};
00222
00223 int ihbhephis[NHBHECR]={11,19,3,27,67,35,59,43,51};
00224
00225 int ihfphis[NHFCR]={3,27,51};
00226
00227 int ihophis[NHOCR]={71,17,35,53};
00228
00229 int ihbheetadepth[NHTRS][NTOPBOT][NFBR][NFCH][2]={
00230 {{{{11,1},{ 7,1},{ 3,1}},
00231 {{ 5,1},{ 1,1},{ 9,1}},
00232 {{11,1},{ 7,1},{ 3,1}},
00233 {{ 5,1},{ 1,1},{ 9,1}},
00234 {{10,1},{ 6,1},{ 2,1}},
00235 {{ 8,1},{ 4,1},{12,1}},
00236 {{10,1},{ 6,1},{ 2,1}},
00237 {{ 8,1},{ 4,1},{12,1}}},
00238 {{{11,1},{ 7,1},{ 3,1}},
00239 {{ 5,1},{ 1,1},{ 9,1}},
00240 {{11,1},{ 7,1},{ 3,1}},
00241 {{ 5,1},{ 1,1},{ 9,1}},
00242 {{10,1},{ 6,1},{ 2,1}},
00243 {{ 8,1},{ 4,1},{12,1}},
00244 {{10,1},{ 6,1},{ 2,1}},
00245 {{ 8,1},{ 4,1},{12,1}}}},
00246 {{{{16,2},{15,2},{14,1}},
00247 {{15,1},{13,1},{16,1}},
00248 {{16,2},{15,2},{14,1}},
00249 {{15,1},{13,1},{16,1}},
00250 {{17,1},{16,3},{26,1}},
00251 {{18,1},{18,2},{26,2}},
00252 {{17,1},{16,3},{25,1}},
00253 {{18,1},{18,2},{25,2}}},
00254 {{{16,2},{15,2},{14,1}},
00255 {{15,1},{13,1},{16,1}},
00256 {{16,2},{15,2},{14,1}},
00257 {{15,1},{13,1},{16,1}},
00258 {{17,1},{16,3},{25,1}},
00259 {{18,1},{18,2},{25,2}},
00260 {{17,1},{16,3},{26,1}},
00261 {{18,1},{18,2},{26,2}}}},
00262 {{{{28,1},{28,2},{29,1}},
00263 {{28,3},{24,2},{24,1}},
00264 {{27,1},{27,2},{29,2}},
00265 {{27,3},{23,2},{23,1}},
00266 {{19,2},{20,1},{22,2}},
00267 {{19,1},{20,2},{22,1}},
00268 {{19,2},{20,1},{21,2}},
00269 {{19,1},{20,2},{21,1}}},
00270 {{{27,1},{27,2},{29,2}},
00271 {{27,3},{23,2},{23,1}},
00272 {{28,1},{28,2},{29,1}},
00273 {{28,3},{24,2},{24,1}},
00274 {{19,2},{20,1},{21,2}},
00275 {{19,1},{20,2},{21,1}},
00276 {{19,2},{20,1},{22,2}},
00277 {{19,1},{20,2},{22,1}}}}
00278 };
00279
00280 int ihfetadepth[NTOPBOT][NFBR][NFCH][2]={
00281 {{{33,1},{31,1},{29,1}},
00282 {{32,1},{30,1},{34,1}},
00283 {{33,2},{31,2},{29,2}},
00284 {{32,2},{30,2},{34,2}},
00285 {{34,2},{32,2},{30,2}},
00286 {{31,2},{29,2},{33,2}},
00287 {{34,1},{32,1},{30,1}},
00288 {{31,1},{29,1},{33,1}}},
00289 {{{41,1},{37,1},{35,1}},
00290 {{38,1},{36,1},{39,1}},
00291 {{41,2},{37,2},{35,2}},
00292 {{38,2},{36,2},{39,2}},
00293 {{40,2},{38,2},{36,2}},
00294 {{37,2},{35,2},{39,2}},
00295 {{40,1},{38,1},{36,1}},
00296 {{37,1},{35,1},{39,1}}}
00297 };
00298
00299
00300
00301 int irm_rmfiHBHE[NHTRS][NTOPBOT][NFBR][2]={
00302 {{{6,1},{7,1},{6,2},{7,2},{4,1},{5,1},{4,2},{5,2}},
00303 {{6,3},{7,3},{6,4},{7,4},{4,3},{5,3},{4,4},{5,4}}},
00304 {{{2,1},{3,1},{2,2},{3,2},{2,1},{3,1},{2,2},{3,2}},
00305 {{2,3},{3,3},{2,4},{3,4},{2,3},{3,3},{2,4},{3,4}}},
00306 {{{4,1},{5,1},{4,2},{5,2},{6,1},{7,1},{6,2},{7,2}},
00307 {{4,3},{5,3},{4,4},{5,4},{6,3},{7,3},{6,4},{7,4}}}
00308 };
00309
00310 int irm_rmfiHF[NHTRS][NTOPBOT][NFBR][2]={
00311 {{{1,2},{2,2},{3,2},{4,2},{1,3},{2,3},{3,3},{4,3}},
00312 {{5,2},{6,2},{7,2},{8,2},{5,3},{6,3},{7,3},{8,3}}},
00313 {{{1,1},{2,1},{3,1},{4,1},{1,2},{2,2},{3,2},{4,2}},
00314 {{5,1},{6,1},{7,1},{8,1},{5,2},{6,2},{7,2},{8,2}}},
00315 {{{1,3},{2,3},{3,3},{4,3},{1,1},{2,1},{3,1},{4,1}},
00316 {{5,3},{6,3},{7,3},{8,3},{5,1},{6,1},{7,1},{8,1}}}
00317 };
00318
00319
00320
00321 int ipixelHB[NRMFIBR][NFCH][NRMSLOT] = {
00322 {{18, 17, 3, 2 }, {13, 3, 17, 7 }, {14, 1, 19, 6 }},
00323 {{19, 2, 18, 1 }, {15, 7, 13, 5 }, {17, 19, 1, 3 }},
00324 {{9, 4, 16, 11}, {5, 8, 12, 15}, {2, 13, 7, 18}},
00325 {{12, 11, 9, 8 }, {7, 15, 5, 13}, {16, 6, 14, 4 }},
00326 {{8, 5, 15, 12}, {4, 9, 11, 16}, {1, 14, 6, 19}},
00327 {{6, 16, 4, 14}, {3, 18, 2, 17}, {11, 12, 8, 9 }}
00328 };
00329
00330 int ipixelHE[NRMFIBR][NFCH][NRMSLOT] = {
00331 {{12, 12, 12, 12}, {16, 7, 16, 7 }, {7, 16, 7, 16}},
00332 {{11, 11, 11, 11}, {19, 3, 19, 3 }, {3, 19, 3, 19}},
00333 {{15, 15, 6, 6 }, {2, 18, 2, 18}, {6, 6, 15, 15}},
00334 {{5, 14, 5, 14}, {14, 5, 14, 5 }, {18, 2, 18, 2 }},
00335 {{17, 1, 17, 1 }, {9, 9, 9, 9 }, {1, 17, 1, 17}},
00336 {{13, 4, 13, 4 }, {8, 8, 8, 8 }, {4, 13, 4, 13}}
00337 };
00338
00339
00340 int iadcquiHBHE[NRMFIBR][NFCH][2];
00341
00342 for (i = 0; i < NRMFIBR; i++){
00343 for (j = 0; j < NFCH; j++){
00344
00345 iadcquiHBHE[i][j][0] = i / 2 + 1;
00346
00347 if (i % 2 == 0) iadcquiHBHE[i][j][1] = j;
00348 else iadcquiHBHE[i][j][1] = NFCH + (j + 1) % 3;
00349 }
00350 }
00351
00352
00353
00354
00355
00356 const char* S_slbin_odd[] ={"A1","B0","B1","A0","A1","B0","B1","A0"};
00357 const char* S_slbin_even[]={"C1","D0","D1","C0","C1","D0","D1","C0"};
00358 const char* rct_rackHBHE[]={"S2E01-RH","S2E03-RH","S2E05-RH","S2E07-RH","S2E09-RH","S2E08-RL","S2E06-RL","S2E04-RL","S2E02-RL",
00359 "S2E02-RH","S2E04-RH","S2E06-RH","S2E08-RH","S2E09-RL","S2E07-RL","S2E05-RL","S2E03-RL","S2E01-RL"};
00360
00361
00362 const char* S_slbin_7[] ={"A0","A1","B0","B1"};
00363 const char* S_slbin_3[] ={"C0","C1","D0","D1"};
00364 const char* rct_rackHF[]={"S2E01-FH","S2E03-FH","S2E05-FH","S2E07-FH","S2E09-FH","S2E08-FL","S2E06-FL","S2E04-FL","S2E02-FL",
00365 "S2E02-FH","S2E04-FH","S2E06-FH","S2E08-FH","S2E09-FL","S2E07-FL","S2E05-FL","S2E03-FL","S2E01-FL"};
00366
00367
00368 int slb_table[29] = {1,1,2,2,3,3,4,4,5,5,6,6,
00369 1,1,2,2,3,3,1,1,
00370 2,2,3,3,4,4,4,4,4};
00371
00372
00373
00374 int HO_RM_table[24][15][2] =
00375 {
00376 {{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{4,2},{4,2},{4,2},{4,2},{4,2}},
00377 {{2,2},{2,2},{2,2},{2,2},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{2,4},{2,4},{2,4},{2,4},{2,4}},
00378 {{3,3},{3,3},{3,3},{3,3},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{2,4},{2,4},{2,4},{2,4},{2,4}},
00379 {{3,3},{3,3},{3,3},{3,3},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{2,4},{2,4},{2,4},{2,4},{2,4}},
00380 {{4,4},{4,4},{4,4},{4,4},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{1,3},{1,3},{1,3},{1,3},{1,3}},
00381 {{4,4},{4,4},{4,4},{4,4},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{1,3},{1,3},{1,3},{1,3},{1,3}},
00382 {{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{1,3},{1,3},{1,3},{1,3},{1,3}},
00383 {{3,3},{3,3},{3,3},{3,3},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{3,1},{3,1},{3,1},{3,1},{3,1}},
00384 {{2,2},{2,2},{2,2},{2,2},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{3,1},{3,1},{3,1},{3,1},{3,1}},
00385 {{2,2},{2,2},{2,2},{2,2},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{3,1},{3,1},{3,1},{3,1},{3,1}},
00386 {{4,4},{4,4},{4,4},{4,4},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{4,2},{4,2},{4,2},{4,2},{4,2}},
00387 {{4,4},{4,4},{4,4},{4,4},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{4,2},{4,2},{4,2},{4,2},{4,2}},
00388 {{3,3},{3,3},{3,3},{3,3},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{4,2},{4,2},{4,2},{4,2},{4,2}},
00389 {{3,3},{3,3},{3,3},{3,3},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{2,4},{2,4},{2,4},{2,4},{2,4}},
00390 {{2,2},{2,2},{2,2},{2,2},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{2,4},{2,4},{2,4},{2,4},{2,4}},
00391 {{2,2},{2,2},{2,2},{2,2},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{2,4},{2,4},{2,4},{2,4},{2,4}},
00392 {{1,1},{1,1},{1,1},{1,1},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{1,3},{1,3},{1,3},{1,3},{1,3}},
00393 {{1,1},{1,1},{1,1},{1,1},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{1,3},{1,3},{1,3},{1,3},{1,3}},
00394 {{2,2},{2,2},{2,2},{2,2},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{1,3},{1,3},{1,3},{1,3},{1,3}},
00395 {{2,2},{2,2},{2,2},{2,2},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{3,1},{3,1},{3,1},{3,1},{3,1}},
00396 {{3,3},{3,3},{3,3},{3,3},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{3,1},{3,1},{3,1},{3,1},{3,1}},
00397 {{3,3},{3,3},{3,3},{3,3},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{3,1},{3,1},{3,1},{3,1},{3,1}},
00398 {{1,1},{1,1},{1,1},{1,1},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{4,2},{4,2},{4,2},{4,2},{4,2}},
00399 {{1,1},{1,1},{1,1},{1,1},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{4,2},{4,2},{4,2},{4,2},{4,2}}
00400 };
00401
00402
00403 int HO_RM_fi_eta5to15[11] = {3, 2, 5, 4, 7, 6, 3, 2, 5, 4, 7};
00404
00405 int HO_htr_fi_eta5to15[2][11] = {{5, 1, 2, 3, 4, 5, 6, 7, 8, 6, 7},
00406 {1, 8, 7, 6, 5, 4, 3, 2, 1, 2, 1}};
00407
00408
00409
00410 int HO_RM_fi_eta1to4[72][2][2] =
00411 {
00412 {{7,3},{4,5}},{{6,2},{4,5}},{{7,3},{4,5}},{{6,2},{4,5}},{{2,6},{5,4}},{{3,7},{5,4}},{{2,6},{5,4}},{{3,7},{5,4}},
00413 {{2,6},{5,4}},{{3,7},{5,4}},{{2,6},{5,4}},{{3,7},{5,4}},{{2,6},{5,4}},{{3,7},{5,4}},{{2,6},{5,4}},{{3,7},{5,4}},
00414 {{7,3},{4,5}},{{6,2},{4,5}},{{7,3},{4,5}},{{6,2},{4,5}},{{7,3},{4,5}},{{6,2},{4,5}},{{7,3},{4,5}},{{6,2},{4,5}},
00415 {{7,3},{4,5}},{{6,2},{4,5}},{{7,3},{4,5}},{{6,2},{4,5}},{{2,6},{5,4}},{{3,7},{5,4}},{{2,6},{5,4}},{{3,7},{5,4}},
00416 {{2,6},{5,4}},{{3,7},{5,4}},{{2,6},{5,4}},{{3,7},{5,4}},{{2,6},{5,4}},{{3,7},{5,4}},{{2,6},{5,4}},{{3,7},{5,4}},
00417 {{7,3},{4,5}},{{6,2},{4,5}},{{7,3},{4,5}},{{6,2},{4,5}},{{7,3},{4,5}},{{6,2},{4,5}},{{7,3},{4,5}},{{6,2},{4,5}},
00418 {{7,3},{4,5}},{{6,2},{4,5}},{{7,3},{4,5}},{{6,2},{4,5}},{{2,6},{5,4}},{{3,7},{5,4}},{{2,6},{5,4}},{{3,7},{5,4}},
00419 {{2,6},{5,4}},{{3,7},{5,4}},{{2,6},{5,4}},{{3,7},{5,4}},{{2,6},{5,4}},{{3,7},{5,4}},{{2,6},{5,4}},{{3,7},{5,4}},
00420 {{7,3},{4,5}},{{6,2},{4,5}},{{7,3},{4,5}},{{6,2},{4,5}},{{7,3},{4,5}},{{6,2},{4,5}},{{7,3},{4,5}},{{6,2},{4,5}}
00421 };
00422
00423
00424
00425 int ipixelHO[NRMFIBR][NFCH][2] = { {{12,12}, {7,7}, {6,3}}, {{4,4}, {8,8}, {5,1} }, {{19,11},{-1000,6},{17,2 }},
00426 {{-1000,9},{1,13},{3,5}}, {{11,19},{16,18},{15,17}}, {{13,15},{9,14}, {14,16}} };
00427
00428 string letterHO[NRMFIBR][NFCH][2] = {{{"E","E"},{"G","L"},{"F","S"}}, {{"Q","M"},{"N","T"},{"P","F"}}, {{"A","C"},{"Z","J"},{"J","Q"}},
00429 {{"Z","K"},{"R","R"},{"H","D"}}, {{"D","A"},{"C","G"},{"B","N"}}, {{"L","H"},{"M","P"},{"K","B"}}};
00430
00431
00432
00433 int hfphi;
00434 char sidesign, S_side;
00435
00436
00437 int phi, phideg, etaslb, oddcard, eta2, eta3, phimod8, ietamod;
00438 int crazy = 0;
00439
00440
00441 int phmod24, phimod6, sidear, iph, iet, isid, ring, sector;
00442 bool phi1458, phi271011, phir0v1, phir0v2, phir0v3, phir0v4;
00443
00444
00445
00446 int ic,is,ih,itb,ifb,ifc,ifwtb;
00447
00448
00449
00450
00451
00452
00453 HTRPatternConfig _config;
00454
00455
00456 for(ic=0; ic<NHBHECR; ic++){
00457
00458 char _buf[50];
00459 sprintf( _buf, "testHTRPatterns_%d.xml", hbhecrate[ic] );
00460 string _fileNameByCrate = _buf;
00461
00462 bool firstBlockWritten = false;
00463
00464 getNewDocument( theFileName );
00465
00466
00467 for(is=0; is<NHSETS; is++){
00468
00469 for(ih=0; ih<NHTRS; ih++){
00470
00471 for(itb=0; itb<NTOPBOT; itb++){
00472
00473 for(ifb=0; ifb<NFBR; ifb++){
00474
00475 for(ifc=0; ifc<NFCH; ifc++){
00476 icrate=hbhecrate[ic];
00477 iside=is<NHSETS/2?-1:1;
00478 ifwtb=(is/2+itb+1)%2;
00479 ieta=ihbheetadepth[ih][ifwtb][ifb][ifc][0];
00480 idepth=ihbheetadepth[ih][ifwtb][ifb][ifc][1];
00481 ihtr=ihslot[is]+ih;
00482 (ieta>16||idepth>2) ? det = "HE": det = "HB";
00483 (itb%2)==1 ? fpga = "bot" : fpga = "top";
00484 ihtr_fi=ifb+1;
00485 ifi_ch=ifc;
00486 iphi=(ieta>20)?(ihbhephis[ic]+(is%2)*4+itb*2-1)%72+1:(ihbhephis[ic]+(is%2)*4+itb*2+(ifb/2+is/2+1)%2-1)%72+1;
00487 ispigot=(is%2)*6+ih*2+itb;
00488 idcc=is<NHSETS/2?1:2;
00489 idcc_sl=idcc==1?9:19;
00490 ifed=fedhbhenum[ic][idcc-1];
00491
00492
00493
00494
00495 if (iside == -1){
00496 S_side = '-';
00497 sidesign = 'M';
00498 irm = irm_rmfiHBHE[ih][(itb + 1) % 2][ifb][1];
00499 irm_fi = irm_rmfiHBHE[ih][(itb + 1) % 2][ifb][0];
00500
00501
00502 if (ieta >= 21 && (irm == 1 || irm == 3)) iwedge = (iphi + 1 + irm + 1) / 4;
00503 else iwedge = (iphi + irm + 1) / 4;
00504
00505
00506 if (iwedge > 18) iwedge -= 18;
00507 }
00508 else{
00509 S_side = '+';
00510 sidesign = 'P';
00511 irm = irm_rmfiHBHE[ih][itb][ifb][1];
00512 irm_fi = irm_rmfiHBHE[ih][itb][ifb][0];
00513
00514
00515 if (ieta >= 21 && (irm == 4 || irm == 2)) iwedge = (iphi + 1 - irm + 6) / 4;
00516 else iwedge = (iphi - irm + 6) / 4;
00517
00518
00519 if (iwedge > 18) iwedge -= 18;
00520 }
00521
00522 sprintf (tempbuff, "%s%c%i%c", det.c_str(), sidesign, iwedge,'\0');
00523 mystream<<tempbuff;
00524 rbx = mystream.str();
00525 mystream.str("");
00526
00527
00528
00529
00530
00531 if (ieta > 16 || idepth > 2) ipixel = ipixelHE[irm_fi - 2][ifc][irm - 1];
00532 else ipixel = ipixelHB[irm_fi - 2][ifc][irm - 1];
00533
00534 iqie = iadcquiHBHE[irm_fi - 2][ifc][0];
00535 iadc = iadcquiHBHE[irm_fi - 2][ifc][1];
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545 phideg = iphi - 3;
00546 if (phideg < 0) phideg = phideg + 72;
00547 phideg = (phideg / 4) * 20 + 10;
00548 irctcra = (( 89 - phideg + 720)%360)/20;
00549 oddcard = irctcra % 2;
00550 irctcra /= 2;
00551 if (iside > 0) irctcra = irctcra + 9;
00552
00553 etaslb = ((ieta - 1) / 2) * 2 + 1;
00554 if (etaslb > 27) etaslb = 27;
00555
00556
00557 sprintf(tempbuff,"SLB_H_%3.3d%c%2.2d%c",phideg,S_side,etaslb,'\0');
00558 mystream<<tempbuff;
00559 slnam = mystream.str();
00560 mystream.str("");
00561
00562 islb = slb_table[ieta - 1];
00563
00564
00565 if (ieta <= 24) {
00566 irctcar = 2 * ((ieta - 1)/8) + oddcard;
00567 irctcon = 2 * (((ieta - 1)/2)%4);
00568 }
00569 else {
00570 irctcar = 6;
00571 eta2 = ieta;
00572 if (eta2 > 28) eta2 = 28;
00573 if (oddcard == 0) eta3 = eta2;
00574 else eta3 = 57 - eta2;
00575 irctcon = 2 * (((eta3 - 1) / 2) % 4);
00576 }
00577 irctcon = 11 * irctcon + 1;
00578
00579 sprintf(tempbuff,"%s-%1d-HD%2.2d",rct_rackHBHE[irctcra],irctcar,irctcon);
00580 mystream<<tempbuff;
00581 rctnam = mystream.str();
00582 mystream.str("");
00583
00584
00585
00586 phimod8 = iphi % 8;
00587
00588 for (i = 0; i < 18; i++){
00589 if (iphi < i * 4 + 3){
00590 crazy = i % 2;
00591 break;
00592 }
00593 }
00594
00595 int ietamod;
00596 if (ieta == 29) ietamod = 0;
00597 else ietamod = ieta % 2;
00598 if (ieta < 25) {
00599 if (ietamod == 1) mystream<<S_slbin_odd[phimod8];
00600 else mystream<<S_slbin_even[phimod8];
00601 }
00602 else if (crazy == 0) {
00603 if (ietamod == 1) mystream<<S_slbin_odd[phimod8];
00604 else mystream<<S_slbin_even[phimod8];
00605 }
00606 else {
00607 if (ietamod == 1) mystream<<S_slbin_even[phimod8];
00608 else mystream<<S_slbin_odd[phimod8];
00609 }
00610
00611 slbin = mystream.str();
00612 mystream.str("");
00613
00614 if (ieta > 20){
00615 idphi = 2;
00616 slbin2 = slbin;
00617 slbin2[1] = '1';
00618 }
00619 else{
00620 idphi = 1;
00621 slbin2 = "NA";
00622 }
00623
00624
00625
00626
00627 int _crate = icrate;
00628 int _slot = ihtr;
00629 int _topbottom = itb;
00630 int _fiber = ihtr_fi;
00631
00632 if ( !firstBlockWritten || _crate != _config . crate || _slot != _config . slot || _topbottom != _config . topbottom || _fiber != _config . fiber )
00633 {
00634 firstBlockWritten = true;
00635 _config . crate = _crate;
00636 _config . slot = _slot;
00637 _config . topbottom = _topbottom;
00638 _config . fiber = _fiber;
00639 _config . generalizedindex = 100*_slot + 10*_topbottom + _fiber;
00640 _config . creationstamp = getTimestamp( time( NULL ) );
00641 addPattern( &_config );
00642 firstBlockWritten = true;
00643 }
00644 }
00645 }
00646 }
00647 }
00648 }
00649 write( _fileNameByCrate );
00650 }
00651
00652
00653 for(ic=0; ic<NHFCR; ic++){
00654
00655 char _buf[50];
00656 sprintf( _buf, "testHTRPatterns_%d.xml", hfcrate[ic] );
00657 string _fileNameByCrate = _buf;
00658
00659 bool firstBlockWritten = false;
00660
00661 getNewDocument( theFileName );
00662
00663
00664 for(is=0; is<NHSETS; is++){
00665
00666 for(ih=0; ih<NHTRS; ih++){
00667
00668 for(itb=0; itb<NTOPBOT; itb++){
00669
00670 for(ifb=0; ifb<NFBR; ifb++){
00671
00672 for(ifc=0; ifc<NFCH; ifc++){
00673 icrate=hfcrate[ic];
00674 iside=is<NHSETS/2?-1:1;
00675 ieta=ihfetadepth[itb][ifb][ifc][0];
00676 idepth=ihfetadepth[itb][ifb][ifc][1];
00677 ihtr=ihslot[is]+ih;
00678 det = "HF";
00679 (itb%2)== 1 ? fpga = "bot" : fpga = "top";
00680 ihtr_fi=ifb+1;
00681 ifi_ch=ifc;
00682 iphi=(ieta>39)?(ihfphis[ic]+(is%2)*12+ih*4-1)%72+1:(ihfphis[ic]+(is%2)*12+ih*4+(ifb/4)*2-1)%72+1;
00683 ispigot=(is%2)*6+ih*2+itb;
00684 idcc=is<NHSETS/2?1:2;
00685 idcc_sl=idcc==1?9:19;
00686 ifed=fedhfnum[ic][idcc-1];
00687
00688 irm = irm_rmfiHF[ih][itb][ifb][1];
00689 irm_fi = irm_rmfiHF[ih][itb][ifb][0];
00690
00691
00692 if (iside == -1){
00693 S_side = '-';
00694 sidesign = 'M';
00695 }
00696 else{
00697 S_side = '+';
00698 sidesign = 'P';
00699 }
00700
00701 if (iphi >= 71) iwedge = 1;
00702 else iwedge = (iphi + 1) / 4 + 1;
00703
00704
00705
00706 if (ieta == 40) hfphi = (iphi + 3) / 2;
00707 else hfphi = (iphi + 1) / 2;
00708
00709
00710 if (hfphi > 36) hfphi -= 36;
00711
00712 sprintf (tempbuff, "%s%c%i%c", det.c_str(), sidesign, (hfphi-1)/3 + 1,'\0');
00713 mystream<<tempbuff;
00714 rbx = mystream.str();
00715 mystream.str("");
00716
00717
00718 ipixel = 0;
00719
00720
00721 iqie = (irm_fi - 1) / 2 + 1;
00722
00723 if (irm_fi % 2 != 0) iadc = ifi_ch;
00724 else iadc = NFCH + (ifi_ch + 1) % 3;
00725
00726
00727
00728 phideg = iphi - 3;
00729 if (phideg < 0) phideg = phideg + 72;
00730 phideg = (phideg / 4) * 20 + 10;
00731 irctcra = (( 89 - phideg + 720)%360)/40;
00732 if (iside > 0) irctcra = irctcra + 9;
00733
00734
00735 irctcar = 99;
00736 irctcon = 0;
00737
00738 etaslb = 29;
00739
00740 sprintf(tempbuff,"SLB_H_%3.3d%c%2.2d",phideg,S_side,etaslb);
00741 mystream<<tempbuff;
00742 slnam = mystream.str();
00743 mystream.str("");
00744
00745 sprintf(tempbuff,"%s-JSC-HF_IN",rct_rackHF[irctcra]);
00746 mystream<<tempbuff;
00747 rctnam = mystream.str();
00748 mystream.str("");
00749
00750 islb = 6;
00751
00752 int phibin = (iphi + 1) % 8 ;
00753 int etabin = (ieta - 29) / 3;
00754 if (etabin < 0) etabin = 0;
00755 if (etabin > 3) etabin = 3;
00756 if (phibin < 4) mystream<<S_slbin_7[etabin];
00757 else mystream<<S_slbin_3[etabin];
00758
00759 slbin = mystream.str();
00760 mystream.str("");
00761
00762
00763
00764
00765
00766
00767
00768
00769 slbin2 = "NA";
00770
00771 if (ieta < 40) idphi = 2;
00772 else idphi = 4;
00773
00774
00775
00776
00777 int _crate = icrate;
00778 int _slot = ihtr;
00779 int _topbottom = itb;
00780 int _fiber = ihtr_fi;
00781
00782 if ( !firstBlockWritten || _crate != _config . crate || _slot != _config . slot || _topbottom != _config . topbottom || _fiber != _config . fiber )
00783 {
00784 firstBlockWritten = true;
00785 _config . crate = _crate;
00786 _config . slot = _slot;
00787 _config . topbottom = _topbottom;
00788 _config . fiber = _fiber;
00789 _config . generalizedindex = 100*_slot + 10*_topbottom + _fiber;
00790 _config . creationstamp = getTimestamp( time( NULL ) );
00791 addPattern( &_config );
00792 firstBlockWritten = true;
00793 }
00794 }
00795 }
00796 }
00797 }
00798 }
00799 write( _fileNameByCrate );
00800 }
00801
00802
00803
00804
00805
00806 titlecounter = 0;
00807
00808 configByCrate . clear();
00809
00810
00811
00812 for(isid = -1; isid < 2; isid+=2){
00813 for (iph = 0; iph < NHOPHI; iph++){
00814 for (iet = 0; iet < NHOETA; iet++){
00815
00816 iphi = iph + 1;
00817 ieta = iet + 1;
00818 iside = isid;
00819
00820 if (iphi >= 71 || iphi < 17) ic = 0;
00821 else if (iphi >= 17 && iphi < 35) ic = 1;
00822 else if (iphi >= 35 && iphi < 53) ic = 2;
00823 else ic = 3;
00824
00825 icrate=hocrate[ic];
00826 idepth=4;
00827 det = "HO";
00828
00829 ihtr_fi=ifb+1;
00830 ifi_ch=ifc;
00831
00832
00833
00834
00835 phimod6 = iphi % 6;
00836
00837 if (ieta >= 5){
00838 if (phimod6 <= 4 && phimod6 >= 2) fpga = "top";
00839 else fpga = "bot";
00840 }
00841 else if (ieta == 4){
00842 if (iside == 1){
00843 if (phimod6 == 1 || phimod6 == 2) fpga = "bot";
00844 else fpga = "top";
00845 }
00846 else{
00847 if (phimod6 == 3 || phimod6 == 4) fpga = "top";
00848 else fpga = "bot";
00849 }
00850 }
00851 else{
00852 if (phimod6 % 2 == 0) fpga = "top";
00853 else fpga = "bot";
00854 }
00855
00856
00857 if (ieta <= 20) idphi = 1;
00858 else idphi = -1000;
00859
00860
00861 if (iside == 1) sidear = 1;
00862 else sidear = 0;
00863
00864 if (fpga == "bot") itb = 1;
00865 else itb = 0;
00866
00867 phmod24 = iph % 24;
00868
00869
00870 irm = HO_RM_table[phmod24][iet][sidear];
00871
00872
00873 if (ieta >= 5) irm_fi = HO_RM_fi_eta5to15[ieta - 5];
00874 else if (ieta <= 3) irm_fi = HO_RM_fi_eta1to4[iph][0][sidear];
00875 else if (ieta == 4) irm_fi = HO_RM_fi_eta1to4[iph][1][sidear];
00876 else irm_fi = -1000;
00877
00878
00879 if (ieta <= 3 || (ieta >= 14 && iside == 1)) ih = 0;
00880 else if (ieta <= 13 && ieta >= 6 && iside == 1) ih = 1;
00881 else if (ieta <= 13 && ieta >= 6 && iside == -1) ih = 3;
00882 else ih = 2;
00883
00884
00885
00886
00887 if (iphi % 18 == 17 || iphi % 18 <= 4) is = 0;
00888 else if (iphi % 18 >= 5 && iphi % 18 <= 10) is = 1;
00889 else is = 2;
00890
00891 ihtr=ihslotho[is][ih];
00892
00893 ispigot=ihtr<9?(ihtr-2)*2+itb:(ihtr-13)*2+itb;
00894 idcc=ihtr<9?1:2;
00895 idcc_sl = idcc == 1 ? 9:19;
00896
00897 ifed=fedhonum[ic][idcc-1];
00898
00899
00900
00901 if (ieta >= 5) ihtr_fi = HO_htr_fi_eta5to15[sidear][ieta - 5];
00902 else if (ieta == 4){
00903 if (phimod6 == 0 || phimod6 == 5) ihtr_fi = 3;
00904 else if (iside == 1) ihtr_fi = 2;
00905 else ihtr_fi = 4;
00906 }
00907 else{
00908 if (iside == 1){
00909 if (phimod6 == 4 || phimod6 == 3) ihtr_fi = 3;
00910 else if (phimod6 == 1 || phimod6 == 2) ihtr_fi = 4;
00911 else if (phimod6 == 0 || phimod6 == 5) ihtr_fi = 5;
00912 }
00913 else{
00914 if (phimod6 == 4 || phimod6 == 3) ihtr_fi = 6;
00915 else if (phimod6 == 1 || phimod6 == 2) ihtr_fi = 7;
00916 else if (phimod6 == 0 || phimod6 == 5) ihtr_fi = 8;
00917 }
00918 }
00919
00920
00921
00922 phi1458 = (iphi % 12 == 1 || iphi % 12 == 4 || iphi % 12 == 5 || iphi % 12 == 8);
00923 phi271011 = (iphi % 12 == 2 || iphi % 12 == 7 || iphi % 12 == 10 || iphi % 12 == 11);
00924
00925
00926 phir0v1 = (iphi % 24 == 0 || iphi % 24 == 2 || iphi % 24 == 4 || iphi % 24 == 18 || iphi % 24 == 20 || iphi % 24 == 22);
00927 phir0v2 = (iphi % 24 == 1 || iphi % 24 == 3 || iphi % 24 == 17 || iphi % 24 == 19 || iphi % 24 == 21 || iphi % 24 == 23);
00928
00929 phir0v3 = (iphi % 24 == 5 || iphi % 24 == 7 || iphi % 24 == 9 || iphi % 24 == 11 || iphi % 24 == 13 || iphi % 24 == 15);
00930 phir0v4 = (iphi % 24 == 6 || iphi % 24 == 8 || iphi % 24 == 10 || iphi % 24 == 12 || iphi % 24 == 14 || iphi % 24 == 16);
00931
00932 if (ieta >= 5){
00933 if (ieta % 2 == 0 && phi1458) ifi_ch = 0;
00934 else if (ieta % 2 == 0 && iphi % 3 == 0) ifi_ch = 1;
00935 else if (ieta % 2 == 0 && phi271011) ifi_ch = 2;
00936 else if (ieta % 2 == 1 && iphi % 3 == 0) ifi_ch = 0;
00937 else if (ieta % 2 == 1 && phi271011) ifi_ch = 1;
00938 else if (ieta % 2 == 1 && phi1458) ifi_ch = 2;
00939 }
00940 else if (ieta == 4){
00941 if (iside == -1){
00942 if (phir0v1) ifi_ch = 0;
00943 else if (phir0v4) ifi_ch = 1;
00944 else if (iphi % 2 == 1) ifi_ch = 2;
00945 }
00946 else{
00947 if (phir0v3) ifi_ch = 0;
00948 else if (phir0v2) ifi_ch = 1;
00949 else if (iphi % 2 == 0) ifi_ch = 2;
00950 }
00951 }
00952
00953 else if ((ieta == 3 && iside == -1) || (ieta == 2 && iside == 1)){
00954 if (phir0v4) ifi_ch = 0;
00955 else if (phir0v3) ifi_ch = 1;
00956 else if (phir0v1 || phir0v2) ifi_ch = 2;
00957 }
00958
00959 else if ((ieta == 3 && iside == 1) || (ieta == 2 && iside == -1)){
00960 if (phir0v2) ifi_ch = 0;
00961 else if (phir0v1) ifi_ch = 1;
00962 else if (phir0v3 || phir0v4) ifi_ch = 2;
00963 }
00964
00965 else if (ieta == 1){
00966 if (phir0v1 || phir0v3) ifi_ch = 0;
00967 else if (phir0v2 || phir0v4) ifi_ch = 1;
00968 }
00969
00970
00971
00972 iqie = (irm_fi - 2) / 2 + 1;
00973
00974 if (irm_fi % 2 == 0) iadc = ifi_ch;
00975 else iadc = NFCH + (ifi_ch + 1) % 3;
00976
00977
00978 if (ieta <= 4){
00979 ipixel = ipixelHO[irm_fi - 2][ifi_ch][0];
00980 letter = letterHO[irm_fi - 2][ifi_ch][0];
00981 }
00982 else{
00983 ipixel = ipixelHO[irm_fi - 2][ifi_ch][1];
00984 letter = letterHO[irm_fi - 2][ifi_ch][1];
00985 }
00986
00987
00988
00989 if (iside == -1) sidesign = 'M';
00990 else sidesign = 'P';
00991
00992 if (ieta <= 4) ring = 0;
00993 else if (ieta >= 5 && ieta <= 10) ring = 1;
00994 else ring = 2;
00995
00996
00997 sector = 0;
00998 for (i = -2; i < iphi; i+=6){
00999 sector++;
01000 }
01001 if (sector > 12) sector = 1;
01002
01003 isector = sector;
01004
01005
01006 if (ring != 0 && sector % 2 != 0) sector++;
01007
01008 if (ring == 0) sprintf (tempbuff, "%s%i%2.2d", det.c_str(), ring, sector);
01009 else sprintf (tempbuff, "%s%i%c%2.2d", det.c_str(), ring, sidesign, sector);
01010 mystream<<tempbuff;
01011 rbx = mystream.str();
01012 mystream.str("");
01013
01014 iwedge = -1000;
01015 irctcra = -1000;
01016 irctcar = -1000;
01017 irctcon = -1000;
01018 rctnam = "RCTNAM";
01019
01020 islb = -1000;
01021 slbin = "SLBIN";
01022 slnam = "SLNAM";
01023 slbin2 = "NA";
01024
01025
01026
01027
01028
01029 int _crate = icrate;
01030 int _slot = ihtr;
01031 int _topbottom = itb;
01032 int _fiber = ihtr_fi;
01033 HTRPatternConfig _config;
01034 _config . crate = _crate;
01035 _config . slot = _slot;
01036 _config . topbottom = _topbottom;
01037 _config . fiber = _fiber;
01038 fillPatternInfo( _config );
01039 }
01040 }
01041 }
01042
01043
01044
01045 cout << configByCrate . size() << endl << endl;
01046
01047 int currentCrate = -1;
01048 string _fileNameByHOCrate;
01049 for( map< HTRPatternID, int >::const_iterator i = configByCrate . begin(); i != configByCrate . end(); i++ )
01050 {
01051
01052 if ( currentCrate != i -> second )
01053 {
01054 if ( currentCrate != -1 ) write( _fileNameByHOCrate );
01055 char _buf[50];
01056 sprintf( _buf, "testHTRPatterns_%d.xml", i -> second );
01057 _fileNameByHOCrate = _buf;
01058 getNewDocument( theFileName );
01059 }
01060
01061 int _crate = i -> first . crate;
01062 int _slot = i -> first . slot;
01063 int _topbottom = i -> first . topbottom;
01064 int _fiber = i -> first . fiber;
01065
01066 _config . crate = _crate;
01067 _config . slot = _slot;
01068 _config . topbottom = _topbottom;
01069 _config . fiber = _fiber;
01070 _config . generalizedindex = 100*_slot + 10*_topbottom + _fiber;
01071 _config . creationstamp = getTimestamp( time( NULL ) );
01072 addPattern( &_config );
01073
01074 currentCrate = i -> second;
01075 }
01076
01077
01078 write( _fileNameByHOCrate );
01079
01080 }
01081
01082
01083
01084
01085
01086
01087
01088