File indexing completed on 2024-04-06 12:10:31
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 DTDigiCollection::DigiRangeIterator detUnitIt;
0038 detUnitIt = digis.begin();
0039
0040 bool b_ros[12] = {false, false, false, false, false, false, false, false, false, false, false, false};
0041 vector<uint32_t> w_ROBROS[12][25];
0042
0043 for (detUnitIt = digis.begin(); detUnitIt != digis.end(); ++detUnitIt) {
0044 const DTLayerId layerId = (*detUnitIt).first;
0045 const DTDigiCollection::Range& digiRange = (*detUnitIt).second;
0046
0047
0048 for (DTDigiCollection::const_iterator digi = digiRange.first; digi != digiRange.second; digi++) {
0049 int dduId = -1, rosId = -1, robId = -1, tdcId = -1, channelId = -1;
0050
0051 int layer = layerId.layer();
0052 DTSuperLayerId superlayerID = layerId.superlayerId();
0053 int superlayer = superlayerID.superlayer();
0054 DTChamberId chamberID = superlayerID.chamberId();
0055 int station = chamberID.station();
0056 int wheel = chamberID.wheel();
0057 int sector = chamberID.sector();
0058
0059 int searchstatus = map->geometryToReadOut(wheel,
0060 station,
0061 sector,
0062 superlayer,
0063 layer,
0064 (*digi).wire(),
0065 dduId,
0066 rosId,
0067 robId,
0068 tdcId,
0069 channelId);
0070
0071 if (searchstatus == 1 && debug)
0072 cout << "[DTDigiToRaw]: warning, geometryToReadOut status = 1" << endl;
0073
0074
0075 if (dduID_ != dduId)
0076 continue;
0077
0078 DTTDCMeasurementWord dttdc_mw;
0079 uint32_t word;
0080 int ntdc = (*digi).countsTDC();
0081 dttdc_mw.set(word, 0, 0, 0, tdcId, channelId, ntdc * 4);
0082
0083
0084 DTTDCMeasurementWord tdcMeasurementWord(word);
0085 int tdcIDCheck = tdcMeasurementWord.tdcID();
0086 int tdcChannelCheck = tdcMeasurementWord.tdcChannel();
0087 int tdcCountsCheck = tdcMeasurementWord.tdcTime();
0088 if (tdcIDCheck == tdcId && channelId == tdcChannelCheck && ntdc == tdcCountsCheck) {
0089 if (rosId <= NROS && rosId > 0)
0090 b_ros[rosId - 1] = true;
0091 else if (debug) {
0092 cout << "[DTDigiToRaw]: invalid value for rosId" << endl;
0093 }
0094
0095 w_ROBROS[rosId - 1][robId].push_back(word);
0096 }
0097 }
0098 }
0099
0100 uint32_t therosList = 0;
0101 for (int i_ros = 0; i_ros < NROS; i_ros++) {
0102 if (b_ros[i_ros])
0103 therosList += uint32_t(pow(2.0, i_ros));
0104 }
0105
0106 if (debug)
0107 cout << "[DTDigiToRaw]: therosList = " << therosList << endl;
0108
0109 for (int i_ros = 0; i_ros < NROS; i_ros++) {
0110 if (b_ros[i_ros]) {
0111 words.push_back(fakeROSHeaderWord);
0112 NWords++;
0113 }
0114
0115 for (int i_rob = 0; i_rob < NROB; i_rob++) {
0116 vector<uint32_t>::const_iterator i_robros;
0117 if (w_ROBROS[i_ros][i_rob].begin() != w_ROBROS[i_ros][i_rob].end()) {
0118 uint32_t word = 0;
0119 DTROBHeaderWord rob_header;
0120 rob_header.set(word, i_rob, 0, 0);
0121
0122 words.push_back(word);
0123 NWords++;
0124
0125 int n_robros = 0;
0126 for (i_robros = w_ROBROS[i_ros][i_rob].begin(); i_robros != w_ROBROS[i_ros][i_rob].end(); i_robros++) {
0127 NWords++;
0128 words.push_back((*i_robros));
0129 n_robros++;
0130 }
0131
0132 NWords++;
0133 DTROBTrailerWord rob_trailer;
0134 rob_trailer.set(word, i_rob, 0, n_robros + 2);
0135
0136 words.push_back(word);
0137 }
0138 }
0139
0140 if (b_ros[i_ros]) {
0141 words.push_back(fakeROSTrailerWord);
0142 NWords++;
0143 }
0144 }
0145
0146 if (NWords % 2 == 1) {
0147 words.push_back(0);
0148 NWords++;
0149 }
0150
0151 words.push_back(0);
0152 words.push_back(0);
0153
0154 uint32_t secondstatusword = therosList << 16;
0155 words.push_back(secondstatusword);
0156
0157 words.push_back(0);
0158 words.push_back(0);
0159 words.push_back(0);
0160
0161
0162 int dataSize = words.size() * sizeof(Word32);
0163 FEDRawData* rawData = new FEDRawData(dataSize);
0164 Word64* word64 = reinterpret_cast<Word64*>(rawData->data());
0165 for (unsigned int i = 0; i < words.size(); i += 2) {
0166 *word64 = (Word64(words[i]) << 32) | words[i + 1];
0167 word64++;
0168 }
0169
0170 return rawData;
0171 }
0172
0173 void DTDigiToRaw::SetdduID(int x) { dduID_ = x; }