Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:14:49

0001 #include <memory>
0002 
0003 #include "EventFilter/EcalDigiToRaw/interface/SRBlockFormatter.h"
0004 
0005 using namespace std;
0006 
0007 SRBlockFormatter::SRBlockFormatter(Config const& iC, Params const& iP) : BlockFormatter(iC, iP) {}
0008 
0009 void SRBlockFormatter::DigiToRaw(int dccid, int dcc_channel, int flag, FEDRawData& rawdata) {
0010   if (debug_)
0011     cout << "enter in SRBlockFormatter::DigiToRaw " << endl;
0012   if (debug_)
0013     print(rawdata);
0014 
0015   int bx = bx_;
0016   int lv1 = lv1_;
0017 
0018   int Nrows_SRP = 5;  // Both for Barrel and EndCap (without the header row)
0019   int SRid = (dccid - 1) / 3 + 1;
0020 
0021   // int Number_SRP_Flags = 68;
0022 
0023   int SRP_index;
0024   int icode = 1000 * dccid + SRid;
0025   if (debug_)
0026     cout << "size of header_ map is " << header_.size() << endl;
0027 
0028   std::map<int, int>::const_iterator it_header = header_.find(icode);
0029 
0030   if (it_header != header_.end()) {
0031     SRP_index = rawdata.size() / 8 - Nrows_SRP;
0032     if (debug_)
0033       cout << "This SRid is already there." << endl;
0034   } else {
0035     if (debug_)
0036       cout << "New SR Block added on Raw data " << endl;
0037     header_[icode] = 1;
0038     SRP_index = rawdata.size() / 8;
0039     rawdata.resize(rawdata.size() + 8 + 8 * Nrows_SRP);  // 1 line for SRP header, 5 lines of data
0040     unsigned char* ppData = rawdata.data();
0041     ppData[8 * SRP_index] = SRid & 0xFF;
0042     ppData[8 * SRP_index + 2] = bx & 0xFF;
0043     ppData[8 * SRP_index + 3] = (bx & 0xF00) >> 8;
0044     ppData[8 * SRP_index + 3] |= 0x80;
0045     ppData[8 * SRP_index + 4] = lv1 & 0xFF;
0046     ppData[8 * SRP_index + 5] = (lv1 & 0xF00) >> 8;
0047     // ppData[8*SRP_index+6] = Number_SRP_Flags;
0048     ppData[8 * SRP_index + 6] = 0;
0049     ppData[8 * SRP_index + 7] = 0x80;
0050     SRP_index++;
0051     if (debug_)
0052       cout << "Added headers and empty lines : " << endl;
0053     if (debug_)
0054       print(rawdata);
0055 
0056     // -- put the B011 and B100 already, since for Endcap there can be empty
0057     // -- lines in the TCC and the SRP blocks
0058     unsigned char* Data = rawdata.data();
0059     for (int iline = SRP_index; iline < SRP_index + Nrows_SRP; iline++) {
0060       Data[8 * iline + 7] |= 0x80;
0061       Data[8 * iline + 3] |= 0x80;
0062     }
0063   }
0064 
0065   unsigned char* pData = rawdata.data();
0066 
0067   // -- Now the TCC Block :
0068 
0069   int nflags = pData[8 * (SRP_index - 1) + 6] & 0x7F;
0070   nflags++;
0071   pData[8 * (SRP_index - 1) + 6] = nflags & 0x7F;
0072 
0073   int jTT = (dcc_channel - 1);
0074   int irow = jTT / 16;
0075   int ival = jTT % 4;
0076   int kval = (jTT % 16) / 4;
0077   SRP_index += irow;
0078 
0079   if (debug_)
0080     cout << "Now add SC to SRBlock " << dec << dcc_channel << " irow ival " << dec << irow << " " << dec << ival
0081          << endl;
0082   if (debug_)
0083     cout << "new data will be added at line " << dec << SRP_index << endl;
0084 
0085   unsigned char* buff = &pData[8 * SRP_index];
0086   Word64* pw = reinterpret_cast<Word64*>(const_cast<unsigned char*>(buff));
0087   int nbits = kval * 16 + 3 * ival;
0088   Word64 wflag = (Word64)((short int)flag & 0x7) << nbits;
0089   *pw |= wflag;
0090   Word64 b1 = (Word64)((Word64)0x80 << 56);
0091   *pw |= b1;
0092   Word64 b2 = (Word64)((Word64)0x80 << 24);
0093   *pw |= b2;
0094 
0095   if (debug_)
0096     print(rawdata);
0097 }