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