Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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_consumesCollector(iC),
0011       m_l1tAlgBlkInputTag(pset.getParameter<edm::InputTag>("l1tAlgBlkInputTag")),
0012       m_l1tExtBlkInputTag(pset.getParameter<edm::InputTag>("l1tExtBlkInputTag")),
0013       m_findL1TAlgBlk(false),
0014       m_findL1TExtBlk(false),
0015       m_readPrescalesFromFile(pset.getParameter<bool>("ReadPrescalesFromFile")),
0016       m_foundPreferredL1TAlgBlk(false),
0017       m_foundPreferredL1TExtBlk(false) {
0018   m_l1tAlgBlkToken = iC.consumes<GlobalAlgBlkBxCollection>(m_l1tAlgBlkInputTag);
0019   m_l1tExtBlkToken = iC.consumes<GlobalExtBlkBxCollection>(m_l1tExtBlkInputTag);
0020 }
0021 
0022 void l1t::L1TGlobalUtilHelper::fillDescription(edm::ParameterSetDescription& desc) {
0023   desc.add<edm::InputTag>("l1tAlgBlkInputTag", edm::InputTag());
0024   desc.add<edm::InputTag>("l1tExtBlkInputTag", edm::InputTag());
0025   desc.add<bool>("ReadPrescalesFromFile", false);
0026 }
0027 
0028 void l1t::L1TGlobalUtilHelper::operator()(edm::BranchDescription const& branchDescription) {
0029   // This is only used if required InputTags were not specified already.
0030   // This is called early in the process, once for each product in the ProductRegistry.
0031   // The callback is registered when callWhenNewProductsRegistered is called.
0032   // It finds products by type and sets the token so that it can be used
0033   // later when getting the product.
0034 
0035   // The code will look for the corresponding product in ProductRegistry.
0036   // If the product is found, it checks the product label in
0037   // a vector of preferred input tags (hardwired now to "gtDigis" and
0038   // "hltGtDigis"). The first input tag from the vector of preferred input tags, with the
0039   // same label as the input tag found from provenance, is kept as input tag, if there are no
0040   // multiple products with the same label.
0041 
0042   // If multiple products are found and no one has a label in the vector of preferred input tags,
0043   // or if multiple products are found with the label in the vector of preferred input tags
0044   // (with different instance or process) the input tag is set to empty input tag, and L1GtUtil
0045   // will produce an error, as it is not possible to safely choose a product. In this case, one must
0046   // provide explicitly the correct input tag via configuration or in the constructor.
0047 
0048   // TODO decide if the preferred input tags must be given as input parameters
0049   // or stay hardwired
0050 
0051   if (branchDescription.dropped()) {
0052     return;
0053   }
0054 
0055   std::vector<edm::InputTag> preferredL1TAlgBlkInputTag = {edm::InputTag("gtStage2Digis"),
0056                                                            edm::InputTag("hltGtStage2Digis")};
0057 
0058   std::vector<edm::InputTag> preferredL1TExtBlkInputTag = {edm::InputTag("gtStage2Digis"),
0059                                                            edm::InputTag("hltGtStage2Digis")};
0060 
0061   // GlobalAlgBlkBxCollection
0062 
0063   if (m_findL1TAlgBlk && (!m_foundMultipleL1TAlgBlk) &&
0064       (branchDescription.unwrappedTypeID() == edm::TypeID(typeid(GlobalAlgBlkBxCollection))) &&
0065       (branchDescription.branchType() == edm::InEvent)) {
0066     edm::InputTag tag{
0067         branchDescription.moduleLabel(), branchDescription.productInstanceName(), branchDescription.processName()};
0068 
0069     if (m_foundPreferredL1TAlgBlk) {
0070       // check if a preferred input tag was already found and compare it with the actual tag
0071       // if the instance or the process names are different, one has incompatible tags - set
0072       // the tag to empty input tag and indicate that multiple preferred input tags are found
0073       // so it is not possibly to choose safely an input tag
0074 
0075       if ((m_l1tAlgBlkInputTag.label() == branchDescription.moduleLabel()) &&
0076           ((m_l1tAlgBlkInputTag.instance() != branchDescription.productInstanceName()) ||
0077            (m_l1tAlgBlkInputTag.process() != branchDescription.processName()))) {
0078         LogDebug("L1TGlobalUtil") << "\nWARNING: Found multiple preferred input tags for GlobalAlgBlkBxCollection, "
0079                                   << "\nwith different instaces or processes."
0080                                   << "\nInput tag already found: " << (m_l1tAlgBlkInputTag) << "\nActual tag: " << (tag)
0081                                   << "\nInput tag set to empty tag." << std::endl;
0082 
0083         m_foundMultipleL1TAlgBlk = true;
0084         m_l1tAlgBlkInputTag = edm::InputTag();
0085       }
0086     } else {
0087       // no preferred input tag found yet, check now with the actual tag
0088       for (std::vector<edm::InputTag>::const_iterator itPrefTag = preferredL1TAlgBlkInputTag.begin(),
0089                                                       itPrefTagEnd = preferredL1TAlgBlkInputTag.end();
0090            itPrefTag != itPrefTagEnd;
0091            ++itPrefTag) {
0092         if (branchDescription.moduleLabel() == itPrefTag->label()) {
0093           m_l1tAlgBlkInputTag = tag;
0094           m_l1tAlgBlkToken = m_consumesCollector.consumes<GlobalAlgBlkBxCollection>(tag);
0095           m_foundPreferredL1TAlgBlk = true;
0096           m_inputTagsL1TAlgBlk.push_back(tag);
0097 
0098           LogDebug("L1TGlobalUtil")
0099               << "\nWARNING: Input tag for GlobalAlgBlkBxCollection product set to preferred input tag" << (tag)
0100               << std::endl;
0101           break;
0102         }
0103       }
0104     }
0105 
0106     if (!m_foundPreferredL1TAlgBlk) {
0107       // check if other input tag was found - if true, there are multiple input tags in the event,
0108       // none in the preferred input tags, so it is not possibly to choose safely an input tag
0109 
0110       if (m_inputTagsL1TAlgBlk.size() > 1) {
0111         LogDebug("L1TGlobalUtil") << "\nWARNING: Found multiple input tags for GlobalAlgBlkBxCollection product."
0112                                   << "\nNone is in the preferred input tags - no safe choice."
0113                                   << "\nInput tag already found: " << (m_l1tAlgBlkInputTag) << "\nActual tag: " << (tag)
0114                                   << "\nInput tag set to empty tag." << std::endl;
0115         m_l1tAlgBlkInputTag = edm::InputTag();
0116         m_foundMultipleL1TAlgBlk = true;
0117 
0118       } else {
0119         if (m_l1tAlgBlkToken.isUninitialized()) {
0120           m_l1tAlgBlkInputTag = tag;
0121           m_inputTagsL1TAlgBlk.push_back(tag);
0122           m_l1tAlgBlkToken = m_consumesCollector.consumes<GlobalAlgBlkBxCollection>(tag);
0123 
0124           LogDebug("L1TGlobalUtil") << "\nWARNING: No preferred input tag found for GlobalAlgBlkBxCollection."
0125                                     << "\nInput tag set to " << (tag) << std::endl;
0126         }
0127       }
0128     }
0129   }
0130 
0131   // GlobalExtBlkBxCollection
0132 
0133   if (m_findL1TExtBlk && (!m_foundMultipleL1TExtBlk) &&
0134       (branchDescription.unwrappedTypeID() == edm::TypeID(typeid(GlobalExtBlkBxCollection))) &&
0135       (branchDescription.branchType() == edm::InEvent)) {
0136     edm::InputTag tag{
0137         branchDescription.moduleLabel(), branchDescription.productInstanceName(), branchDescription.processName()};
0138 
0139     if (m_foundPreferredL1TExtBlk) {
0140       // check if a preferred input tag was already found and compare it with the actual tag
0141       // if the instance or the process names are different, one has incompatible tags - set
0142       // the tag to empty input tag and indicate that multiple preferred input tags are found
0143       // so it is not possibly to choose safely an input tag
0144 
0145       if ((m_l1tExtBlkInputTag.label() == branchDescription.moduleLabel()) &&
0146           ((m_l1tExtBlkInputTag.instance() != branchDescription.productInstanceName()) ||
0147            (m_l1tExtBlkInputTag.process() != branchDescription.processName()))) {
0148         LogDebug("L1TGlobalUtil") << "\nWARNING: Found multiple preferred input tags for GlobalExtBlkBxCollection, "
0149                                   << "\nwith different instaces or processes."
0150                                   << "\nInput tag already found: " << (m_l1tExtBlkInputTag) << "\nActual tag: " << (tag)
0151                                   << "\nInput tag set to empty tag." << std::endl;
0152 
0153         m_foundMultipleL1TExtBlk = true;
0154         m_l1tExtBlkInputTag = edm::InputTag();
0155       }
0156     } else {
0157       // no preferred input tag found yet, check now with the actual tag
0158 
0159       for (std::vector<edm::InputTag>::const_iterator itPrefTag = preferredL1TExtBlkInputTag.begin(),
0160                                                       itPrefTagEnd = preferredL1TExtBlkInputTag.end();
0161            itPrefTag != itPrefTagEnd;
0162            ++itPrefTag) {
0163         if (branchDescription.moduleLabel() == itPrefTag->label()) {
0164           m_l1tExtBlkInputTag = tag;
0165           m_l1tExtBlkToken = m_consumesCollector.consumes<GlobalExtBlkBxCollection>(tag);
0166           m_foundPreferredL1TExtBlk = true;
0167           m_inputTagsL1TExtBlk.push_back(tag);
0168 
0169           LogDebug("L1TGlobalUtil")
0170               << "\nWARNING: Input tag for GlobalExtBlkBxCollection product set to preferred input tag" << (tag)
0171               << std::endl;
0172           break;
0173         }
0174       }
0175     }
0176 
0177     if (!m_foundPreferredL1TExtBlk) {
0178       // check if other input tag was found - if true, there are multiple input tags in the event,
0179       // none in the preferred input tags, so it is not possibly to choose safely an input tag
0180 
0181       if (m_inputTagsL1TExtBlk.size() > 1) {
0182         LogDebug("L1TGlobalUtil") << "\nWARNING: Found multiple input tags for GlobalExtBlkBxCollection."
0183                                   << "\nNone is in the preferred input tags - no safe choice."
0184                                   << "\nInput tag already found: " << (m_l1tExtBlkInputTag) << "\nActual tag: " << (tag)
0185                                   << "\nInput tag set to empty tag." << std::endl;
0186         m_l1tExtBlkInputTag = edm::InputTag();
0187         m_foundMultipleL1TExtBlk = true;
0188 
0189       } else {
0190         if (m_l1tExtBlkToken.isUninitialized()) {
0191           m_l1tExtBlkInputTag = tag;
0192           m_inputTagsL1TExtBlk.push_back(tag);
0193           m_l1tExtBlkToken = m_consumesCollector.consumes<GlobalExtBlkBxCollection>(tag);
0194 
0195           LogDebug("L1TGlobalUtil") << "\nWARNING: No preferred input tag found for GlobalExtBlkBxCollection product."
0196                                     << "\nInput tag set to " << (tag) << std::endl;
0197         }
0198       }
0199     }
0200   }
0201 }