CMS 3D CMS Logo

GEMRawToDigiModule.cc
Go to the documentation of this file.
1 
33 
34 class GEMRawToDigiModule : public edm::global::EDProducer<edm::RunCache<GEMROMapping> > {
35 public:
38 
39  // global::EDProducer
40  std::shared_ptr<GEMROMapping> globalBeginRun(edm::Run const&, edm::EventSetup const&) const override;
41  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
42  void globalEndRun(edm::Run const&, edm::EventSetup const&) const override{};
43 
44  // Fill parameters descriptions
45  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
46 
47 private:
50  bool useDBEMap_;
52  std::unique_ptr<GEMRawToDigi> gemRawToDigi_;
53 };
54 
57 
58 using namespace gem;
59 
61  : fed_token(consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("InputLabel"))),
62  useDBEMap_(pset.getParameter<bool>("useDBEMap")),
63  unPackStatusDigis_(pset.getParameter<bool>("unPackStatusDigis")),
64  gemRawToDigi_(std::make_unique<GEMRawToDigi>()) {
65  produces<GEMDigiCollection>();
66  if (unPackStatusDigis_) {
67  produces<GEMVfatStatusDigiCollection>("vfatStatus");
68  produces<GEMGEBdataCollection>("gebStatus");
69  produces<GEMAMCdataCollection>("AMCdata");
70  produces<GEMAMC13EventCollection>("AMC13Event");
71  }
72  if (useDBEMap_) {
73  gemEMapToken_ = esConsumes<GEMeMap, GEMeMapRcd, edm::Transition::BeginRun>();
74  }
75 }
76 
79  desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
80  desc.add<bool>("useDBEMap", false);
81  desc.add<bool>("unPackStatusDigis", false);
82  descriptions.add("muonGEMDigisDefault", desc);
83 }
84 
85 std::shared_ptr<GEMROMapping> GEMRawToDigiModule::globalBeginRun(edm::Run const&, edm::EventSetup const& iSetup) const {
86  auto gemROmap = std::make_shared<GEMROMapping>();
87  if (useDBEMap_) {
88  const auto& eMap = iSetup.getData(gemEMapToken_);
89  auto gemEMap = std::make_unique<GEMeMap>(eMap);
90  gemEMap->convert(*gemROmap);
91  gemEMap.reset();
92  } else {
93  // no EMap in DB, using dummy
94  auto gemEMap = std::make_unique<GEMeMap>();
95  gemEMap->convertDummy(*gemROmap);
96  gemEMap.reset();
97  }
98  return gemROmap;
99 }
100 
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>();
107 
108  // Take raw from the event
110  iEvent.getByToken(fed_token, fed_buffers);
111 
112  auto gemROMap = runCache(iEvent.getRun().index());
113 
115  const FEDRawData& fedData = fed_buffers->FEDData(fedId);
116 
117  int nWords = fedData.size() / sizeof(uint64_t);
118  LogDebug("GEMRawToDigiModule") << "fedId:" << fedId << " words: " << nWords;
119 
120  if (nWords < 5)
121  continue;
122 
123  // trailer checks
124  FEDTrailer trailer(fedData.data() + fedData.size() - FEDTrailer::length);
125 
126  bool failTrailerCheck = false, failTrailerMatch = false;
127  if (!trailer.check() || (trailer.fragmentLength() * sizeof(uint64_t) != fedData.size())) {
128  failTrailerCheck = true;
129  }
130 
131  const unsigned char* data = fedData.data();
132  const uint64_t* word = reinterpret_cast<const uint64_t*>(data);
133  auto amc13Event = gemRawToDigi_->convertWordToAMC13Event(word);
134 
135  if (amc13Event == nullptr) {
136  LogDebug("GEMRawToDigiModule") << "AMC13Event FAILED to be produced";
137  continue;
138  }
139 
140  // compare trailers found by last word of fedData.size() and gemRawToDigi
141  // caused by error in no. of AMC, GEB or VFAT stored in FEDs
142  if ((amc13Event->fragmentLength() != trailer.fragmentLength()) || (amc13Event->crc() != trailer.crc()))
143  failTrailerMatch = true;
144 
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();
149 
150  if (failTrailerCheck || failTrailerMatch) {
151  // best to skip these events since FED is most likely corrupt
152  edm::LogWarning("GEMRawToDigiModule")
153  << "FED trailer: fail check? " << failTrailerCheck << " fail match? " << failTrailerMatch;
154  continue;
155  }
156 
157  bool unknownChamber = false, unknownVFat = false, badVfat = false;
158 
159  // Read AMC data
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());
165 
166  // Read GEB data
167  for (auto gebData : *amcData.gebs()) {
168  uint8_t gebId = gebData.inputID();
169  GEMROMapping::chamEC geb_ec = {fedId, amcNum, gebId};
170 
171  // check if Chamber exists.
172  if (!gemROMap->isValidChamber(geb_ec)) {
173  unknownChamber = true;
174  LogDebug("GEMRawToDigiModule") << "InValid: amcNum " << int(amcNum) << " gebId " << int(gebId);
175  continue;
176  }
177 
178  GEMROMapping::chamDC geb_dc = gemROMap->chamberPos(geb_ec);
179  GEMDetId gemChId = geb_dc.detId;
180 
181  //Read vfat data
182  for (auto vfatData : *gebData.vFATs()) {
183  vfatData.setVersion(geb_dc.vfatVer);
184  uint16_t vfatId = vfatData.vfatId();
185  GEMROMapping::vfatEC vfat_ec = {vfatId, gemChId};
186 
187  // check if ChipID exists.
188  if (!gemROMap->isValidChipID(vfat_ec)) {
189  unknownVFat = true;
190  LogDebug("GEMRawToDigiModule") << "InValid: amcNum " << int(amcNum) << " gebId " << int(gebId) << " vfatId "
191  << int(vfatId) << " vfat Pos " << int(vfatData.position());
192  continue;
193  }
194 
195  // check vfat data
196  if (vfatData.quality()) {
197  badVfat = true;
198  LogDebug("GEMRawToDigiModule")
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();
203  }
204  }
205 
206  GEMROMapping::vfatDC vfat_dc = gemROMap->vfatPos(vfat_ec);
207 
208  vfatData.setPhi(vfat_dc.localPhi);
209  GEMDetId gemId = vfat_dc.detId;
210  int bx(vfatData.bc() - amcBx);
211 
212  for (int chan = 0; chan < VFATdata::nChannels; ++chan) {
213  uint8_t chan0xf = 0;
214  if (chan < 64)
215  chan0xf = ((vfatData.lsData() >> chan) & 0x1);
216  else
217  chan0xf = ((vfatData.msData() >> (chan - 64)) & 0x1);
218 
219  // no hits
220  if (chan0xf == 0)
221  continue;
222 
223  GEMROMapping::channelNum chMap = {vfat_dc.vfatType, chan};
224  GEMROMapping::stripNum stMap = gemROMap->hitPos(chMap);
225 
226  int stripId = stMap.stNum + vfatData.phi() * GEMeMap::maxChan_;
227 
228  GEMDigi digi(stripId, bx);
229 
230  LogDebug("GEMRawToDigiModule")
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();
234 
235  outGEMDigis.get()->insertDigi(gemId, digi);
236 
237  } // end of channel loop
238 
239  if (unPackStatusDigis_) {
240  outVFATStatus.get()->insertDigi(gemId, GEMVfatStatusDigi(vfatData));
241  }
242 
243  } // end of vfat loop
244 
245  if (unPackStatusDigis_) {
246  gebData.clearVFATs();
247  outGEBStatus.get()->insertDigi(gemChId.chamberId(), (gebData));
248  }
249 
250  } // end of geb loop
251 
252  if (unPackStatusDigis_) {
253  amcData.clearGEBs();
254  outAMCdata.get()->insertDigi(amcData.boardId(), (amcData));
255  }
256 
257  } // end of amc loop
258 
259  if (unPackStatusDigis_) {
260  amc13Event->clearAMCpayloads();
261  outAMC13Event.get()->insertDigi(amc13Event->bxId(), AMC13Event(*amc13Event));
262  }
263 
264  if (unknownChamber || unknownVFat || badVfat) {
265  edm::LogWarning("GEMRawToDigiModule") << "unpacking error: unknown Chamber " << unknownChamber << " unknown VFat "
266  << unknownVFat << " bad VFat " << badVfat;
267  }
268 
269  } // end of amc13Event
270 
271  iEvent.put(std::move(outGEMDigis));
272 
273  if (unPackStatusDigis_) {
274  iEvent.put(std::move(outVFATStatus), "vfatStatus");
275  iEvent.put(std::move(outGEBStatus), "gebStatus");
276  iEvent.put(std::move(outAMCdata), "AMCdata");
277  iEvent.put(std::move(outAMC13Event), "AMC13Event");
278  }
279 }
ConfigurationDescriptions.h
FEDNumbering.h
edm::StreamID
Definition: StreamID.h:30
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
GEMRawToDigiModule::GEMRawToDigiModule
GEMRawToDigiModule(const edm::ParameterSet &pset)
Constructor.
Definition: GEMRawToDigiModule.cc:60
GEMROMapping::vfatDC::vfatType
int vfatType
Definition: GEMROMapping.h:45
GEMeMapRcd.h
MessageLogger.h
GEMGEBdataCollection.h
GEMRawToDigiModule::unPackStatusDigis_
bool unPackStatusDigis_
Definition: GEMRawToDigiModule.cc:51
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< FEDRawDataCollection >
GEMDigi::bx
int16_t bx() const
Definition: GEMDigi.h:27
FEDRawDataCollection
Definition: FEDRawDataCollection.h:18
GEMAMC13EventCollection.h
edm
HLT enums.
Definition: AlignableModifier.h:19
VFATdata.h
GEMROMapping::chamDC
Definition: GEMROMapping.h:26
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
GEMRawToDigiModule
Definition: GEMRawToDigiModule.cc:34
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
ecaldqm::nChannels
Definition: EcalDQMCommonUtils.h:113
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
GEMROMapping::stripNum
Definition: GEMROMapping.h:72
GEMAMCdataCollection.h
edm::Handle< FEDRawDataCollection >
gem::AMC13Event
Definition: AMC13Event.h:68
ESGetToken.h
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
FEDRawData::data
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
FEDRawData
Definition: FEDRawData.h:19
FEDNumbering::MINGEMFEDID
Definition: FEDNumbering.h:123
GEMROMapping::chamDC::vfatVer
int vfatVer
Definition: GEMROMapping.h:28
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
GEMROMapping::vfatDC::detId
GEMDetId detId
Definition: GEMROMapping.h:46
GEMROMapping::vfatDC::localPhi
int localPhi
Definition: GEMROMapping.h:47
MakerMacros.h
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
GEMRawToDigiModule::fed_token
edm::EDGetTokenT< FEDRawDataCollection > fed_token
Definition: GEMRawToDigiModule.cc:48
GEMRawToDigiModule::globalEndRun
void globalEndRun(edm::Run const &, edm::EventSetup const &) const override
Definition: GEMRawToDigiModule.cc:42
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
GEMeMap.h
GEMVfatStatusDigi
Definition: GEMVfatStatusDigi.h:7
GEMDigi::strip
uint16_t strip() const
Definition: GEMDigi.h:26
GEMRawToDigiModule::gemEMapToken_
edm::ESGetToken< GEMeMap, GEMeMapRcd > gemEMapToken_
Definition: GEMRawToDigiModule.cc:49
Run.h
GEMROMapping.h
GEMRawToDigiModule::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: GEMRawToDigiModule.cc:77
Transition.h
ParameterSetDescription.h
FEDRawDataCollection::FEDData
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Definition: FEDRawDataCollection.cc:19
GEMROMapping::vfatDC
Definition: GEMROMapping.h:44
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
GEMROMapping::channelNum::chNum
int chNum
Definition: GEMROMapping.h:63
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
FEDTrailer
Definition: FEDTrailer.h:14
Event.h
GEMDetId
Definition: GEMDetId.h:18
GEMROMapping::chamEC
Definition: GEMROMapping.h:9
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
FEDRawDataCollection.h
GEMDigi
Definition: GEMDigi.h:15
GEMRawToDigi.h
edm::EventSetup
Definition: EventSetup.h:58
l1tstage2_dqm_sourceclient-live_cfg.fedId
fedId
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:88
gem
Definition: AMC13Event.h:6
edm::ESGetToken< GEMeMap, GEMeMapRcd >
FEDRawData::size
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
InputTag.h
GEMROMapping::stripNum::stNum
int stNum
Definition: GEMROMapping.h:74
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
GEMRawToDigi
Definition: GEMRawToDigi.h:9
GEMROMapping::channelNum
Definition: GEMROMapping.h:61
officialStyle.chan
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi....
Definition: officialStyle.py:106
FEDTrailer::length
static const uint32_t length
Definition: FEDTrailer.h:57
GEMDetId::chamberId
constexpr GEMDetId chamberId() const
Definition: GEMDetId.h:204
GEMRawToDigiModule::globalBeginRun
std::shared_ptr< GEMROMapping > globalBeginRun(edm::Run const &, edm::EventSetup const &) const override
Definition: GEMRawToDigiModule.cc:85
GEMVfatStatusDigiCollection.h
GEMRawToDigiModule::gemRawToDigi_
std::unique_ptr< GEMRawToDigi > gemRawToDigi_
Definition: GEMRawToDigiModule.cc:52
FEDNumbering::MAXGEMFEDID
Definition: FEDNumbering.h:126
EventSetup.h
AMC13Event.h
GEMDigiCollection.h
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
ParameterSet.h
GEMROMapping::chamDC::detId
GEMDetId detId
Definition: GEMROMapping.h:27
EDProducer.h
edm::Event
Definition: Event.h:73
GEMRawToDigiModule::useDBEMap_
bool useDBEMap_
Definition: GEMRawToDigiModule.cc:50
GEMROMapping::vfatEC
Definition: GEMROMapping.h:32
edm::InputTag
Definition: InputTag.h:15
GEMeMap::maxChan_
static const int maxChan_
Definition: GEMeMap.h:69
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
GEMRawToDigiModule::produce
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
Definition: GEMRawToDigiModule.cc:101
FEDTrailer.h