30 produces<DTDigiCollection>();
31 produces<std::vector<DTuROSFEDData>>();
35 debug_ =
pset.getUntrackedParameter<
bool>(
"debug",
false);
49 std::vector<DTuROSFEDData> words;
54 auto uROSDTDigi_product = std::make_unique<DTDigiCollection>(digis);
55 auto uROSDTWord_product = std::make_unique<std::vector<DTuROSFEDData>>(words);
64 std::vector<DTuROSFEDData>& words) {
71 for (
int w_i = 0; w_i <
nfeds_; ++w_i) {
75 words.push_back(fwords);
87 std::vector<long> DTuROSWordContainer;
90 int BOEevTy, DTuROSId;
93 int chkEOE, evtLgth,
CRC;
96 std::map<uint32_t, int> hitOrder;
101 if (dturosdata.
size() == 0)
108 const int posBOEevTy = 60;
109 const int posDTuROSId = 8;
110 const int posNslost = 52;
111 const int posSlotFED = 16;
113 BOEevTy = (dataWord >> posBOEevTy) & 0xF;
114 DTuROSId = (dataWord >> posDTuROSId) & 0xFFF;
116 if ((BOEevTy != 0x5) || (DTuROSId != DTuROSFED)) {
118 edm::LogWarning(
"dturos_unpacker") <<
"Not a DTuROS FED " << DTuROSFED <<
" or header " << std::hex << dataWord;
128 int crate = DTuROSId;
135 int nslots = (dataWord >> posNslost) & 0xF;
141 std::map<int, int> slot_size;
142 for (
int j = 0;
j < nslots; ++
j) {
146 int slot = (dataWord >> posSlotFED) & 0xF;
148 if ((slot < 1) || (slot > 12)) {
154 slot_size[slot] = (dataWord >> 32) & 0xFFFFFF;
161 std::map<int, int>::iterator sziterator = slot_size.begin();
162 std::map<int, int>::iterator szitend = slot_size.end();
163 for (; sziterator != szitend; ++sziterator) {
164 for (
int k = 0;
k < sziterator->second; ++
k) {
168 DTuROSWordContainer.push_back(dataWord);
181 const int posEOE = 60;
182 const int posEvtLenght = 32;
183 const int posCRC = 16;
184 chkEOE = (dataWord >> posEOE) & 0xF;
188 edm::LogWarning(
"dturos_unpacker") <<
"Trailer " << std::hex << dataWord <<
" does not start with 0xA";
192 evtLgth = (dataWord >> posEvtLenght) & 0xFFFFFF;
193 CRC = (dataWord >> posCRC) & 0xFFFF;
199 edm::LogWarning(
"dturos_unpacker") <<
"Calculated CRC " << std::hex << newCRC <<
" differs from CRC in trailer "
204 if (
lines != evtLgth) {
216 std::vector<long>::iterator DTuROSiterator = DTuROSWordContainer.begin();
217 std::vector<long>::iterator DTuROSitend = DTuROSWordContainer.end();
219 const int posSlot = 56;
221 for (; DTuROSiterator != DTuROSitend; ++DTuROSiterator) {
224 dataWord = (*DTuROSiterator);
226 int slot = (dataWord >> posSlot) & 0xF;
228 if ((slot < 1) || (slot > 12)) {
230 edm::LogWarning(
"dturos_unpacker") <<
"Slot " <<
std::dec << slot <<
" out of range (1-12) in crate " << crate;
238 dataWord = (*DTuROSiterator);
241 int slotMap = dataWord & 0xF;
244 const int posSel1 = 60;
245 const int posSel2 = 28;
246 const int posTDCTime = 32;
247 const int posTDCChannel = 46;
248 const int posTDCId = 51;
249 const int posLink = 53;
250 const int posTDCChannelSel2Null = 14;
251 const int posTDCIdSel2Null = 19;
252 const int posLinkSel2Null = 21;
253 const int posErrorSel3 = 32;
255 for (
int k = 2;
k < slot_size[slot] - 1; ++
k) {
257 dataWord = (*DTuROSiterator);
258 int selector = (dataWord >> posSel1) & 0xF;
259 int selector2 = (dataWord >> posSel2) & 0
x1;
269 }
else if (selector >= 8 && selector <= 13) {
273 }
else if (selector == 15) {
280 int tdcTime = (dataWord >> posTDCTime) & 0x3FFF;
281 int tdcChannel = (dataWord >> posTDCChannel) & 0x1F;
282 int tdcId = (dataWord >> posTDCId) & 0x3;
283 int link = (dataWord >> posLink) & 0x7F;
287 bool tenDDU = !
mapping->readOutToGeometry(779, 7, 1, 1, 1,
dummy,
dummy,
dummy,
dummy,
dummy,
dummy);
289 int dduId =
theDDU(crate, slotMap,
link, tenDDU);
294 if (hitOrder.find(channelIndex.
getCode()) == hitOrder.end())
295 hitOrder[channelIndex.
getCode()] = 0;
297 hitOrder[channelIndex.
getCode()]++;
299 int wheelId, stationId, sectorId, slId, layerId, cellId;
300 if (!
mapping->readOutToGeometry(
301 dduId, rosId, robId, tdcId, tdcChannel, wheelId, stationId, sectorId, slId, layerId, cellId)) {
302 DTWireId detId =
DTWireId(wheelId, stationId, sectorId, slId, layerId, cellId);
303 int wire = detId.
wire();
305 DTDigi digi(wire, tdcTime, hitOrder[channelIndex.
getCode()]);
306 digis.insertDigi(detId.
layerId(), digi);
309 }
else if (selector == 3) {
313 <<
std::dec <<
" in slot " << slot <<
" in crate " << crate;
315 int error = (dataWord >> posErrorSel3) & 0x1FFFFFFF;
319 if ((dataWord & 0x1FFFFFFF) == 0x1FFFFFFF)
322 if (selector2 == 0) {
324 int tdcTime = (dataWord)&0x3FFF;
325 int tdcChannel = (dataWord >> posTDCChannelSel2Null) & 0x1F;
326 int tdcId = (dataWord >> posTDCIdSel2Null) & 0x3;
327 int link = (dataWord >> posLinkSel2Null) & 0x7F;
329 if (tdcTime == 16383)
334 bool tenDDU = !
mapping->readOutToGeometry(779, 7, 1, 1, 1,
dummy,
dummy,
dummy,
dummy,
dummy,
dummy);
336 int dduId =
theDDU(crate, slotMap,
link, tenDDU);
341 if (hitOrder.find(channelIndex.
getCode()) == hitOrder.end())
342 hitOrder[channelIndex.
getCode()] = 0;
344 hitOrder[channelIndex.
getCode()]++;
346 int wheelId, stationId, sectorId, slId, layerId, cellId;
347 if (!
mapping->readOutToGeometry(
348 dduId, rosId, robId, tdcId, tdcChannel, wheelId, stationId, sectorId, slId, layerId, cellId)) {
349 DTWireId detId =
DTWireId(wheelId, stationId, sectorId, slId, layerId, cellId);
350 int wire = detId.
wire();
352 DTDigi digi(wire, tdcTime, hitOrder[channelIndex.
getCode()]);
353 digis.insertDigi(detId.
layerId(), digi);
356 }
else if (selector2 == 1) {
360 <<
std::dec <<
" in slot " << slot <<
" in crate " << crate;
362 int error = (dataWord)&0x1FFFFFFF;
369 dataWord = (*DTuROSiterator);
405 if (ros > 6 && tenDDU && ddu < 775)
415 int ros = (
link / 24) + 3 * (slot % 6) - 2;