Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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_consumesCollector(iC),
0011       m_l1GtRecordInputTag(pset.getParameter<edm::InputTag>("l1GtRecordInputTag")),
0012       m_l1GtReadoutRecordInputTag(pset.getParameter<edm::InputTag>("l1GtReadoutRecordInputTag")),
0013       m_l1GtTriggerMenuLiteInputTag(pset.getParameter<edm::InputTag>("l1GtTriggerMenuLiteInputTag")),
0014       m_findRecord(false),
0015       m_findReadoutRecord(false),
0016       m_findMenuLite(false),
0017       m_foundPreferredRecord(false),
0018       m_foundPreferredReadoutRecord(false),
0019       m_foundPreferredMenuLite(false) {
0020   m_l1GtRecordToken = iC.consumes<L1GlobalTriggerRecord>(m_l1GtRecordInputTag);
0021   m_l1GtReadoutRecordToken = iC.consumes<L1GlobalTriggerReadoutRecord>(m_l1GtReadoutRecordInputTag);
0022   if (useL1GtTriggerMenuLite) {
0023     m_l1GtTriggerMenuLiteToken = iC.consumes<L1GtTriggerMenuLite, edm::InRun>(m_l1GtTriggerMenuLiteInputTag);
0024   }
0025 }
0026 
0027 void L1GtUtilsHelper::fillDescription(edm::ParameterSetDescription& desc) {
0028   desc.add<edm::InputTag>("l1GtRecordInputTag", edm::InputTag());
0029   desc.add<edm::InputTag>("l1GtReadoutRecordInputTag", edm::InputTag());
0030   desc.add<edm::InputTag>("l1GtTriggerMenuLiteInputTag", edm::InputTag());
0031 }
0032 
0033 void L1GtUtilsHelper::operator()(edm::BranchDescription const& branchDescription) {
0034   // This is only used if required InputTags were not specified already.
0035   // This is called early in the process, once for each product in the ProductRegistry.
0036   // The callback is registered when callWhenNewProductsRegistered is called.
0037   // It finds products by type and sets the token so that it can be used
0038   // later when getting the product.
0039 
0040   // The code will look for the corresponding product in ProductRegistry.
0041   // If the product is found, it checks the product label in
0042   // a vector of preferred input tags (hardwired now to "gtDigis" and
0043   // "hltGtDigis"). The first input tag from the vector of preferred input tags, with the
0044   // same label as the input tag found from provenance, is kept as input tag, if there are no
0045   // multiple products with the same label.
0046 
0047   // If multiple products are found and no one has a label in the vector of preferred input tags,
0048   // or if multiple products are found with the label in the vector of preferred input tags
0049   // (with different instance or process) the input tag is set to empty input tag, and L1GtUtil
0050   // will produce an error, as it is not possible to safely choose a product. In this case, one must
0051   // provide explicitly the correct input tag via configuration or in the constructor.
0052 
0053   // TODO decide if the preferred input tags must be given as input parameters
0054   // or stay hardwired
0055 
0056   std::vector<edm::InputTag> preferredL1GtRecordInputTag = {edm::InputTag("gtDigis"), edm::InputTag("hltGtDigis")};
0057 
0058   std::vector<edm::InputTag> preferredL1GtReadoutRecordInputTag = {edm::InputTag("gtDigis"),
0059                                                                    edm::InputTag("hltGtDigis")};
0060 
0061   std::vector<edm::InputTag> preferredL1GtTriggerMenuLiteInputTag = {edm::InputTag("gtDigis"),
0062                                                                      edm::InputTag("hltGtDigis")};
0063 
0064   // L1GlobalTriggerRecord
0065 
0066   if (m_findRecord && (!m_foundMultipleL1GtRecord) &&
0067       (branchDescription.unwrappedTypeID() == edm::TypeID(typeid(L1GlobalTriggerRecord))) &&
0068       (branchDescription.branchType() == edm::InEvent)) {
0069     edm::InputTag tag{
0070         branchDescription.moduleLabel(), branchDescription.productInstanceName(), branchDescription.processName()};
0071 
0072     if (m_foundPreferredRecord) {
0073       // check if a preferred input tag was already found and compare it with the actual tag
0074       // if the instance or the process names are different, one has incompatible tags - set
0075       // the tag to empty input tag and indicate that multiple preferred input tags are found
0076       // so it is not possibly to choose safely an input tag
0077 
0078       if ((m_l1GtRecordInputTag.label() == branchDescription.moduleLabel()) &&
0079           ((m_l1GtRecordInputTag.instance() != branchDescription.productInstanceName()) ||
0080            (m_l1GtRecordInputTag.process() != branchDescription.processName()))) {
0081         LogDebug("L1GtUtils") << "\nWARNING: Found multiple preferred input tags for L1GlobalTriggerRecord product, "
0082                               << "\nwith different instaces or processes."
0083                               << "\nInput tag already found: " << (m_l1GtRecordInputTag) << "\nActual tag: " << (tag)
0084                               << "\nInput tag set to empty tag." << std::endl;
0085 
0086         m_foundMultipleL1GtRecord = true;
0087         m_l1GtRecordInputTag = edm::InputTag();
0088       }
0089     } else {
0090       // no preferred input tag found yet, check now with the actual tag
0091       for (std::vector<edm::InputTag>::const_iterator itPrefTag = preferredL1GtRecordInputTag.begin(),
0092                                                       itPrefTagEnd = preferredL1GtRecordInputTag.end();
0093            itPrefTag != itPrefTagEnd;
0094            ++itPrefTag) {
0095         if (branchDescription.moduleLabel() == itPrefTag->label()) {
0096           m_l1GtRecordInputTag = tag;
0097           m_l1GtRecordToken = m_consumesCollector.consumes<L1GlobalTriggerRecord>(tag);
0098           m_foundPreferredRecord = true;
0099           m_inputTagsL1GtRecord.push_back(tag);
0100 
0101           LogDebug("L1GtUtils") << "\nWARNING: Input tag for L1GlobalTriggerRecord product set to preferred input tag"
0102                                 << (tag) << std::endl;
0103           break;
0104         }
0105       }
0106     }
0107 
0108     if (!m_foundPreferredRecord) {
0109       // check if other input tag was found - if true, there are multiple input tags in the event,
0110       // none in the preferred input tags, so it is not possibly to choose safely an input tag
0111 
0112       if (m_inputTagsL1GtRecord.size() > 1) {
0113         LogDebug("L1GtUtils") << "\nWARNING: Found multiple input tags for L1GlobalTriggerRecord product."
0114                               << "\nNone is in the preferred input tags - no safe choice."
0115                               << "\nInput tag already found: " << (m_l1GtRecordInputTag) << "\nActual tag: " << (tag)
0116                               << "\nInput tag set to empty tag." << std::endl;
0117         m_l1GtRecordInputTag = edm::InputTag();
0118         m_foundMultipleL1GtRecord = true;
0119 
0120       } else {
0121         if (m_l1GtRecordToken.isUninitialized()) {
0122           m_l1GtRecordInputTag = tag;
0123           m_inputTagsL1GtRecord.push_back(tag);
0124           m_l1GtRecordToken = m_consumesCollector.consumes<L1GlobalTriggerRecord>(tag);
0125 
0126           LogDebug("L1GtUtils") << "\nWARNING: No preferred input tag found for L1GlobalTriggerReadoutRecord product."
0127                                 << "\nInput tag set to " << (tag) << std::endl;
0128         }
0129       }
0130     }
0131   }
0132 
0133   // L1GlobalTriggerReadoutRecord
0134 
0135   if (m_findReadoutRecord && (!m_foundMultipleL1GtReadoutRecord) &&
0136       (branchDescription.unwrappedTypeID() == edm::TypeID(typeid(L1GlobalTriggerReadoutRecord))) &&
0137       (branchDescription.branchType() == edm::InEvent)) {
0138     edm::InputTag tag{
0139         branchDescription.moduleLabel(), branchDescription.productInstanceName(), branchDescription.processName()};
0140 
0141     if (m_foundPreferredReadoutRecord) {
0142       // check if a preferred input tag was already found and compare it with the actual tag
0143       // if the instance or the process names are different, one has incompatible tags - set
0144       // the tag to empty input tag and indicate that multiple preferred input tags are found
0145       // so it is not possibly to choose safely an input tag
0146 
0147       if ((m_l1GtReadoutRecordInputTag.label() == branchDescription.moduleLabel()) &&
0148           ((m_l1GtReadoutRecordInputTag.instance() != branchDescription.productInstanceName()) ||
0149            (m_l1GtReadoutRecordInputTag.process() != branchDescription.processName()))) {
0150         LogDebug("L1GtUtils")
0151             << "\nWARNING: Found multiple preferred input tags for L1GlobalTriggerReadoutRecord product, "
0152             << "\nwith different instaces or processes."
0153             << "\nInput tag already found: " << (m_l1GtReadoutRecordInputTag) << "\nActual tag: " << (tag)
0154             << "\nInput tag set to empty tag." << std::endl;
0155 
0156         m_foundMultipleL1GtReadoutRecord = true;
0157         m_l1GtReadoutRecordInputTag = edm::InputTag();
0158       }
0159     } else {
0160       // no preferred input tag found yet, check now with the actual tag
0161 
0162       for (std::vector<edm::InputTag>::const_iterator itPrefTag = preferredL1GtReadoutRecordInputTag.begin(),
0163                                                       itPrefTagEnd = preferredL1GtReadoutRecordInputTag.end();
0164            itPrefTag != itPrefTagEnd;
0165            ++itPrefTag) {
0166         if (branchDescription.moduleLabel() == itPrefTag->label()) {
0167           m_l1GtReadoutRecordInputTag = tag;
0168           m_l1GtReadoutRecordToken = m_consumesCollector.consumes<L1GlobalTriggerReadoutRecord>(tag);
0169           m_foundPreferredReadoutRecord = true;
0170           m_inputTagsL1GtReadoutRecord.push_back(tag);
0171 
0172           LogDebug("L1GtUtils")
0173               << "\nWARNING: Input tag for L1GlobalTriggerReadoutRecord product set to preferred input tag" << (tag)
0174               << std::endl;
0175           break;
0176         }
0177       }
0178     }
0179 
0180     if (!m_foundPreferredReadoutRecord) {
0181       // check if other input tag was found - if true, there are multiple input tags in the event,
0182       // none in the preferred input tags, so it is not possibly to choose safely an input tag
0183 
0184       if (m_inputTagsL1GtReadoutRecord.size() > 1) {
0185         LogDebug("L1GtUtils") << "\nWARNING: Found multiple input tags for L1GlobalTriggerReadoutRecord product."
0186                               << "\nNone is in the preferred input tags - no safe choice."
0187                               << "\nInput tag already found: " << (m_l1GtReadoutRecordInputTag)
0188                               << "\nActual tag: " << (tag) << "\nInput tag set to empty tag." << std::endl;
0189         m_l1GtReadoutRecordInputTag = edm::InputTag();
0190         m_foundMultipleL1GtReadoutRecord = true;
0191 
0192       } else {
0193         if (m_l1GtReadoutRecordToken.isUninitialized()) {
0194           m_l1GtReadoutRecordInputTag = tag;
0195           m_inputTagsL1GtReadoutRecord.push_back(tag);
0196           m_l1GtReadoutRecordToken = m_consumesCollector.consumes<L1GlobalTriggerReadoutRecord>(tag);
0197 
0198           LogDebug("L1GtUtils") << "\nWARNING: No preferred input tag found for L1GlobalTriggerReadoutRecord product."
0199                                 << "\nInput tag set to " << (tag) << std::endl;
0200         }
0201       }
0202     }
0203   }
0204 
0205   // L1GtTriggerMenuLite
0206 
0207   if (m_findMenuLite && (!m_foundMultipleL1GtMenuLite) &&
0208       (branchDescription.unwrappedTypeID() == edm::TypeID(typeid(L1GtTriggerMenuLite))) &&
0209       (branchDescription.branchType() == edm::InEvent)) {
0210     edm::InputTag tag{
0211         branchDescription.moduleLabel(), branchDescription.productInstanceName(), branchDescription.processName()};
0212 
0213     if (m_foundPreferredMenuLite) {
0214       // check if a preferred input tag was already found and compare it with the actual tag
0215       // if the instance or the process names are different, one has incompatible tags - set
0216       // the tag to empty input tag and indicate that multiple preferred input tags are found
0217       // so it is not possibly to choose safely an input tag
0218 
0219       if ((m_l1GtTriggerMenuLiteInputTag.label() == branchDescription.moduleLabel()) &&
0220           ((m_l1GtTriggerMenuLiteInputTag.instance() != branchDescription.productInstanceName()) ||
0221            (m_l1GtTriggerMenuLiteInputTag.process() != branchDescription.processName()))) {
0222         LogDebug("L1GtUtils") << "\nWARNING: Found multiple preferred input tags for L1GtTriggerMenuLite product, "
0223                               << "\nwith different instaces or processes."
0224                               << "\nInput tag already found: " << (m_l1GtTriggerMenuLiteInputTag)
0225                               << "\nActual tag: " << (tag) << "\nInput tag set to empty tag." << std::endl;
0226 
0227         m_foundMultipleL1GtMenuLite = true;
0228         m_l1GtTriggerMenuLiteInputTag = edm::InputTag();
0229       }
0230     } else {
0231       // no preferred input tag found yet, check now with the actual tag
0232 
0233       for (std::vector<edm::InputTag>::const_iterator itPrefTag = preferredL1GtTriggerMenuLiteInputTag.begin(),
0234                                                       itPrefTagEnd = preferredL1GtTriggerMenuLiteInputTag.end();
0235            itPrefTag != itPrefTagEnd;
0236            ++itPrefTag) {
0237         if (branchDescription.moduleLabel() == itPrefTag->label()) {
0238           m_l1GtTriggerMenuLiteInputTag = tag;
0239           m_l1GtTriggerMenuLiteToken = m_consumesCollector.consumes<L1GtTriggerMenuLite>(tag);
0240           m_foundPreferredMenuLite = true;
0241           m_inputTagsL1GtMenuLite.push_back(tag);
0242 
0243           LogDebug("L1GtUtils") << "\nWARNING: Input tag for L1GtTriggerMenuLite product set to preferred input tag"
0244                                 << (tag) << std::endl;
0245           break;
0246         }
0247       }
0248     }
0249 
0250     if (!m_foundPreferredMenuLite) {
0251       // check if other input tag was found - if true, there are multiple input tags in the event,
0252       // none in the preferred input tags, so it is not possibly to choose safely an input tag
0253 
0254       if (m_inputTagsL1GtMenuLite.size() > 1) {
0255         LogDebug("L1GtUtils") << "\nWARNING: Found multiple input tags for L1GtTriggerMenuLite product."
0256                               << "\nNone is in the preferred input tags - no safe choice."
0257                               << "\nInput tag already found: " << (m_l1GtTriggerMenuLiteInputTag)
0258                               << "\nActual tag: " << (tag) << "\nInput tag set to empty tag." << std::endl;
0259         m_l1GtTriggerMenuLiteInputTag = edm::InputTag();
0260         m_foundMultipleL1GtMenuLite = true;
0261 
0262       } else {
0263         if (m_l1GtTriggerMenuLiteToken.isUninitialized()) {
0264           m_l1GtTriggerMenuLiteInputTag = tag;
0265           m_inputTagsL1GtMenuLite.push_back(tag);
0266           m_l1GtTriggerMenuLiteToken = m_consumesCollector.consumes<L1GtTriggerMenuLite>(tag);
0267 
0268           LogDebug("L1GtUtils") << "\nWARNING: No preferred input tag found for L1GtTriggerMenuLite product."
0269                                 << "\nInput tag set to " << (tag) << std::endl;
0270         }
0271       }
0272     }
0273   }
0274 }