CMS 3D CMS Logo

BlockFormatter.cc

Go to the documentation of this file.
00001 #include <memory>
00002 
00003 // user include files
00004 
00005 
00006 #include "EventFilter/EcalDigiToRaw/interface/EcalDigiToRaw.h"
00007 #include "EventFilter/EcalDigiToRaw/interface/BlockFormatter.h"
00008 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00009 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
00010 
00011 
00012 using namespace std;
00013 
00014 BlockFormatter::BlockFormatter() {
00015 
00016   EcalFEDIds=FEDNumbering::getEcalFEDIds();
00017 }
00018 
00019 BlockFormatter::~BlockFormatter() {
00020 }
00021 
00022 
00023 void BlockFormatter::SetParam(EcalDigiToRaw* base) {
00024 
00025  pcounter_ = (base -> GetCounter());
00026  debug_   = base -> GetDebug();
00027  porbit_number_ = (base -> GetOrbit());
00028  plv1_ = (base -> GetLV1());
00029  pbx_  = (base -> GetBX());
00030  prunnumber_ = (base -> GetRunNumber());
00031  doBarrel_ = base -> GetDoBarrel();
00032  doEndCap_ = base -> GetDoEndCap();
00033  plistDCCId_ = base -> GetListDCCId();
00034  doTCC_ = base -> GetDoTCC();
00035  doSR_ = base -> GetDoSR();
00036  doTower_ = base -> GetDoTower();
00037 
00038 }
00039 
00040 
00041 void BlockFormatter::DigiToRaw(FEDRawDataCollection* productRawData) {
00042 
00043  int run_number = *prunnumber_;
00044  int orbit_number_ = *porbit_number_;
00045  int bx = *pbx_;
00046  int lv1 = *plv1_;
00047 
00048  if (debug_) cout << "in BlockFormatter::DigiToRaw  run_number orbit_number bx lv1 " << dec << run_number << " " <<
00049          orbit_number_ << " " << bx << " " << lv1 << endl;
00050 
00051  for (int idcc=1; idcc <= 54; idcc++) {
00052         if ( (! doBarrel_) && 
00053              (idcc >= EcalElectronicsId::MIN_DCCID_EBM && idcc <= EcalElectronicsId::MAX_DCCID_EBP)) continue;
00054         if ( (! doEndCap_) && 
00055              (idcc <= EcalElectronicsId::MAX_DCCID_EEM || idcc >= EcalElectronicsId::MIN_DCCID_EEP)) continue;
00056  
00057         int FEDid = EcalFEDIds.first + idcc;
00058         FEDRawData& rawdata = productRawData -> FEDData(FEDid);
00059         unsigned char * pData;
00060         short int DCC_ERRORS = 0;
00061 
00062         if (rawdata.size() == 0) {
00063                 rawdata.resize(8);
00064                 pData = rawdata.data();
00065 
00066                 Word64 word = 0x18 + ((FEDid & 0xFFF)<<8)
00067                             + ((Word64)((Word64)bx & 0xFFF)<<20)
00068                             + ((Word64)((Word64)lv1 & 0xFFFFFF)<<32)
00069                             + (Word64)((Word64)0x51<<56);
00070                 Word64* pw = reinterpret_cast<Word64*>(const_cast<unsigned char*>(pData));
00071                 *pw = word;    // DAQ header
00072 
00073                 rawdata.resize(rawdata.size() + 8*8);   // DCC header
00074                 pData = rawdata.data();
00075                 pData[11] = DCC_ERRORS & 0xFF;
00076                 pData[12] = run_number & 0xFF;
00077                 pData[13] = (run_number >>8) & 0xFF;
00078                 pData[14] = (run_number >> 16) & 0xFF;
00079                 pData[15] = 0x01;
00080 
00081                 for (int i=16; i <= 22; i++) {
00082                  pData[i] = 0;    // to be filled for local data taking or calibration
00083                 }
00084                 pData[23] = 0x02;
00085                 pData[24] = orbit_number_ & 0xFF;
00086                 pData[25] = (orbit_number_ >>8) & 0xFF;
00087                 pData[26] = (orbit_number_ >>16) & 0xFF;
00088                 pData[27] = (orbit_number_ >>24) & 0xFF;
00089                 int SRenable_ = 1;
00090                 int SR = SRenable_;
00091                 int ZS = 0;
00092                 int TZS = 0;
00093                 // int SR_CHSTATUS = 0;
00094                 pData[28] = (SR&0x1) + ((ZS&0x1)<<1) + ((TZS&0x1)<<2);
00095                 pData[31] = 0x03;
00096 
00097                 for (int i=0; i<=4; i++) {
00098                   for (int j=0; j<7; j++) {
00099                    pData[32 +8*i + j] = 0;
00100                   }
00101                   pData[32 +8*i + 7] = 0x04;
00102                 }
00103 
00104         } // endif rawdatasize == 0
00105  } // loop on id
00106 
00107 }
00108 
00109 
00110 
00111 void BlockFormatter::print(FEDRawData& rawdata) {
00112         int size = rawdata.size();
00113         cout << "Print RawData  size " << dec << size << endl;
00114         unsigned char* pData = rawdata.data();
00115 
00116         int n = size/8;
00117         for (int i=0; i < n; i++) {
00118                 for (int j=7; j>=0; j--) {
00119                   if (8*i+j <= size) cout << hex << (int)pData[8*i+j] << " ";
00120                 }
00121                 cout << endl;
00122         }
00123 }
00124 
00125 
00126 
00127 void BlockFormatter::CleanUp(FEDRawDataCollection* productRawData,
00128                                 map<int, map<int,int> >* FEDorder ) {
00129 
00130 
00131  for (int id=0; id < 36 + 18; id++) {
00132         if ( (! doBarrel_) && (id >= 9 && id <= 44)) continue;
00133         if ( (! doEndCap_) && (id <= 8 || id >= 45)) continue;
00134 
00135         int FEDid = EcalFEDIds.first + id +1;
00136         FEDRawData& rawdata = productRawData -> FEDData(FEDid);
00137 
00138         // ---- if raw need not be made for a given fed, set its size to empty and return 
00139         if ( find( (*plistDCCId_).begin(), (*plistDCCId_).end(), (id+1) ) == (*plistDCCId_).end() )
00140         {
00141             rawdata.resize( 0 );
00142             continue;
00143         }
00144 
00145         // ---- Add the trailer word
00146         int lastline = rawdata.size();
00147         rawdata.resize( lastline + 8);
00148         unsigned char * pData = rawdata.data(); 
00149         int event_length = (lastline + 8) / 8;   // in 64 bits words
00150 
00151         pData[lastline+7] = 0xa0;
00152         // pData[lastline+4] = event_length & 0xFFFFFF;
00153         pData[lastline+4] = event_length & 0xFF;
00154         pData[lastline+5] = (event_length >> 8) & 0xFF;
00155         pData[lastline+6] = (event_length >> 16) & 0xFF;
00156         int event_status = 0;
00157         pData[lastline+1] = event_status & 0x0F;
00158         int tts = 0 <<4;
00159         pData[lastline] = tts & 0xF0;
00160 
00161         // ---- Write the event length in the DCC header
00162         // pData[8] = event_length & 0xFFFFFF;
00163         pData[8] = event_length & 0xFF;
00164         pData[9] = (event_length >> 8) & 0xFF;
00165         pData[10] = (event_length >> 16) & 0xFF;
00166         
00167         // cout << " in BlockFormatter::CleanUp. FEDid = " << FEDid << " event_length*8 " << dec << event_length*8 << endl;
00168 
00169         map<int, map<int,int> >::iterator fen = FEDorder -> find(FEDid);
00170 
00171         bool FED_has_data = true;
00172         if (fen == FEDorder->end()) FED_has_data = false;
00173         if (debug_ && (! FED_has_data)) cout << " FEDid is not in FEDorder ! " << endl;
00174         if ( ! FED_has_data) {
00175                 int ch_status = 7;
00176                 for (int iFE=1; iFE <= 68; iFE++) {
00177                         int irow = (iFE-1) / 14;
00178                         int kval = ( (iFE-1) % 14) / 2;
00179                         if (iFE % 2 ==1) pData[32 + 8*irow + kval] |= ch_status & 0xFF;
00180                         else pData[32 + 8*irow + kval] |= ((ch_status <<4) & 0xFF);
00181                 }
00182         }
00183 
00184         if (FED_has_data) {
00185         map<int, int>& FEorder = (*fen).second;
00186 
00187         for (int iFE=1; iFE <= 68; iFE++) {
00188           map<int,int>::iterator fe = FEorder.find(iFE);
00189           int ch_status = 0;
00190           if (fe == FEorder.end())      // FE not present due to SRP, update CH_status
00191                 ch_status = 7;          // CH_SUPPRESS
00192           int irow = (iFE-1) / 14;
00193           int kval = ( (iFE-1) % 14) / 2;
00194           if (iFE % 2 ==1) pData[32 + 8*irow + kval] |= ch_status & 0xFF;
00195           else pData[32 + 8*irow + kval] |= ((ch_status <<4) & 0xFF);
00196 
00197         }
00198         }
00199         
00200  }
00201 }
00202 
00203 
00204 void BlockFormatter::PrintSizes(FEDRawDataCollection* productRawData) {
00205 
00206 
00207  for (int id=0; id < 36 + 18; id++) {
00208 
00209         // if ( (! doBarrel_) && (id >= 9 && id <= 44)) continue;
00210         // if ( (! doEndCap_) && (id <= 8 || id >= 45)) continue;
00211 
00212 
00213         int FEDid = EcalFEDIds.first + id;
00214         FEDRawData& rawdata = productRawData -> FEDData(FEDid);
00215         if (rawdata.size() > 0)
00216         cout << "Size of FED id " << dec << FEDid << " is : " << dec << rawdata.size() << endl;
00217 
00218  }
00219 }
00220 
00221 

Generated on Tue Jun 9 17:34:30 2009 for CMSSW by  doxygen 1.5.4