CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/EventFilter/EcalDigiToRaw/src/SRBlockFormatter.cc

Go to the documentation of this file.
00001 #include <memory>
00002 
00003 #include "EventFilter/EcalDigiToRaw/interface/SRBlockFormatter.h"
00004 
00005 
00006 using namespace std;
00007 
00008 
00009 SRBlockFormatter::SRBlockFormatter() {
00010 
00011 }
00012 
00013 SRBlockFormatter::~SRBlockFormatter() {
00014 
00015 }
00016 
00017 
00018 void SRBlockFormatter::StartEvent() {
00019   if (debug_) cout << "enter in StartEvent. header_ size is  " << header_.size() << endl;
00020   header_ .clear() ;
00021   if (debug_) cout << "after empty : header_ size is  " << header_.size() << endl;
00022   return;
00023 }
00024 
00025 void SRBlockFormatter::DigiToRaw(int dccid, int dcc_channel, int flag, FEDRawData& rawdata)
00026 {
00027 
00028   if (debug_) cout << "enter in SRBlockFormatter::DigiToRaw " << endl;
00029   if (debug_) print(rawdata);
00030 
00031   int bx = *pbx_;
00032   int lv1 = *plv1_;
00033 
00034   int Nrows_SRP = 5;   // Both for Barrel and EndCap (without the header row)
00035   int SRid = (dccid -1) / 3 +1;
00036 
00037 
00038         // int Number_SRP_Flags = 68;
00039 
00040         int SRP_index;
00041         int icode = 1000 * dccid +  SRid;
00042         if (debug_) cout << "size of header_ map is " << header_.size() << endl;
00043 
00044         std::map<int, int>::const_iterator it_header = header_.find(icode);
00045 
00046         if ( it_header != header_.end() ) {
00047                 SRP_index = rawdata.size() / 8 - Nrows_SRP;
00048                 if (debug_) cout << "This SRid is already there." << endl; 
00049         }
00050         else {
00051                 if (debug_) cout << "New SR Block added on Raw data " << endl;
00052                 header_[icode] = 1;
00053                 SRP_index = rawdata.size() / 8;
00054                 rawdata.resize (rawdata.size() + 8 + 8*Nrows_SRP);  // 1 line for SRP header, 5 lines of data
00055                 unsigned char* ppData = rawdata.data();
00056                 ppData[8*SRP_index] = SRid & 0xFF;
00057                 ppData[8*SRP_index+2] = bx & 0xFF; 
00058                 ppData[8*SRP_index+3] = (bx & 0xF00)>>8;
00059                 ppData[8*SRP_index+3] |= 0x80;
00060                 ppData[8*SRP_index+4] = lv1 & 0xFF;
00061                 ppData[8*SRP_index+5] = (lv1 & 0xF00)>>8;
00062                 // ppData[8*SRP_index+6] = Number_SRP_Flags;  
00063                 ppData[8*SRP_index+6] = 0;
00064                 ppData[8*SRP_index+7] = 0x80;
00065                 SRP_index ++;
00066                 if (debug_) cout << "Added headers and empty lines : " << endl;
00067                 if (debug_) print(rawdata);
00068 
00069                 // -- put the B011 and B100 already, since for Endcap there can be empty
00070                 // -- lines in the TCC and the SRP blocks
00071                 unsigned char* Data = rawdata.data();
00072                 for (int iline=SRP_index; iline < SRP_index+Nrows_SRP; iline++) {
00073                  Data[8*iline + 7] |= 0x80;
00074                  Data[8*iline + 3] |= 0x80;
00075                 }
00076         }
00077 
00078         unsigned char* pData = rawdata.data();
00079 
00080         // -- Now the TCC Block :
00081 
00082         int nflags = pData[8*(SRP_index-1) +6] & 0x7F;
00083         nflags ++;
00084         pData[8*(SRP_index-1) + 6] = nflags & 0x7F;
00085 
00086         int jTT = (dcc_channel-1);
00087         int irow = jTT/16 ;
00088         int ival = jTT % 4;
00089         int kval = (jTT % 16) / 4;
00090         SRP_index += irow;
00091 
00092         if (debug_) cout << "Now add SC to SRBlock " << dec << dcc_channel << " irow ival " << dec << irow << " " << dec << ival << endl;
00093         if (debug_) cout << "new data will be added at line " << dec << SRP_index << endl;
00094 
00095  
00096         unsigned char* buff = &pData[8*SRP_index];
00097         Word64* pw = reinterpret_cast<Word64*>(const_cast<unsigned char*>(buff));
00098         int nbits = kval*16 + 3*ival;
00099          Word64 wflag = (Word64)((short int)flag & 0x7) << nbits;
00100          *pw |= wflag; 
00101          Word64 b1 = (Word64)((Word64)0x80 <<56);
00102          *pw |= b1 ;
00103          Word64 b2 = (Word64)((Word64)0x80 <<24);
00104          *pw |= b2 ;
00105 
00106         if (debug_) print(rawdata);
00107 
00108         
00109 }
00110 
00111