File indexing completed on 2023-03-17 11:12:15
0001 #include "L1Trigger/L1TGlobal/interface/L1TGlobalUtilHelper.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 l1t::L1TGlobalUtilHelper::L1TGlobalUtilHelper(edm::ParameterSet const& pset, edm::ConsumesCollector& iC)
0010 : m_l1tAlgBlkInputTag(pset.getParameter<edm::InputTag>("l1tAlgBlkInputTag")),
0011 m_l1tExtBlkInputTag(pset.getParameter<edm::InputTag>("l1tExtBlkInputTag")),
0012 m_readPrescalesFromFile(pset.getParameter<bool>("ReadPrescalesFromFile")) {
0013 m_l1tAlgBlkToken = iC.consumes<GlobalAlgBlkBxCollection>(m_l1tAlgBlkInputTag);
0014 m_l1tExtBlkToken = iC.consumes<GlobalExtBlkBxCollection>(m_l1tExtBlkInputTag);
0015 }
0016
0017 void l1t::L1TGlobalUtilHelper::fillDescription(edm::ParameterSetDescription& desc,
0018 edm::InputTag const& iAlg,
0019 edm::InputTag const& iExt,
0020 bool readPrescalesFromFile) {
0021 desc.add<edm::InputTag>("l1tAlgBlkInputTag", iAlg);
0022 desc.add<edm::InputTag>("l1tExtBlkInputTag", iExt);
0023 desc.add<bool>("ReadPrescalesFromFile", readPrescalesFromFile);
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
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 throw cms::Exception("L1GtUtils::TooManyChoices")
0051 << "Found multiple preferred input tags for " << iTypeForErrorMessage << " product, "
0052 << "\nwith different instaces or processes."
0053 << "\nTag already found: " << (ioTag) << "\nOther tag: "
0054 << (edm::InputTag{iDesc.moduleLabel(), iDesc.productInstanceName(), iDesc.processName()});
0055 }
0056 } else {
0057
0058
0059 auto itFound = std::find(iPreferredTags.begin(), iPreferredTags.end(), iDesc.moduleLabel());
0060 if (itFound != iPreferredTags.end()) {
0061
0062 auto oldTag = ioTag;
0063 ioTag = edm::InputTag{iDesc.moduleLabel(), iDesc.productInstanceName(), iDesc.processName()};
0064
0065 ioToken = iCollector.consumes(ioTag);
0066 edm::LogWarning("L1GtUtils") << "Found preferred tag " << (ioTag) << "\n after having set unpreferred tag ("
0067 << oldTag << ") for " << iTypeForErrorMessage
0068 << ".\n Please change configuration to explicitly use the tag given above.\n "
0069 "This will avoid unnecessary prefetching of data not used.";
0070 } else {
0071
0072 edm::LogWarning("L1GtUtils") << "Found multiple input tags for " << iTypeForErrorMessage << " product."
0073 << "\nNone is in the preferred input tags - no safe choice."
0074 << "\nTag already found: " << (ioTag) << "\nOther tag: "
0075 << (edm::InputTag{
0076 iDesc.moduleLabel(), iDesc.productInstanceName(), iDesc.processName()})
0077 << "\nToken set to invalid." << std::endl;
0078 ioToken = T{};
0079 }
0080 }
0081 }
0082 }
0083 }
0084
0085 void l1t::L1TGlobalUtilHelper::checkToUpdateTags(edm::BranchDescription const& branchDescription,
0086 edm::ConsumesCollector consumesCollector,
0087 bool findL1TAlgBlk,
0088 bool findL1TExtBlk) {
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111 if (branchDescription.dropped()) {
0112 return;
0113 }
0114
0115 std::vector<edm::InputTag> preferredL1TAlgBlkInputTag = {edm::InputTag("gtStage2Digis"),
0116 edm::InputTag("hltGtStage2Digis")};
0117
0118 std::vector<edm::InputTag> preferredL1TExtBlkInputTag = {edm::InputTag("gtStage2Digis"),
0119 edm::InputTag("hltGtStage2Digis")};
0120
0121
0122
0123 if (findL1TAlgBlk && (branchDescription.unwrappedTypeID() == edm::TypeID(typeid(GlobalAlgBlkBxCollection))) &&
0124 (branchDescription.branchType() == edm::InEvent)) {
0125 setConsumesAndCheckAmbiguities(branchDescription,
0126 preferredL1TAlgBlkInputTag,
0127 m_l1tAlgBlkToken,
0128 m_l1tAlgBlkInputTag,
0129 consumesCollector,
0130 "GlobalAlgBlkBxCollection");
0131 }
0132
0133
0134
0135 if (findL1TExtBlk && (branchDescription.unwrappedTypeID() == edm::TypeID(typeid(GlobalExtBlkBxCollection))) &&
0136 (branchDescription.branchType() == edm::InEvent)) {
0137 setConsumesAndCheckAmbiguities(branchDescription,
0138 preferredL1TExtBlkInputTag,
0139 m_l1tExtBlkToken,
0140 m_l1tExtBlkInputTag,
0141 consumesCollector,
0142 "GlobalExtBlkBxCollection");
0143 }
0144 }