32 produces<DTDigiCollection>();
33 produces<std::vector<DTuROSFEDData>>();
55 std::vector<DTuROSFEDData> words;
59 auto uROSDTDigi_product = std::make_unique<DTDigiCollection>(digis);
60 auto uROSDTWord_product = std::make_unique<std::vector<DTuROSFEDData>>(words);
77 for (
int w_i = 0; w_i <
nfeds_; ++w_i) {
80 words.push_back(fwords);
95 std::vector<long> DTuROSWordContainer;
99 int BOEevTy, DTuROSId;
103 int chkEOE, evtLgth, CRC;
107 std::map<uint32_t, int> hitOrder;
114 if ( dturosdata.
size() == 0 )
return;
121 const int posBOEevTy = 60 ;
122 const int posDTuROSId = 8 ;
123 const int posNslost = 52 ;
124 const int posSlotFED = 16 ;
126 BOEevTy = ( dataWord >> posBOEevTy ) & 0xF;
127 DTuROSId = ( dataWord >> posDTuROSId ) & 0xFFF;
130 if ( (BOEevTy != 0x5) || (DTuROSId != DTuROSFED) ) {
131 if (
debug_ )
edm::LogWarning(
"dturos_unpacker") <<
"Not a DTuROS FED " << DTuROSFED <<
" or header " << std::hex << dataWord;
143 int crate = DTuROSId;
152 int nslots = ( dataWord >> posNslost ) & 0xF;
160 std::map<int, int> slot_size;
161 for (
int j = 0; j < nslots; ++j) {
166 int slot = ( dataWord >> posSlotFED ) & 0xF;
168 if ( (slot < 1) || (slot > 12) ) {
174 slot_size[slot] = ( dataWord >> 32 ) & 0xFFFFFF;
184 std::map<int,int>::iterator sziterator = slot_size.begin();
185 std::map<int,int>::iterator szitend = slot_size.end();
186 for (; sziterator != szitend; ++sziterator) {
187 for (
int k=0;
k<sziterator->second; ++
k) {
192 DTuROSWordContainer.push_back(dataWord);
209 const int posEOE = 60;
210 const int posEvtLenght = 32;
211 const int posCRC = 16;
212 chkEOE = ( dataWord >> posEOE ) & 0xF;
215 if ( chkEOE != 0xA ) {
216 if (
debug_ )
edm::LogWarning(
"dturos_unpacker") <<
"Trailer " << std::hex << dataWord <<
" does not start with 0xA";
221 evtLgth = ( dataWord >> posEvtLenght ) & 0xFFFFFF;
222 CRC = ( dataWord >> posCRC ) & 0xFFFF;
227 if ( newCRC != CRC ) {
229 <<
"Calculated CRC " << std::hex << newCRC <<
" differs from CRC in trailer " << std::hex << CRC;
234 if ( lines != evtLgth ) {
236 <<
"Number of words read != event length " <<
std::dec << lines <<
" " << evtLgth;
248 std::vector<long>::iterator DTuROSiterator = DTuROSWordContainer.begin();
249 std::vector<long>::iterator DTuROSitend = DTuROSWordContainer.end();
251 const int posSlot = 56;
253 for (; DTuROSiterator != DTuROSitend; ++DTuROSiterator) {
258 dataWord = (*DTuROSiterator);
261 int slot = ( dataWord >> posSlot ) & 0xF;
264 if ( (slot < 1) || (slot > 12) ) {
275 dataWord = (*DTuROSiterator);
279 int slotMap = dataWord & 0xF;
280 if (slotMap == 0) slotMap=slot;
281 const int posSel1 = 60 ;
282 const int posSel2 = 28 ;
283 const int posTDCTime = 32 ;
284 const int posTDCChannel = 46 ;
285 const int posTDCId = 51 ;
286 const int posLink = 53 ;
287 const int posTDCChannelSel2Null = 14 ;
288 const int posTDCIdSel2Null = 19 ;
289 const int posLinkSel2Null = 21 ;
290 const int posErrorSel3 = 32 ;
292 for (
int k=2;
k<slot_size[slot]-1; ++
k) {
296 dataWord = (*DTuROSiterator);
297 int selector = ( dataWord >> posSel1 ) & 0xF;
298 int selector2 = ( dataWord >> posSel2 ) & 0
x1;
300 if ( selector == 4 ) {
306 else if ( selector >= 8 && selector <= 13 ) {
311 else if ( selector == 15 ) {
318 if ( selector == 2 ) {
320 int tdcTime = ( dataWord >> posTDCTime ) & 0x3FFF;
321 int tdcChannel = ( dataWord >> posTDCChannel ) & 0x1F;
322 int tdcId = ( dataWord >> posTDCId ) & 0x3;
323 int link = ( dataWord >> posLink ) & 0x7F;
329 dummy, dummy, dummy);
331 int dduId =
theDDU(crate, slotMap, link, tenDDU);
332 int rosId =
theROS(slotMap, link);
333 int robId =
theROB(slotMap, link);
337 if (hitOrder.find(channelIndex.
getCode()) == hitOrder.end()) hitOrder[channelIndex.
getCode()] = 0;
338 else hitOrder[channelIndex.
getCode()]++;
341 int wheelId, stationId, sectorId, slId,layerId, cellId;
343 wheelId, stationId, sectorId, slId, layerId, cellId)) {
345 DTWireId detId =
DTWireId(wheelId, stationId, sectorId, slId, layerId, cellId);
348 DTDigi digi(wire, tdcTime, hitOrder[channelIndex.
getCode()]);
349 digis.insertDigi(detId.
layerId(),digi);
354 else if ( selector == 3 ) {
357 <<
std::dec <<
" in slot " << slot <<
" in crate " << crate;
359 int error = ( dataWord >> posErrorSel3 ) & 0x1FFFFFFF;
365 if ((dataWord & 0x1FFFFFFF) == 0x1FFFFFFF)
continue;
367 if ( selector2 == 0 ) {
369 int tdcTime = ( dataWord ) & 0x3FFF;
370 int tdcChannel = ( dataWord >> posTDCChannelSel2Null ) & 0x1F;
371 int tdcId = ( dataWord >> posTDCIdSel2Null ) & 0x3;
372 int link = ( dataWord >> posLinkSel2Null ) & 0x7F;
375 if (tdcTime == 16383)
continue;
381 dummy, dummy, dummy);
383 int dduId =
theDDU(crate, slotMap, link, tenDDU);
384 int rosId =
theROS(slotMap, link);
385 int robId =
theROB(slotMap, link);
389 if (hitOrder.find(channelIndex.
getCode()) == hitOrder.end()) hitOrder[channelIndex.
getCode()] = 0;
390 else hitOrder[channelIndex.
getCode()]++;
393 int wheelId, stationId, sectorId, slId,layerId, cellId;
395 wheelId, stationId, sectorId, slId, layerId, cellId)) {
397 DTWireId detId =
DTWireId(wheelId, stationId, sectorId, slId, layerId, cellId);
400 DTDigi digi(wire, tdcTime, hitOrder[channelIndex.
getCode()]);
401 digis.insertDigi(detId.
layerId(),digi);
406 else if ( selector2 == 1 ) {
409 <<
std::dec <<
" in slot " << slot <<
" in crate " << crate;
411 int error = ( dataWord ) & 0x1FFFFFFF;
422 dataWord = (*DTuROSiterator);
437 int ros =
theROS(slot,link);
460 if (ros > 6 && tenDDU && ddu < 775)
469 if (slot%6 == 5)
return link+1;
471 int ros = (link/24) + 3*(slot%6) - 2;
478 if (slot%6 == 5)
return 23;
481 if (rob < 15)
return rob;
482 if (rob == 15)
return 24;
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void setuROS(int slot, DTuROSROSData rwords)
int theROS(int slot, int link)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
void settrailer(long dword)
void process(int DTuROSFED, edm::Handle< FEDRawDataCollection > data, edm::ESHandle< DTReadOutMapping > mapping, DTDigiCollection &digis, DTuROSFEDData &fwords)
~DTuROSRawToDigi() override
Destructor.
int theROB(int slot, int link)
void settrailer(long dword)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
int readOutToGeometry(int dduId, int rosId, int robId, int tdcId, int channelId, DTWireId &wireId) const
transform identifiers
#define DEFINE_FWK_MODULE(type)
void setheader1(long dword)
size_t size() const
Lenght of the data buffer in bytes.
void setokxword(int i, long okxword)
void setslotsize(int slot, int size)
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void setexword(long exword)
uint32_t getCode() const
Getters ///////////////////////.
void readline(int &lines, long &dataWord)
int theDDU(int crate, int slot, int link, bool tenDDU)
void setokword1(long okword)
void produce(edm::Event &e, const edm::EventSetup &c) override
Produce digis out of raw data.
void setheader2(long dword)
bool fillRawData(edm::Event &e, const edm::EventSetup &c, DTDigiCollection &digis, std::vector< DTuROSFEDData > &words)
Generate and fill FED raw data for a full event.
void setheader1(long dword)
int wire() const
Return the wire number.
edm::InputTag DTuROSInputTag_
DTuROSRawToDigi(const edm::ParameterSet &pset)
Constructor.
void setnslots(int nslots)
edm::EDGetTokenT< FEDRawDataCollection > Raw_token
void setheader2(long dword)
DTLayerId layerId() const
Return the corresponding LayerId.
void calcCRC(long, int &)
char data[epos_bytes_allocation]
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
void setokword2(long okword)
void setevtlgth(int evtLgth)