Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:04

0001 #include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtUtilsHelper.h"
0002 #include "DataFormats/Provenance/interface/BranchDescription.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0004 #include "FWCore/Utilities/interface/BranchType.h"
0005 #include "FWCore/Utilities/interface/TypeID.h"
0006 
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 
0009 L1GtUtilsHelper::L1GtUtilsHelper(edm::ParameterSet const& pset, edm::ConsumesCollector& iC, bool useL1GtTriggerMenuLite)
0010     : m_l1GtRecordInputTag(pset.getParameter<edm::InputTag>("l1GtRecordInputTag")),
0011       m_l1GtReadoutRecordInputTag(pset.getParameter<edm::InputTag>("l1GtReadoutRecordInputTag")),
0012       m_l1GtTriggerMenuLiteInputTag(pset.getParameter<edm::InputTag>("l1GtTriggerMenuLiteInputTag")) {
0013   m_l1GtRecordToken = iC.consumes<L1GlobalTriggerRecord>(m_l1GtRecordInputTag);
0014   m_l1GtReadoutRecordToken = iC.consumes<L1GlobalTriggerReadoutRecord>(m_l1GtReadoutRecordInputTag);
0015   if (useL1GtTriggerMenuLite) {
0016     m_l1GtTriggerMenuLiteToken = iC.consumes<L1GtTriggerMenuLite, edm::InRun>(m_l1GtTriggerMenuLiteInputTag);
0017   }
0018 }
0019 
0020 void L1GtUtilsHelper::fillDescription(edm::ParameterSetDescription& desc) {
0021   desc.add<edm::InputTag>("l1GtRecordInputTag", edm::InputTag());
0022   desc.add<edm::InputTag>("l1GtReadoutRecordInputTag", edm::InputTag());
0023   desc.add<edm::InputTag>("l1GtTriggerMenuLiteInputTag", edm::InputTag());
0024 }
0025 
0026 namespace {
0027   template <typename C, typename T>
0028   void setConsumesAndCheckAmbiguities(edm::BranchDescription const& iDesc,
0029                                       C const& iPreferredTags,
0030                                       T& ioToken,
0031                                       edm::InputTag& ioTag,
0032                                       edm::ConsumesCollector& iCollector,
0033                                       const char* iTypeForErrorMessage) {
0034     if (ioTag.label().empty()) {
0035       //hasn't been set yet
0036       ioTag = edm::InputTag{iDesc.moduleLabel(), iDesc.productInstanceName(), iDesc.processName()};
0037 
0038       ioToken = iCollector.consumes(ioTag);
0039       LogDebug("L1GtUtils")
0040           << "Input tag found for " << iTypeForErrorMessage << " product.\n Input tag set to " << (ioTag) << "\n Tag is"
0041           << ((iPreferredTags.end() != std::find(iPreferredTags.begin(), iPreferredTags.end(), ioTag.label())) ? ""
0042                                                                                                                : " not")
0043           << " found in preferred tags list " << std::endl;
0044 
0045     } else {
0046       bool alreadyFoundPreferred =
0047           iPreferredTags.end() != std::find(iPreferredTags.begin(), iPreferredTags.end(), ioTag.label());
0048       if (alreadyFoundPreferred) {
0049         if (std::find(iPreferredTags.begin(), iPreferredTags.end(), iDesc.moduleLabel()) != iPreferredTags.end()) {
0050           edm::LogError("L1GtUtils") << "Found multiple preferred input tags for " << iTypeForErrorMessage
0051                                      << " product, "
0052                                      << "\nwith different instaces or processes."
0053                                      << "\nTag already found: " << (ioTag) << "\nOther tag: "
0054                                      << (edm::InputTag{
0055                                             iDesc.moduleLabel(), iDesc.productInstanceName(), iDesc.processName()})
0056                                      << "\nToken set to invalid." << std::endl;
0057           //another preferred also found
0058           ioToken = T{};
0059         }
0060       } else {
0061         //previous choice was not preferred
0062 
0063         auto itFound = std::find(iPreferredTags.begin(), iPreferredTags.end(), iDesc.moduleLabel());
0064         if (itFound != iPreferredTags.end()) {
0065           //reset to preferred
0066           auto oldTag = ioTag;
0067           ioTag = edm::InputTag{iDesc.moduleLabel(), iDesc.productInstanceName(), iDesc.processName()};
0068 
0069           ioToken = iCollector.consumes(ioTag);
0070           edm::LogWarning("L1GtUtils") << "Found preferred tag " << (ioTag) << "\n after having set unpreferred tag ("
0071                                        << oldTag << ") for " << iTypeForErrorMessage
0072                                        << ".\n Please change configuration to explicitly use the tag given above.\n "
0073                                           "This will avoid unnecessary prefetching of data not used.";
0074         } else {
0075           //hit an ambiguity
0076           edm::LogWarning("L1GtUtils") << "Found multiple input tags for " << iTypeForErrorMessage << " product."
0077                                        << "\nNone is in the preferred input tags - no safe choice."
0078                                        << "\nTag already found: " << (ioTag) << "\nOther tag: "
0079                                        << (edm::InputTag{
0080                                               iDesc.moduleLabel(), iDesc.productInstanceName(), iDesc.processName()})
0081                                        << "\nToken set to invalid." << std::endl;
0082           ioToken = T{};
0083         }
0084       }
0085     }
0086   }
0087 }  // namespace
0088 void L1GtUtilsHelper::checkToUpdateTags(edm::BranchDescription const& branchDescription,
0089                                         edm::ConsumesCollector consumesCollector,
0090                                         bool findRecord,
0091                                         bool findReadoutRecord,
0092                                         bool findMenuLite) {
0093   if (branchDescription.dropped()) {
0094     return;
0095   }
0096   // This is only used if required InputTags were not specified already.
0097   // This is called early in the process, once for each product in the ProductRegistry.
0098   // The callback is registered when callWhenNewProductsRegistered is called.
0099   // It finds products by type and sets the token so that it can be used
0100   // later when getting the product.
0101 
0102   // The code will look for the corresponding product in ProductRegistry.
0103   // If the product is found, it checks the product label in
0104   // a vector of preferred input tags (hardwired now to "gtDigis" and
0105   // "hltGtDigis"). The first input tag from the vector of preferred input tags, with the
0106   // same label as the input tag found from provenance, is kept as input tag, if there are no
0107   // multiple products with the same label.
0108 
0109   // If multiple products are found and no one has a label in the vector of preferred input tags,
0110   // or if multiple products are found with the label in the vector of preferred input tags
0111   // (with different instance or process) the input tag is set to empty input tag, and L1GtUtil
0112   // will produce an error, as it is not possible to safely choose a product. In this case, one must
0113   // provide explicitly the correct input tag via configuration or in the constructor.
0114 
0115   // TODO decide if the preferred input tags must be given as input parameters
0116   // or stay hardwired
0117 
0118   std::vector<edm::InputTag> preferredL1GtRecordInputTag = {edm::InputTag("gtDigis"), edm::InputTag("hltGtDigis")};
0119 
0120   std::vector<edm::InputTag> preferredL1GtReadoutRecordInputTag = {edm::InputTag("gtDigis"),
0121                                                                    edm::InputTag("hltGtDigis")};
0122 
0123   std::vector<edm::InputTag> preferredL1GtTriggerMenuLiteInputTag = {edm::InputTag("gtDigis"),
0124                                                                      edm::InputTag("hltGtDigis")};
0125 
0126   // L1GlobalTriggerRecord
0127 
0128   if (findRecord && (branchDescription.unwrappedTypeID() == edm::TypeID(typeid(L1GlobalTriggerRecord))) &&
0129       (branchDescription.branchType() == edm::InEvent)) {
0130     setConsumesAndCheckAmbiguities(branchDescription,
0131                                    preferredL1GtRecordInputTag,
0132                                    m_l1GtRecordToken,
0133                                    m_l1GtRecordInputTag,
0134                                    consumesCollector,
0135                                    "L1GlobalTriggerRecord");
0136   }
0137 
0138   // L1GlobalTriggerReadoutRecord
0139 
0140   if (findReadoutRecord && (branchDescription.unwrappedTypeID() == edm::TypeID(typeid(L1GlobalTriggerReadoutRecord))) &&
0141       (branchDescription.branchType() == edm::InEvent)) {
0142     setConsumesAndCheckAmbiguities(branchDescription,
0143                                    preferredL1GtReadoutRecordInputTag,
0144                                    m_l1GtReadoutRecordToken,
0145                                    m_l1GtReadoutRecordInputTag,
0146                                    consumesCollector,
0147                                    "L1GlobalTriggerReadoutRecord");
0148   }
0149 
0150   // L1GtTriggerMenuLite
0151 
0152   if (findMenuLite && (branchDescription.unwrappedTypeID() == edm::TypeID(typeid(L1GtTriggerMenuLite))) &&
0153       (branchDescription.branchType() == edm::InEvent)) {
0154     setConsumesAndCheckAmbiguities(branchDescription,
0155                                    preferredL1GtTriggerMenuLiteInputTag,
0156                                    m_l1GtTriggerMenuLiteToken,
0157                                    m_l1GtTriggerMenuLiteInputTag,
0158                                    consumesCollector,
0159                                    "L1GtTriggerMenuLite");
0160   }
0161 }