19 useDBEMap_(
pset.getParameter<
bool>(
"useDBEMap")),
20 unPackStatusDigis_(
pset.getParameter<
bool>(
"unPackStatusDigis")) {
22 gemEMapToken_ = esConsumes<GEMeMap, GEMeMapRcd, edm::Transition::BeginRun>();
24 produces<GEMDigiCollection>();
26 produces<GEMVfatStatusDigiCollection>(
"vfatStatus");
27 produces<GEMGEBdataCollection>(
"gebStatus");
28 produces<GEMAMCdataCollection>(
"AMCdata");
29 produces<GEMAMC13EventCollection>(
"AMC13Event");
36 desc.
add<
bool>(
"useDBEMap",
false);
37 desc.
add<
bool>(
"unPackStatusDigis",
false);
38 descriptions.
add(
"muonGEMDigisDefault", desc);
42 auto gemROmap = std::make_shared<GEMROMapping>();
45 auto gemEMap = std::make_unique<GEMeMap>(eMap);
46 gemEMap->convert(*gemROmap);
50 auto gemEMap = std::make_unique<GEMeMap>();
51 gemEMap->convertDummy(*gemROmap);
58 auto outGEMDigis = std::make_unique<GEMDigiCollection>();
59 auto outVFATStatus = std::make_unique<GEMVfatStatusDigiCollection>();
60 auto outGEBStatus = std::make_unique<GEMGEBdataCollection>();
61 auto outAMCdata = std::make_unique<GEMAMCdataCollection>();
62 auto outAMC13Event = std::make_unique<GEMAMC13EventCollection>();
68 auto gemROMap = runCache(
iEvent.getRun().index());
74 LogDebug(
"GEMRawToDigiModule") <<
" words " << nWords;
78 const unsigned char*
data = fedData.
data();
80 auto amc13Event = std::make_unique<AMC13Event>();
84 amc13Event->setCDFHeader(*
word);
85 amc13Event->setAMC13Header(*(++
word));
87 bool unknownChamber =
false, unknownVFat =
false, badVfat =
false;
90 for (uint8_t
i = 0;
i < amc13Event->nAMC(); ++
i)
91 amc13Event->addAMCheader(*(++
word));
94 for (uint8_t
i = 0;
i < amc13Event->nAMC(); ++
i) {
95 auto amcData = std::make_unique<AMCdata>();
96 amcData->setAMCheader1(*(++
word));
97 amcData->setAMCheader2(*(++
word));
98 amcData->setGEMeventHeader(*(++
word));
99 uint16_t amcBx = amcData->bx();
100 uint8_t amcNum = amcData->amcNum();
103 for (uint8_t
j = 0;
j < amcData->davCnt(); ++
j) {
104 auto gebData = std::make_unique<GEBdata>();
105 gebData->setChamberHeader(*(++
word));
107 uint8_t gebId = gebData->inputID();
111 if (!gemROMap->isValidChamber(geb_ec)) {
112 unknownChamber =
true;
113 LogDebug(
"GEMRawToDigiModule") <<
"InValid: amcNum " <<
int(amcNum) <<
" gebId " <<
int(gebId);
120 for (uint16_t
k = 0;
k < gebData->vfatWordCnt() / 3;
k++) {
121 auto vfatData = std::make_unique<VFATdata>();
122 vfatData->read_fw(*(++
word));
123 vfatData->read_sw(*(++
word));
124 vfatData->read_tw(*(++
word));
126 vfatData->setVersion(geb_dc.
vfatVer);
127 uint16_t vfatId = vfatData->vfatId();
131 if (!gemROMap->isValidChipID(vfat_ec)) {
133 LogDebug(
"GEMRawToDigiModule") <<
"InValid: amcNum " <<
int(amcNum) <<
" gebId " <<
int(gebId) <<
" vfatId "
134 <<
int(vfatId) <<
" vfat Pos " <<
int(vfatData->position());
139 if (vfatData->quality()) {
142 <<
"Quality " <<
int(vfatData->quality()) <<
" b1010 " <<
int(vfatData->b1010()) <<
" b1100 "
143 <<
int(vfatData->b1100()) <<
" b1110 " <<
int(vfatData->b1110());
144 if (vfatData->crc() != vfatData->checkCRC()) {
145 LogDebug(
"GEMRawToDigiModule") <<
"DIFFERENT CRC :" << vfatData->crc() <<
" " << vfatData->checkCRC();
153 uint16_t bc = vfatData->bc();
160 chan0xf = ((vfatData->lsData() >>
chan) & 0
x1);
162 chan0xf = ((vfatData->msData() >> (
chan - 64)) & 0x1);
176 <<
" fed: " <<
fedId <<
" amc:" <<
int(amcNum) <<
" geb:" <<
int(gebId) <<
" vfat:" << vfat_dc.
localPhi
177 <<
",type: " << vfat_dc.
vfatType <<
" id:" << gemId <<
" ch:" << chMap.
chNum <<
" st:" << digi.
strip()
178 <<
" bx:" << digi.
bx();
180 outGEMDigis.get()->insertDigi(gemId, digi);
190 gebData->setChamberTrailer(*(++
word));
193 outGEBStatus.get()->insertDigi(gemChId.
chamberId(), (*gebData));
198 amcData->setGEMeventTrailer(*(++
word));
199 amcData->setAMCTrailer(*(++
word));
202 outAMCdata.get()->insertDigi(amcData->boardId(), (*amcData));
207 amc13Event->setAMC13Trailer(*(++
word));
208 amc13Event->setCDFTrailer(*(++
word));
211 outAMC13Event.get()->insertDigi(amc13Event->bxId(),
AMC13Event(*amc13Event));
214 if (unknownChamber || unknownVFat || badVfat) {
215 edm::LogWarning(
"GEMRawToDigiModule") <<
"unpacking error: unknown Chamber " << unknownChamber <<
" unknown VFat "
216 << unknownVFat <<
" bad VFat " << badVfat;