File indexing completed on 2025-01-31 02:19:46
0001 #include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtUtilsHelper.h"
0002 #include "DataFormats/Provenance/interface/ProductDescription.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::ProductDescription 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 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
0058 ioToken = T{};
0059 }
0060 } else {
0061
0062
0063 auto itFound = std::find(iPreferredTags.begin(), iPreferredTags.end(), iDesc.moduleLabel());
0064 if (itFound != iPreferredTags.end()) {
0065
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
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 }
0088 void L1GtUtilsHelper::checkToUpdateTags(edm::ProductDescription const& productDescription,
0089 edm::ConsumesCollector consumesCollector,
0090 bool findRecord,
0091 bool findReadoutRecord,
0092 bool findMenuLite) {
0093 if (productDescription.dropped()) {
0094 return;
0095 }
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
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
0127
0128 if (findRecord && (productDescription.unwrappedTypeID() == edm::TypeID(typeid(L1GlobalTriggerRecord))) &&
0129 (productDescription.branchType() == edm::InEvent)) {
0130 setConsumesAndCheckAmbiguities(productDescription,
0131 preferredL1GtRecordInputTag,
0132 m_l1GtRecordToken,
0133 m_l1GtRecordInputTag,
0134 consumesCollector,
0135 "L1GlobalTriggerRecord");
0136 }
0137
0138
0139
0140 if (findReadoutRecord &&
0141 (productDescription.unwrappedTypeID() == edm::TypeID(typeid(L1GlobalTriggerReadoutRecord))) &&
0142 (productDescription.branchType() == edm::InEvent)) {
0143 setConsumesAndCheckAmbiguities(productDescription,
0144 preferredL1GtReadoutRecordInputTag,
0145 m_l1GtReadoutRecordToken,
0146 m_l1GtReadoutRecordInputTag,
0147 consumesCollector,
0148 "L1GlobalTriggerReadoutRecord");
0149 }
0150
0151
0152
0153 if (findMenuLite && (productDescription.unwrappedTypeID() == edm::TypeID(typeid(L1GtTriggerMenuLite))) &&
0154 (productDescription.branchType() == edm::InEvent)) {
0155 setConsumesAndCheckAmbiguities(productDescription,
0156 preferredL1GtTriggerMenuLiteInputTag,
0157 m_l1GtTriggerMenuLiteToken,
0158 m_l1GtTriggerMenuLiteInputTag,
0159 consumesCollector,
0160 "L1GtTriggerMenuLite");
0161 }
0162 }