CMS 3D CMS Logo

L1TGlobalUtilHelper.cc
Go to the documentation of this file.
6 
8 
10  : m_l1tAlgBlkInputTag(pset.getParameter<edm::InputTag>("l1tAlgBlkInputTag")),
11  m_l1tExtBlkInputTag(pset.getParameter<edm::InputTag>("l1tExtBlkInputTag")),
12  m_readPrescalesFromFile(pset.getParameter<bool>("ReadPrescalesFromFile")) {
15 }
16 
18  edm::InputTag const& iAlg,
19  edm::InputTag const& iExt,
20  bool readPrescalesFromFile) {
21  desc.add<edm::InputTag>("l1tAlgBlkInputTag", iAlg);
22  desc.add<edm::InputTag>("l1tExtBlkInputTag", iExt);
23  desc.add<bool>("ReadPrescalesFromFile", readPrescalesFromFile);
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  throw cms::Exception("L1GtUtils::TooManyChoices")
51  << "Found multiple preferred input tags for " << iTypeForErrorMessage << " product, "
52  << "\nwith different instaces or processes."
53  << "\nTag already found: " << (ioTag) << "\nOther tag: "
54  << (edm::InputTag{iDesc.moduleLabel(), iDesc.productInstanceName(), iDesc.processName()});
55  }
56  } else {
57  //previous choice was not preferred
58 
59  auto itFound = std::find(iPreferredTags.begin(), iPreferredTags.end(), iDesc.moduleLabel());
60  if (itFound != iPreferredTags.end()) {
61  //reset to preferred
62  auto oldTag = ioTag;
63  ioTag = edm::InputTag{iDesc.moduleLabel(), iDesc.productInstanceName(), iDesc.processName()};
64 
65  ioToken = iCollector.consumes(ioTag);
66  edm::LogWarning("L1GtUtils") << "Found preferred tag " << (ioTag) << "\n after having set unpreferred tag ("
67  << oldTag << ") for " << iTypeForErrorMessage
68  << ".\n Please change configuration to explicitly use the tag given above.\n "
69  "This will avoid unnecessary prefetching of data not used.";
70  } else {
71  //hit an ambiguity
72  edm::LogWarning("L1GtUtils") << "Found multiple input tags for " << iTypeForErrorMessage << " product."
73  << "\nNone is in the preferred input tags - no safe choice."
74  << "\nTag already found: " << (ioTag) << "\nOther tag: "
75  << (edm::InputTag{
76  iDesc.moduleLabel(), iDesc.productInstanceName(), iDesc.processName()})
77  << "\nToken set to invalid." << std::endl;
78  ioToken = T{};
79  }
80  }
81  }
82  }
83 } // namespace
84 
86  edm::ConsumesCollector consumesCollector,
87  bool findL1TAlgBlk,
88  bool findL1TExtBlk) {
89  // This is only used if required InputTags were not specified already.
90  // This is called early in the process, once for each product in the ProductRegistry.
91  // The callback is registered when callWhenNewProductsRegistered is called.
92  // It finds products by type and sets the token so that it can be used
93  // later when getting the product.
94 
95  // The code will look for the corresponding product in ProductRegistry.
96  // If the product is found, it checks the product label in
97  // a vector of preferred input tags (hardwired now to "gtDigis" and
98  // "hltGtDigis"). The first input tag from the vector of preferred input tags, with the
99  // same label as the input tag found from provenance, is kept as input tag, if there are no
100  // multiple products with the same label.
101 
102  // If multiple products are found and no one has a label in the vector of preferred input tags,
103  // or if multiple products are found with the label in the vector of preferred input tags
104  // (with different instance or process) the input tag is set to empty input tag, and L1GtUtil
105  // will produce an error, as it is not possible to safely choose a product. In this case, one must
106  // provide explicitly the correct input tag via configuration or in the constructor.
107 
108  // TODO decide if the preferred input tags must be given as input parameters
109  // or stay hardwired
110 
111  if (branchDescription.dropped()) {
112  return;
113  }
114 
115  std::vector<edm::InputTag> preferredL1TAlgBlkInputTag = {edm::InputTag("gtStage2Digis"),
116  edm::InputTag("hltGtStage2Digis")};
117 
118  std::vector<edm::InputTag> preferredL1TExtBlkInputTag = {edm::InputTag("gtStage2Digis"),
119  edm::InputTag("hltGtStage2Digis")};
120 
121  // GlobalAlgBlkBxCollection
122 
123  if (findL1TAlgBlk && (branchDescription.unwrappedTypeID() == edm::TypeID(typeid(GlobalAlgBlkBxCollection))) &&
124  (branchDescription.branchType() == edm::InEvent)) {
125  setConsumesAndCheckAmbiguities(branchDescription,
126  preferredL1TAlgBlkInputTag,
127  m_l1tAlgBlkToken,
128  m_l1tAlgBlkInputTag,
129  consumesCollector,
130  "GlobalAlgBlkBxCollection");
131  }
132 
133  // GlobalExtBlkBxCollection
134 
135  if (findL1TExtBlk && (branchDescription.unwrappedTypeID() == edm::TypeID(typeid(GlobalExtBlkBxCollection))) &&
136  (branchDescription.branchType() == edm::InEvent)) {
137  setConsumesAndCheckAmbiguities(branchDescription,
138  preferredL1TExtBlkInputTag,
139  m_l1tExtBlkToken,
140  m_l1tExtBlkInputTag,
141  consumesCollector,
142  "GlobalExtBlkBxCollection");
143  }
144 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
BranchType const & branchType() const
TypeID unwrappedTypeID() const
std::string const & processName() const
std::string const & label() const
Definition: InputTag.h:36
L1TGlobalUtilHelper(edm::ParameterSet const &pset, edm::ConsumesCollector &iC)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::EDGetTokenT< GlobalExtBlkBxCollection > m_l1tExtBlkToken
static void fillDescription(edm::ParameterSetDescription &desc, edm::InputTag const &iAlg, edm::InputTag const &iExt, bool readPrescalesFromFile)
std::string const & productInstanceName() const
edm::EDGetTokenT< GlobalAlgBlkBxCollection > m_l1tAlgBlkToken
void checkToUpdateTags(edm::BranchDescription const &branchDescription, edm::ConsumesCollector, bool findL1TAlgBlk, bool findL1TExtBlk)
HLT enums.
Log< level::Warning, false > LogWarning
long double T
std::string const & moduleLabel() const
#define LogDebug(id)