Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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       //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           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         //previous choice was not preferred
0058 
0059         auto itFound = std::find(iPreferredTags.begin(), iPreferredTags.end(), iDesc.moduleLabel());
0060         if (itFound != iPreferredTags.end()) {
0061           //reset to preferred
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           //hit an ambiguity
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 }  // namespace
0084 
0085 void l1t::L1TGlobalUtilHelper::checkToUpdateTags(edm::BranchDescription const& branchDescription,
0086                                                  edm::ConsumesCollector consumesCollector,
0087                                                  bool findL1TAlgBlk,
0088                                                  bool findL1TExtBlk) {
0089   // This is only used if required InputTags were not specified already.
0090   // This is called early in the process, once for each product in the ProductRegistry.
0091   // The callback is registered when callWhenNewProductsRegistered is called.
0092   // It finds products by type and sets the token so that it can be used
0093   // later when getting the product.
0094 
0095   // The code will look for the corresponding product in ProductRegistry.
0096   // If the product is found, it checks the product label in
0097   // a vector of preferred input tags (hardwired now to "gtDigis" and
0098   // "hltGtDigis"). The first input tag from the vector of preferred input tags, with the
0099   // same label as the input tag found from provenance, is kept as input tag, if there are no
0100   // multiple products with the same label.
0101 
0102   // If multiple products are found and no one has a label in the vector of preferred input tags,
0103   // or if multiple products are found with the label in the vector of preferred input tags
0104   // (with different instance or process) the input tag is set to empty input tag, and L1GtUtil
0105   // will produce an error, as it is not possible to safely choose a product. In this case, one must
0106   // provide explicitly the correct input tag via configuration or in the constructor.
0107 
0108   // TODO decide if the preferred input tags must be given as input parameters
0109   // or stay hardwired
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   // GlobalAlgBlkBxCollection
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   // GlobalExtBlkBxCollection
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 }