CMS 3D CMS Logo

GEMRawToDigiModule.cc
Go to the documentation of this file.
1 
37 
38 class GEMRawToDigiModule : public edm::global::EDProducer<edm::RunCache<GEMROMapping> > {
39 public:
42 
43  // global::EDProducer
44  std::shared_ptr<GEMROMapping> globalBeginRun(edm::Run const&, edm::EventSetup const&) const override;
45  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
46  void globalEndRun(edm::Run const&, edm::EventSetup const&) const override{};
47 
48  // Fill parameters descriptions
49  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
50 
51 private:
56  std::unique_ptr<GEMRawToDigi> gemRawToDigi_;
57 };
58 
61 
62 using namespace gem;
63 
65  : fed_token(consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("InputLabel"))),
66  useDBEMap_(pset.getParameter<bool>("useDBEMap")),
67  keepDAQStatus_(pset.getParameter<bool>("keepDAQStatus")),
68  readMultiBX_(pset.getParameter<bool>("readMultiBX")),
69  unPackStatusDigis_(pset.getParameter<bool>("unPackStatusDigis")),
70  gemRawToDigi_(std::make_unique<GEMRawToDigi>()) {
71  produces<GEMDigiCollection>();
72  if (keepDAQStatus_) {
73  produces<GEMAMC13StatusCollection>("AMC13Status");
74  produces<GEMAMCStatusCollection>("AMCStatus");
75  produces<GEMOHStatusCollection>("OHStatus");
76  produces<GEMVFATStatusCollection>("VFATStatus");
77  }
78  if (unPackStatusDigis_) {
79  // to be removed
80  produces<GEMVfatStatusDigiCollection>("vfatStatus");
81  produces<GEMGEBdataCollection>("gebStatus");
82  produces<GEMAMCdataCollection>("AMCdata");
83  produces<GEMAMC13EventCollection>("AMC13Event");
84  }
85  if (useDBEMap_) {
86  gemEMapToken_ = esConsumes<GEMeMap, GEMeMapRcd, edm::Transition::BeginRun>();
87  }
88 }
89 
92  desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
93  desc.add<bool>("useDBEMap", false);
94  desc.add<bool>("unPackStatusDigis", false);
95  desc.add<bool>("keepDAQStatus", false);
96  desc.add<bool>("readMultiBX", false);
97  descriptions.add("muonGEMDigisDefault", desc);
98 }
99 
100 std::shared_ptr<GEMROMapping> GEMRawToDigiModule::globalBeginRun(edm::Run const&, edm::EventSetup const& iSetup) const {
101  auto gemROmap = std::make_shared<GEMROMapping>();
102  if (useDBEMap_) {
103  const auto& eMap = iSetup.getData(gemEMapToken_);
104  auto gemEMap = std::make_unique<GEMeMap>(eMap);
105  gemEMap->convert(*gemROmap);
106  gemEMap.reset();
107  } else {
108  // no EMap in DB, using dummy
109  auto gemEMap = std::make_unique<GEMeMap>();
110  gemEMap->convertDummy(*gemROmap);
111  gemEMap.reset();
112  }
113  return gemROmap;
114 }
115 
117  auto outGEMDigis = std::make_unique<GEMDigiCollection>();
118  auto outAMC13Status = std::make_unique<GEMAMC13StatusCollection>();
119  auto outAMCStatus = std::make_unique<GEMAMCStatusCollection>();
120  auto outOHStatus = std::make_unique<GEMOHStatusCollection>();
121  auto outVFATStatus = std::make_unique<GEMVFATStatusCollection>();
122 
123  // to be removed
124  auto outVFATStatusOld = std::make_unique<GEMVfatStatusDigiCollection>();
125  auto outGEBStatus = std::make_unique<GEMGEBdataCollection>();
126  auto outAMCdata = std::make_unique<GEMAMCdataCollection>();
127  auto outAMC13Event = std::make_unique<GEMAMC13EventCollection>();
128 
129  // Take raw from the event
131  iEvent.getByToken(fed_token, fed_buffers);
132 
133  auto gemROMap = runCache(iEvent.getRun().index());
134 
136  const FEDRawData& fedData = fed_buffers->FEDData(fedId);
137 
138  int nWords = fedData.size() / sizeof(uint64_t);
139  LogDebug("GEMRawToDigiModule") << "fedId:" << fedId << " words: " << nWords;
140  GEMAMC13Status st_amc13(fedData);
141  if (st_amc13.isBad()) {
142  LogDebug("GEMRawToDigiModule") << st_amc13;
143  if (keepDAQStatus_) {
144  outAMC13Status.get()->insertDigi(fedId, st_amc13);
145  }
146  continue;
147  }
148 
149  const uint64_t* word = reinterpret_cast<const uint64_t*>(fedData.data());
150  auto amc13Event = gemRawToDigi_->convertWordToAMC13Event(word);
151  LogDebug("GEMRawToDigiModule") << "Event bx:" << iEvent.bunchCrossing() << " lv1Id:" << iEvent.id().event()
152  << " orbitNumber:" << iEvent.orbitNumber();
153  LogDebug("GEMRawToDigiModule") << "AMC13 bx:" << amc13Event->bunchCrossing()
154  << " lv1Id:" << int(amc13Event->lv1Id())
155  << " orbitNumber:" << amc13Event->orbitNumber();
156 
157  // Read AMC data
158  for (auto amcData : *(amc13Event->getAMCpayloads())) {
159  uint8_t amcNum = amcData.amcNum();
160  GEMROMapping::sectorEC amcEC{fedId, amcNum};
161  if (!gemROMap->isValidAMC(amcEC)) {
162  st_amc13.inValidAMC();
163  continue;
164  }
165 
166  GEMAMCStatus st_amc(amc13Event.get(), amcData);
167  if (st_amc.isBad()) {
168  LogDebug("GEMRawToDigiModule") << st_amc;
169  if (keepDAQStatus_) {
170  outAMCStatus.get()->insertDigi(fedId, st_amc);
171  }
172  continue;
173  }
174 
175  uint16_t amcBx = amcData.bunchCrossing();
176  LogDebug("GEMRawToDigiModule") << "AMC no.:" << int(amcData.amcNum()) << " bx:" << int(amcData.bunchCrossing())
177  << " lv1Id:" << int(amcData.lv1Id())
178  << " orbitNumber:" << int(amcData.orbitNumber());
179 
180  // Read GEB data
181  for (auto optoHybrid : *amcData.gebs()) {
182  uint8_t gebId = optoHybrid.inputID();
183  GEMROMapping::chamEC geb_ec{fedId, amcNum, gebId};
184 
185  bool isValidChamber = gemROMap->isValidChamber(geb_ec);
186  if (!isValidChamber) {
187  st_amc.inValidOH();
188  continue;
189  }
190  GEMROMapping::chamDC geb_dc = gemROMap->chamberPos(geb_ec);
191  GEMDetId gemChId = geb_dc.detId;
192 
193  GEMOHStatus st_oh(optoHybrid);
194  if (st_oh.isBad()) {
195  LogDebug("GEMRawToDigiModule") << st_oh;
196  if (keepDAQStatus_) {
197  outOHStatus.get()->insertDigi(gemChId, st_oh);
198  }
199  }
200 
201  //Read vfat data
202  for (auto vfatData : *optoHybrid.vFATs()) {
203  // set vfat fw version
204  vfatData.setVersion(geb_dc.vfatVer);
205  uint16_t vfatId = vfatData.vfatId();
206  GEMROMapping::vfatEC vfat_ec{vfatId, gemChId};
207 
208  if (!gemROMap->isValidChipID(vfat_ec)) {
209  st_oh.inValidVFAT();
210  continue;
211  }
212 
213  GEMROMapping::vfatDC vfat_dc = gemROMap->vfatPos(vfat_ec);
214  vfatData.setPhi(vfat_dc.localPhi);
215  GEMDetId gemId = vfat_dc.detId;
216 
217  GEMVFATStatus st_vfat(amcData, vfatData, vfatData.phi(), readMultiBX_);
218  if (st_vfat.isBad()) {
219  LogDebug("GEMRawToDigiModule") << st_vfat;
220  if (keepDAQStatus_) {
221  outVFATStatus.get()->insertDigi(gemId, st_vfat);
222  }
223  continue;
224  }
225 
226  int bx(vfatData.bc() - amcBx);
227 
228  for (int chan = 0; chan < VFATdata::nChannels; ++chan) {
229  uint8_t chan0xf = 0;
230  if (chan < 64)
231  chan0xf = ((vfatData.lsData() >> chan) & 0x1);
232  else
233  chan0xf = ((vfatData.msData() >> (chan - 64)) & 0x1);
234 
235  // no hits
236  if (chan0xf == 0)
237  continue;
238 
239  GEMROMapping::channelNum chMap{vfat_dc.vfatType, chan};
240  GEMROMapping::stripNum stMap = gemROMap->hitPos(chMap);
241 
242  int stripId = stMap.stNum + vfatData.phi() * GEMeMap::maxChan_;
243 
244  GEMDigi digi(stripId, bx);
245 
246  LogDebug("GEMRawToDigiModule")
247  << "fed: " << fedId << " amc:" << int(amcNum) << " geb:" << int(gebId) << " vfat id:" << int(vfatId)
248  << ",type:" << vfat_dc.vfatType << " id:" << gemId << " ch:" << chMap.chNum << " st:" << digi.strip()
249  << " bx:" << digi.bx();
250 
251  outGEMDigis.get()->insertDigi(gemId, digi);
252 
253  } // end of channel loop
254 
255  if (keepDAQStatus_) {
256  outVFATStatus.get()->insertDigi(gemId, st_vfat);
257  }
258  if (unPackStatusDigis_) {
259  outVFATStatusOld.get()->insertDigi(gemId, GEMVfatStatusDigi(vfatData));
260  }
261 
262  } // end of vfat loop
263 
264  if (keepDAQStatus_) {
265  outOHStatus.get()->insertDigi(gemChId, st_oh);
266  }
267  if (unPackStatusDigis_) {
268  optoHybrid.clearVFATs();
269  outGEBStatus.get()->insertDigi(gemChId.chamberId(), (optoHybrid));
270  }
271 
272  } // end of optohybrid loop
273 
274  if (keepDAQStatus_) {
275  outAMCStatus.get()->insertDigi(fedId, st_amc);
276  }
277  if (unPackStatusDigis_) {
278  amcData.clearGEBs();
279  outAMCdata.get()->insertDigi(amcData.boardId(), (amcData));
280  }
281 
282  } // end of amc loop
283 
284  if (keepDAQStatus_) {
285  outAMC13Status.get()->insertDigi(fedId, st_amc13);
286  }
287 
288  if (unPackStatusDigis_) {
289  amc13Event->clearAMCpayloads();
290  }
291 
292  } // end of amc13Event
293 
294  iEvent.put(std::move(outGEMDigis));
295 
296  if (keepDAQStatus_) {
297  iEvent.put(std::move(outAMC13Status), "AMC13Status");
298  iEvent.put(std::move(outAMCStatus), "AMCStatus");
299  iEvent.put(std::move(outOHStatus), "OHStatus");
300  iEvent.put(std::move(outVFATStatus), "VFATStatus");
301  }
302  if (unPackStatusDigis_) {
303  // to be removed
304  iEvent.put(std::move(outVFATStatusOld), "vfatStatus");
305  iEvent.put(std::move(outGEBStatus), "gebStatus");
306  iEvent.put(std::move(outAMCdata), "AMCdata");
307  iEvent.put(std::move(outAMC13Event), "AMC13Event");
308  }
309 }
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:64
GEMROMapping::vfatDC::vfatType
int vfatType
Definition: GEMROMapping.h:61
GEMOHStatusCollection.h
GEMeMapRcd.h
MessageLogger.h
GEMGEBdataCollection.h
FEDNumbering::MAXGEMFEDID
Definition: FEDNumbering.h:126
GEMRawToDigiModule::unPackStatusDigis_
bool unPackStatusDigis_
Definition: GEMRawToDigiModule.cc:55
edm::Run
Definition: Run.h:45
GEMVFATStatus
Definition: GEMVFATStatus.h:8
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:42
GEMOHStatus::inValidVFAT
void inValidVFAT()
Definition: GEMOHStatus.h:61
GEMRawToDigiModule::readMultiBX_
bool readMultiBX_
Definition: GEMRawToDigiModule.cc:54
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
GEMRawToDigiModule
Definition: GEMRawToDigiModule.cc:38
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
ecaldqm::nChannels
Definition: EcalDQMCommonUtils.h:113
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
GEMAMC13Status::isBad
bool isBad() const
Definition: GEMAMC13Status.h:57
GEMROMapping::sectorEC
Definition: GEMROMapping.h:13
GEMROMapping::stripNum
Definition: GEMROMapping.h:88
GEMAMCdataCollection.h
edm::Handle< FEDRawDataCollection >
GEMRawToDigiModule::keepDAQStatus_
bool keepDAQStatus_
Definition: GEMRawToDigiModule.cc:54
ESGetToken.h
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
GEMROMapping::chamDC::vfatVer
int vfatVer
Definition: GEMROMapping.h:44
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
GEMROMapping::vfatDC::detId
GEMDetId detId
Definition: GEMROMapping.h:62
GEMROMapping::vfatDC::localPhi
int localPhi
Definition: GEMROMapping.h:63
MakerMacros.h
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
GEMRawToDigiModule::fed_token
edm::EDGetTokenT< FEDRawDataCollection > fed_token
Definition: GEMRawToDigiModule.cc:52
GEMRawToDigiModule::globalEndRun
void globalEndRun(edm::Run const &, edm::EventSetup const &) const override
Definition: GEMRawToDigiModule.cc:46
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
GEMAMC13StatusCollection.h
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:53
Run.h
GEMROMapping.h
GEMRawToDigiModule::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: GEMRawToDigiModule.cc:90
Transition.h
ParameterSetDescription.h
GEMAMC13Status
Definition: GEMAMC13Status.h:10
FEDRawDataCollection::FEDData
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Definition: FEDRawDataCollection.cc:19
GEMROMapping::vfatDC
Definition: GEMROMapping.h:60
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
GEMAMCStatus
Definition: GEMAMCStatus.h:8
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
GEMDetId
Definition: GEMDetId.h:18
GEMROMapping::chamEC
Definition: GEMROMapping.h:25
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
GEMOHStatus::isBad
bool isBad() const
Definition: GEMOHStatus.h:67
l1tstage2_dqm_sourceclient-live_cfg.fedId
fedId
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:89
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:90
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:77
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
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:100
GEMVfatStatusDigiCollection.h
GEMRawToDigiModule::gemRawToDigi_
std::unique_ptr< GEMRawToDigi > gemRawToDigi_
Definition: GEMRawToDigiModule.cc:56
EventSetup.h
GEMVFATStatusCollection.h
FEDNumbering::MINGEMFEDID
Definition: FEDNumbering.h:123
AMC13Event.h
GEMAMC13Status::inValidAMC
void inValidAMC()
Definition: GEMAMC13Status.h:51
GEMDigiCollection.h
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
ParameterSet.h
GEMROMapping::chamDC::detId
GEMDetId detId
Definition: GEMROMapping.h:43
EDProducer.h
edm::Event
Definition: Event.h:73
GEMAMCStatusCollection.h
GEMRawToDigiModule::useDBEMap_
bool useDBEMap_
Definition: GEMRawToDigiModule.cc:54
GEMROMapping::vfatEC
Definition: GEMROMapping.h:48
edm::InputTag
Definition: InputTag.h:15
GEMOHStatus
Definition: GEMOHStatus.h:8
GEMeMap::maxChan_
static const int maxChan_
Definition: GEMeMap.h:72
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:116
FEDTrailer.h