CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/EventFilter/EcalTBRawToDigi/src/DCCDataMapper.cc

Go to the documentation of this file.
00001 #include "DCCDataMapper.h"
00002  
00003 /*--------------------------------------------*/
00004 /* DCCTBDataMapper::DCCTBDataMapper               */
00005 /* class constructor                          */
00006 /*--------------------------------------------*/
00007 DCCTBDataMapper::DCCTBDataMapper( DCCTBDataParser * myParser)
00008 : parser_(myParser){
00009   
00010   dccFields_        = new std::set<DCCTBDataField  * , DCCTBDataFieldComparator>;
00011   emptyEventFields_ = new std::set<DCCTBDataField  * , DCCTBDataFieldComparator>;
00012   
00013   tcc68Fields_    = new std::set<DCCTBDataField  * , DCCTBDataFieldComparator>; 
00014   tcc32Fields_    = new std::set<DCCTBDataField  * , DCCTBDataFieldComparator>;
00015   tcc16Fields_    = new std::set<DCCTBDataField  * , DCCTBDataFieldComparator>;
00016 
00017   srp68Fields_    = new std::set<DCCTBDataField  * , DCCTBDataFieldComparator>;
00018   srp32Fields_    = new std::set<DCCTBDataField  * , DCCTBDataFieldComparator>;
00019   srp16Fields_    = new std::set<DCCTBDataField  * , DCCTBDataFieldComparator>;
00020   
00021   towerFields_  = new std::set<DCCTBDataField  * , DCCTBDataFieldComparator>;   
00022   xtalFields_   = new std::set<DCCTBDataField  * , DCCTBDataFieldComparator>;
00023   trailerFields_= new std::set<DCCTBDataField  * , DCCTBDataFieldComparator>;
00024         
00025   buildDCCFields();
00026   buildTCCFields(); 
00027   buildSRPFields(); 
00028   buildTowerFields();
00029   buildXtalFields();
00030   buildTrailerFields(); 
00031 }
00032 
00033 /*---------------------------------------------*/
00034 /* DCCTBDataMapper::~DCCTBDataMapper               */
00035 /* class destructor (free memory)              */
00036 /*---------------------------------------------*/
00037 DCCTBDataMapper::~DCCTBDataMapper(){
00038   
00039   std::set<DCCTBDataField *,DCCTBDataFieldComparator>::iterator it;
00040   
00041   for(it = dccFields_->begin()    ;it != dccFields_->end();     it++){ delete (*it);}
00042   for(it = emptyEventFields_->begin()    ;it != emptyEventFields_->end();     it++){ delete (*it);}
00043   
00044   for(it = tcc68Fields_->begin()  ;it != tcc68Fields_->end();     it++){ delete (*it);}         
00045   for(it = tcc32Fields_->begin()  ;it != tcc32Fields_->end();     it++){ delete (*it);}
00046   for(it = tcc16Fields_->begin()  ;it != tcc16Fields_->end();     it++){ delete (*it);}
00047   
00048   for(it = srp68Fields_->begin()  ;it != srp68Fields_->end();     it++){ delete (*it);}
00049   for(it = srp32Fields_->begin()  ;it != srp32Fields_->end();     it++){ delete (*it);}
00050   for(it = srp16Fields_->begin()  ;it != srp16Fields_->end();     it++){ delete (*it);}
00051         
00052   for(it = towerFields_->begin()  ;it != towerFields_->end();   it++){ delete (*it);}
00053   for(it = xtalFields_->begin()   ;it != xtalFields_->end();    it++){ delete (*it);}
00054   for(it = trailerFields_->begin();it != trailerFields_->end(); it++){ delete (*it);}
00055         
00056   delete dccFields_;
00057   delete emptyEventFields_;
00058 
00059   delete tcc68Fields_;
00060   delete tcc32Fields_;
00061   delete tcc16Fields_;
00062   
00063   delete srp68Fields_;
00064   delete srp32Fields_;
00065   delete srp16Fields_;
00066   
00067   delete towerFields_;
00068   delete xtalFields_;
00069   delete trailerFields_;
00070 }
00071 
00072 
00073 /*-------------------------------------------------*/
00074 /* DCCTBDataMapper::buildDccFields                   */
00075 /* builds raw data header fields                   */
00076 /*-------------------------------------------------*/
00077 void DCCTBDataMapper::buildDCCFields(){
00078 
00079   //32 Bit word numb 0
00080   dccFields_->insert( new DCCTBDataField("H",H_WPOSITION,H_BPOSITION,H_MASK));
00081   emptyEventFields_->insert( new DCCTBDataField("H",H_WPOSITION,H_BPOSITION,H_MASK));
00082   
00083   dccFields_->insert( new DCCTBDataField("FOV",FOV_WPOSITION,FOV_BPOSITION,FOV_MASK));
00084   emptyEventFields_->insert( new DCCTBDataField("FOV",FOV_WPOSITION,FOV_BPOSITION,FOV_MASK));
00085   
00086   dccFields_->insert( new DCCTBDataField("FED/DCC ID",DCCID_WPOSITION,DCCID_BPOSITION,DCCID_MASK));
00087   emptyEventFields_->insert( new DCCTBDataField("FED/DCC ID",DCCID_WPOSITION,DCCID_BPOSITION,DCCID_MASK));
00088         
00089   dccFields_->insert( new DCCTBDataField("BX",DCCBX_WPOSITION,DCCBX_BPOSITION,DCCBX_MASK));
00090   emptyEventFields_->insert( new DCCTBDataField("BX",DCCBX_WPOSITION,DCCBX_BPOSITION,DCCBX_MASK));
00091 
00092   //32Bit word numb 1
00093   dccFields_->insert( new DCCTBDataField("LV1",DCCL1_WPOSITION ,DCCL1_BPOSITION,DCCL1_MASK));
00094   emptyEventFields_->insert( new DCCTBDataField("LV1",DCCL1_WPOSITION ,DCCL1_BPOSITION,DCCL1_MASK));
00095         
00096   dccFields_->insert( new DCCTBDataField("TRIGGER TYPE",TRIGGERTYPE_WPOSITION,TRIGGERTYPE_BPOSITION,TRIGGERTYPE_MASK));
00097   emptyEventFields_->insert( new DCCTBDataField("TRIGGER TYPE",TRIGGERTYPE_WPOSITION,TRIGGERTYPE_BPOSITION,TRIGGERTYPE_MASK));
00098         
00099   dccFields_->insert( new DCCTBDataField("BOE",BOE_WPOSITION,BOE_BPOSITION,BOE_MASK));
00100   emptyEventFields_->insert( new DCCTBDataField("BOE",BOE_WPOSITION,BOE_BPOSITION,BOE_MASK));
00101 
00102   //32Bit word numb 2
00103   dccFields_->insert( new DCCTBDataField("EVENT LENGTH",EVENTLENGTH_WPOSITION,EVENTLENGTH_BPOSITION,EVENTLENGTH_MASK));
00104   emptyEventFields_->insert( new DCCTBDataField("EVENT LENGTH",EVENTLENGTH_WPOSITION,EVENTLENGTH_BPOSITION,EVENTLENGTH_MASK));
00105   
00106   dccFields_->insert( new DCCTBDataField("DCC ERRORS",DCCERRORS_WPOSITION  ,DCCERRORS_BPOSITION,DCCERRORS_MASK));
00107   emptyEventFields_->insert( new DCCTBDataField("DCC ERRORS",DCCERRORS_WPOSITION  ,DCCERRORS_BPOSITION,DCCERRORS_MASK));
00108   
00109   //32Bit word numb 3 
00110   dccFields_->insert( new DCCTBDataField("RUN NUMBER",RNUMB_WPOSITION,RNUMB_BPOSITION,RNUMB_MASK));
00111   emptyEventFields_->insert( new DCCTBDataField("RUN NUMBER",RNUMB_WPOSITION,RNUMB_BPOSITION,RNUMB_MASK));
00112         
00113   //32 Bit word numb 4
00114   dccFields_->insert( new DCCTBDataField("RUN TYPE",RUNTYPE_WPOSITION,RUNTYPE_BPOSITION,RUNTYPE_MASK)); 
00115   emptyEventFields_->insert( new DCCTBDataField("RUN TYPE",RUNTYPE_WPOSITION,RUNTYPE_BPOSITION,RUNTYPE_MASK));  
00116   
00117   //32Bit word numb 5 
00118   dccFields_->insert( new DCCTBDataField("DETAILED TRIGGER TYPE",DETAILEDTT_WPOSITION,DETAILEDTT_BPOSITION,DETAILEDTT_MASK));
00119   emptyEventFields_->insert( new DCCTBDataField("DETAILED TRIGGER TYPE",DETAILEDTT_WPOSITION,DETAILEDTT_BPOSITION,DETAILEDTT_MASK));
00120 
00121   //32 Bit word numb 6
00122   dccFields_->insert( new DCCTBDataField("ORBIT COUNTER",ORBITCOUNTER_WPOSITION,ORBITCOUNTER_BPOSITION,ORBITCOUNTER_MASK));
00123 
00124   //32 Bit word numb 7
00125   dccFields_->insert( new DCCTBDataField("SR",SR_WPOSITION,SR_BPOSITION,SR_MASK));
00126   dccFields_->insert( new DCCTBDataField("ZS",ZS_WPOSITION,ZS_BPOSITION,ZS_MASK));
00127   dccFields_->insert( new DCCTBDataField("TZS",TZS_WPOSITION,TZS_BPOSITION,TZS_MASK));
00128         
00129   dccFields_->insert( new DCCTBDataField("SR_CHSTATUS",SR_CHSTATUS_WPOSITION,SR_CHSTATUS_BPOSITION,SR_CHSTATUS_MASK));  
00130   dccFields_->insert( new DCCTBDataField("TCC_CHSTATUS#1",TCC_CHSTATUS_WPOSITION,TCC_CHSTATUS_BPOSITION,TCC_CHSTATUS_MASK));    
00131   dccFields_->insert( new DCCTBDataField("TCC_CHSTATUS#2",TCC_CHSTATUS_WPOSITION,TCC_CHSTATUS_BPOSITION+4,TCC_CHSTATUS_MASK));
00132   dccFields_->insert( new DCCTBDataField("TCC_CHSTATUS#3",TCC_CHSTATUS_WPOSITION,TCC_CHSTATUS_BPOSITION+8,TCC_CHSTATUS_MASK));  
00133   dccFields_->insert( new DCCTBDataField("TCC_CHSTATUS#4",TCC_CHSTATUS_WPOSITION,TCC_CHSTATUS_BPOSITION+12,TCC_CHSTATUS_MASK));
00134   
00135 
00136   //add Headers Qualifiers: 8 words with 6 bits each written on the 2nd 32bit words
00137   for(uint32_t i=1;i<=8;i++){
00138     std::string header = std::string("H") + parser_->getDecString(i);
00139     dccFields_->insert( new DCCTBDataField(header,HD_WPOSITION + (i-1)*2 ,HD_BPOSITION,HD_MASK));               
00140 
00141     //fill only for empty events
00142     if(i<3){ emptyEventFields_->insert( new DCCTBDataField(header,HD_WPOSITION + (i-1)*2 ,HD_BPOSITION,HD_MASK));       }       
00143   }
00144 
00145 
00146   //add FE_CHSTATUS: 5 words each having 14 FE_CHSTATUS
00147   for(uint32_t wcount = 1; wcount<=5; wcount++){
00148 
00149     //1st word 32 bit
00150     for(uint32_t i=1;i<=8;i++){
00151       std::string chStatus = std::string("FE_CHSTATUS#") + parser_->getDecString( (wcount-1)*14 + i );
00152       dccFields_->insert( new DCCTBDataField(chStatus, FE_CHSTATUS_WPOSITION +(wcount-1)*2, 4*(i-1),FE_CHSTATUS_MASK)); 
00153     }
00154 
00155     //2nd word 32 bit
00156     for(uint32_t i=9;i<=14;i++){
00157       std::string chStatus = std::string("FE_CHSTATUS#") + parser_->getDecString((wcount-1)*14 + i);
00158       dccFields_->insert( new DCCTBDataField(chStatus, FE_CHSTATUS_WPOSITION + (wcount-1)*2 + 1,4*(i-9),FE_CHSTATUS_MASK));     
00159     }
00160     
00161   }
00162 
00163 }
00164 
00165 /*-------------------------------------------------*/
00166 /* DCCTBDataMapper::buildTCCFields                   */
00167 /* builds raw data TCC block fields                */
00168 /*-------------------------------------------------*/
00169 void DCCTBDataMapper::buildTCCFields(){
00170         
00171   std::vector<std::set<DCCTBDataField *, DCCTBDataFieldComparator> *> pVector;
00172   pVector.push_back(tcc16Fields_);
00173   pVector.push_back(tcc32Fields_);
00174   pVector.push_back(tcc68Fields_);
00175         
00176   for(int i=0; i< ((int)(pVector.size())) ;i++){
00177     (pVector[i])->insert( new DCCTBDataField("TCC ID",TCCID_WPOSITION ,TCCID_BPOSITION,TCCID_MASK));
00178     (pVector[i])->insert( new DCCTBDataField("BX",TCCBX_WPOSITION ,TCCBX_BPOSITION,TCCBX_MASK));        
00179     (pVector[i])->insert( new DCCTBDataField("E0",TCCE0_WPOSITION ,TCCE0_BPOSITION,TCCE0_MASK));
00180     (pVector[i])->insert( new DCCTBDataField("LV1",TCCL1_WPOSITION ,TCCL1_BPOSITION,TCCL1_MASK));
00181     (pVector[i])->insert( new DCCTBDataField("E1", TCCE1_WPOSITION, TCCE1_BPOSITION, TCCE1_MASK));      
00182     (pVector[i])->insert( new DCCTBDataField("#TT", NTT_WPOSITION, NTT_BPOSITION, NTT_MASK));
00183     (pVector[i])->insert( new DCCTBDataField("#TIME SAMPLES",TCCTSAMP_WPOSITION, TCCTSAMP_BPOSITION,TCCTSAMP_MASK));    
00184     (pVector[i])->insert( new DCCTBDataField("LE0",TCCLE0_WPOSITION, TCCLE0_BPOSITION, TCCLE0_MASK));   
00185     (pVector[i])->insert( new DCCTBDataField("LE1",TCCLE1_WPOSITION, TCCLE1_BPOSITION, TCCLE1_MASK));   
00186   }
00187   
00188   uint32_t nTSamples = parser_->numbTriggerSamples();
00189         
00190   uint32_t totalTT   = 68*nTSamples; 
00191   
00192   uint32_t filter1 = 16*nTSamples;
00193   uint32_t filter2 = 32*nTSamples;
00194         
00195   uint32_t count(2) ;
00196         
00197   // Fill block with TT definition 
00198   for(uint32_t tt=1; tt<=totalTT; tt++){
00199     std::string tpg    = std::string("TPG#") + parser_->getDecString(tt);
00200     std::string ttFlag = std::string("TTF#") + parser_->getDecString(tt);
00201 
00202     if(tt<=filter1){ 
00203       tcc16Fields_->insert( new DCCTBDataField(tpg, TPG_WPOSITION -1 + count/2, TPG_BPOSITION + 16*( (count+2)%2 ),TPG_MASK));
00204       tcc16Fields_->insert( new DCCTBDataField(ttFlag, TTF_WPOSITION -1 + count/2, TTF_BPOSITION + 16*( (count+2)%2 ),TTF_MASK));
00205     }
00206     if(tt<=filter2){
00207       tcc32Fields_->insert( new DCCTBDataField(tpg, TPG_WPOSITION -1 + count/2, TPG_BPOSITION + 16*( (count+2)%2 ),TPG_MASK));
00208       tcc32Fields_->insert( new DCCTBDataField(ttFlag, TTF_WPOSITION -1 + count/2, TTF_BPOSITION + 16*( (count+2)%2 ),TTF_MASK));
00209     }
00210     
00211     tcc68Fields_->insert( new DCCTBDataField(tpg, TPG_WPOSITION -1 + count/2, TPG_BPOSITION + 16*( (count+2)%2 ),TPG_MASK));
00212     tcc68Fields_->insert( new DCCTBDataField(ttFlag, TTF_WPOSITION -1 + count/2, TTF_BPOSITION + 16*( (count+2)%2 ),TTF_MASK));
00213     count++;
00214   }
00215                 
00216 }
00217 
00218 // ---> update with the correct number of SRP fields
00219 void DCCTBDataMapper::buildSRPFields(){
00220   std::vector<std::set<DCCTBDataField *, DCCTBDataFieldComparator> * > pVector;
00221   pVector.push_back(srp68Fields_);
00222   pVector.push_back(srp32Fields_);
00223   pVector.push_back(srp16Fields_);
00224   
00225   for(int i=0; i< ((int)(pVector.size())) ;i++){
00226     // This method must be modified to take into account the different SRP blocks : 68 SRF in the barrel, 34 ,35 or 36 in the EE
00227     (pVector[i])->insert( new DCCTBDataField("SRP ID",SRPID_WPOSITION ,SRPID_BPOSITION,SRPID_MASK));
00228     (pVector[i])->insert( new DCCTBDataField("BX",SRPBX_WPOSITION ,SRPBX_BPOSITION,SRPBX_MASK));        
00229     (pVector[i])->insert( new DCCTBDataField("E0",SRPE0_WPOSITION ,SRPE0_BPOSITION,SRPE0_MASK));
00230     
00231     (pVector[i])->insert( new DCCTBDataField("LV1",SRPL1_WPOSITION ,SRPL1_BPOSITION,SRPL1_MASK));
00232     (pVector[i])->insert( new DCCTBDataField("E1", SRPE1_WPOSITION, SRPE1_BPOSITION, SRPE1_MASK));      
00233     (pVector[i])->insert( new DCCTBDataField("#SR FLAGS",NSRF_WPOSITION, NSRF_BPOSITION,NSRF_MASK));
00234     (pVector[i])->insert( new DCCTBDataField("LE0",SRPLE0_WPOSITION, SRPLE0_BPOSITION, SRPLE0_MASK));   
00235     (pVector[i])->insert( new DCCTBDataField("LE1",SRPLE1_WPOSITION, SRPLE1_BPOSITION, SRPLE1_MASK));   
00236   }
00237   
00238   uint32_t srpFlags(68); 
00239   
00240   uint32_t count1(1), count2(1), srSize(3), factor(0), wcount(0);
00241   for(uint32_t nsr =1; nsr<=srpFlags; nsr++){
00242     
00243     std::string sr = std::string("SR#") + parser_->getDecString(nsr);
00244     
00245     srp68Fields_->insert( new DCCTBDataField(sr,SRF_WPOSITION + wcount, SRF_BPOSITION + SRPBOFFSET*factor + (count2-1)*srSize,SRF_MASK));
00246     if( nsr<=32 ){ srp32Fields_->insert( new DCCTBDataField(sr,SRF_WPOSITION + wcount, SRF_BPOSITION + SRPBOFFSET*factor + (count2-1)*srSize,SRF_MASK));}
00247     if( nsr<=16 ){ srp16Fields_->insert( new DCCTBDataField(sr,SRF_WPOSITION + wcount, SRF_BPOSITION + SRPBOFFSET*factor + (count2-1)*srSize,SRF_MASK));}
00248     
00249     count1++; count2++; 
00250     
00251     //update word count
00252     if( count1 > 8){ wcount++; count1=1;}       
00253     
00254     //update bit offset
00255     if(count1 > 4){ factor = 1;}
00256     else{factor = 0;}
00257     
00258     //update bit shift
00259     if( count2 > 4){ count2 = 1;}
00260     
00261   }
00262 }
00263 
00264 
00265 /*-------------------------------------------------*/
00266 /* DCCTBDataMapper::buildTowerFields                 */
00267 /* builds raw data Tower Data fields               */
00268 /*-------------------------------------------------*/
00269 void DCCTBDataMapper::buildTowerFields(){
00270   //32bit word numb 1
00271   towerFields_->insert( new DCCTBDataField("TT/SC ID",TOWERID_WPOSITION ,TOWERID_BPOSITION,TOWERID_MASK));
00272   towerFields_->insert( new DCCTBDataField("#TIME SAMPLES",XSAMP_WPOSITION ,XSAMP_BPOSITION,XSAMP_MASK));
00273   towerFields_->insert( new DCCTBDataField("BX", TOWERBX_WPOSITION ,TOWERBX_BPOSITION,TOWERBX_MASK));   
00274   towerFields_->insert( new DCCTBDataField("E0",TOWERE0_WPOSITION ,TOWERE0_BPOSITION,TOWERE0_MASK));
00275   
00276   //32 bit word numb 2
00277   towerFields_->insert( new DCCTBDataField("LV1",TOWERL1_WPOSITION ,TOWERL1_BPOSITION, TOWERL1_MASK));
00278   towerFields_->insert( new DCCTBDataField("E1", TOWERE1_WPOSITION, TOWERE1_BPOSITION, TOWERE1_MASK));  
00279   towerFields_->insert( new DCCTBDataField("BLOCK LENGTH",TOWERLENGTH_WPOSITION, TOWERLENGTH_BPOSITION,TOWERLENGTH_MASK));
00280 }
00281 
00282 
00283 /*-------------------------------------------------*/
00284 /* DCCTBDataMapper::buildXtalFields                  */
00285 /* builds raw data Crystal Data fields             */
00286 /*-------------------------------------------------*/
00287 void DCCTBDataMapper::buildXtalFields(){
00288         
00289   //32bit word numb 1   
00290   xtalFields_->insert(new DCCTBDataField("STRIP ID",STRIPID_WPOSITION,STRIPID_BPOSITION,STRIPID_MASK));
00291   xtalFields_->insert(new DCCTBDataField("XTAL ID",XTALID_WPOSITION,XTALID_BPOSITION,XTALID_MASK));
00292   xtalFields_->insert(new DCCTBDataField("M",M_WPOSITION,M_BPOSITION,M_MASK));
00293   xtalFields_->insert(new DCCTBDataField("SMF",SMF_WPOSITION,SMF_BPOSITION,SMF_MASK));
00294   xtalFields_->insert(new DCCTBDataField("GMF",GMF_WPOSITION,GMF_BPOSITION,GMF_MASK));
00295 
00296   //first ADC is still on 1st word
00297   xtalFields_->insert(new DCCTBDataField("ADC#1",ADC_WPOSITION,ADCBOFFSET,ADC_MASK));
00298         
00299   //add the rest of the ADCs 
00300   for(uint32_t i=2; i <= parser_->numbXtalSamples();i++){
00301     std::string adc = std::string("ADC#") + parser_->getDecString(i);
00302     if(i%2){ xtalFields_->insert(new DCCTBDataField(adc,ADC_WPOSITION + i/2, ADCBOFFSET,ADC_MASK)); }
00303     else   { xtalFields_->insert(new DCCTBDataField(adc,ADC_WPOSITION + i/2, 0,ADC_MASK)); }
00304   }
00305 
00306   //the last word has written the test zero suppression flag and the gain decision bit
00307   uint32_t tzsOffset_ = parser_->numbXtalSamples()/2;
00308   xtalFields_->insert(new DCCTBDataField("TZS",XTAL_TZS_WPOSITION+tzsOffset_,XTAL_TZS_BPOSITION,XTAL_TZS_MASK));
00309   xtalFields_->insert(new DCCTBDataField("GDECISION",XTAL_GDECISION_WPOSITION+tzsOffset_,XTAL_GDECISION_BPOSITION,XTAL_GDECISION_MASK));
00310 }
00311 
00312 
00313 /*-------------------------------------------------*/
00314 /* DCCTBDataMapper::buildTrailerFields               */
00315 /* builds raw data Trailer words                   */
00316 /*-------------------------------------------------*/
00317 void DCCTBDataMapper::buildTrailerFields(){
00318   //32bit word numb 1
00319   trailerFields_->insert(new DCCTBDataField("T",T_WPOSITION,T_BPOSITION,T_MASK));
00320   trailerFields_->insert(new DCCTBDataField("TTS",TTS_WPOSITION,TTS_BPOSITION,TTS_MASK));
00321   trailerFields_->insert(new DCCTBDataField("EVENT STATUS",ESTAT_WPOSITION,ESTAT_BPOSITION,ESTAT_MASK));
00322   trailerFields_->insert(new DCCTBDataField("CRC",CRC_WPOSITION,CRC_BPOSITION,CRC_MASK));
00323 
00324   //32bit word numb 2
00325   trailerFields_->insert(new DCCTBDataField("EVENT LENGTH",TLENGTH_WPOSITION,TLENGTH_BPOSITION,TLENGTH_MASK));
00326   trailerFields_->insert(new DCCTBDataField("EOE",EOE_WPOSITION,EOE_BPOSITION,EOE_MASK));
00327         
00328 }