Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:32

0001 #include <memory>
0002 
0003 // user include files
0004 
0005 #include "EventFilter/EcalDigiToRaw/interface/BlockFormatter.h"
0006 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0007 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
0008 
0009 using namespace std;
0010 
0011 BlockFormatter::BlockFormatter(Config const& iC, Params const& iP)
0012     : plistDCCId_{iC.plistDCCId_},
0013       counter_{iP.counter_},
0014       orbit_number_{iP.orbit_number_},
0015       bx_{iP.bx_},
0016       lv1_{iP.lv1_},
0017       runnumber_{iP.runnumber_},
0018       debug_{iC.debug_},
0019       doBarrel_{iC.doBarrel_},
0020       doEndCap_{iC.doEndCap_},
0021       doTCC_{iC.doTCC_},
0022       doSR_{iC.doSR_},
0023       doTower_{iC.doTower_} {}
0024 
0025 void BlockFormatter::DigiToRaw(FEDRawDataCollection* productRawData) {
0026   int run_number = runnumber_;
0027   int bx = bx_;
0028   int lv1 = lv1_;
0029 
0030   if (debug_)
0031     cout << "in BlockFormatter::DigiToRaw  run_number orbit_number bx lv1 " << dec << run_number << " " << orbit_number_
0032          << " " << bx << " " << lv1 << endl;
0033 
0034   for (int idcc = 1; idcc <= 54; idcc++) {
0035     if ((!doBarrel_) && (idcc >= EcalElectronicsId::MIN_DCCID_EBM && idcc <= EcalElectronicsId::MAX_DCCID_EBP))
0036       continue;
0037     if ((!doEndCap_) && (idcc <= EcalElectronicsId::MAX_DCCID_EEM || idcc >= EcalElectronicsId::MIN_DCCID_EEP))
0038       continue;
0039 
0040     int FEDid = FEDNumbering::MINECALFEDID + idcc;
0041     FEDRawData& rawdata = productRawData->FEDData(FEDid);
0042     unsigned char* pData;
0043     short int DCC_ERRORS = 0;
0044 
0045     if (rawdata.size() == 0) {
0046       rawdata.resize(8);
0047       pData = rawdata.data();
0048 
0049       Word64 word = 0x18 + ((FEDid & 0xFFF) << 8) + ((Word64)((Word64)bx & 0xFFF) << 20) +
0050                     ((Word64)((Word64)lv1 & 0xFFFFFF) << 32) + (Word64)((Word64)0x51 << 56);
0051       Word64* pw = reinterpret_cast<Word64*>(const_cast<unsigned char*>(pData));
0052       *pw = word;  // DAQ header
0053 
0054       rawdata.resize(rawdata.size() + 8 * 8);  // DCC header
0055       pData = rawdata.data();
0056       pData[11] = DCC_ERRORS & 0xFF;
0057       pData[12] = run_number & 0xFF;
0058       pData[13] = (run_number >> 8) & 0xFF;
0059       pData[14] = (run_number >> 16) & 0xFF;
0060       pData[15] = 0x01;
0061 
0062       for (int i = 16; i <= 22; i++) {
0063         pData[i] = 0;  // to be filled for local data taking or calibration
0064       }
0065       pData[23] = 0x02;
0066       pData[24] = orbit_number_ & 0xFF;
0067       pData[25] = (orbit_number_ >> 8) & 0xFF;
0068       pData[26] = (orbit_number_ >> 16) & 0xFF;
0069       pData[27] = (orbit_number_ >> 24) & 0xFF;
0070       int SRenable_ = 1;
0071       int SR = SRenable_;
0072       int ZS = 0;
0073       int TZS = 0;
0074       // int SR_CHSTATUS = 0;
0075       pData[28] = (SR & 0x1) + ((ZS & 0x1) << 1) + ((TZS & 0x1) << 2);
0076       pData[31] = 0x03;
0077 
0078       for (int i = 0; i <= 4; i++) {
0079         for (int j = 0; j < 7; j++) {
0080           pData[32 + 8 * i + j] = 0;
0081         }
0082         pData[32 + 8 * i + 7] = 0x04;
0083       }
0084 
0085     }  // endif rawdatasize == 0
0086   }    // loop on id
0087 }
0088 
0089 void BlockFormatter::print(FEDRawData& rawdata) {
0090   int size = rawdata.size();
0091   cout << "Print RawData  size " << dec << size << endl;
0092   unsigned char* pData = rawdata.data();
0093 
0094   int n = size / 8;
0095   for (int i = 0; i < n; i++) {
0096     for (int j = 7; j >= 0; j--) {
0097       if (8 * i + j <= size)
0098         cout << hex << (int)pData[8 * i + j] << " ";
0099     }
0100     cout << endl;
0101   }
0102 }
0103 
0104 void BlockFormatter::CleanUp(FEDRawDataCollection* productRawData, map<int, map<int, int> >* FEDorder) {
0105   for (int id = 0; id < 36 + 18; id++) {
0106     if ((!doBarrel_) && (id >= 9 && id <= 44))
0107       continue;
0108     if ((!doEndCap_) && (id <= 8 || id >= 45))
0109       continue;
0110 
0111     int FEDid = FEDNumbering::MINECALFEDID + id + 1;
0112     FEDRawData& rawdata = productRawData->FEDData(FEDid);
0113 
0114     // ---- if raw need not be made for a given fed, set its size to empty and return
0115     if (find((*plistDCCId_).begin(), (*plistDCCId_).end(), (id + 1)) == (*plistDCCId_).end()) {
0116       rawdata.resize(0);
0117       continue;
0118     }
0119 
0120     // ---- Add the trailer word
0121     int lastline = rawdata.size();
0122     rawdata.resize(lastline + 8);
0123     unsigned char* pData = rawdata.data();
0124     int event_length = (lastline + 8) / 8;  // in 64 bits words
0125 
0126     pData[lastline + 7] = 0xa0;
0127     // pData[lastline+4] = event_length & 0xFFFFFF;
0128     pData[lastline + 4] = event_length & 0xFF;
0129     pData[lastline + 5] = (event_length >> 8) & 0xFF;
0130     pData[lastline + 6] = (event_length >> 16) & 0xFF;
0131     int event_status = 0;
0132     pData[lastline + 1] = event_status & 0x0F;
0133     int tts = 0 << 4;
0134     pData[lastline] = tts & 0xF0;
0135 
0136     // ---- Write the event length in the DCC header
0137     // pData[8] = event_length & 0xFFFFFF;
0138     pData[8] = event_length & 0xFF;
0139     pData[9] = (event_length >> 8) & 0xFF;
0140     pData[10] = (event_length >> 16) & 0xFF;
0141 
0142     // cout << " in BlockFormatter::CleanUp. FEDid = " << FEDid << " event_length*8 " << dec << event_length*8 << endl;
0143 
0144     map<int, map<int, int> >::iterator fen = FEDorder->find(FEDid);
0145 
0146     bool FED_has_data = true;
0147     if (fen == FEDorder->end())
0148       FED_has_data = false;
0149     if (debug_ && (!FED_has_data))
0150       cout << " FEDid is not in FEDorder ! " << endl;
0151     if (!FED_has_data) {
0152       int ch_status = 7;
0153       for (int iFE = 1; iFE <= 68; iFE++) {
0154         int irow = (iFE - 1) / 14;
0155         int kval = ((iFE - 1) % 14) / 2;
0156         if (iFE % 2 == 1)
0157           pData[32 + 8 * irow + kval] |= ch_status & 0xFF;
0158         else
0159           pData[32 + 8 * irow + kval] |= ((ch_status << 4) & 0xFF);
0160       }
0161     }
0162 
0163     if (FED_has_data) {
0164       map<int, int>& FEorder = (*fen).second;
0165 
0166       for (int iFE = 1; iFE <= 68; iFE++) {
0167         map<int, int>::iterator fe = FEorder.find(iFE);
0168         int ch_status = 0;
0169         if (fe == FEorder.end())  // FE not present due to SRP, update CH_status
0170           ch_status = 7;          // CH_SUPPRESS
0171         int irow = (iFE - 1) / 14;
0172         int kval = ((iFE - 1) % 14) / 2;
0173         if (iFE % 2 == 1)
0174           pData[32 + 8 * irow + kval] |= ch_status & 0xFF;
0175         else
0176           pData[32 + 8 * irow + kval] |= ((ch_status << 4) & 0xFF);
0177       }
0178     }
0179   }
0180 }
0181 
0182 void BlockFormatter::PrintSizes(FEDRawDataCollection* productRawData) {
0183   for (int id = 0; id < 36 + 18; id++) {
0184     // if ( (! doBarrel_) && (id >= 9 && id <= 44)) continue;
0185     // if ( (! doEndCap_) && (id <= 8 || id >= 45)) continue;
0186 
0187     int FEDid = FEDNumbering::MINECALFEDID + id;
0188     FEDRawData& rawdata = productRawData->FEDData(FEDid);
0189     if (rawdata.size() > 0)
0190       cout << "Size of FED id " << dec << FEDid << " is : " << dec << rawdata.size() << endl;
0191   }
0192 }