Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-10 01:53:46

0001 ///
0002 /// \class l1t::GtRecordDump.cc
0003 ///
0004 /// Description: Dump/Analyze Input Collections for GT.
0005 ///
0006 /// Implementation:
0007 ///    Based off of Michael Mulhearn's YellowParamTester
0008 ///
0009 /// \author: Brian Winer Ohio State
0010 ///
0011 
0012 //
0013 //  This simple module simply retreives the YellowParams object from the event
0014 //  setup, and sends its payload as an INFO message, for debugging purposes.
0015 //
0016 
0017 #include "FWCore/Framework/interface/MakerMacros.h"
0018 
0019 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0020 //#include "FWCore/ParameterSet/interface/InputTag.h"
0021 
0022 // system include files
0023 #include <fstream>
0024 #include <iomanip>
0025 #include <memory>
0026 
0027 // user include files
0028 //   base class
0029 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0030 
0031 #include "FWCore/Framework/interface/Event.h"
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 #include "FWCore/Utilities/interface/EDGetToken.h"
0034 #include "FWCore/Utilities/interface/InputTag.h"
0035 #include "FWCore/Framework/interface/EventSetup.h"
0036 #include "FWCore/Framework/interface/Frameworkfwd.h"
0037 
0038 #include "DataFormats/L1Trigger/interface/EGamma.h"
0039 #include "DataFormats/L1Trigger/interface/Muon.h"
0040 #include "DataFormats/L1Trigger/interface/Tau.h"
0041 #include "DataFormats/L1Trigger/interface/Jet.h"
0042 #include "DataFormats/L1Trigger/interface/EtSum.h"
0043 
0044 #include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
0045 #include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"
0046 #include "DataFormats/L1TGlobal/interface/GlobalObject.h"
0047 
0048 #include "DataFormats/L1TGlobal/interface/GlobalObjectMapFwd.h"
0049 #include "DataFormats/L1TGlobal/interface/GlobalObjectMap.h"
0050 #include "DataFormats/L1TGlobal/interface/GlobalObjectMapRecord.h"
0051 
0052 #include "L1Trigger/L1TGlobal/interface/L1TGlobalUtil.h"
0053 
0054 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0055 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0056 
0057 using namespace edm;
0058 using namespace std;
0059 
0060 namespace l1t {
0061 
0062   // class declaration
0063   class GtRecordDump : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0064   public:
0065     explicit GtRecordDump(const edm::ParameterSet&);
0066     ~GtRecordDump() override{};
0067     void beginRun(edm::Run const&, edm::EventSetup const&) override {}
0068     void analyze(const edm::Event&, const edm::EventSetup&) override;
0069     void endRun(edm::Run const&, edm::EventSetup const&) override;
0070 
0071     InputTag uGtAlgInputTag;
0072     InputTag uGtExtInputTag;
0073     EDGetToken egToken;
0074     EDGetToken muToken;
0075     EDGetToken tauToken;
0076     EDGetToken jetToken;
0077     EDGetToken etsumToken;
0078     EDGetToken uGtAlgToken;
0079     EDGetToken uGtExtToken;
0080     EDGetToken uGtObjectMapToken;
0081 
0082     void dumpTestVectors(int bx,
0083                          std::ofstream& myCout,
0084                          Handle<BXVector<l1t::Muon>> muons,
0085                          Handle<BXVector<l1t::EGamma>> egammas,
0086                          Handle<BXVector<l1t::Tau>> taus,
0087                          Handle<BXVector<l1t::Jet>> jets,
0088                          Handle<BXVector<l1t::EtSum>> etsums,
0089                          Handle<BXVector<GlobalAlgBlk>> uGtAlg,
0090                          Handle<BXVector<GlobalExtBlk>> uGtExt);
0091 
0092     cms_uint64_t formatMuon(std::vector<l1t::Muon>::const_iterator mu);
0093     unsigned int formatEG(std::vector<l1t::EGamma>::const_iterator eg);
0094     unsigned int formatTau(std::vector<l1t::Tau>::const_iterator tau);
0095     unsigned int formatJet(std::vector<l1t::Jet>::const_iterator jet);
0096     unsigned int formatMissET(std::vector<l1t::EtSum>::const_iterator etSum);
0097     unsigned int formatTotalET(std::vector<l1t::EtSum>::const_iterator etSum);
0098     unsigned int formatTowerCounts(std::vector<l1t::EtSum>::const_iterator etSum);
0099     unsigned int formatAsym(std::vector<l1t::EtSum>::const_iterator etSum);
0100     unsigned int formatHMB(std::vector<l1t::EtSum>::const_iterator etSum);
0101     std::pair<unsigned int, unsigned int> formatCentrality(std::vector<l1t::EtSum>::const_iterator etSum);
0102     std::map<std::string, std::vector<int>> m_algoSummary;
0103 
0104     unsigned int m_absBx;
0105     int m_bxOffset;
0106 
0107     std::ofstream m_testVectorFile;
0108 
0109     bool m_dumpTestVectors;
0110     bool m_dumpGTRecord;
0111     bool m_dumpObjectMap;
0112     bool m_dumpTriggerResults;
0113     int m_minBx;
0114     int m_maxBx;
0115     int m_minBxVectors;
0116     int m_maxBxVectors;
0117 
0118     std::unique_ptr<L1TGlobalUtil> m_gtUtil;
0119 
0120   private:
0121     int m_tvVersion;
0122   };
0123 
0124   GtRecordDump::GtRecordDump(const edm::ParameterSet& iConfig) {
0125     uGtAlgInputTag = iConfig.getParameter<InputTag>("uGtAlgInputTag");
0126     uGtExtInputTag = iConfig.getParameter<InputTag>("uGtExtInputTag");
0127     egToken = consumes<BXVector<l1t::EGamma>>(iConfig.getParameter<InputTag>("egInputTag"));
0128     muToken = consumes<BXVector<l1t::Muon>>(iConfig.getParameter<InputTag>("muInputTag"));
0129     tauToken = consumes<BXVector<l1t::Tau>>(iConfig.getParameter<InputTag>("tauInputTag"));
0130     jetToken = consumes<BXVector<l1t::Jet>>(iConfig.getParameter<InputTag>("jetInputTag"));
0131     etsumToken = consumes<BXVector<l1t::EtSum>>(iConfig.getParameter<InputTag>("etsumInputTag"));
0132     uGtAlgToken = consumes<BXVector<GlobalAlgBlk>>(uGtAlgInputTag);
0133     uGtExtToken = consumes<BXVector<GlobalExtBlk>>(uGtExtInputTag);
0134     uGtObjectMapToken = consumes<GlobalObjectMapRecord>(iConfig.getParameter<InputTag>("uGtObjectMapInputTag"));
0135 
0136     m_minBx = iConfig.getParameter<int>("minBx");
0137     m_maxBx = iConfig.getParameter<int>("maxBx");
0138     m_dumpGTRecord = iConfig.getParameter<bool>("dumpGTRecord");
0139     m_dumpObjectMap = iConfig.getParameter<bool>("dumpGTObjectMap");
0140     m_dumpTriggerResults = iConfig.getParameter<bool>("dumpTrigResults");
0141 
0142     m_minBxVectors = iConfig.getParameter<int>("minBxVec");
0143     m_maxBxVectors = iConfig.getParameter<int>("maxBxVec");
0144     m_dumpTestVectors = iConfig.getParameter<bool>("dumpVectors");
0145     std::string fileName = iConfig.getParameter<std::string>("tvFileName");
0146     if (m_dumpTestVectors)
0147       m_testVectorFile.open(fileName.c_str());
0148     m_tvVersion = iConfig.getParameter<int>("tvVersion");
0149 
0150     m_bxOffset = iConfig.getParameter<int>("bxOffset");
0151 
0152     m_absBx = 0;
0153     m_absBx += m_bxOffset;
0154 
0155     std::string preScaleFileName = iConfig.getParameter<std::string>("psFileName");
0156     unsigned int preScColumn = iConfig.getParameter<int>("psColumn");
0157 
0158     m_gtUtil = std::make_unique<L1TGlobalUtil>(
0159         iConfig, consumesCollector(), *this, uGtAlgInputTag, uGtExtInputTag, l1t::UseEventSetupIn::Event);
0160     m_gtUtil->OverridePrescalesAndMasks(preScaleFileName, preScColumn);
0161   }
0162 
0163   // loop over events
0164   void GtRecordDump::analyze(const edm::Event& iEvent, const edm::EventSetup& evSetup) {
0165     //inputs
0166     Handle<BXVector<l1t::EGamma>> egammas;
0167     iEvent.getByToken(egToken, egammas);
0168 
0169     Handle<BXVector<l1t::Muon>> muons;
0170     iEvent.getByToken(muToken, muons);
0171 
0172     Handle<BXVector<l1t::Tau>> taus;
0173     iEvent.getByToken(tauToken, taus);
0174 
0175     Handle<BXVector<l1t::Jet>> jets;
0176     iEvent.getByToken(jetToken, jets);
0177 
0178     Handle<BXVector<l1t::EtSum>> etsums;
0179     iEvent.getByToken(etsumToken, etsums);
0180 
0181     Handle<BXVector<GlobalAlgBlk>> uGtAlg;
0182     iEvent.getByToken(uGtAlgToken, uGtAlg);
0183 
0184     Handle<BXVector<GlobalExtBlk>> uGtExt;
0185     iEvent.getByToken(uGtExtToken, uGtExt);
0186 
0187     Handle<GlobalObjectMapRecord> gtObjectMapRecord;
0188     iEvent.getByToken(uGtObjectMapToken, gtObjectMapRecord);
0189 
0190     //Fill the L1 result maps
0191     m_gtUtil->retrieveL1(iEvent, evSetup, uGtAlgToken);
0192 
0193     LogDebug("GtRecordDump") << "retrieved L1 data " << endl;
0194 
0195     // grab the map for the final decisions
0196     const std::vector<std::pair<std::string, bool>> initialDecisions = m_gtUtil->decisionsInitial();
0197     const std::vector<std::pair<std::string, bool>> intermDecisions = m_gtUtil->decisionsInterm();
0198     const std::vector<std::pair<std::string, bool>> finalDecisions = m_gtUtil->decisionsFinal();
0199     const std::vector<std::pair<std::string, double>> prescales = m_gtUtil->prescales();
0200     const std::vector<std::pair<std::string, std::vector<int>>> masks = m_gtUtil->masks();
0201 
0202     LogDebug("GtRecordDump") << "retrieved all event vectors " << endl;
0203 
0204     // Dump the results
0205     if (m_dumpTriggerResults) {
0206       cout << "    Bit                  Algorithm Name                                      Init    aBXM  Final   PS "
0207               "Factor     Num Bx Masked    "
0208            << endl;
0209       cout << "========================================================================================================"
0210               "======================="
0211            << endl;
0212     }
0213     for (unsigned int i = 0; i < initialDecisions.size(); i++) {
0214       // get the name and trigger result
0215       std::string name = (initialDecisions.at(i)).first;
0216       bool resultInit = (initialDecisions.at(i)).second;
0217 
0218       //  put together our map of algorithms and counts across events
0219       if (m_algoSummary.count(name) == 0) {
0220         std::vector<int> tst;
0221         tst.resize(3);
0222         m_algoSummary[name] = tst;
0223       }
0224       if (resultInit)
0225         (m_algoSummary.find(name)->second).at(0) += 1;
0226 
0227       // get prescaled and final results (need some error checking here)
0228       bool resultInterm = (intermDecisions.at(i)).second;
0229       if (resultInterm)
0230         (m_algoSummary.find(name)->second).at(1) += 1;
0231       bool resultFin = (finalDecisions.at(i)).second;
0232       if (resultFin)
0233         (m_algoSummary.find(name)->second).at(2) += 1;
0234 
0235       // get the prescale and mask (needs some error checking here)
0236       double prescale = (prescales.at(i)).second;
0237       std::vector<int> mask = (masks.at(i)).second;
0238 
0239       if (m_dumpTriggerResults && name != "NULL")
0240         cout << std::dec << setfill(' ') << "   " << setw(5) << i << "   " << setw(60) << name.c_str() << "   "
0241              << setw(7) << resultInit << setw(7) << resultInterm << setw(7) << resultFin << setw(10) << prescale
0242              << setw(11) << mask.size() << endl;
0243     }
0244     bool finOR = m_gtUtil->getFinalOR();
0245     if (m_dumpTriggerResults) {
0246       cout << "                                                                                    FinalOR = " << finOR
0247            << endl;
0248       cout << "========================================================================================================"
0249               "========================"
0250            << endl;
0251     }
0252 
0253     if (m_dumpObjectMap) {
0254       if (!gtObjectMapRecord.isValid()) {
0255         edm::LogWarning("GtRecordDump")
0256             << " Warning: GlobalObjectMapRecord requested in configuration, but not found in the event." << std::endl;
0257       } else {
0258         const std::vector<GlobalObjectMap>& objMaps = gtObjectMapRecord->gtObjectMap();
0259         for (size_t imap = 0; imap < objMaps.size(); imap++) {
0260           GlobalObjectMap oMap = objMaps.at(imap);
0261 
0262           int bit = oMap.algoBitNumber();  //  same as bit from L1T Menu
0263           int mapDecision = oMap.algoGtlResult();
0264 
0265           // Check Object Map Result Agrees with GlobalAlgBlk result
0266           if (mapDecision != (finalDecisions.at(bit)).second) {
0267             std::cout << "WARNING: GlobalAlgBlk and ObjectMap Disagree on result for bit " << bit
0268                       << " Alg: " << oMap.algoName() << std::endl;
0269           }
0270 
0271           // dump only if we have a positive trigger
0272           if (mapDecision != 0) {
0273             // Header info
0274             std::cout
0275                 << " -------------------------------------------------------------------------------------------- \n"
0276                 << " Bit " << setw(3) << bit << " Decision " << setw(2) << mapDecision << " Alg Name " << setw(40)
0277                 << oMap.algoName() << std::endl;
0278 
0279             // Combination
0280             const std::vector<GlobalLogicParser::OperandToken>& opTokenVecObjMap = oMap.operandTokenVector();
0281             const std::vector<L1TObjectTypeInCond>& condObjTypeVec = oMap.objectTypeVector();
0282             //         const std::vector<CombinationsInCond>& condCombinations = oMapcombinationVector();
0283 
0284             for (size_t iCond = 0; iCond < opTokenVecObjMap.size(); iCond++) {
0285               std::cout << "       " << iCond << ") Condition Token: " << opTokenVecObjMap.at(iCond).tokenName
0286                         << "  Types: ";
0287               std::vector<l1t::GlobalObject> condObjType = condObjTypeVec[iCond];
0288               for (size_t iCondType = 0; iCondType < condObjType.size(); iCondType++) {
0289                 std::cout << condObjType.at(iCondType) << "  ";
0290               }
0291               std::cout << std::endl;
0292 
0293               const CombinationsInCond* condComb = oMap.getCombinationsInCond(iCond);
0294               std::cout << "            Combinations in Condition [" << condComb->size() << "] : ";
0295               for (std::vector<SingleCombInCond>::const_iterator itComb = (*condComb).begin();
0296                    itComb != (*condComb).end();
0297                    itComb++) {
0298                 // loop over objects in a combination for a given condition
0299                 //
0300                 unsigned int iType = 0;
0301                 std::cout << "(";
0302                 for (SingleCombInCond::const_iterator itObject = (*itComb).begin(); itObject != (*itComb).end();
0303                      itObject++) {
0304                   // loop over types for the object in a combination.  This object might have more then one type (i.e. mu-eg)
0305                   //
0306 
0307                   //                     for (size_t iType =0; iType < condObjType.size(); iType++) {
0308 
0309                   // get object type and push indices on the list
0310                   //
0311                   //const l1t::GlobalObject objTypeVal = condObjType.at(iType);
0312 
0313                   std::cout << (*itObject);
0314                   //std::cout <<objTypeVal << "@" << (*itObject);
0315                   if (iType < condObjType.size() - 1)
0316                     std::cout << ",";
0317                   //std::cout
0318                   //<< "\tAdd object of type " << objTypeVal << " and index " << (*itObject) << " to the seed list."
0319                   //<< std::endl;
0320 
0321                   //                     } // end loop over objs in combination
0322                   iType++;
0323 
0324                 }  //end loop over objects for a condition
0325                 std::cout << ")  ";
0326               }
0327               std::cout << std::endl;
0328             }
0329           }  //end if alg fired
0330         }    //end loop over maps
0331       }      //end if valid record
0332     }        //end if dump maps
0333 
0334     if (m_dumpGTRecord) {
0335       cout << " -----------------------------------------------------  " << endl;
0336       cout << " *********** Run " << std::dec << iEvent.id().run() << " Event " << iEvent.id().event()
0337            << " **************  " << endl;
0338       cout << " ----------------------------------------------------- " << endl;
0339 
0340       //Loop over BX
0341       for (int i = m_minBx; i <= m_maxBx; ++i) {
0342         cout << " ========= Rel BX = " << std::dec << i << " ======  Total BX = " << m_absBx << "   ==========" << endl;
0343 
0344         //Loop over EGamma
0345         int nObj = 0;
0346         cout << " ------ EGammas -------- " << endl;
0347         if (egammas.isValid()) {
0348           if (i >= egammas->getFirstBX() && i <= egammas->getLastBX()) {
0349             for (std::vector<l1t::EGamma>::const_iterator eg = egammas->begin(i); eg != egammas->end(i); ++eg) {
0350               cout << "  " << std::dec << std::setw(2) << std::setfill(' ') << nObj << std::setfill('0') << ")";
0351               cout << "   Pt " << std::dec << std::setw(3) << eg->hwPt() << " (0x" << std::hex << std::setw(3)
0352                    << std::setfill('0') << eg->hwPt() << ")";
0353               cout << "   Eta " << std::dec << std::setw(3) << eg->hwEta() << " (0x" << std::hex << std::setw(2)
0354                    << std::setfill('0') << (eg->hwEta() & 0xff) << ")";
0355               cout << "   Phi " << std::dec << std::setw(3) << eg->hwPhi() << " (0x" << std::hex << std::setw(2)
0356                    << std::setfill('0') << eg->hwPhi() << ")";
0357               cout << "   Iso " << std::dec << std::setw(1) << eg->hwIso();
0358               cout << "   Qual " << std::dec << std::setw(1) << eg->hwQual();
0359               cout << endl;
0360               nObj++;
0361             }
0362           } else {
0363             cout << "No EG stored for this bx " << i << endl;
0364           }
0365         } else {
0366           cout << "No EG Data in this event " << endl;
0367         }
0368 
0369         //Loop over Muons
0370         nObj = 0;
0371         cout << " ------ Muons --------" << endl;
0372         if (muons.isValid()) {
0373           if (i >= muons->getFirstBX() && i <= muons->getLastBX()) {
0374             for (std::vector<l1t::Muon>::const_iterator mu = muons->begin(i); mu != muons->end(i); ++mu) {
0375               cout << "  " << std::dec << std::setw(2) << std::setfill(' ') << nObj << std::setfill('0') << ")";
0376               cout << "   Pt " << std::dec << std::setw(3) << mu->hwPt() << " (0x" << std::hex << std::setw(3)
0377                    << std::setfill('0') << mu->hwPt() << ")";
0378               cout << "   EtaAtVtx " << std::dec << std::setw(3) << mu->hwEtaAtVtx() << " (0x" << std::hex
0379                    << std::setw(3) << std::setfill('0') << (mu->hwEtaAtVtx() & 0x1ff) << ")";
0380               cout << "   Eta " << std::dec << std::setw(3) << mu->hwEta() << " (0x" << std::hex << std::setw(3)
0381                    << std::setfill('0') << (mu->hwEta() & 0x1ff) << ")";
0382               cout << "   PhiAtVtx " << std::dec << std::setw(3) << mu->hwPhiAtVtx() << " (0x" << std::hex
0383                    << std::setw(3) << std::setfill('0') << mu->hwPhiAtVtx() << ")";
0384               cout << "   Phi " << std::dec << std::setw(3) << mu->hwPhi() << " (0x" << std::hex << std::setw(3)
0385                    << std::setfill('0') << mu->hwPhi() << ")";
0386               cout << "   Iso " << std::dec << std::setw(1) << mu->hwIso();
0387               cout << "   Qual " << std::dec << std::setw(1) << mu->hwQual();
0388               cout << "   Chrg " << std::dec << std::setw(1) << mu->hwCharge();
0389               cout << endl;
0390               nObj++;
0391             }
0392           } else {
0393             cout << "No Muons stored for this bx " << i << endl;
0394           }
0395         } else {
0396           cout << "No Muon Data in this event " << endl;
0397         }
0398 
0399         //Loop over Taus
0400         nObj = 0;
0401         cout << " ------ Taus ----------" << endl;
0402         if (taus.isValid()) {
0403           if (i >= taus->getFirstBX() && i <= taus->getLastBX()) {
0404             for (std::vector<l1t::Tau>::const_iterator tau = taus->begin(i); tau != taus->end(i); ++tau) {
0405               cout << "  " << std::dec << std::setw(2) << std::setfill(' ') << nObj << std::setfill('0') << ")";
0406               cout << "   Pt " << std::dec << std::setw(3) << tau->hwPt() << " (0x" << std::hex << std::setw(3)
0407                    << std::setfill('0') << tau->hwPt() << ")";
0408               cout << "   Eta " << std::dec << std::setw(3) << tau->hwEta() << " (0x" << std::hex << std::setw(2)
0409                    << std::setfill('0') << (tau->hwEta() & 0xff) << ")";
0410               cout << "   Phi " << std::dec << std::setw(3) << tau->hwPhi() << " (0x" << std::hex << std::setw(2)
0411                    << std::setfill('0') << tau->hwPhi() << ")";
0412               cout << "   Iso " << std::dec << std::setw(1) << tau->hwIso();
0413               cout << "   Qual " << std::dec << std::setw(1) << tau->hwQual();
0414               cout << endl;
0415               nObj++;
0416             }
0417           } else {
0418             cout << "No Taus stored for this bx " << i << endl;
0419           }
0420         } else {
0421           cout << "No Tau Data in this event " << endl;
0422         }
0423 
0424         //Loop over Jets
0425         nObj = 0;
0426         cout << " ------ Jets ----------" << endl;
0427         if (jets.isValid()) {
0428           if (i >= jets->getFirstBX() && i <= jets->getLastBX()) {
0429             for (std::vector<l1t::Jet>::const_iterator jet = jets->begin(i); jet != jets->end(i); ++jet) {
0430               cout << "  " << std::dec << std::setw(2) << std::setfill(' ') << nObj << std::setfill('0') << ")";
0431               cout << "   Pt " << std::dec << std::setw(3) << jet->hwPt() << " (0x" << std::hex << std::setw(3)
0432                    << std::setfill('0') << jet->hwPt() << ")";
0433               cout << "   Eta " << std::dec << std::setw(3) << jet->hwEta() << " (0x" << std::hex << std::setw(2)
0434                    << std::setfill('0') << (jet->hwEta() & 0xff) << ")";
0435               cout << "   Phi " << std::dec << std::setw(3) << jet->hwPhi() << " (0x" << std::hex << std::setw(2)
0436                    << std::setfill('0') << jet->hwPhi() << ")";
0437               cout << "   Qual " << std::dec << std::setw(1) << jet->hwQual();
0438               cout << endl;
0439               nObj++;
0440             }
0441           } else {
0442             cout << "No Jets stored for this bx " << i << endl;
0443           }
0444         } else {
0445           cout << "No jet Data in this event " << endl;
0446         }
0447 
0448         //Dump Content
0449         cout << " ------ EtSums ----------" << endl;
0450         if (etsums.isValid()) {
0451           if (i >= etsums->getFirstBX() && i <= etsums->getLastBX()) {
0452             for (std::vector<l1t::EtSum>::const_iterator etsum = etsums->begin(i); etsum != etsums->end(i); ++etsum) {
0453               switch (etsum->getType()) {
0454                 case l1t::EtSum::EtSumType::kMissingEt:
0455                   cout << " ETM:  ";
0456                   break;
0457                 case l1t::EtSum::EtSumType::kMissingEtHF:
0458                   cout << " ETMHF:";
0459                   break;
0460                 case l1t::EtSum::EtSumType::kMissingHtHF:
0461                   cout << " HTMHF:";
0462                   break;
0463                 case l1t::EtSum::EtSumType::kMissingHt:
0464                   cout << " HTM:  ";
0465                   break;
0466                 case l1t::EtSum::EtSumType::kTotalEt:
0467                   cout << " ETT:  ";
0468                   break;
0469                 case l1t::EtSum::EtSumType::kTotalEtEm:
0470                   cout << " ETTem:";
0471                   break;
0472                 case l1t::EtSum::EtSumType::kTotalHt:
0473                   cout << " HTT:  ";
0474                   break;
0475                 case l1t::EtSum::EtSumType::kTowerCount:
0476                   cout << " TowerCounts:  ";
0477                   break;
0478                 case l1t::EtSum::EtSumType::kAsymEt:
0479                   cout << " AsymEt:  ";
0480                   break;
0481                 case l1t::EtSum::EtSumType::kAsymHt:
0482                   cout << " AsymHt:  ";
0483                   break;
0484                 case l1t::EtSum::EtSumType::kAsymEtHF:
0485                   cout << " AsymEtHF:  ";
0486                   break;
0487                 case l1t::EtSum::EtSumType::kAsymHtHF:
0488                   cout << " AsymHtHF:  ";
0489                   break;
0490                 case l1t::EtSum::EtSumType::kMinBiasHFP0:
0491                   cout << " HFP0: ";
0492                   break;
0493                 case l1t::EtSum::EtSumType::kMinBiasHFM0:
0494                   cout << " HFM0: ";
0495                   break;
0496                 case l1t::EtSum::EtSumType::kMinBiasHFP1:
0497                   cout << " HFP1: ";
0498                   break;
0499                 case l1t::EtSum::EtSumType::kMinBiasHFM1:
0500                   cout << " HFM1: ";
0501                   break;
0502                 case l1t::EtSum::EtSumType::kCentrality:
0503                   cout << " Centrality: ";
0504                   break;
0505                 default:
0506                   cout << " Unknown: ";
0507                   break;
0508               }
0509               cout << " Et " << std::dec << std::setw(3) << etsum->hwPt() << " (0x" << std::hex << std::setw(3)
0510                    << std::setfill('0') << etsum->hwPt() << ")";
0511               if (etsum->getType() == l1t::EtSum::EtSumType::kMissingEt ||
0512                   etsum->getType() == l1t::EtSum::EtSumType::kMissingHt ||
0513                   etsum->getType() == l1t::EtSum::EtSumType::kMissingEtHF)
0514                 cout << " Phi " << std::dec << std::setw(3) << etsum->hwPhi() << " (0x" << std::hex << std::setw(2)
0515                      << std::setfill('0') << etsum->hwPhi() << ")";
0516               cout << endl;
0517             }
0518           } else {
0519             cout << "No EtSums stored for this bx " << i << endl;
0520           }
0521         } else {
0522           cout << "No EtSum Data in this event " << endl;
0523         }
0524 
0525         // Dump the output record
0526         cout << " ------ uGtExt ----------" << endl;
0527         if (uGtExt.isValid()) {
0528           if (i >= uGtExt->getFirstBX() && i <= uGtExt->getLastBX()) {
0529             for (std::vector<GlobalExtBlk>::const_iterator extBlk = uGtExt->begin(i); extBlk != uGtExt->end(i);
0530                  ++extBlk) {
0531               extBlk->print(std::cout);
0532             }
0533           } else {
0534             cout << "No Ext Conditions stored for this bx " << i << endl;
0535           }
0536         } else {
0537           cout << "No uGtExt Data in this event " << endl;
0538         }
0539 
0540         // Dump the output record
0541         cout << " ------ uGtAlg ----------" << endl;
0542         if (uGtAlg.isValid()) {
0543           if (i >= uGtAlg->getFirstBX() && i <= uGtAlg->getLastBX()) {
0544             for (std::vector<GlobalAlgBlk>::const_iterator algBlk = uGtAlg->begin(i); algBlk != uGtAlg->end(i);
0545                  ++algBlk) {
0546               algBlk->print(std::cout);
0547             }
0548           } else {
0549             cout << "No Alg Decisions stored for this bx " << i << endl;
0550           }
0551         } else {
0552           cout << "No uGtAlg Data in this event " << endl;
0553         }
0554 
0555       }  //loop over Bx
0556       cout << std::dec << endl;
0557     }  //if dumpGtRecord
0558 
0559     // Dump Test Vectors for this bx
0560     if (m_dumpTestVectors) {
0561       for (int i = m_minBxVectors; i <= m_maxBxVectors; i++) {
0562         //         if(  (i>=egammas->getFirstBX() && i<=egammas->getLastBX())&&
0563         //        (i>=muons->getFirstBX()   && i<=muons->getLastBX())  &&
0564         //        (i>=taus->getFirstBX()    && i<=taus->getLastBX())   &&
0565         //        (i>=jets->getFirstBX()    && i<=jets->getLastBX())   &&
0566         //        (i>=etsums->getFirstBX()  && i<=etsums->getLastBX()) &&
0567         //        (i>=uGtAlg->getFirstBX()  && i<=uGtAlg->getLastBX()) &&
0568         //        (i>=uGtAlg->getFirstBX()  && i<=uGtAlg->getLastBX()) ) {
0569         dumpTestVectors(i, m_testVectorFile, muons, egammas, taus, jets, etsums, uGtAlg, uGtExt);
0570         //   } else {
0571         //        edm::LogWarning("GtRecordDump") << "WARNING: Not enough information to dump test vectors for this bx=" << i << endl;
0572         //   }
0573       }
0574     }
0575   }
0576 
0577   // ------------ method called when ending the processing of a run  ------------
0578 
0579   void GtRecordDump::endRun(edm::Run const&, edm::EventSetup const&) {
0580     // Dump the results
0581     cout << "=========================== Global Trigger Summary Report  ==================================" << endl;
0582     cout << "                       Algorithm Name                              Init     aBXM     Final   " << endl;
0583     cout << "=============================================================================================" << endl;
0584     for (std::map<std::string, std::vector<int>>::const_iterator itAlgo = m_algoSummary.begin();
0585          itAlgo != m_algoSummary.end();
0586          itAlgo++) {
0587       std::string name = itAlgo->first;
0588       int initCnt = (itAlgo->second).at(0);
0589       int initPre = (itAlgo->second).at(1);
0590       int initFnl = (itAlgo->second).at(2);
0591       if (name != "NULL")
0592         cout << std::dec << setfill(' ') << setw(60) << name.c_str() << setw(10) << initCnt << setw(10) << initPre
0593              << setw(10) << initFnl << endl;
0594     }
0595     cout
0596         << "==========================================================================================================="
0597         << endl;
0598   }
0599 
0600   void GtRecordDump::dumpTestVectors(int bx,
0601                                      std::ofstream& myOutFile,
0602                                      Handle<BXVector<l1t::Muon>> muons,
0603                                      Handle<BXVector<l1t::EGamma>> egammas,
0604                                      Handle<BXVector<l1t::Tau>> taus,
0605                                      Handle<BXVector<l1t::Jet>> jets,
0606                                      Handle<BXVector<l1t::EtSum>> etsums,
0607                                      Handle<BXVector<GlobalAlgBlk>> uGtAlg,
0608                                      Handle<BXVector<GlobalExtBlk>> uGtExt) {
0609     const int empty = 0;
0610 
0611     // Dump Bx (4 digits)
0612     myOutFile << std::dec << std::setw(4) << std::setfill('0') << m_absBx;
0613 
0614     // Dump 8 Muons (16 digits + space)
0615     int nDumped = 0;
0616     if (muons.isValid()) {
0617       for (std::vector<l1t::Muon>::const_iterator mu = muons->begin(bx); mu != muons->end(bx); ++mu) {
0618         cms_uint64_t packedWd = formatMuon(mu);
0619         if (nDumped < 8) {
0620           myOutFile << " " << std::hex << std::setw(16) << std::setfill('0') << packedWd;
0621           nDumped++;
0622         }
0623       }
0624     }
0625     for (int i = nDumped; i < 8; i++) {
0626       myOutFile << " " << std::hex << std::setw(16) << std::setfill('0') << empty;
0627     }
0628 
0629     // Dump 12 EG (8 digits + space)
0630     nDumped = 0;
0631     if (egammas.isValid()) {
0632       for (std::vector<l1t::EGamma>::const_iterator eg = egammas->begin(bx); eg != egammas->end(bx); ++eg) {
0633         unsigned int packedWd = formatEG(eg);
0634         if (nDumped < 12) {
0635           myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << packedWd;
0636           nDumped++;
0637         }
0638       }
0639     }
0640     for (int i = nDumped; i < 12; i++) {
0641       myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
0642     }
0643 
0644     // Dump 8 tau (8 digits + space)
0645     nDumped = 0;
0646     int maxTau = 8;
0647     if (m_tvVersion > 1)
0648       maxTau = 12;
0649     if (taus.isValid()) {
0650       for (std::vector<l1t::Tau>::const_iterator tau = taus->begin(bx); tau != taus->end(bx); ++tau) {
0651         unsigned int packedWd = formatTau(tau);
0652         if (nDumped < maxTau) {
0653           myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << packedWd;
0654           nDumped++;
0655         }
0656       }
0657     }
0658     for (int i = nDumped; i < maxTau; i++) {
0659       myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
0660     }
0661 
0662     // Dump 12 Jets (8 digits + space)
0663     nDumped = 0;
0664     if (jets.isValid()) {
0665       for (std::vector<l1t::Jet>::const_iterator jet = jets->begin(bx); jet != jets->end(bx); ++jet) {
0666         unsigned int packedWd = formatJet(jet);
0667         if (nDumped < 12) {
0668           myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << packedWd;
0669           nDumped++;
0670         }
0671       }
0672     }
0673     for (int i = nDumped; i < 12; i++) {
0674       myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
0675     }
0676 
0677     // Dump Et Sums (ETT, HT, ETM, ETMHF, HTM)
0678     unsigned int ETTpackWd = 0;
0679     unsigned int HTTpackWd = 0;
0680     unsigned int ETMpackWd = 0;
0681     unsigned int HTMpackWd = 0;
0682     unsigned int ETMHFpackWd = 0;
0683     unsigned int HTMHFpackWd = 0;
0684 
0685     // quantities packed into the words
0686     unsigned int ETTempackWd = 0;
0687     unsigned int HFP0packWd = 0;
0688     unsigned int HFM0packWd = 0;
0689     unsigned int HFP1packWd = 0;
0690     unsigned int HFM1packWd = 0;
0691     unsigned int TowerCountspackWd = 0;  // ccla
0692     unsigned int AsymEtpackWd = 0;
0693     unsigned int AsymHtpackWd = 0;
0694     unsigned int AsymEtHFpackWd = 0;
0695     unsigned int AsymHtHFpackWd = 0;
0696     unsigned int CENT30packWd = 0;  // centrality bits 3:0 in ETMHF word
0697     unsigned int CENT74packWd = 0;  // centrality bits 7:4 in HTMHF word
0698     std::pair<unsigned int, unsigned int> centrality(0, 0);
0699 
0700     if (etsums.isValid()) {
0701       for (std::vector<l1t::EtSum>::const_iterator etsum = etsums->begin(bx); etsum != etsums->end(bx); ++etsum) {
0702         switch (etsum->getType()) {
0703           case l1t::EtSum::EtSumType::kMissingEt:
0704             ETMpackWd = formatMissET(etsum);
0705             break;
0706           case l1t::EtSum::EtSumType::kMissingEtHF:
0707             ETMHFpackWd = formatMissET(etsum);
0708             break;
0709           case l1t::EtSum::EtSumType::kMissingHtHF:
0710             HTMHFpackWd = formatMissET(etsum);
0711             break;
0712           case l1t::EtSum::EtSumType::kMissingHt:
0713             HTMpackWd = formatMissET(etsum);
0714             break;
0715           case l1t::EtSum::EtSumType::kTotalEt:
0716             ETTpackWd = formatTotalET(etsum);
0717             break;
0718           case l1t::EtSum::EtSumType::kTotalEtEm:
0719             ETTempackWd = formatTotalET(etsum);
0720             break;
0721           case l1t::EtSum::EtSumType::kTotalHt:
0722             HTTpackWd = formatTotalET(etsum);
0723             break;
0724           case l1t::EtSum::EtSumType::kTowerCount:
0725             TowerCountspackWd = formatTowerCounts(etsum);
0726             break;
0727           case l1t::EtSum::EtSumType::kMinBiasHFP0:
0728             HFP0packWd = formatHMB(etsum);
0729             break;
0730           case l1t::EtSum::EtSumType::kMinBiasHFM0:
0731             HFM0packWd = formatHMB(etsum);
0732             break;
0733           case l1t::EtSum::EtSumType::kMinBiasHFP1:
0734             HFP1packWd = formatHMB(etsum);
0735             break;
0736           case l1t::EtSum::EtSumType::kMinBiasHFM1:
0737             HFM1packWd = formatHMB(etsum);
0738             break;
0739           case l1t::EtSum::EtSumType::kCentrality:
0740             centrality = formatCentrality(etsum);
0741             CENT30packWd = centrality.first;
0742             CENT74packWd = centrality.second;
0743             break;
0744           case l1t::EtSum::EtSumType::kAsymEt:
0745             AsymEtpackWd = formatAsym(etsum);
0746             break;
0747           case l1t::EtSum::EtSumType::kAsymHt:
0748             AsymHtpackWd = formatAsym(etsum);
0749             break;
0750           case l1t::EtSum::EtSumType::kAsymEtHF:
0751             AsymEtHFpackWd = formatAsym(etsum);
0752             break;
0753           case l1t::EtSum::EtSumType::kAsymHtHF:
0754             AsymHtHFpackWd = formatAsym(etsum);
0755             break;
0756           default:
0757             break;
0758         }  //end switch statement
0759       }    //end loop over etsums
0760     }
0761 
0762     // Put HMB bits in upper part of other SumEt Words
0763     ETTpackWd |= HFP0packWd;
0764     HTTpackWd |= HFM0packWd;
0765     ETMpackWd |= HFP1packWd;
0766     HTMpackWd |= HFM1packWd;
0767 
0768     // ETTem goes into ETT word bits 12 - 23
0769     if (m_tvVersion > 1)
0770       ETTpackWd |= (ETTempackWd << 12);
0771 
0772     // ccla Towercounts go in HTT word, bits 12-24
0773     if (m_tvVersion > 1)
0774       HTTpackWd |= (TowerCountspackWd << 12);
0775     if (m_tvVersion > 2) {
0776       ETMpackWd |= AsymEtpackWd;
0777       HTMpackWd |= AsymHtpackWd;
0778       ETMHFpackWd |= AsymEtHFpackWd;
0779       HTMHFpackWd |= AsymHtHFpackWd;
0780 
0781       ETMHFpackWd |= CENT30packWd;
0782       HTMHFpackWd |= CENT74packWd;
0783     }
0784     // Fill in the words in appropriate order
0785     myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << ETTpackWd;
0786     myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << HTTpackWd;
0787     myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << ETMpackWd;
0788     myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << HTMpackWd;
0789     if (m_tvVersion > 1) {
0790       myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << ETMHFpackWd;
0791       if (m_tvVersion > 2) {
0792         myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << HTMHFpackWd;
0793       } else {
0794         myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
0795       }
0796     }
0797 
0798     // If tvVersion > 1 put in placeholds for empty link (6 words (frames)) all zeros.
0799     if (m_tvVersion > 1) {
0800       for (int i = 0; i < 6; i++)
0801         myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
0802     }
0803 
0804     // External Condition (64 digits + space)
0805     int digit = 0;
0806     myOutFile << " ";
0807     if (uGtExt.isValid()) {
0808       for (std::vector<GlobalExtBlk>::const_iterator extBlk = uGtExt->begin(bx); extBlk != uGtExt->end(bx); ++extBlk) {
0809         for (int i = 255; i > -1; i--) {
0810           if (extBlk->getExternalDecision(i))
0811             digit |= (1 << (i % 4));
0812           if ((i % 4) == 0) {
0813             myOutFile << std::hex << std::setw(1) << digit;
0814             digit = 0;
0815           }
0816         }  //end loop over external bits
0817       }    //loop over objects
0818     } else {
0819       myOutFile << std::hex << std::setw(64) << std::setfill('0') << empty;
0820     }
0821 
0822     // Algorithm Dump (128 digits + space)
0823     digit = 0;
0824     myOutFile << " ";
0825     if (uGtAlg.isValid()) {
0826       for (std::vector<GlobalAlgBlk>::const_iterator algBlk = uGtAlg->begin(bx); algBlk != uGtAlg->end(bx); ++algBlk) {
0827         for (int i = 511; i > -1; i--) {
0828           if (algBlk->getAlgoDecisionFinal(i))
0829             digit |= (1 << (i % 4));
0830           if ((i % 4) == 0) {
0831             myOutFile << std::hex << std::setw(1) << digit;
0832             digit = 0;
0833           }
0834         }  //end loop over algorithm bits
0835 
0836         // Final OR (1 digit + space)
0837         unsigned int finalOr = (algBlk->getFinalOR() & 0x1);
0838         myOutFile << " " << std::hex << std::setw(1) << std::setfill('0') << finalOr;
0839       }
0840     } else {
0841       myOutFile << std::hex << std::setw(128) << std::setfill('0') << empty;
0842     }
0843 
0844     myOutFile << endl;
0845 
0846     m_absBx++;
0847   }
0848 
0849   cms_uint64_t GtRecordDump::formatMuon(std::vector<l1t::Muon>::const_iterator mu) {
0850     cms_uint64_t packedVal = 0;
0851 
0852     // Pack Bits
0853     packedVal |= ((cms_uint64_t)(mu->hwPhi() & 0x3ff) << 43);
0854     packedVal |= ((cms_uint64_t)(mu->hwPhiAtVtx() & 0x3ff) << 0);  // & 0x3ff) <<18);
0855     // packedVal |= ((cms_uint64_t)(mu->hwEta() & 0x1ff) << 53);         // removed
0856     packedVal |= ((cms_uint64_t)(mu->hwPtUnconstrained() & 0xff) << 53);  // added
0857     packedVal |= ((cms_uint64_t)(mu->hwDXY() & 0x3) << 62);               // added
0858     packedVal |= ((cms_uint64_t)(mu->hwEtaAtVtx() & 0x1ff) << 23);        // & 0x1ff) <<9);
0859     packedVal |= ((cms_uint64_t)(mu->hwPt() & 0x1ff) << 10);              // & 0x1ff) <<0);
0860     packedVal |= ((cms_uint64_t)(mu->hwChargeValid() & 0x1) << 35);       // & 0x1)   <<28);
0861     packedVal |= ((cms_uint64_t)(mu->hwCharge() & 0x1) << 34);            // & 0x1)   <<29);
0862     packedVal |= ((cms_uint64_t)(mu->hwQual() & 0xf) << 19);              // & 0xf)   <<30);
0863     packedVal |= ((cms_uint64_t)(mu->hwIso() & 0x3) << 32);               // & 0x3)   <<34);
0864 
0865     //    if (false) {  // for debugging purposes
0866     //      std::cout << "----------------------" << std::endl;
0867     //      std::cout << "<<  0; mu->hwPhiAtVtx()        = " << std::hex << std::setw(16) << std::setfill('0')
0868     //                << ((cms_uint64_t)(mu->hwPhiAtVtx() & 0x3ff) << 0) << std::endl;
0869     //      std::cout << "<< 10; mu->hwPt()              = " << std::hex << std::setw(16) << std::setfill('0')
0870     //                << ((cms_uint64_t)(mu->hwPt() & 0x1ff) << 10) << std::endl;
0871     //      std::cout << "<< 19; mu->hwQual()            = " << std::hex << std::setw(16) << std::setfill('0')
0872     //                << ((cms_uint64_t)(mu->hwQual() & 0xf) << 19) << std::endl;
0873     //      std::cout << "<< 23; mu->hwEtaAtVtx()        = " << std::hex << std::setw(16) << std::setfill('0')
0874     //                << ((cms_uint64_t)(mu->hwEtaAtVtx() & 0x1ff) << 23) << std::endl;
0875     //      std::cout << "<< 32; mu->hwIso()             = " << std::hex << std::setw(16) << std::setfill('0')
0876     //                << ((cms_uint64_t)(mu->hwIso() & 0x3) << 32) << std::endl;
0877     //      std::cout << "<< 34; mu->hwCharge()          = " << std::hex << std::setw(16) << std::setfill('0')
0878     //                << ((cms_uint64_t)(mu->hwCharge() & 0x1) << 34) << std::endl;
0879     //      std::cout << "<< 35; mu->hwChargeValid()     = " << std::hex << std::setw(16) << std::setfill('0')
0880     //                << ((cms_uint64_t)(mu->hwChargeValid() & 0x1) << 35) << std::endl;
0881     //      std::cout << "<< 43; mu->hwPhi()             = " << std::hex << std::setw(16) << std::setfill('0')
0882     //                << ((cms_uint64_t)(mu->hwPhi() & 0x3ff) << 43) << std::endl;
0883     //      std::cout << "<< 53; mu->hwPtUnconstrained() = " << std::hex << std::setw(16) << std::setfill('0')
0884     //                << ((cms_uint64_t)(mu->hwPtUnconstrained() & 0xff) << 53) << std::endl;
0885     //      std::cout << "<< 62; mu->hwDXY()             = " << std::hex << std::setw(16) << std::setfill('0')
0886     //                << ((cms_uint64_t)(mu->hwDXY() & 0x3) << 62) << std::endl;
0887     //      std::cout << "packedWord                     = " << std::hex << std::setw(16) << std::setfill('0') << packedVal
0888     //                << std::endl;
0889     //      std::cout << "----------------------" << std::endl;
0890     //    }
0891 
0892     return packedVal;
0893   }
0894 
0895   unsigned int GtRecordDump::formatEG(std::vector<l1t::EGamma>::const_iterator eg) {
0896     unsigned int packedVal = 0;
0897 
0898     // Pack Bits
0899     packedVal |= ((eg->hwPhi() & 0xff) << 17);
0900     packedVal |= ((eg->hwEta() & 0xff) << 9);
0901     packedVal |= ((eg->hwPt() & 0x1ff) << 0);
0902     packedVal |= ((eg->hwIso() & 0x3) << 25);
0903     packedVal |= ((eg->hwQual() & 0x31) << 27);
0904 
0905     return packedVal;
0906   }
0907 
0908   unsigned int GtRecordDump::formatTau(std::vector<l1t::Tau>::const_iterator tau) {
0909     unsigned int packedVal = 0;
0910 
0911     // Pack Bits
0912     packedVal |= ((tau->hwPhi() & 0xff) << 17);
0913     packedVal |= ((tau->hwEta() & 0xff) << 9);
0914     packedVal |= ((tau->hwPt() & 0x1ff) << 0);
0915     packedVal |= ((tau->hwIso() & 0x3) << 25);
0916     packedVal |= ((tau->hwQual() & 0x31) << 27);
0917 
0918     return packedVal;
0919   }
0920 
0921   unsigned int GtRecordDump::formatJet(std::vector<l1t::Jet>::const_iterator jet) {
0922     unsigned int packedVal = 0;
0923 
0924     // Pack Bits
0925     packedVal |= ((jet->hwPhi() & 0xff) << 19);
0926     packedVal |= ((jet->hwEta() & 0xff) << 11);
0927     packedVal |= ((jet->hwPt() & 0x7ff) << 0);
0928     packedVal |= ((jet->hwQual() & 0x1) << 27);
0929 
0930     return packedVal;
0931   }
0932 
0933   unsigned int GtRecordDump::formatMissET(std::vector<l1t::EtSum>::const_iterator etSum) {
0934     unsigned int packedVal = 0;
0935 
0936     // Pack Bits
0937     packedVal |= ((etSum->hwPhi() & 0xff) << 12);
0938     packedVal |= ((etSum->hwPt() & 0xfff) << 0);
0939 
0940     return packedVal;
0941   }
0942 
0943   unsigned int GtRecordDump::formatTotalET(std::vector<l1t::EtSum>::const_iterator etSum) {
0944     unsigned int packedVal = 0;
0945 
0946     // Pack Bits
0947     packedVal |= ((etSum->hwPt() & 0xfff) << 0);
0948 
0949     return packedVal;
0950   }
0951 
0952   unsigned int GtRecordDump::formatTowerCounts(std::vector<l1t::EtSum>::const_iterator etSum) {
0953     unsigned int packedVal = 0;
0954     //unsigned int shift = 12;
0955 
0956     // Pack Bits
0957     //packedVal |= ((etSum->hwPt()     & 0xfff)   << shift);
0958 
0959     //towercount takes 13 bits
0960     packedVal |= ((etSum->hwPt() & 0x1fff) << 0);
0961 
0962     return packedVal;
0963   }
0964 
0965   unsigned int GtRecordDump::formatAsym(std::vector<l1t::EtSum>::const_iterator etSum) {
0966     //asym takes 8 bits, occupying bits 20-27 in ETM, HTM, ETMHF, and HTMHF etsums
0967     unsigned int packedVal = 0;
0968     unsigned int shift = 20;
0969 
0970     // Pack Bits
0971     packedVal |= ((etSum->hwPt() & 0xff) << shift);
0972 
0973     return packedVal;
0974   }
0975 
0976   unsigned int GtRecordDump::formatHMB(std::vector<l1t::EtSum>::const_iterator etSum) {
0977     // 4 bits, occupying bits 28-31.
0978     unsigned int packedVal = 0;
0979     unsigned int shift = 28;
0980 
0981     // Pack Bits
0982     packedVal |= ((etSum->hwPt() & 0xf) << shift);
0983 
0984     return packedVal;
0985   }
0986 
0987   std::pair<unsigned int, unsigned int> GtRecordDump::formatCentrality(std::vector<l1t::EtSum>::const_iterator etSum) {
0988     unsigned int centword = etSum->hwPt();
0989 
0990     // unpack word into 2 4 bit words
0991     int firstfour = (centword & 0xF);
0992     int lastfour = (centword >> 4) & 0xF;
0993 
0994     // 4 bits, occupying bits 28-31.
0995     unsigned int packedValLN = 0;
0996     unsigned int packedValUN = 0;
0997     unsigned int shift = 28;
0998 
0999     // Pack Bits
1000     packedValLN |= ((firstfour & 0xf) << shift);
1001     packedValUN |= ((lastfour & 0xf) << shift);
1002 
1003     std::pair<unsigned int, unsigned int> centrality(packedValLN, packedValUN);
1004     return centrality;
1005   }
1006 
1007 }  // namespace l1t
1008 
1009 DEFINE_FWK_MODULE(l1t::GtRecordDump);