Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-07 05:50:21

0001 /** \file
0002  *
0003  *  \author A. Tumanov - Rice
0004  *  But long, long ago...
0005  */
0006 
0007 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0008 #include "DataFormats/CSCDigi/interface/CSCConstants.h"
0009 #include "EventFilter/CSCRawToDigi/interface/CSCDigiToRaw.h"
0010 #include "EventFilter/CSCRawToDigi/interface/CSCDigiToRawAccept.h"
0011 #include "EventFilter/CSCRawToDigi/interface/CSCDCCEventData.h"
0012 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0013 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0014 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0015 #include "boost/dynamic_bitset.hpp"
0016 #include "EventFilter/CSCRawToDigi/interface/bitset_append.h"
0017 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
0018 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
0019 #include "FWCore/Utilities/interface/CRC16.h"
0020 #include "CondFormats/CSCObjects/interface/CSCChamberMap.h"
0021 #include "FWCore/Utilities/interface/Exception.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 
0024 #include <algorithm>
0025 
0026 using namespace edm;
0027 using namespace std;
0028 
0029 CSCDigiToRaw::CSCDigiToRaw(const edm::ParameterSet& pset)
0030     : alctWindowMin_(pset.getParameter<int>("alctWindowMin")),
0031       alctWindowMax_(pset.getParameter<int>("alctWindowMax")),
0032       clctWindowMin_(pset.getParameter<int>("clctWindowMin")),
0033       clctWindowMax_(pset.getParameter<int>("clctWindowMax")),
0034       preTriggerWindowMin_(pset.getParameter<int>("preTriggerWindowMin")),
0035       preTriggerWindowMax_(pset.getParameter<int>("preTriggerWindowMax")),
0036       // pre-LS1 - '2005'. post-LS1 - '2013', Run3 - '2020'
0037       formatVersion_(pset.getParameter<unsigned>("formatVersion")),
0038       // don't check for consistency with trig primitives
0039       // overrides usePreTriggers
0040       packEverything_(pset.getParameter<bool>("packEverything")),
0041       usePreTriggers_(pset.getParameter<bool>("usePreTriggers")),
0042       packByCFEB_(pset.getParameter<bool>("packByCFEB")) {}
0043 
0044 CSCEventData& CSCDigiToRaw::findEventData(const CSCDetId& cscDetId, FindEventDataInfo& info) const {
0045   CSCDetId chamberId = CSCDigiToRawAccept::chamberID(cscDetId);
0046   // find the entry into the map
0047   map<CSCDetId, CSCEventData>::iterator chamberMapItr = info.theChamberDataMap.find(chamberId);
0048   if (chamberMapItr == info.theChamberDataMap.end()) {
0049     // make an entry, telling it the correct chamberType
0050     int chamberType = chamberId.iChamberType();
0051     chamberMapItr = info.theChamberDataMap
0052                         .insert(pair<CSCDetId, CSCEventData>(chamberId, CSCEventData(chamberType, info.formatVersion_)))
0053                         .first;
0054   }
0055   CSCEventData& cscData = chamberMapItr->second;
0056   cscData.dmbHeader()->setCrateAddress(info.theElectronicsMap->crate(cscDetId), info.theElectronicsMap->dmb(cscDetId));
0057 
0058   if (info.formatVersion_ >= 2013) {
0059     // Set DMB version field to distinguish between ME11s and other chambers (ME11 - 2, others - 1)
0060     bool me11 = ((chamberId.station() == 1) && (chamberId.ring() == 4)) ||
0061                 ((chamberId.station() == 1) && (chamberId.ring() == 1));
0062     if (me11) {
0063       cscData.dmbHeader()->setdmbVersion(2);
0064     } else {
0065       cscData.dmbHeader()->setdmbVersion(1);
0066     }
0067   }
0068   return cscData;
0069 }
0070 
0071 void CSCDigiToRaw::add(const CSCStripDigiCollection& stripDigis,
0072                        const CSCCLCTPreTriggerCollection* preTriggers,
0073                        const CSCCLCTPreTriggerDigiCollection* preTriggerDigis,
0074                        FindEventDataInfo& fedInfo) const {
0075   //iterate over chambers with strip digis in them
0076   for (CSCStripDigiCollection::DigiRangeIterator j = stripDigis.begin(); j != stripDigis.end(); ++j) {
0077     CSCDetId cscDetId = (*j).first;
0078     // only digitize if there are pre-triggers
0079 
0080     // determine where the pretriggers are
0081     std::vector<bool> preTriggerInCFEB;
0082     preTriggerInCFEB.resize(CSCConstants::MAX_CFEBS_RUN2);
0083 
0084     // pretrigger flag must be set and the pretrigger collection must be nonzero!
0085     const bool usePreTriggers = usePreTriggers_ and preTriggers != nullptr;
0086     if (!usePreTriggers || packEverything_ ||
0087         (usePreTriggers && CSCDigiToRawAccept::accept(cscDetId,
0088                                                       *preTriggerDigis,
0089                                                       preTriggerWindowMin_,
0090                                                       preTriggerWindowMax_,
0091                                                       CSCConstants::CLCT_CENTRAL_BX,
0092                                                       preTriggerInCFEB))) {
0093       bool me1a = (cscDetId.station() == 1) && (cscDetId.ring() == 4);
0094       bool zplus = (cscDetId.endcap() == 1);
0095       bool me1b = (cscDetId.station() == 1) && (cscDetId.ring() == 1);
0096 
0097       CSCEventData& cscData = findEventData(cscDetId, fedInfo);
0098 
0099       std::vector<CSCStripDigi>::const_iterator digiItr = (*j).second.first;
0100       std::vector<CSCStripDigi>::const_iterator last = (*j).second.second;
0101       for (; digiItr != last; ++digiItr) {
0102         CSCStripDigi digi = *digiItr;
0103         int strip = digi.getStrip();
0104         int cfeb = digi.getCFEB();
0105         // CSC strip digis in ME1/a have CFEB number 0, 1, or 2
0106         // But a pretrigger in ME1/a has CFEB number 4, 5, or 6 (+4)
0107         if (me1a)
0108           cfeb += CSCConstants::NUM_CFEBS_ME1B;
0109 
0110         // At this point, if we are packing by CFEBs and there is no
0111         // pretrigger in this CFEB, ignore this strip digi
0112         if (packByCFEB_ and not preTriggerInCFEB[cfeb])
0113           continue;
0114 
0115         // From LS1 on ME1a strips are unganged
0116         if (fedInfo.formatVersion_ >= 2013) {
0117           if (me1a && zplus) {
0118             digi.setStrip(CSCConstants::NUM_STRIPS_ME1A_UNGANGED + 1 - strip);  // 1-48 -> 48-1
0119           }
0120           if (me1b && !zplus) {
0121             digi.setStrip(CSCConstants::NUM_STRIPS_ME1B + 1 - strip);  // 1-64 -> 64-1
0122           }
0123           if (me1a) {
0124             strip = digi.getStrip();  // reset back 1-16 to 65-80 digi
0125             digi.setStrip(strip + CSCConstants::NUM_STRIPS_ME1B);
0126           }
0127         }
0128         // During Run-1 ME1a strips are triple-ganged
0129         else {
0130           if (me1a && zplus) {
0131             digi.setStrip(CSCConstants::NUM_STRIPS_ME1A_GANGED + 1 - strip);  // 1-16 -> 16-1
0132           }
0133           if (me1b && !zplus) {
0134             digi.setStrip(CSCConstants::NUM_STRIPS_ME1B + 1 - strip);  // 1-64 -> 64-1
0135           }
0136           if (me1a) {
0137             strip = digi.getStrip();  // reset back 1-16 to 65-80 digi
0138             digi.setStrip(strip + CSCConstants::NUM_STRIPS_ME1B);
0139           }
0140         }
0141         cscData.add(digi, cscDetId.layer());
0142       }
0143     }
0144   }
0145 }
0146 
0147 void CSCDigiToRaw::add(const CSCWireDigiCollection& wireDigis,
0148                        const CSCALCTDigiCollection& alctDigis,
0149                        FindEventDataInfo& fedInfo) const {
0150   add(alctDigis, fedInfo);
0151   for (CSCWireDigiCollection::DigiRangeIterator j = wireDigis.begin(); j != wireDigis.end(); ++j) {
0152     CSCDetId cscDetId = (*j).first;
0153     if (packEverything_ || CSCDigiToRawAccept::accept(
0154                                cscDetId, alctDigis, alctWindowMin_, alctWindowMax_, CSCConstants::ALCT_CENTRAL_BX)) {
0155       CSCEventData& cscData = findEventData(cscDetId, fedInfo);
0156       std::vector<CSCWireDigi>::const_iterator digiItr = (*j).second.first;
0157       std::vector<CSCWireDigi>::const_iterator last = (*j).second.second;
0158       for (; digiItr != last; ++digiItr) {
0159         cscData.add(*digiItr, cscDetId.layer());
0160       }
0161     }
0162   }
0163 }
0164 
0165 void CSCDigiToRaw::add(const CSCComparatorDigiCollection& comparatorDigis,
0166                        const CSCCLCTDigiCollection& clctDigis,
0167                        FindEventDataInfo& fedInfo) const {
0168   add(clctDigis, fedInfo);
0169   for (auto const& j : comparatorDigis) {
0170     CSCDetId cscDetId = j.first;
0171     CSCEventData& cscData = findEventData(cscDetId, fedInfo);
0172     if (packEverything_ || CSCDigiToRawAccept::accept(
0173                                cscDetId, clctDigis, clctWindowMin_, clctWindowMax_, CSCConstants::CLCT_CENTRAL_BX)) {
0174       bool me1a = (cscDetId.station() == 1) && (cscDetId.ring() == 4);
0175 
0176       /*
0177         Add the comparator digi to the fedInfo.
0178         Move ME1/A comparators from CFEB=0 to CFEB=4 if this has not
0179         been done already.
0180         Consider the case for triple-ganged and unganged ME1A strips
0181        */
0182       for (auto digi = j.second.first; digi != j.second.second; ++digi) {
0183         if (fedInfo.formatVersion_ >= 2013) {
0184           // unganged case
0185           if (me1a && digi->getStrip() <= CSCConstants::NUM_STRIPS_ME1A_UNGANGED) {
0186             CSCComparatorDigi digi_corr(
0187                 CSCConstants::NUM_STRIPS_ME1B + digi->getStrip(), digi->getComparator(), digi->getTimeBinWord());
0188             cscData.add(digi_corr, cscDetId);
0189           } else {
0190             cscData.add(*digi, cscDetId);
0191           }
0192         }
0193         // triple-ganged case
0194         else {
0195           if (me1a && digi->getStrip() <= CSCConstants::NUM_STRIPS_ME1A_GANGED) {
0196             CSCComparatorDigi digi_corr(
0197                 CSCConstants::NUM_STRIPS_ME1B + digi->getStrip(), digi->getComparator(), digi->getTimeBinWord());
0198             cscData.add(digi_corr, cscDetId.layer());
0199           } else {
0200             cscData.add(*digi, cscDetId.layer());
0201           }
0202         }
0203       }
0204     }
0205   }
0206 }
0207 
0208 void CSCDigiToRaw::add(const CSCALCTDigiCollection& alctDigis, FindEventDataInfo& fedInfo) const {
0209   for (CSCALCTDigiCollection::DigiRangeIterator j = alctDigis.begin(); j != alctDigis.end(); ++j) {
0210     CSCDetId cscDetId = (*j).first;
0211     CSCEventData& cscData = findEventData(cscDetId, fedInfo);
0212 
0213     cscData.add(std::vector<CSCALCTDigi>((*j).second.first, (*j).second.second));
0214   }
0215 }
0216 
0217 void CSCDigiToRaw::add(const CSCCLCTDigiCollection& clctDigis, FindEventDataInfo& fedInfo) const {
0218   for (CSCCLCTDigiCollection::DigiRangeIterator j = clctDigis.begin(); j != clctDigis.end(); ++j) {
0219     CSCDetId cscDetId = (*j).first;
0220     CSCEventData& cscData = findEventData(cscDetId, fedInfo);
0221 
0222     bool me11a = cscDetId.station() == 1 && cscDetId.ring() == 4;
0223     //CLCTs are packed by chamber not by A/B parts in ME11
0224     //me11a appears only in simulation with SLHC algorithm settings
0225     //without the shift, it's impossible to distinguish A and B parts
0226     if (me11a && fedInfo.formatVersion_ >= 2013) {
0227       std::vector<CSCCLCTDigi> shiftedDigis((*j).second.first, (*j).second.second);
0228       for (std::vector<CSCCLCTDigi>::iterator iC = shiftedDigis.begin(); iC != shiftedDigis.end(); ++iC) {
0229         if (iC->getCFEB() < CSCConstants::NUM_CFEBS_ME1A_UNGANGED) {  //sanity check, mostly
0230           (*iC) = CSCCLCTDigi(iC->isValid(),
0231                               iC->getQuality(),
0232                               iC->getPattern(),
0233                               iC->getStripType(),
0234                               iC->getBend(),
0235                               iC->getStrip(),
0236                               iC->getCFEB() + CSCConstants::NUM_CFEBS_ME1B,
0237                               iC->getBX(),
0238                               iC->getTrknmb(),
0239                               iC->getFullBX());
0240         }
0241       }
0242       cscData.add(shiftedDigis);
0243     } else {
0244       cscData.add(std::vector<CSCCLCTDigi>((*j).second.first, (*j).second.second));
0245     }
0246   }
0247 }
0248 
0249 void CSCDigiToRaw::add(const CSCCorrelatedLCTDigiCollection& corrLCTDigis, FindEventDataInfo& fedInfo) const {
0250   for (CSCCorrelatedLCTDigiCollection::DigiRangeIterator j = corrLCTDigis.begin(); j != corrLCTDigis.end(); ++j) {
0251     CSCDetId cscDetId = (*j).first;
0252     CSCEventData& cscData = findEventData(cscDetId, fedInfo);
0253 
0254     bool me11a = cscDetId.station() == 1 && cscDetId.ring() == 4;
0255     //LCTs are packed by chamber not by A/B parts in ME11
0256     //me11a appears only in simulation with SLHC algorithm settings
0257     //without the shift, it's impossible to distinguish A and B parts
0258     if (me11a && fedInfo.formatVersion_ >= 2013) {
0259       std::vector<CSCCorrelatedLCTDigi> shiftedDigis((*j).second.first, (*j).second.second);
0260       for (std::vector<CSCCorrelatedLCTDigi>::iterator iC = shiftedDigis.begin(); iC != shiftedDigis.end(); ++iC) {
0261         if (iC->getStrip() < CSCConstants::NUM_HALF_STRIPS_ME1A_UNGANGED) {  //sanity check, mostly
0262           (*iC) = CSCCorrelatedLCTDigi(iC->getTrknmb(),
0263                                        iC->isValid(),
0264                                        iC->getQuality(),
0265                                        iC->getKeyWG(),
0266                                        iC->getStrip() + CSCConstants::NUM_HALF_STRIPS_ME1B,
0267                                        iC->getPattern(),
0268                                        iC->getBend(),
0269                                        iC->getBX(),
0270                                        iC->getMPCLink(),
0271                                        iC->getBX0(),
0272                                        iC->getSyncErr(),
0273                                        iC->getCSCID());
0274         }
0275       }
0276       cscData.add(shiftedDigis);
0277     } else {
0278       cscData.add(std::vector<CSCCorrelatedLCTDigi>((*j).second.first, (*j).second.second));
0279     }
0280   }
0281 }
0282 
0283 void CSCDigiToRaw::add(const CSCShowerDigiCollection& cscShowerDigis,
0284                        FindEventDataInfo& fedInfo,
0285                        enum CSCShowerType showerType) const {
0286   for (const auto& shower : cscShowerDigis) {
0287     const CSCDetId& cscDetId = shower.first;
0288     CSCEventData& cscData = findEventData(cscDetId, fedInfo);
0289 
0290     switch (showerType) {
0291       case CSCShowerType::lctShower:
0292         cscData.addShower(std::vector<CSCShowerDigi>(shower.second.first, shower.second.second));
0293         break;
0294       case CSCShowerType::anodeShower:
0295         cscData.addAnodeShower(std::vector<CSCShowerDigi>(shower.second.first, shower.second.second));
0296         break;
0297       case CSCShowerType::cathodeShower:
0298         cscData.addCathodeShower(std::vector<CSCShowerDigi>(shower.second.first, shower.second.second));
0299         break;
0300       case CSCShowerType::anodeALCTShower:
0301         cscData.addAnodeALCTShower(std::vector<CSCShowerDigi>(shower.second.first, shower.second.second));
0302         break;
0303       default:
0304         cscData.addShower(std::vector<CSCShowerDigi>(shower.second.first, shower.second.second));
0305     }
0306   }
0307 }
0308 
0309 void CSCDigiToRaw::add(const GEMPadDigiClusterCollection& gemPadClusters, FindEventDataInfo& fedInfo) const {
0310   for (const auto& jclus : gemPadClusters) {
0311     const GEMDetId& gemDetId = jclus.first;
0312 
0313     const int zendcap = gemDetId.region() == 1 ? 1 : 2;
0314     CSCDetId cscDetId(zendcap, gemDetId.station(), 1, gemDetId.chamber(), 0);
0315     CSCEventData& cscData = findEventData(cscDetId, fedInfo);
0316 
0317     cscData.add(std::vector<GEMPadDigiCluster>(jclus.second.first, jclus.second.second), gemDetId);
0318   }
0319 }
0320 
0321 void CSCDigiToRaw::createFedBuffers(const CSCStripDigiCollection& stripDigis,
0322                                     const CSCWireDigiCollection& wireDigis,
0323                                     const CSCComparatorDigiCollection& comparatorDigis,
0324                                     const CSCALCTDigiCollection& alctDigis,
0325                                     const CSCCLCTDigiCollection& clctDigis,
0326                                     const CSCCLCTPreTriggerCollection* preTriggers,
0327                                     const CSCCLCTPreTriggerDigiCollection* preTriggerDigis,
0328                                     const CSCCorrelatedLCTDigiCollection& correlatedLCTDigis,
0329                                     const CSCShowerDigiCollection* cscShowerDigis,
0330                                     const CSCShowerDigiCollection* anodeShowerDigis,
0331                                     const CSCShowerDigiCollection* cathodeShowerDigis,
0332                                     const CSCShowerDigiCollection* anodeALCTShowerDigis,
0333                                     const GEMPadDigiClusterCollection* gemPadDigiClusters,
0334                                     FEDRawDataCollection& fed_buffers,
0335                                     const CSCChamberMap* mapping,
0336                                     const EventID& eid) const {
0337   //get fed object from fed_buffers
0338   // make a map from the index of a chamber to the event data from it
0339   FindEventDataInfo fedInfo{mapping, formatVersion_};
0340 
0341   add(stripDigis, preTriggers, preTriggerDigis, fedInfo);
0342   add(wireDigis, alctDigis, fedInfo);
0343   add(comparatorDigis, clctDigis, fedInfo);
0344   add(correlatedLCTDigis, fedInfo);
0345 
0346   // Starting Run-3, the CSC DAQ will pack/unpack CSC showers
0347   // lctShower 4-bits sent from OTMB to MPC in trigger data
0348   // anodeShower - anodeHMT 2-bits in OTMB
0349   // cathodeShower - cathodeHMT 2-bits in OTMB
0350   // anodeALCTShower - vector of anode HMT 2-bits  per ALCT bx sent by ALCT board to OTMB
0351   if (cscShowerDigis) {
0352     add(*cscShowerDigis, fedInfo, CSCShowerType::lctShower);
0353     add(*anodeShowerDigis, fedInfo, CSCShowerType::anodeShower);
0354     add(*cathodeShowerDigis, fedInfo, CSCShowerType::cathodeShower);
0355     add(*anodeALCTShowerDigis, fedInfo, CSCShowerType::anodeALCTShower);
0356   }
0357 
0358   // Starting Run-3, the CSC DAQ will pack/unpack GEM clusters
0359   if (gemPadDigiClusters) {
0360     add(*gemPadDigiClusters, fedInfo);
0361   }
0362   int l1a = eid.event();  //need to add increments or get it from lct digis
0363   int bx = l1a;           //same as above
0364 
0365   if (fedInfo.formatVersion_ == 2005)  /// Handle pre-LS1 format data
0366   {
0367     std::map<int, CSCDCCEventData> dccMap;
0368     //idcc goes from startingFed to startingFED+7
0369     for (int idcc = FEDNumbering::MINCSCFEDID; idcc <= FEDNumbering::MAXCSCFEDID; ++idcc) {
0370       dccMap.insert(std::pair<int, CSCDCCEventData>(idcc, CSCDCCEventData(idcc, CSCConstants::NUM_DDUS, bx, l1a)));
0371     }
0372 
0373     for (int idcc = FEDNumbering::MINCSCFEDID; idcc <= FEDNumbering::MAXCSCFEDID; ++idcc) {
0374       // for every chamber with data, add to a DDU in this DCC Event
0375       for (map<CSCDetId, CSCEventData>::iterator chamberItr = fedInfo.theChamberDataMap.begin();
0376            chamberItr != fedInfo.theChamberDataMap.end();
0377            ++chamberItr) {
0378         int indexDCC = mapping->slink(chamberItr->first);
0379         if (indexDCC == idcc) {
0380           //FIXME (What does this mean? Is something wrong?)
0381           std::map<int, CSCDCCEventData>::iterator dccMapItr = dccMap.find(indexDCC);
0382           if (dccMapItr == dccMap.end()) {
0383             throw cms::Exception("CSCDigiToRaw") << "Bad DCC number:" << indexDCC;
0384           }
0385           // get id's based on ChamberId from mapping
0386 
0387           int dduId = mapping->ddu(chamberItr->first);
0388           int dduSlot = mapping->dduSlot(chamberItr->first);
0389           int dduInput = mapping->dduInput(chamberItr->first);
0390           int dmbId = mapping->dmb(chamberItr->first);
0391           dccMapItr->second.addChamber(chamberItr->second, dduId, dduSlot, dduInput, dmbId, formatVersion_);
0392         }
0393       }
0394     }
0395 
0396     // FIXME: FEDRawData size set to 2*64 to add FED header and trailer
0397     for (std::map<int, CSCDCCEventData>::iterator dccMapItr = dccMap.begin(); dccMapItr != dccMap.end(); ++dccMapItr) {
0398       boost::dynamic_bitset<> dccBits = dccMapItr->second.pack();
0399       FEDRawData& fedRawData = fed_buffers.FEDData(dccMapItr->first);
0400       fedRawData.resize(dccBits.size());
0401       //fill data with dccEvent
0402       bitset_utilities::bitsetToChar(dccBits, fedRawData.data());
0403       FEDTrailer cscFEDTrailer(fedRawData.data() + (fedRawData.size() - 8));
0404       cscFEDTrailer.set(fedRawData.data() + (fedRawData.size() - 8),
0405                         fedRawData.size() / 8,
0406                         evf::compute_crc(fedRawData.data(), fedRawData.size()),
0407                         0,
0408                         0);
0409     }
0410   }
0411   /// Handle post-LS1 format data
0412   else if (formatVersion_ >= 2013) {
0413     std::map<int, CSCDDUEventData> dduMap;
0414     unsigned int ddu_fmt_version = 0x7;  /// 2013 Format
0415     const unsigned postLS1_map[] = {841, 842, 843, 844, 845, 846, 847, 848, 849, 831, 832, 833,
0416                                     834, 835, 836, 837, 838, 839, 861, 862, 863, 864, 865, 866,
0417                                     867, 868, 869, 851, 852, 853, 854, 855, 856, 857, 858, 859};
0418 
0419     /// Create dummy DDU buffers
0420     for (unsigned int i = 0; i < 36; i++) {
0421       unsigned int iddu = postLS1_map[i];
0422       // make a new one
0423       CSCDDUHeader newDDUHeader(bx, l1a, iddu, ddu_fmt_version);
0424 
0425       dduMap.insert(std::pair<int, CSCDDUEventData>(iddu, CSCDDUEventData(newDDUHeader)));
0426     }
0427 
0428     /// Loop over post-LS1 DDU FEDs
0429     for (unsigned int i = 0; i < 36; i++) {
0430       unsigned int iddu = postLS1_map[i];
0431       // for every chamber with data, add to a DDU in this DCC Event
0432       for (map<CSCDetId, CSCEventData>::iterator chamberItr = fedInfo.theChamberDataMap.begin();
0433            chamberItr != fedInfo.theChamberDataMap.end();
0434            ++chamberItr) {
0435         unsigned int indexDDU = mapping->slink(chamberItr->first);
0436 
0437         /// Lets handle possible mapping issues
0438         // Still preLS1 DCC FEDs mapping
0439         if ((indexDDU >= FEDNumbering::MINCSCFEDID) && (indexDDU <= FEDNumbering::MAXCSCFEDID)) {
0440           int dduID = mapping->ddu(chamberItr->first);  // try to switch to DDU ID mapping
0441           // DDU ID is in expectedi post-LS1 FED ID range
0442           if ((dduID >= FEDNumbering::MINCSCDDUFEDID) && (dduID <= FEDNumbering::MAXCSCDDUFEDID)) {
0443             indexDDU = dduID;
0444           } else  // Messy
0445           {
0446             // Lets try to change pre-LS1 1-36 ID range to post-LS1 MINCSCDDUFEDID - MAXCSCDDUFEDID range
0447             dduID &= 0xFF;
0448             // indexDDU = FEDNumbering::MINCSCDDUFEDID + dduID-1;
0449             if ((dduID <= 36) && (dduID > 0))
0450               indexDDU = postLS1_map[dduID - 1];
0451           }
0452         }
0453 
0454         if (indexDDU == iddu) {
0455           std::map<int, CSCDDUEventData>::iterator dduMapItr = dduMap.find(indexDDU);
0456           if (dduMapItr == dduMap.end()) {
0457             throw cms::Exception("CSCDigiToRaw") << "Bad DDU number:" << indexDDU;
0458           }
0459           // get id's based on ChamberId from mapping
0460 
0461           int dduInput = mapping->dduInput(chamberItr->first);
0462           int dmbId = mapping->dmb(chamberItr->first);
0463           // int crateId  = mapping->crate(chamberItr->first);
0464           dduMapItr->second.add(chamberItr->second, dmbId, dduInput, formatVersion_);
0465         }
0466       }
0467     }
0468 
0469     // FIXME: FEDRawData size set to 2*64 to add FED header and trailer
0470     for (std::map<int, CSCDDUEventData>::iterator dduMapItr = dduMap.begin(); dduMapItr != dduMap.end(); ++dduMapItr) {
0471       boost::dynamic_bitset<> dduBits = dduMapItr->second.pack();
0472       FEDRawData& fedRawData = fed_buffers.FEDData(dduMapItr->first);
0473       fedRawData.resize(dduBits.size() / 8);
0474       //fill data with dduEvent
0475       bitset_utilities::bitsetToChar(dduBits, fedRawData.data());
0476       FEDTrailer cscFEDTrailer(fedRawData.data() + (fedRawData.size() - 8));
0477       cscFEDTrailer.set(fedRawData.data() + (fedRawData.size() - 8),
0478                         fedRawData.size() / 8,
0479                         evf::compute_crc(fedRawData.data(), fedRawData.size()),
0480                         0,
0481                         0);
0482     }
0483   }
0484 }