28 produces<DTDigiCollection>();
29 produces<std::vector<DTuROSFEDData>>();
33 debug_ =
pset.getUntrackedParameter<
bool>(
"debug",
false);
41 mapping_token_ = esConsumes<DTReadOutMapping, DTReadOutMappingRcd>();
48 std::vector<DTuROSFEDData> words;
53 auto uROSDTDigi_product = std::make_unique<DTDigiCollection>(digis);
54 auto uROSDTWord_product = std::make_unique<std::vector<DTuROSFEDData>>(words);
63 std::vector<DTuROSFEDData>& words) {
69 for (
int w_i = 0; w_i <
nfeds_; ++w_i) {
73 words.push_back(fwords);
85 std::vector<long> DTuROSWordContainer;
88 int BOEevTy, DTuROSId;
91 int chkEOE, evtLgth,
CRC;
94 std::map<uint32_t, int> hitOrder;
99 if (dturosdata.
size() == 0)
106 const int posBOEevTy = 60;
107 const int posDTuROSId = 8;
108 const int posNslost = 52;
109 const int posSlotFED = 16;
111 BOEevTy = (dataWord >> posBOEevTy) & 0xF;
112 DTuROSId = (dataWord >> posDTuROSId) & 0xFFF;
114 if ((BOEevTy != 0x5) || (DTuROSId != DTuROSFED)) {
116 edm::LogWarning(
"dturos_unpacker") <<
"Not a DTuROS FED " << DTuROSFED <<
" or header " << std::hex << dataWord;
126 int crate = DTuROSId;
133 int nslots = (dataWord >> posNslost) & 0xF;
139 std::map<int, int> slot_size;
140 for (
int j = 0;
j < nslots; ++
j) {
144 int slot = (dataWord >> posSlotFED) & 0xF;
152 slot_size[
slot] = (dataWord >> 32) & 0xFFFFFF;
159 std::map<int, int>::iterator sziterator = slot_size.begin();
160 std::map<int, int>::iterator szitend = slot_size.end();
161 for (; sziterator != szitend; ++sziterator) {
162 for (
int k = 0;
k < sziterator->second; ++
k) {
166 DTuROSWordContainer.push_back(dataWord);
179 const int posEOE = 60;
180 const int posEvtLenght = 32;
181 const int posCRC = 16;
182 chkEOE = (dataWord >> posEOE) & 0xF;
186 edm::LogWarning(
"dturos_unpacker") <<
"Trailer " << std::hex << dataWord <<
" does not start with 0xA";
190 evtLgth = (dataWord >> posEvtLenght) & 0xFFFFFF;
191 CRC = (dataWord >> posCRC) & 0xFFFF;
197 edm::LogWarning(
"dturos_unpacker") <<
"Calculated CRC " << std::hex << newCRC <<
" differs from CRC in trailer " 202 if (
lines != evtLgth) {
214 std::vector<long>::iterator DTuROSiterator = DTuROSWordContainer.begin();
215 std::vector<long>::iterator DTuROSitend = DTuROSWordContainer.end();
217 const int posSlot = 56;
219 for (; DTuROSiterator != DTuROSitend; ++DTuROSiterator) {
222 dataWord = (*DTuROSiterator);
224 int slot = (dataWord >> posSlot) & 0xF;
236 dataWord = (*DTuROSiterator);
239 int slotMap = dataWord & 0xF;
242 const int posSel1 = 60;
243 const int posSel2 = 28;
244 const int posTDCTime = 32;
245 const int posTDCChannel = 46;
246 const int posTDCId = 51;
247 const int posLink = 53;
248 const int posTDCChannelSel2Null = 14;
249 const int posTDCIdSel2Null = 19;
250 const int posLinkSel2Null = 21;
251 const int posErrorSel3 = 32;
253 for (
int k = 2;
k < slot_size[
slot] - 1; ++
k) {
255 dataWord = (*DTuROSiterator);
256 int selector = (dataWord >> posSel1) & 0xF;
257 int selector2 = (dataWord >> posSel2) & 0
x1;
278 int tdcTime = (dataWord >> posTDCTime) & 0x3FFF;
279 int tdcChannel = (dataWord >> posTDCChannel) & 0x1F;
280 int tdcId = (dataWord >> posTDCId) & 0x3;
281 int link = (dataWord >> posLink) & 0x7F;
285 bool tenDDU = !
mapping->readOutToGeometry(779, 7, 1, 1, 1,
dummy,
dummy,
dummy,
dummy,
dummy,
dummy);
288 int rosId =
theROS(slotMap, link);
289 int robId =
theROB(slotMap, link);
292 if (hitOrder.find(
channelIndex.getCode()) == hitOrder.end())
297 int wheelId, stationId, sectorId, slId, layerId, cellId;
298 if (!
mapping->readOutToGeometry(
299 dduId, rosId, robId, tdcId, tdcChannel, wheelId, stationId, sectorId, slId, layerId, cellId)) {
304 digis.insertDigi(
detId.layerId(), digi);
313 int error = (dataWord >> posErrorSel3) & 0x1FFFFFFF;
317 if ((dataWord & 0x1FFFFFFF) == 0x1FFFFFFF)
320 if (selector2 == 0) {
322 int tdcTime = (dataWord) & 0x3FFF;
323 int tdcChannel = (dataWord >> posTDCChannelSel2Null) & 0x1F;
324 int tdcId = (dataWord >> posTDCIdSel2Null) & 0x3;
325 int link = (dataWord >> posLinkSel2Null) & 0x7F;
327 if (tdcTime == 16383)
332 bool tenDDU = !
mapping->readOutToGeometry(779, 7, 1, 1, 1,
dummy,
dummy,
dummy,
dummy,
dummy,
dummy);
335 int rosId =
theROS(slotMap, link);
336 int robId =
theROB(slotMap, link);
339 if (hitOrder.find(
channelIndex.getCode()) == hitOrder.end())
344 int wheelId, stationId, sectorId, slId, layerId, cellId;
345 if (!
mapping->readOutToGeometry(
346 dduId, rosId, robId, tdcId, tdcChannel, wheelId, stationId, sectorId, slId, layerId, cellId)) {
351 digis.insertDigi(
detId.layerId(), digi);
354 }
else if (selector2 == 1) {
360 int error = (dataWord) & 0x1FFFFFFF;
367 dataWord = (*DTuROSiterator);
403 if (ros > 6 && tenDDU && ddu < 775)
413 int ros = (link / 24) + 3 * (
slot % 6) - 2;
void setuROS(int slot, DTuROSROSData rwords)
int theROS(int slot, int link)
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)
__host__ __device__ std::uint32_t channelIndex(fedId_t fed, fedCh_t channel)
size_t size() const
Lenght of the data buffer in bytes.
void setheader1(long dword)
void setokxword(int i, long okxword)
void setslotsize(int slot, int size)
void setexword(long exword)
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.
#define DEFINE_FWK_MODULE(type)
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)
edm::InputTag DTuROSInputTag_
DTuROSRawToDigi(const edm::ParameterSet &pset)
Constructor.
void setnslots(int nslots)
edm::EDGetTokenT< FEDRawDataCollection > Raw_token
void setheader2(long dword)
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)
Log< level::Warning, false > LogWarning
edm::ESGetToken< DTReadOutMapping, DTReadOutMappingRcd > mapping_token_
void setevtlgth(int evtLgth)