CMS 3D CMS Logo

GEMDigiToRawModule.cc
Go to the documentation of this file.
1 
28 
29 class GEMDigiToRawModule : public edm::global::EDProducer<edm::RunCache<GEMROMapping>> {
30 public:
33 
34  // global::EDProducer
35  std::shared_ptr<GEMROMapping> globalBeginRun(edm::Run const&, edm::EventSetup const&) const override;
36  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
37  void globalEndRun(edm::Run const&, edm::EventSetup const&) const override{};
38 
39  // Fill parameters descriptions
40  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
41 
42 private:
46  bool useDBEMap_;
47 };
48 
51 
52 using namespace gem;
53 
55  : event_type_(pset.getParameter<int>("eventType")),
56  digi_token(consumes<GEMDigiCollection>(pset.getParameter<edm::InputTag>("gemDigi"))),
57  useDBEMap_(pset.getParameter<bool>("useDBEMap")) {
58  produces<FEDRawDataCollection>();
59  if (useDBEMap_) {
60  gemEMapToken_ = esConsumes<GEMeMap, GEMeMapRcd, edm::Transition::BeginRun>();
61  }
62 }
63 
66  desc.add<edm::InputTag>("gemDigi", edm::InputTag("simMuonGEMDigis"));
67  desc.add<int>("eventType", 0);
68  desc.add<bool>("useDBEMap", false);
69  descriptions.add("gemPackerDefault", desc);
70 }
71 
72 std::shared_ptr<GEMROMapping> GEMDigiToRawModule::globalBeginRun(edm::Run const&, edm::EventSetup const& iSetup) const {
73  auto gemROmap = std::make_shared<GEMROMapping>();
74  if (useDBEMap_) {
75  const auto& eMap = iSetup.getData(gemEMapToken_);
76  auto gemEMap = std::make_unique<GEMeMap>(eMap);
77  gemEMap->convert(*gemROmap);
78  gemEMap.reset();
79  } else {
80  // no EMap in DB, using dummy
81  auto gemEMap = std::make_unique<GEMeMap>();
82  gemEMap->convertDummy(*gemROmap);
83  gemEMap.reset();
84  }
85  return gemROmap;
86 }
87 
89  auto fedRawDataCol = std::make_unique<FEDRawDataCollection>();
90 
92  iEvent.getByToken(digi_token, gemDigis);
93  if (!gemDigis.isValid()) {
94  iEvent.put(std::move(fedRawDataCol));
95  return;
96  }
97 
98  auto gemROMap = runCache(iEvent.getRun().index());
99 
100  std::vector<std::unique_ptr<AMC13Event>> amc13Events;
101  amc13Events.reserve(FEDNumbering::MAXGEMFEDID - FEDNumbering::MINGEMFEDID + 1);
102 
103  int LV1_id = iEvent.id().event();
104  uint8_t BX_id(iEvent.bunchCrossing());
105  int OrN = iEvent.orbitNumber();
106 
107  // making map of bx GEMDigiCollection
108  // each bx will be saved as new AMC13Event, so GEMDigiCollection needs to be split into bx
109  std::map<int, GEMDigiCollection> gemBxMap;
110  for (auto const& etaPart : *gemDigis) {
111  GEMDetId gemId = etaPart.first;
112  const GEMDigiCollection::Range& digis = etaPart.second;
113  for (auto digi = digis.first; digi != digis.second; ++digi) {
114  int bx = digi->bx();
115  auto search = gemBxMap.find(bx);
116  if (search != gemBxMap.end()) {
117  search->second.insertDigi(gemId, *digi);
118  } else {
119  GEMDigiCollection newGDC;
120  newGDC.insertDigi(gemId, *digi);
121  gemBxMap.insert(std::pair<int, GEMDigiCollection>(bx, newGDC));
122  }
123  }
124  }
125 
127  uint32_t amc13EvtLength = 0;
128  std::unique_ptr<AMC13Event> amc13Event = std::make_unique<AMC13Event>();
129 
130  for (uint8_t amcNum = 0; amcNum <= GEMeMap::maxAMCs_; ++amcNum) {
131  uint32_t amcSize = 0;
132  std::unique_ptr<AMCdata> amcData = std::make_unique<AMCdata>();
133 
134  for (uint8_t gebId = 0; gebId <= GEMeMap::maxGEBs_; ++gebId) {
135  std::unique_ptr<GEBdata> gebData = std::make_unique<GEBdata>();
136  GEMROMapping::chamEC geb_ec{fedId, amcNum, gebId};
137 
138  if (!gemROMap->isValidChamber(geb_ec))
139  continue;
140  GEMROMapping::chamDC geb_dc = gemROMap->chamberPos(geb_ec);
141 
142  auto vfats = gemROMap->getVfats(geb_dc.detId);
143  for (auto const& vfat_ec : vfats) {
144  GEMROMapping::vfatDC vfat_dc = gemROMap->vfatPos(vfat_ec);
145  GEMDetId gemId = vfat_dc.detId;
146  uint16_t vfatId = vfat_ec.vfatAdd;
147 
148  for (auto const& gemBx : gemBxMap) {
149  int bc = BX_id + gemBx.first;
150 
151  bool hasDigi = false;
152  uint64_t lsData = 0;
153  uint64_t msData = 0;
154 
155  GEMDigiCollection inBxGemDigis = gemBx.second;
156  const GEMDigiCollection::Range& range = inBxGemDigis.get(gemId);
157  for (GEMDigiCollection::const_iterator digiIt = range.first; digiIt != range.second; ++digiIt) {
158  const GEMDigi& digi = (*digiIt);
159 
160  int localStrip = digi.strip() - vfat_dc.localPhi * GEMeMap::maxChan_;
161 
162  // skip strips not in current vFat
163  if (localStrip < 0 || localStrip > GEMeMap::maxChan_ - 1)
164  continue;
165 
166  hasDigi = true;
167  GEMROMapping::stripNum stMap = {vfat_dc.vfatType, localStrip};
168  GEMROMapping::channelNum chMap = gemROMap->hitPos(stMap);
169 
170  if (chMap.chNum < 64)
171  lsData |= 1UL << chMap.chNum;
172  else
173  msData |= 1UL << (chMap.chNum - 64);
174 
175  LogDebug("GEMDigiToRawModule")
176  << " fed: " << fedId << " amc:" << int(amcNum) << " geb:" << int(gebId)
177  << " vfat:" << vfat_dc.localPhi << ",type: " << vfat_dc.vfatType << " id:" << gemId
178  << " ch:" << chMap.chNum << " st:" << digi.strip() << " bx:" << digi.bx();
179  }
180 
181  if (!hasDigi)
182  continue;
183  // only make vfat with hits
184  amcSize += 3;
185  auto vfatData = std::make_unique<VFATdata>(geb_dc.vfatVer, bc, 0, vfatId, lsData, msData);
186  gebData->addVFAT(*vfatData);
187  }
188  } // end of vfats in GEB
189 
190  if (!gebData->vFATs()->empty()) {
191  amcSize += 2;
192  gebData->setChamberHeader(gebData->vFATs()->size() * 3, gebId);
193  gebData->setChamberTrailer(LV1_id, BX_id, gebData->vFATs()->size() * 3);
194  amcData->addGEB(*gebData);
195  }
196  } // end of GEB loop
197 
198  if (!amcData->gebs()->empty()) {
199  amcSize += 5;
200  amcData->setAMCheader1(amcSize, BX_id, LV1_id, amcNum);
201  amcData->setAMCheader2(amcNum, OrN, 1);
202  amcData->setGEMeventHeader(amcData->gebs()->size(), 0);
203  amc13Event->addAMCpayload(*amcData);
204  // AMC header in AMC13Event
205  amc13Event->addAMCheader(amcSize, 0, amcNum, 0);
206  amc13EvtLength += amcSize + 1; // AMC data size + AMC header size
207  }
208  } // end of AMC loop
209 
210  if (!amc13Event->getAMCpayloads()->empty()) {
211  // CDFHeader
212  amc13Event->setCDFHeader(event_type_, LV1_id, BX_id, fedId);
213  // AMC13header
214  uint8_t nAMC = amc13Event->getAMCpayloads()->size();
215  amc13Event->setAMC13Header(1, nAMC, OrN);
216  amc13Event->setAMC13Trailer(BX_id, LV1_id, BX_id);
217  //CDF trailer
218  uint32_t EvtLength = amc13EvtLength + 4; // 2 header and 2 trailer
219  amc13Event->setCDFTrailer(EvtLength);
220  amc13Events.emplace_back(std::move(amc13Event));
221  } // finished making amc13Event data
222  } // end of FED loop
223 
224  // read out amc13Events into fedRawData
225  for (const auto& amc13e : amc13Events) {
226  std::vector<uint64_t> words;
227  words.emplace_back(amc13e->getCDFHeader());
228  words.emplace_back(amc13e->getAMC13Header());
229 
230  for (const auto& w : *amc13e->getAMCheaders())
231  words.emplace_back(w);
232 
233  for (const auto& amc : *amc13e->getAMCpayloads()) {
234  words.emplace_back(amc.getAMCheader1());
235  words.emplace_back(amc.getAMCheader2());
236  words.emplace_back(amc.getGEMeventHeader());
237 
238  for (const auto& geb : *amc.gebs()) {
239  words.emplace_back(geb.getChamberHeader());
240 
241  for (const auto& vfat : *geb.vFATs()) {
242  words.emplace_back(vfat.get_fw());
243  words.emplace_back(vfat.get_sw());
244  words.emplace_back(vfat.get_tw());
245  }
246 
247  words.emplace_back(geb.getChamberTrailer());
248  }
249 
250  words.emplace_back(amc.getGEMeventTrailer());
251  words.emplace_back(amc.getAMCTrailer());
252  }
253 
254  words.emplace_back(amc13e->getAMC13Trailer());
255  words.emplace_back(amc13e->getCDFTrailer());
256 
257  FEDRawData& fedRawData = fedRawDataCol->FEDData(amc13e->sourceId());
258 
259  int dataSize = (words.size()) * sizeof(uint64_t);
260  fedRawData.resize(dataSize);
261 
262  uint64_t* w = reinterpret_cast<uint64_t*>(fedRawData.data());
263  for (const auto& word : words) {
264  *(w++) = word;
265  }
266  LogDebug("GEMDigiToRawModule") << "fedId:" << amc13e->sourceId() << " words:" << words.size();
267  }
268 
269  iEvent.put(std::move(fedRawDataCol));
270 }
ConfigurationDescriptions.h
FEDNumbering.h
edm::StreamID
Definition: StreamID.h:30
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
GEMROMapping::vfatDC::vfatType
int vfatType
Definition: GEMROMapping.h:45
GEMeMapRcd.h
MessageLogger.h
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< GEMDigiCollection >
GEMDigi::bx
int16_t bx() const
Definition: GEMDigi.h:27
edm
HLT enums.
Definition: AlignableModifier.h:19
GEMROMapping::chamDC
Definition: GEMROMapping.h:26
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
GEMROMapping::stripNum
Definition: GEMROMapping.h:72
FEDRawData.h
edm::Handle< GEMDigiCollection >
ESGetToken.h
MuonDigiCollection::const_iterator
std::vector< DigiType >::const_iterator const_iterator
Definition: MuonDigiCollection.h:94
FEDRawData
Definition: FEDRawData.h:19
FEDNumbering::MINGEMFEDID
Definition: FEDNumbering.h:123
GEMDigiToRawModule::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: GEMDigiToRawModule.cc:64
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
l1t_dqm_sourceclient-live_cfg.fedRawData
fedRawData
Definition: l1t_dqm_sourceclient-live_cfg.py:188
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::maxGEBs_
static const int maxGEBs_
Definition: GEMeMap.h:62
GEMeMap.h
w
const double w
Definition: UKUtility.cc:23
GEMDigi::strip
uint16_t strip() const
Definition: GEMDigi.h:26
Run.h
GEMROMapping.h
cond::persistency::search
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:21
ParameterSetDescription.h
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
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
GEMDigiToRawModule::globalEndRun
void globalEndRun(edm::Run const &, edm::EventSetup const &) const override
Definition: GEMDigiToRawModule.cc:37
FEDRawDataCollection.h
GEMDigiToRawModule::gemEMapToken_
edm::ESGetToken< GEMeMap, GEMeMapRcd > gemEMapToken_
Definition: GEMDigiToRawModule.cc:45
GEMDigi
Definition: GEMDigi.h:15
GEMDigiToRawModule
Definition: GEMDigiToRawModule.cc:29
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 >
GEMDigiToRawModule::produce
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
Definition: GEMDigiToRawModule.cc:88
InputTag.h
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
GEMeMap::maxAMCs_
static const int maxAMCs_
Definition: GEMeMap.h:65
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
GEMDigiToRawModule::globalBeginRun
std::shared_ptr< GEMROMapping > globalBeginRun(edm::Run const &, edm::EventSetup const &) const override
Definition: GEMDigiToRawModule.cc:72
GEMDigiToRawModule::useDBEMap_
bool useDBEMap_
Definition: GEMDigiToRawModule.cc:46
GEMROMapping::channelNum
Definition: GEMROMapping.h:61
GEMDigiCollection
FEDNumbering::MAXGEMFEDID
Definition: FEDNumbering.h:126
EventSetup.h
MuonDigiCollection::Range
std::pair< const_iterator, const_iterator > Range
Definition: MuonDigiCollection.h:95
amc
Definition: AMCSpec.h:8
AMC13Event.h
GEMDigiCollection.h
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::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
FEDHeader.h
GEMDigiToRawModule::GEMDigiToRawModule
GEMDigiToRawModule(const edm::ParameterSet &pset)
Constructor.
Definition: GEMDigiToRawModule.cc:54
edm::InputTag
Definition: InputTag.h:15
GEMDigiToRawModule::digi_token
edm::EDGetTokenT< GEMDigiCollection > digi_token
Definition: GEMDigiToRawModule.cc:44
GEMeMap::maxChan_
static const int maxChan_
Definition: GEMeMap.h:69
GEMDigiToRawModule::event_type_
int event_type_
Definition: GEMDigiToRawModule.cc:43
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
FEDTrailer.h