62 useDBEMap_(
pset.getParameter<
bool>(
"useDBEMap")),
63 unPackStatusDigis_(
pset.getParameter<
bool>(
"unPackStatusDigis")),
65 produces<GEMDigiCollection>();
67 produces<GEMVfatStatusDigiCollection>(
"vfatStatus");
68 produces<GEMGEBdataCollection>(
"gebStatus");
69 produces<GEMAMCdataCollection>(
"AMCdata");
70 produces<GEMAMC13EventCollection>(
"AMC13Event");
73 gemEMapToken_ = esConsumes<GEMeMap, GEMeMapRcd, edm::Transition::BeginRun>();
80 desc.add<
bool>(
"useDBEMap",
false);
81 desc.add<
bool>(
"unPackStatusDigis",
false);
82 descriptions.
add(
"muonGEMDigisDefault",
desc);
86 auto gemROmap = std::make_shared<GEMROMapping>();
89 auto gemEMap = std::make_unique<GEMeMap>(eMap);
90 gemEMap->convert(*gemROmap);
94 auto gemEMap = std::make_unique<GEMeMap>();
95 gemEMap->convertDummy(*gemROmap);
102 auto outGEMDigis = std::make_unique<GEMDigiCollection>();
103 auto outVFATStatus = std::make_unique<GEMVfatStatusDigiCollection>();
104 auto outGEBStatus = std::make_unique<GEMGEBdataCollection>();
105 auto outAMCdata = std::make_unique<GEMAMCdataCollection>();
106 auto outAMC13Event = std::make_unique<GEMAMC13EventCollection>();
112 auto gemROMap = runCache(
iEvent.getRun().index());
118 LogDebug(
"GEMRawToDigiModule") <<
"fedId:" <<
fedId <<
" words: " << nWords;
126 bool failTrailerCheck =
false, failTrailerMatch =
false;
127 if (!trailer.check() || (trailer.fragmentLength() *
sizeof(
uint64_t) != fedData.
size())) {
128 failTrailerCheck =
true;
131 const unsigned char*
data = fedData.
data();
135 if (amc13Event ==
nullptr) {
136 LogDebug(
"GEMRawToDigiModule") <<
"AMC13Event FAILED to be produced";
142 if ((amc13Event->fragmentLength() != trailer.fragmentLength()) || (amc13Event->crc() != trailer.crc()))
143 failTrailerMatch =
true;
145 LogDebug(
"GEMRawToDigiModule") <<
"Event bx:" <<
iEvent.bunchCrossing() <<
" lv1Id:" <<
iEvent.id().event()
146 <<
" orbitNumber:" <<
iEvent.orbitNumber();
147 LogDebug(
"GEMRawToDigiModule") <<
"AMC13 bx:" << amc13Event->bxId() <<
" lv1Id:" <<
int(amc13Event->lv1Id())
148 <<
" orbitNumber:" << amc13Event->orbitNumber();
150 if (failTrailerCheck || failTrailerMatch) {
153 <<
"FED trailer: fail check? " << failTrailerCheck <<
" fail match? " << failTrailerMatch;
157 bool unknownChamber =
false, unknownVFat =
false, badVfat =
false;
160 for (
auto amcData : *(amc13Event->getAMCpayloads())) {
161 uint16_t amcBx = amcData.bx();
162 uint8_t amcNum = amcData.amcNum();
163 LogDebug(
"GEMRawToDigiModule") <<
"AMC no.:" <<
int(amcData.amcNum()) <<
" bx:" <<
int(amcData.bx())
164 <<
" lv1Id:" <<
int(amcData.l1A()) <<
" orbitNumber:" <<
int(amcData.orbitNum());
167 for (
auto gebData : *amcData.gebs()) {
168 uint8_t gebId = gebData.inputID();
172 if (!gemROMap->isValidChamber(geb_ec)) {
173 unknownChamber =
true;
174 LogDebug(
"GEMRawToDigiModule") <<
"InValid: amcNum " <<
int(amcNum) <<
" gebId " <<
int(gebId);
182 for (
auto vfatData : *gebData.vFATs()) {
183 vfatData.setVersion(geb_dc.
vfatVer);
184 uint16_t vfatId = vfatData.vfatId();
188 if (!gemROMap->isValidChipID(vfat_ec)) {
190 LogDebug(
"GEMRawToDigiModule") <<
"InValid: amcNum " <<
int(amcNum) <<
" gebId " <<
int(gebId) <<
" vfatId "
191 <<
int(vfatId) <<
" vfat Pos " <<
int(vfatData.position());
196 if (vfatData.quality()) {
199 <<
"Quality " <<
int(vfatData.quality()) <<
" b1010 " <<
int(vfatData.b1010()) <<
" b1100 "
200 <<
int(vfatData.b1100()) <<
" b1110 " <<
int(vfatData.b1110());
201 if (vfatData.crc() != vfatData.checkCRC()) {
202 LogDebug(
"GEMRawToDigiModule") <<
"DIFFERENT CRC :" << vfatData.crc() <<
" " << vfatData.checkCRC();
210 int bx(vfatData.bc() - amcBx);
215 chan0xf = ((vfatData.lsData() >>
chan) & 0
x1);
217 chan0xf = ((vfatData.msData() >> (
chan - 64)) & 0x1);
231 <<
" fed: " <<
fedId <<
" amc:" <<
int(amcNum) <<
" geb:" <<
int(gebId) <<
" vfat:" << vfat_dc.
localPhi
232 <<
",type: " << vfat_dc.
vfatType <<
" id:" << gemId <<
" ch:" << chMap.
chNum <<
" st:" << digi.
strip()
233 <<
" bx:" << digi.
bx();
235 outGEMDigis.get()->insertDigi(gemId, digi);
246 gebData.clearVFATs();
247 outGEBStatus.get()->insertDigi(gemChId.
chamberId(), (gebData));
254 outAMCdata.get()->insertDigi(amcData.boardId(), (amcData));
260 amc13Event->clearAMCpayloads();
261 outAMC13Event.get()->insertDigi(amc13Event->bxId(),
AMC13Event(*amc13Event));
264 if (unknownChamber || unknownVFat || badVfat) {
265 edm::LogWarning(
"GEMRawToDigiModule") <<
"unpacking error: unknown Chamber " << unknownChamber <<
" unknown VFat "
266 << unknownVFat <<
" bad VFat " << badVfat;