CMS 3D CMS Logo

L1GtUtilsHelper.cc
Go to the documentation of this file.
6 
8 
10  : m_l1GtRecordInputTag(pset.getParameter<edm::InputTag>("l1GtRecordInputTag")),
11  m_l1GtReadoutRecordInputTag(pset.getParameter<edm::InputTag>("l1GtReadoutRecordInputTag")),
12  m_l1GtTriggerMenuLiteInputTag(pset.getParameter<edm::InputTag>("l1GtTriggerMenuLiteInputTag")) {
17  }
18 }
19 
21  desc.add<edm::InputTag>("l1GtRecordInputTag", edm::InputTag());
22  desc.add<edm::InputTag>("l1GtReadoutRecordInputTag", edm::InputTag());
23  desc.add<edm::InputTag>("l1GtTriggerMenuLiteInputTag", edm::InputTag());
24 }
25 
26 namespace {
27  template <typename C, typename T>
28  void setConsumesAndCheckAmbiguities(edm::BranchDescription const& iDesc,
29  C const& iPreferredTags,
30  T& ioToken,
31  edm::InputTag& ioTag,
32  edm::ConsumesCollector& iCollector,
33  const char* iTypeForErrorMessage) {
34  if (ioTag.label().empty()) {
35  //hasn't been set yet
36  ioTag = edm::InputTag{iDesc.moduleLabel(), iDesc.productInstanceName(), iDesc.processName()};
37 
38  ioToken = iCollector.consumes(ioTag);
39  LogDebug("L1GtUtils")
40  << "Input tag found for " << iTypeForErrorMessage << " product.\n Input tag set to " << (ioTag) << "\n Tag is"
41  << ((iPreferredTags.end() != std::find(iPreferredTags.begin(), iPreferredTags.end(), ioTag.label())) ? ""
42  : " not")
43  << " found in preferred tags list " << std::endl;
44 
45  } else {
46  bool alreadyFoundPreferred =
47  iPreferredTags.end() != std::find(iPreferredTags.begin(), iPreferredTags.end(), ioTag.label());
48  if (alreadyFoundPreferred) {
49  if (std::find(iPreferredTags.begin(), iPreferredTags.end(), iDesc.moduleLabel()) != iPreferredTags.end()) {
50  edm::LogError("L1GtUtils") << "Found multiple preferred input tags for " << iTypeForErrorMessage
51  << " product, "
52  << "\nwith different instaces or processes."
53  << "\nTag already found: " << (ioTag) << "\nOther tag: "
54  << (edm::InputTag{
55  iDesc.moduleLabel(), iDesc.productInstanceName(), iDesc.processName()})
56  << "\nToken set to invalid." << std::endl;
57  //another preferred also found
58  ioToken = T{};
59  }
60  } else {
61  //previous choice was not preferred
62 
63  auto itFound = std::find(iPreferredTags.begin(), iPreferredTags.end(), iDesc.moduleLabel());
64  if (itFound != iPreferredTags.end()) {
65  //reset to preferred
66  auto oldTag = ioTag;
67  ioTag = edm::InputTag{iDesc.moduleLabel(), iDesc.productInstanceName(), iDesc.processName()};
68 
69  ioToken = iCollector.consumes(ioTag);
70  edm::LogWarning("L1GtUtils") << "Found preferred tag " << (ioTag) << "\n after having set unpreferred tag ("
71  << oldTag << ") for " << iTypeForErrorMessage
72  << ".\n Please change configuration to explicitly use the tag given above.\n "
73  "This will avoid unnecessary prefetching of data not used.";
74  } else {
75  //hit an ambiguity
76  edm::LogWarning("L1GtUtils") << "Found multiple input tags for " << iTypeForErrorMessage << " product."
77  << "\nNone is in the preferred input tags - no safe choice."
78  << "\nTag already found: " << (ioTag) << "\nOther tag: "
79  << (edm::InputTag{
80  iDesc.moduleLabel(), iDesc.productInstanceName(), iDesc.processName()})
81  << "\nToken set to invalid." << std::endl;
82  ioToken = T{};
83  }
84  }
85  }
86  }
87 } // namespace
89  edm::ConsumesCollector consumesCollector,
90  bool findRecord,
91  bool findReadoutRecord,
92  bool findMenuLite) {
93  if (branchDescription.dropped()) {
94  return;
95  }
96  // This is only used if required InputTags were not specified already.
97  // This is called early in the process, once for each product in the ProductRegistry.
98  // The callback is registered when callWhenNewProductsRegistered is called.
99  // It finds products by type and sets the token so that it can be used
100  // later when getting the product.
101 
102  // The code will look for the corresponding product in ProductRegistry.
103  // If the product is found, it checks the product label in
104  // a vector of preferred input tags (hardwired now to "gtDigis" and
105  // "hltGtDigis"). The first input tag from the vector of preferred input tags, with the
106  // same label as the input tag found from provenance, is kept as input tag, if there are no
107  // multiple products with the same label.
108 
109  // If multiple products are found and no one has a label in the vector of preferred input tags,
110  // or if multiple products are found with the label in the vector of preferred input tags
111  // (with different instance or process) the input tag is set to empty input tag, and L1GtUtil
112  // will produce an error, as it is not possible to safely choose a product. In this case, one must
113  // provide explicitly the correct input tag via configuration or in the constructor.
114 
115  // TODO decide if the preferred input tags must be given as input parameters
116  // or stay hardwired
117 
118  std::vector<edm::InputTag> preferredL1GtRecordInputTag = {edm::InputTag("gtDigis"), edm::InputTag("hltGtDigis")};
119 
120  std::vector<edm::InputTag> preferredL1GtReadoutRecordInputTag = {edm::InputTag("gtDigis"),
121  edm::InputTag("hltGtDigis")};
122 
123  std::vector<edm::InputTag> preferredL1GtTriggerMenuLiteInputTag = {edm::InputTag("gtDigis"),
124  edm::InputTag("hltGtDigis")};
125 
126  // L1GlobalTriggerRecord
127 
128  if (findRecord && (branchDescription.unwrappedTypeID() == edm::TypeID(typeid(L1GlobalTriggerRecord))) &&
129  (branchDescription.branchType() == edm::InEvent)) {
130  setConsumesAndCheckAmbiguities(branchDescription,
131  preferredL1GtRecordInputTag,
134  consumesCollector,
135  "L1GlobalTriggerRecord");
136  }
137 
138  // L1GlobalTriggerReadoutRecord
139 
140  if (findReadoutRecord && (branchDescription.unwrappedTypeID() == edm::TypeID(typeid(L1GlobalTriggerReadoutRecord))) &&
141  (branchDescription.branchType() == edm::InEvent)) {
142  setConsumesAndCheckAmbiguities(branchDescription,
143  preferredL1GtReadoutRecordInputTag,
146  consumesCollector,
147  "L1GlobalTriggerReadoutRecord");
148  }
149 
150  // L1GtTriggerMenuLite
151 
152  if (findMenuLite && (branchDescription.unwrappedTypeID() == edm::TypeID(typeid(L1GtTriggerMenuLite))) &&
153  (branchDescription.branchType() == edm::InEvent)) {
154  setConsumesAndCheckAmbiguities(branchDescription,
155  preferredL1GtTriggerMenuLiteInputTag,
158  consumesCollector,
159  "L1GtTriggerMenuLite");
160  }
161 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::InputTag m_l1GtReadoutRecordInputTag
BranchType const & branchType() const
TypeID unwrappedTypeID() const
std::string const & processName() const
edm::EDGetTokenT< L1GtTriggerMenuLite > m_l1GtTriggerMenuLiteToken
std::string const & label() const
Definition: InputTag.h:36
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::InputTag m_l1GtTriggerMenuLiteInputTag
edm::InputTag m_l1GtRecordInputTag
std::string const & productInstanceName() const
static void fillDescription(edm::ParameterSetDescription &desc)
edm::EDGetTokenT< L1GlobalTriggerRecord > m_l1GtRecordToken
void checkToUpdateTags(edm::BranchDescription const &branchDescription, edm::ConsumesCollector, bool findRecord, bool findReadoutRecord, bool findMenuLite)
static const bool useL1GtTriggerMenuLite(true)
HLT enums.
Log< level::Warning, false > LogWarning
edm::EDGetTokenT< L1GlobalTriggerReadoutRecord > m_l1GtReadoutRecordToken
long double T
std::string const & moduleLabel() const
L1GtUtilsHelper(edm::ParameterSet const &pset, edm::ConsumesCollector &iC, bool useL1GtTriggerMenuLite)
#define LogDebug(id)