@@ -100,9 +100,9 @@ void GEMDigiToRawModule::produce(edm::StreamID iID, edm::Event& iEvent, edm::Eve
100100 std::vector<std::unique_ptr<AMC13Event>> amc13Events;
101101 amc13Events.reserve (FEDNumbering::MAXGEMFEDID - FEDNumbering::MINGEMFEDID + 1 );
102102
103- uint32_t LV1_id = iEvent.id ().event ();
104- uint16_t BX_id = iEvent.bunchCrossing ();
105- uint32_t OrN = iEvent.orbitNumber ();
103+ int LV1_id = iEvent.id ().event ();
104+ uint8_t BX_id ( iEvent.bunchCrossing () );
105+ int OrN = iEvent.orbitNumber ();
106106
107107 // making map of bx GEMDigiCollection
108108 // each bx will be saved as new AMC13Event, so GEMDigiCollection needs to be split into bx
@@ -123,37 +123,36 @@ void GEMDigiToRawModule::produce(edm::StreamID iID, edm::Event& iEvent, edm::Eve
123123 }
124124 }
125125
126- for (unsigned int fedId = FEDNumbering::MINGEMFEDID; fedId <= FEDNumbering::MAXGEMFEDID ; ++fedId) {
126+ for (unsigned int fedId = FEDNumbering::MINGEMFEDID; fedId <= FEDNumbering::MAXME0FEDID ; ++fedId) {
127127 uint32_t amc13EvtLength = 0 ;
128128 std::unique_ptr<AMC13Event> amc13Event = std::make_unique<AMC13Event>();
129129
130- for (auto const & gemBx : gemBxMap ) {
131- int bx = gemBx. first ;
132- GEMDigiCollection inBxGemDigis = gemBx. second ;
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>() ;
133133
134- for (uint8_t amcNum = 0 ; amcNum < GEMeMap::maxAMCs_ ; ++amcNum ) {
135- uint32_t amcSize = 0 ;
136- std::unique_ptr<AMCdata> amcData = std::make_unique<AMCdata>() ;
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} ;
137137
138- for ( uint8_t gebId = 0 ; gebId < GEMeMap::maxGEBs_; ++gebId) {
139- std::unique_ptr<GEBdata> gebData = std::make_unique<GEBdata>() ;
140- GEMROMapping::chamEC geb_ec{fedId, amcNum, gebId} ;
138+ if (!gemROMap-> isValidChamber (geb_ec))
139+ continue ;
140+ GEMROMapping::chamDC geb_dc = gemROMap-> chamberPos (geb_ec) ;
141141
142- if (!gemROMap->isValidChamber (geb_ec))
143- continue ;
144- GEMROMapping::chamDC geb_dc = gemROMap->chamberPos (geb_ec);
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 ;
145147
146- auto vfats = gemROMap->getVfats (geb_dc.detId );
147- for (auto const & vfat_ec : vfats) {
148- GEMROMapping::vfatDC vfat_dc = gemROMap->vfatPos (vfat_ec);
149- GEMDetId gemId = vfat_dc.detId ;
150- uint16_t vfatId = vfat_ec.vfatAdd ;
148+ for (auto const & gemBx : gemBxMap) {
149+ int bc = BX_id + gemBx.first ;
151150
152151 bool hasDigi = false ;
153-
154152 uint64_t lsData = 0 ; // /<channels from 1to64
155153 uint64_t msData = 0 ; // /<channels from 65to128
156154
155+ GEMDigiCollection inBxGemDigis = gemBx.second ;
157156 const GEMDigiCollection::Range& range = inBxGemDigis.get (gemId);
158157 for (GEMDigiCollection::const_iterator digiIt = range.first ; digiIt != range.second ; ++digiIt) {
159158 const GEMDigi& digi = (*digiIt);
@@ -183,36 +182,30 @@ void GEMDigiToRawModule::produce(edm::StreamID iID, edm::Event& iEvent, edm::Eve
183182 continue ;
184183 // only make vfat with hits
185184 amcSize += 3 ;
186- auto vfatData = std::make_unique<VFATdata>(geb_dc.vfatVer , bx , 0 , vfatId, lsData, msData);
185+ auto vfatData = std::make_unique<VFATdata>(geb_dc.vfatVer , bc , 0 , vfatId, lsData, msData);
187186 gebData->addVFAT (*vfatData);
188-
189- } // end of vfats in GEB
190-
191- if (!gebData->vFATs ()->empty ()) {
192- amcSize += 2 ;
193- gebData->setChamberHeader (gebData->vFATs ()->size () * 3 , gebId);
194- gebData->setChamberTrailer (0 , 0 , gebData->vFATs ()->size () * 3 );
195- amcData->addGEB (*gebData);
196187 }
197188
198- } // end of GEB loop
199-
200- if (!amcData->gebs ()->empty ()) {
201- amcSize += 5 ;
202- amcData->setAMCheader1 (amcSize, bx, LV1_id, amcNum);
203- amcData->setAMCheader2 (amcNum, OrN, 1 );
204- amcData->setGEMeventHeader (amcData->gebs ()->size (), 0 );
205- amc13Event->addAMCpayload (*amcData);
206- // AMC header in AMC13Event
207- uint8_t Blk_No = 0 ;
208- uint8_t AMC_No = 0 ;
209- uint16_t BoardID = 0 ;
210- amc13Event->addAMCheader (amcSize, Blk_No, AMC_No, BoardID);
211- amc13EvtLength += amcSize + 1 ; // AMC data size + AMC header size
189+ } // end of vfats in GEB
190+
191+ if (!gebData->vFATs ()->empty ()) {
192+ amcSize += 2 ;
193+ gebData->setChamberHeader (gebData->vFATs ()->size () * 3 , gebId);
194+ gebData->setChamberTrailer (LV1_id, BX_id, gebData->vFATs ()->size () * 3 );
195+ amcData->addGEB (*gebData);
212196 }
197+ } // end of GEB loop
213198
214- } // end of AMC loop
215- } // end of BX loop
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
216209
217210 if (!amc13Event->getAMCpayloads ()->empty ()) {
218211 // CDFHeader
@@ -223,9 +216,8 @@ void GEMDigiToRawModule::produce(edm::StreamID iID, edm::Event& iEvent, edm::Eve
223216 amc13Event->setAMC13Trailer (BX_id, LV1_id, BX_id);
224217 // CDF trailer
225218 uint32_t EvtLength = amc13EvtLength + 4 ; // 2 header and 2 trailer
226- LogDebug (" GEMDigiToRawModule" ) << " EvtLength: " << int (EvtLength);
227-
228219 amc13Event->setCDFTrailer (EvtLength);
220+
229221 amc13Events.emplace_back (std::move (amc13Event));
230222 } // finished making amc13Event data
231223 } // end of FED loop
@@ -270,7 +262,6 @@ void GEMDigiToRawModule::produce(edm::StreamID iID, edm::Event& iEvent, edm::Eve
270262
271263 uint64_t * w = reinterpret_cast <uint64_t *>(fedRawData.data ());
272264 for (const auto & word : words) {
273- LogDebug (" GEMDigiToRawModule" ) << std::bitset<64 >(word);
274265 *(w++) = word;
275266 }
276267 LogDebug (" GEMDigiToRawModule" ) << " words " << words.size ();
0 commit comments