Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <EventFilter/DTRawToDigi/plugins/DTDigiToRaw.h>
0002 #include <DataFormats/DTDigi/interface/DTDDUWords.h>
0003 
0004 #include <cmath>
0005 #include <iostream>
0006 
0007 using namespace edm;
0008 using namespace std;
0009 
0010 DTDigiToRaw::DTDigiToRaw(const edm::ParameterSet& ps) : pset(ps) {
0011   debug = pset.getUntrackedParameter<bool>("debugMode", false);
0012   if (debug)
0013     cout << "[DTDigiToRaw]: constructor" << endl;
0014 }
0015 
0016 DTDigiToRaw::~DTDigiToRaw() {
0017   if (debug)
0018     cout << "[DTDigiToRaw]: destructor" << endl;
0019 }
0020 
0021 FEDRawData* DTDigiToRaw::createFedBuffers(const DTDigiCollection& digis, edm::ESHandle<DTReadOutMapping>& map) {
0022   int NROS = 12;
0023   int NROB = 25;
0024 
0025   vector<uint32_t> words;
0026 
0027   uint32_t fakeROSHeaderWord = DTROSWordType::headerControlWord << WORDCONTROLSHIFT | DTROSWordType::rosTypeWord
0028                                                                                           << WORDTYPESHIFT;
0029 
0030   uint32_t fakeROSTrailerWord = DTROSWordType::trailerControlWord << WORDCONTROLSHIFT | DTROSWordType::rosTypeWord
0031                                                                                             << WORDTYPESHIFT;
0032 
0033   int NWords = 2;
0034   words.push_back(0);
0035   words.push_back(0);
0036 
0037   int NTDCMeaWords = 0;
0038 
0039   int NLayers = 0;
0040   int NDigis = 0;
0041 
0042   DTDigiCollection::DigiRangeIterator detUnitIt;
0043   detUnitIt = digis.begin();
0044 
0045   bool b_ros[12] = {false, false, false, false, false, false, false, false, false, false, false, false};
0046   vector<uint32_t> w_ROBROS[12][25];
0047 
0048   for (detUnitIt = digis.begin(); detUnitIt != digis.end(); ++detUnitIt) {
0049     NLayers++;
0050 
0051     const DTLayerId layerId = (*detUnitIt).first;
0052     const DTDigiCollection::Range& digiRange = (*detUnitIt).second;
0053     // Loop over all digis in the given range
0054 
0055     for (DTDigiCollection::const_iterator digi = digiRange.first; digi != digiRange.second; digi++) {
0056       NDigis++;
0057       int dduId = -1, rosId = -1, robId = -1, tdcId = -1, channelId = -1;
0058 
0059       int layer = layerId.layer();
0060       DTSuperLayerId superlayerID = layerId.superlayerId();
0061       int superlayer = superlayerID.superlayer();
0062       DTChamberId chamberID = superlayerID.chamberId();
0063       int station = chamberID.station();
0064       int wheel = chamberID.wheel();
0065       int sector = chamberID.sector();
0066 
0067       int searchstatus = map->geometryToReadOut(wheel,
0068                                                 station,
0069                                                 sector,
0070                                                 superlayer,
0071                                                 layer,
0072                                                 (*digi).wire(),  //"input"
0073                                                 dduId,
0074                                                 rosId,
0075                                                 robId,
0076                                                 tdcId,
0077                                                 channelId);  //"output"
0078 
0079       if (searchstatus == 1 && debug)
0080         cout << "[DTDigiToRaw]: warning, geometryToReadOut status = 1" << endl;
0081 
0082       //create FED corresponding to current ddu
0083       if (dduID_ != dduId)
0084         continue;
0085 
0086       DTTDCMeasurementWord dttdc_mw;
0087       uint32_t word;
0088       int ntdc = (*digi).countsTDC();
0089       dttdc_mw.set(word, 0, 0, 0, tdcId, channelId, ntdc * 4);  //FIXME
0090 
0091       //provisional fix
0092       DTTDCMeasurementWord tdcMeasurementWord(word);
0093       int tdcIDCheck = tdcMeasurementWord.tdcID();
0094       int tdcChannelCheck = tdcMeasurementWord.tdcChannel();
0095       int tdcCountsCheck = tdcMeasurementWord.tdcTime();
0096       if (tdcIDCheck == tdcId && channelId == tdcChannelCheck && ntdc == tdcCountsCheck) {
0097         if (rosId <= NROS && rosId > 0)
0098           b_ros[rosId - 1] = true;
0099         else if (debug) {
0100           cout << "[DTDigiToRaw]: invalid value for rosId" << endl;
0101         }
0102 
0103         NTDCMeaWords++;
0104         w_ROBROS[rosId - 1][robId].push_back(word);
0105       }
0106     }
0107   }
0108 
0109   uint32_t therosList = 0;
0110   for (int i_ros = 0; i_ros < NROS; i_ros++) {
0111     if (b_ros[i_ros])
0112       therosList += uint32_t(pow(2.0, i_ros));
0113   }
0114 
0115   if (debug)
0116     cout << "[DTDigiToRaw]: therosList = " << therosList << endl;
0117 
0118   for (int i_ros = 0; i_ros < NROS; i_ros++) {
0119     if (b_ros[i_ros]) {
0120       words.push_back(fakeROSHeaderWord);
0121       NWords++;
0122     }
0123 
0124     for (int i_rob = 0; i_rob < NROB; i_rob++) {
0125       vector<uint32_t>::const_iterator i_robros;
0126       if (w_ROBROS[i_ros][i_rob].begin() != w_ROBROS[i_ros][i_rob].end()) {
0127         uint32_t word = 0;
0128         DTROBHeaderWord rob_header;
0129         rob_header.set(word, i_rob, 0, 0);
0130         //static void set(uint32_t &word, int rob_id, int event_id, int bunch_id)
0131         words.push_back(word);
0132         NWords++;
0133 
0134         int n_robros = 0;
0135         for (i_robros = w_ROBROS[i_ros][i_rob].begin(); i_robros != w_ROBROS[i_ros][i_rob].end(); i_robros++) {
0136           NWords++;
0137           words.push_back((*i_robros));
0138           n_robros++;
0139         }
0140 
0141         NWords++;
0142         DTROBTrailerWord rob_trailer;
0143         rob_trailer.set(word, i_rob, 0, n_robros + 2);
0144         //static void set(uint32_t &word, int rob_id, int event_id, int word_count)
0145         words.push_back(word);
0146       }
0147     }
0148 
0149     if (b_ros[i_ros]) {
0150       words.push_back(fakeROSTrailerWord);
0151       NWords++;
0152     }
0153   }
0154 
0155   if (NWords % 2 == 1) {
0156     words.push_back(0);
0157     NWords++;
0158   }
0159 
0160   words.push_back(0);
0161   words.push_back(0);
0162   //include rosList in raw data information
0163   uint32_t secondstatusword = therosList << 16;
0164   words.push_back(secondstatusword);
0165 
0166   words.push_back(0);
0167   words.push_back(0);
0168   words.push_back(0);
0169 
0170   // Write Raw Data
0171   int dataSize = words.size() * sizeof(Word32);
0172   FEDRawData* rawData = new FEDRawData(dataSize);
0173   Word64* word64 = reinterpret_cast<Word64*>(rawData->data());
0174   for (unsigned int i = 0; i < words.size(); i += 2) {
0175     *word64 = (Word64(words[i]) << 32) | words[i + 1];
0176     word64++;
0177   }
0178 
0179   return rawData;
0180 }
0181 
0182 void DTDigiToRaw::SetdduID(int x) { dduID_ = x; }