30 produces<DTDigiCollection>();
31 produces<std::vector<DTuROSFEDData>>();
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);
290 int rosId =
theROS(slotMap, link);
291 int robId =
theROB(slotMap, link);
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;
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);
337 int rosId =
theROS(slotMap, link);
338 int robId =
theROB(slotMap, link);
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;
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);
380 int ros =
theROS(slot, link);
405 if (ros > 6 && tenDDU && ddu < 775)
415 int ros = (link / 24) + 3 * (slot % 6) - 2;
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
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)
#define DEFINE_FWK_MODULE(type)
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)