CMS 3D CMS Logo

GEMDigiToRawModule.cc
Go to the documentation of this file.
1 
11 
18 
20 
21 using namespace gem;
22 
24  : event_type_(pset.getParameter<int>("eventType")),
25  digi_token(consumes<GEMDigiCollection>(pset.getParameter<edm::InputTag>("gemDigi"))),
26  useDBEMap_(pset.getParameter<bool>("useDBEMap")) {
27  produces<FEDRawDataCollection>();
28 }
29 
32  desc.add<edm::InputTag>("gemDigi", edm::InputTag("simMuonGEMDigis"));
33  desc.add<int>("eventType", 0);
34  desc.add<bool>("useDBEMap", false);
35  descriptions.add("gemPackerDefault", desc);
36 }
37 
38 std::shared_ptr<GEMROMapping> GEMDigiToRawModule::globalBeginRun(edm::Run const&, edm::EventSetup const& iSetup) const {
39  auto gemROmap = std::make_shared<GEMROMapping>();
40  if (useDBEMap_) {
41  edm::ESHandle<GEMeMap> gemEMapRcd;
42  iSetup.get<GEMeMapRcd>().get(gemEMapRcd);
43  auto gemEMap = std::make_unique<GEMeMap>(*(gemEMapRcd.product()));
44  gemEMap->convert(*gemROmap);
45  gemEMap.reset();
46  } else {
47  // no EMap in DB, using dummy
48  auto gemEMap = std::make_unique<GEMeMap>();
49  gemEMap->convertDummy(*gemROmap);
50  gemEMap.reset();
51  }
52  return gemROmap;
53 }
54 
56  auto fedRawDataCol = std::make_unique<FEDRawDataCollection>();
57 
59  iEvent.getByToken(digi_token, gemDigis);
60  if (!gemDigis.isValid()) {
61  iEvent.put(std::move(fedRawDataCol));
62  return;
63  }
64 
65  auto gemROMap = runCache(iEvent.getRun().index());
66 
67  std::vector<std::unique_ptr<AMC13Event>> amc13Events;
68  amc13Events.reserve(FEDNumbering::MAXGEMFEDID - FEDNumbering::MINGEMFEDID + 1);
69 
71  std::unique_ptr<AMC13Event> amc13Event = std::make_unique<AMC13Event>();
72 
73  for (uint8_t amcNum = 0; amcNum < GEMeMap::maxAMCs_; ++amcNum) {
74  std::unique_ptr<AMCdata> amcData = std::make_unique<AMCdata>();
75 
76  for (uint8_t gebId = 0; gebId < GEMeMap::maxGEBs_; ++gebId) {
77  std::unique_ptr<GEBdata> gebData = std::make_unique<GEBdata>();
78  GEMROMapping::chamEC geb_ec{fedId, amcNum, gebId};
79 
80  if (!gemROMap->isValidChamber(geb_ec))
81  continue;
82  GEMROMapping::chamDC geb_dc = gemROMap->chamberPos(geb_ec);
83 
84  auto vfats = gemROMap->getVfats(geb_dc.detId);
85  for (auto vfat_ec : vfats) {
86  GEMROMapping::vfatDC vfat_dc = gemROMap->vfatPos(vfat_ec);
87  GEMDetId gemId = vfat_dc.detId;
88  uint16_t vfatId = vfat_ec.vfatAdd;
89 
90  for (uint16_t bc = 0; bc < 2 * GEMeMap::amcBX_; ++bc) {
91  bool hasDigi = false;
92 
93  uint64_t lsData = 0;
94  uint64_t msData = 0;
95 
96  GEMDigiCollection::Range range = gemDigis->get(gemId);
97  for (GEMDigiCollection::const_iterator digiIt = range.first; digiIt != range.second; ++digiIt) {
98  const GEMDigi& digi = (*digiIt);
99  if (digi.bx() != bc - GEMeMap::amcBX_)
100  continue;
101 
102  int localStrip = digi.strip() - vfat_dc.localPhi * GEMeMap::maxChan_;
103 
104  // skip strips not in current vFat
105  if (localStrip < 0 || localStrip > GEMeMap::maxChan_ - 1)
106  continue;
107 
108  hasDigi = true;
109  GEMROMapping::stripNum stMap = {vfat_dc.vfatType, localStrip};
110  GEMROMapping::channelNum chMap = gemROMap->hitPos(stMap);
111 
112  if (chMap.chNum < 64)
113  lsData |= 1UL << chMap.chNum;
114  else
115  msData |= 1UL << (chMap.chNum - 64);
116 
117  LogDebug("GEMDigiToRawModule")
118  << " fed: " << fedId << " amc:" << int(amcNum) << " geb:" << int(gebId)
119  << " vfat:" << vfat_dc.localPhi << ",type: " << vfat_dc.vfatType << " id:" << gemId
120  << " ch:" << chMap.chNum << " st:" << digi.strip() << " bx:" << digi.bx();
121  }
122 
123  if (!hasDigi)
124  continue;
125  // only make vfat with hits
126  auto vfatData = std::make_unique<VFATdata>(geb_dc.vfatVer, bc, 0, vfatId, lsData, msData);
127  gebData->addVFAT(*vfatData);
128  }
129 
130  } // end of vfats in GEB
131 
132  if (!gebData->vFATs()->empty()) {
133  gebData->setChamberHeader(gebData->vFATs()->size() * 3, gebId);
134  gebData->setChamberTrailer(0, 0, gebData->vFATs()->size() * 3);
135  amcData->addGEB(*gebData);
136  }
137 
138  } // end of GEB loop
139 
140  if (!amcData->gebs()->empty()) {
141  amcData->setAMCheader1(0, GEMeMap::amcBX_, 0, amcNum);
142  amcData->setAMCheader2(amcNum, 0, 1);
143  amcData->setGEMeventHeader(amcData->gebs()->size(), 0);
144  amc13Event->addAMCpayload(*amcData);
145  }
146 
147  } // end of AMC loop
148 
149  if (!amc13Event->getAMCpayloads()->empty()) {
150  // CDFHeader
151  uint32_t LV1_id = iEvent.id().event();
152  uint16_t BX_id = iEvent.bunchCrossing();
153  amc13Event->setCDFHeader(event_type_, LV1_id, BX_id, fedId);
154 
155  // AMC13header
156  uint8_t CalTyp = 1;
157  uint8_t nAMC = amc13Event->getAMCpayloads()->size();
158  uint32_t OrN = 2;
159  amc13Event->setAMC13Header(CalTyp, nAMC, OrN);
160 
161  for (unsigned short i = 0; i < amc13Event->nAMC(); ++i) {
162  uint32_t AMC_size = 0;
163  uint8_t Blk_No = 0;
164  uint8_t AMC_No = 0;
165  uint16_t BoardID = 0;
166  amc13Event->addAMCheader(AMC_size, Blk_No, AMC_No, BoardID);
167  }
168 
169  //AMC13 trailer
170  uint8_t Blk_NoT = 0;
171  uint8_t LV1_idT = 0;
172  uint16_t BX_idT = BX_id;
173  amc13Event->setAMC13Trailer(Blk_NoT, LV1_idT, BX_idT);
174  //CDF trailer
175  uint32_t EvtLength = 0;
176  amc13Event->setCDFTrailer(EvtLength);
177  amc13Events.emplace_back(std::move(amc13Event));
178  } // finished making amc13Event data
179 
180  } // end of FED loop
181 
182  // read out amc13Events into fedRawData
183  for (const auto& amc13e : amc13Events) {
184  std::vector<uint64_t> words;
185  words.emplace_back(amc13e->getCDFHeader());
186  words.emplace_back(amc13e->getAMC13Header());
187 
188  for (const auto& w : *amc13e->getAMCheaders())
189  words.emplace_back(w);
190 
191  for (const auto& amc : *amc13e->getAMCpayloads()) {
192  words.emplace_back(amc.getAMCheader1());
193  words.emplace_back(amc.getAMCheader2());
194  words.emplace_back(amc.getGEMeventHeader());
195 
196  for (const auto& geb : *amc.gebs()) {
197  words.emplace_back(geb.getChamberHeader());
198 
199  for (const auto& vfat : *geb.vFATs()) {
200  words.emplace_back(vfat.get_fw());
201  words.emplace_back(vfat.get_sw());
202  words.emplace_back(vfat.get_tw());
203  }
204 
205  words.emplace_back(geb.getChamberTrailer());
206  }
207 
208  words.emplace_back(amc.getGEMeventTrailer());
209  words.emplace_back(amc.getAMCTrailer());
210  }
211 
212  words.emplace_back(amc13e->getAMC13Trailer());
213  words.emplace_back(amc13e->getCDFTrailer());
214 
215  FEDRawData& fedRawData = fedRawDataCol->FEDData(amc13e->sourceId());
216 
217  int dataSize = (words.size()) * sizeof(uint64_t);
218  fedRawData.resize(dataSize);
219 
220  uint64_t* w = reinterpret_cast<uint64_t*>(fedRawData.data());
221  for (const auto& word : words)
222  *(w++) = word;
223 
224  LogDebug("GEMDigiToRawModule") << " words " << words.size();
225  }
226 
227  iEvent.put(std::move(fedRawDataCol));
228 }
FEDNumbering.h
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
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:372
mps_fire.i
i
Definition: mps_fire.py:355
GEMROMapping::vfatDC::vfatType
int vfatType
Definition: GEMROMapping.h:45
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
ESHandle.h
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
GEMROMapping::chamDC
Definition: GEMROMapping.h:26
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
GEMROMapping::stripNum
Definition: GEMROMapping.h:72
FEDRawData.h
edm::Handle< GEMDigiCollection >
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:30
GEMROMapping::chamDC::vfatVer
int vfatVer
Definition: GEMROMapping.h:28
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
GEMDigi::bx
int bx() const
Definition: GEMDigi.h:27
GEMROMapping::vfatDC::detId
GEMDetId detId
Definition: GEMROMapping.h:46
GEMROMapping::vfatDC::localPhi
int localPhi
Definition: GEMROMapping.h:47
GEMDigi::strip
int strip() const
Definition: GEMDigi.h:26
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
l1t_dqm_sourceclient-live_cfg.fedRawData
fedRawData
Definition: l1t_dqm_sourceclient-live_cfg.py:188
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:64
w
const double w
Definition: UKUtility.cc:23
Run.h
edm::ESHandle
Definition: DTSurvey.h:22
ParameterSetDescription.h
GEMROMapping::vfatDC
Definition: GEMROMapping.h:44
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
GEMROMapping::channelNum::chNum
int chNum
Definition: GEMROMapping.h:63
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
GEMeMap::amcBX_
static const int amcBX_
Definition: GEMeMap.h:70
Event.h
GEMDetId
Definition: GEMDetId.h:17
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
edm::EventSetup
Definition: EventSetup.h:57
l1tstage2_dqm_sourceclient-live_cfg.fedId
fedId
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:88
get
#define get
gem
Definition: AMC13Event.h:6
GEMDigiToRawModule::produce
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
Definition: GEMDigiToRawModule.cc:55
InputTag.h
GEMeMap::maxAMCs_
static const int maxAMCs_
Definition: GEMeMap.h:65
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:38
GEMDigiToRawModule::useDBEMap_
bool useDBEMap_
Definition: GEMDigiToRawModule.h:43
GEMROMapping::channelNum
Definition: GEMROMapping.h:61
GEMDigiCollection
FEDNumbering::MAXGEMFEDID
Definition: FEDNumbering.h:124
EventSetup.h
MuonDigiCollection::Range
std::pair< const_iterator, const_iterator > Range
Definition: MuonDigiCollection.h:95
amc
Definition: AMCSpec.h:8
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
ParameterSet.h
GEMROMapping::chamDC::detId
GEMDetId detId
Definition: GEMROMapping.h:27
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
FEDHeader.h
GEMDigiToRawModule.h
GEMDigiToRawModule::GEMDigiToRawModule
GEMDigiToRawModule(const edm::ParameterSet &pset)
Constructor.
Definition: GEMDigiToRawModule.cc:23
edm::InputTag
Definition: InputTag.h:15
GEMDigiToRawModule::digi_token
edm::EDGetTokenT< GEMDigiCollection > digi_token
Definition: GEMDigiToRawModule.h:42
GEMeMap::maxChan_
static const int maxChan_
Definition: GEMeMap.h:69
GEMeMapRcd
Definition: GEMeMapRcd.h:23
GEMDigiToRawModule::event_type_
int event_type_
Definition: GEMDigiToRawModule.h:41
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
FEDTrailer.h