Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:22:18

0001 /**
0002  * \class CompareToObjectMapRecord
0003  *
0004  *
0005  * Description: see header file.
0006  *
0007  * Implementation:
0008  *    <TODO: enter implementation details>
0009  *
0010  * \author: Vasile Mihai Ghete - HEPHY Vienna
0011  * \author: W. David Dagenhart
0012  *
0013  *
0014  */
0015 
0016 #include "CompareToObjectMapRecord.h"
0017 
0018 #include <algorithm>
0019 #include <iostream>
0020 #include <string>
0021 #include <vector>
0022 
0023 #include "DataFormats/Common/interface/Handle.h"
0024 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMap.h"
0025 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapFwd.h"
0026 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapRecord.h"
0027 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMaps.h"
0028 #include "DataFormats/L1GlobalTrigger/interface/L1GtLogicParser.h"
0029 #include "FWCore/Framework/interface/Event.h"
0030 #include "FWCore/Framework/interface/MakerMacros.h"
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032 #include "FWCore/ParameterSet/interface/Registry.h"
0033 #include "FWCore/Utilities/interface/Algorithms.h"
0034 #include "FWCore/Utilities/interface/Exception.h"
0035 
0036 CompareToObjectMapRecord::CompareToObjectMapRecord(const edm::ParameterSet &pset)
0037     : m_l1GtObjectMapTag(pset.getParameter<edm::InputTag>("L1GtObjectMapTag")),
0038       m_l1GtObjectMapsTag(pset.getParameter<edm::InputTag>("L1GtObjectMapsTag")),
0039       verbose_(pset.getUntrackedParameter<bool>("verbose", false)) {}
0040 
0041 CompareToObjectMapRecord::~CompareToObjectMapRecord() {}
0042 
0043 void CompareToObjectMapRecord::analyze(edm::Event const &event, edm::EventSetup const &es) {
0044   // Read in the data in the old format
0045   edm::Handle<L1GlobalTriggerObjectMapRecord> gtObjectMapRecord;
0046   event.getByLabel(m_l1GtObjectMapTag, gtObjectMapRecord);
0047 
0048   // Read in the data in the new format
0049   edm::Handle<L1GlobalTriggerObjectMaps> gtObjectMaps;
0050   event.getByLabel(m_l1GtObjectMapsTag, gtObjectMaps);
0051 
0052   // In the new format the names are not in the event data,
0053   // They are in the ParameterSet registry
0054   edm::pset::Registry *psetRegistry = edm::pset::Registry::instance();
0055   edm::ParameterSet const *pset = psetRegistry->getMapped(gtObjectMaps->namesParameterSetID());
0056   if (pset == nullptr) {
0057     cms::Exception ex("L1GlobalTrigger");
0058     ex << "Could not find L1 trigger names ParameterSet in the registry";
0059     ex.addContext("Calling CompareToObjectMapRecord::analyze");
0060     throw ex;
0061   }
0062 
0063   // First compare the algorithm bit numbers
0064   std::vector<int> algoBitNumbers1;
0065   std::vector<L1GlobalTriggerObjectMap> const &vectorInRecord = gtObjectMapRecord->gtObjectMap();
0066   algoBitNumbers1.reserve(vectorInRecord.size());
0067   for (std::vector<L1GlobalTriggerObjectMap>::const_iterator i = vectorInRecord.begin(), iEnd = vectorInRecord.end();
0068        i != iEnd;
0069        ++i) {
0070     algoBitNumbers1.push_back(i->algoBitNumber());
0071     if (verbose_) {
0072       // This will print out all the data from the
0073       // L1GlobalTriggerObjectMapRecord
0074       i->print(std::cout);
0075     }
0076   }
0077   edm::sort_all(algoBitNumbers1);
0078 
0079   std::vector<int> algoBitNumbers2;
0080   gtObjectMaps->getAlgorithmBitNumbers(algoBitNumbers2);
0081   if (algoBitNumbers1 != algoBitNumbers2) {
0082     cms::Exception ex("L1GlobalTrigger");
0083     ex << "Algorithm bit numbers do not match";
0084     ex.addContext("Calling CompareToObjectMapRecord::analyze");
0085     throw ex;
0086   }
0087 
0088   // Now test the algorithm names
0089   std::vector<std::string> algoNames2 = pset->getParameter<std::vector<std::string>>("@algorithmNames");
0090 
0091   // In the ParameterSet, the algorithm names are referenced by position
0092   // in the vector. If the bit number for a position in the vector is
0093   // not assigned, then the algorithm name should be an empty string.
0094   for (int i = 0; i < static_cast<int>(algoNames2.size()); ++i) {
0095     if (!std::binary_search(algoBitNumbers1.begin(), algoBitNumbers1.end(), i)) {
0096       if (algoNames2[i] != std::string("")) {
0097         cms::Exception ex("L1GlobalTrigger");
0098         ex << "Undefined algorithm should have empty name";
0099         ex.addContext("Calling CompareToObjectMapRecord::analyze");
0100         throw ex;
0101       }
0102     }
0103   }
0104 
0105   // Main loop over algorithms
0106   for (std::vector<int>::const_iterator iBit = algoBitNumbers1.begin(), endBits = algoBitNumbers1.end();
0107        iBit != endBits;
0108        ++iBit) {
0109     L1GlobalTriggerObjectMap const *objMap = gtObjectMapRecord->getObjectMap(*iBit);
0110     const std::string &algoName1 = objMap->algoName();
0111 
0112     if (algoName1 != algoNames2.at(*iBit)) {
0113       cms::Exception ex("L1GlobalTrigger");
0114       ex << "Algorithm names do not match";
0115       ex.addContext("Calling CompareToObjectMapRecord::analyze");
0116       throw ex;
0117     }
0118 
0119     // Now test the algorithm results
0120     if (objMap->algoGtlResult() != gtObjectMaps->algorithmResult(*iBit)) {
0121       cms::Exception ex("L1GlobalTrigger");
0122       ex << "Algorithm results do not match";
0123       ex.addContext("Calling CompareToObjectMapRecord::analyze");
0124       throw ex;
0125     }
0126 
0127     std::vector<L1GtLogicParser::OperandToken> const &operandTokens1 = objMap->operandTokenVector();
0128 
0129     L1GlobalTriggerObjectMaps::ConditionsInAlgorithm conditions2 = gtObjectMaps->getConditionsInAlgorithm(*iBit);
0130     if (conditions2.nConditions() != operandTokens1.size()) {
0131       cms::Exception ex("L1GlobalTrigger");
0132       ex << "Number of conditions does not match";
0133       ex.addContext("Calling CompareToObjectMapRecord::analyze");
0134       throw ex;
0135     }
0136 
0137     std::vector<std::string> conditionNames2;
0138     conditionNames2 = pset->getParameter<std::vector<std::string>>(algoNames2.at(*iBit));
0139 
0140     // Print out data from L1GlobalTriggerObjectMaps and ParameterSet registry
0141     if (verbose_) {
0142       std::cout << *iBit << "  " << algoNames2[*iBit] << "  " << gtObjectMaps->algorithmResult(*iBit) << "\n";
0143 
0144       for (unsigned j = 0; j < gtObjectMaps->getNumberOfConditions(*iBit); ++j) {
0145         L1GlobalTriggerObjectMaps::ConditionsInAlgorithm conditions = gtObjectMaps->getConditionsInAlgorithm(*iBit);
0146         std::cout << "    " << j << "  " << conditionNames2[j] << "  " << conditions.getConditionResult(j) << "\n";
0147         L1GlobalTriggerObjectMaps::CombinationsInCondition combinations =
0148             gtObjectMaps->getCombinationsInCondition(*iBit, j);
0149         for (unsigned m = 0; m < combinations.nCombinations(); ++m) {
0150           std::cout << "    ";
0151           for (unsigned n = 0; n < combinations.nObjectsPerCombination(); ++n) {
0152             std::cout << "  " << static_cast<unsigned>(combinations.getObjectIndex(m, n));
0153           }
0154           std::cout << "\n";
0155         }
0156       }
0157     }
0158 
0159     // Loop over conditions
0160     unsigned iCondition = 0;
0161     for (std::vector<L1GtLogicParser::OperandToken>::const_iterator iToken1 = operandTokens1.begin(),
0162                                                                     endTokens1 = operandTokens1.end();
0163          iToken1 != endTokens1;
0164          ++iToken1, ++iCondition) {
0165       // Compare condition numbers
0166       if (iToken1->tokenNumber != static_cast<int>(iCondition)) {
0167         cms::Exception ex("L1GlobalTrigger");
0168         ex << "Token numbers not sequential";
0169         ex.addContext("Calling CompareToObjectMapRecord::analyze");
0170         throw ex;
0171       }
0172 
0173       // Compare condition names
0174       if (iToken1->tokenResult != conditions2.getConditionResult(iCondition)) {
0175         cms::Exception ex("L1GlobalTrigger");
0176         ex << "Condition results do not match";
0177         ex.addContext("Calling CompareToObjectMapRecord::analyze");
0178         throw ex;
0179       }
0180 
0181       // Compare condition names
0182       if (iToken1->tokenName != conditionNames2.at(iCondition)) {
0183         cms::Exception ex("L1GlobalTrigger");
0184         ex << "Condition names do not match";
0185         ex.addContext("Calling CompareToObjectMapRecord::analyze");
0186         throw ex;
0187       }
0188 
0189       // Compare the combinations of Indexes into the L1 collections
0190       L1GlobalTriggerObjectMaps::CombinationsInCondition combinations2 =
0191           gtObjectMaps->getCombinationsInCondition(*iBit, iCondition);
0192 
0193       CombinationsInCond const *combinations1 = objMap->getCombinationsInCond(iToken1->tokenNumber);
0194       if (combinations1->size() != combinations2.nCombinations()) {
0195         cms::Exception ex("L1GlobalTrigger");
0196         ex << "The number of combinations in a condition does not match";
0197         ex.addContext("Calling CompareToObjectMapRecord::analyze");
0198         throw ex;
0199       }
0200 
0201       for (CombinationsInCond::const_iterator iCombo = combinations1->begin(), endCombos = combinations1->end();
0202            iCombo != endCombos;
0203            ++iCombo) {
0204         if (iCombo->size() != combinations2.nObjectsPerCombination()) {
0205           cms::Exception ex("L1GlobalTrigger");
0206           ex << "The number of indexes in a combination does not match";
0207           ex.addContext("Calling CompareToObjectMapRecord::analyze");
0208           throw ex;
0209         }
0210 
0211         for (std::vector<int>::const_iterator iIndex = iCombo->begin(), endIndexes = iCombo->end();
0212              iIndex != endIndexes;
0213              ++iIndex) {
0214           if (*iIndex != combinations2.getObjectIndex(iCombo - combinations1->begin(), iIndex - iCombo->begin())) {
0215             cms::Exception ex("L1GlobalTrigger");
0216             ex << "Object index does not match";
0217             ex.addContext("Calling CompareToObjectMapRecord::analyze");
0218             throw ex;
0219           }
0220         }
0221       }
0222     }
0223   }
0224 }
0225 
0226 DEFINE_FWK_MODULE(CompareToObjectMapRecord);