ATLAS Offline Software
DecisionAccess.icc
Go to the documentation of this file.
1 #if !defined(XAOD_STANDALONE) && !defined(XAOD_ANALYSIS) // Full athena
2 
3 template<class T>
4 Trig::Feature<T> Trig::DecisionAccess::ancestor(const HLT::TriggerElement* te, std::string label) const {
5  Trig::Feature<T> f;
6  std::vector<Trig::Feature<T> > data;
7  FeatureAccessImpl::collect<T>(te, data, label, TrigDefs::alsoDeactivateTEs, "", cgm()->navigation());
8 
9  for( Feature<T>& f : data ) {
10  if ( f.owned() ) {
11  cgm()->deleteAtTheEndOfEvent( f.cptr() );
12  }
13  }
14 
15  if (data.size() == 1)
16  f = data[0];
17  return f;
18 }
19 
20 
21 template<class T>
22 std::vector<Trig::Feature<T> > Trig::DecisionAccess::ancestors(const HLT::TriggerElement* te, std::string label, unsigned int condition, const std::string& teName) const {
23  std::vector<Trig::Feature<T> > data;
24  FeatureAccessImpl::collect<T>(te, data, label, condition, teName, cgm()->navigation());
25  for( Feature<T>& f : data ) {
26  if ( f.owned() ) {
27  cgm()->deleteAtTheEndOfEvent( f.cptr() );
28  }
29  }
30  return data;
31 }
32 
33 #else // AnalysisBase
34 
35 template<class T>
36 Trig::Feature<T> Trig::DecisionAccess::ancestor(const HLT::TriggerElement* /*te*/, std::string /*label*/) const {
37  ATH_MSG_WARNING("DecisionAccess::ancestor not implemented in Standalone mode, since it needs compile-time type information. Returning empty Feature");
38  return Trig::Feature<T>();
39 }
40 
41 template<class T>
42 std::vector<Trig::Feature<T> > Trig::DecisionAccess::ancestors(const HLT::TriggerElement* /*te*/, std::string /*label*/, unsigned int /*condition*/, const std::string& /*teName*/) const {
43  ATH_MSG_WARNING("DecisionAccess::ancestor not implemented in Standalone mode, since it needs compile-time type information. Returning empty vector");
44  return std::vector<Trig::Feature<T> >();
45 }
46 
47 #endif
48 
49 template<class CONTAINER>
50 std::vector< TrigCompositeUtils::LinkInfo<CONTAINER> > Trig::DecisionAccess::features(const Trig::FeatureRequestDescriptor& featureRequest) const {
51  return features<CONTAINER>(featureRequest.chainGroup(), featureRequest.condition(), featureRequest.SGKey(),
52  featureRequest.featureCollectionMode(), featureRequest.linkName(), featureRequest.restrictRequestToLeg());
53 }
54 
55 template<class CONTAINER>
56 std::vector< TrigCompositeUtils::LinkInfo<CONTAINER> > Trig::DecisionAccess::features(const Trig::ChainGroup* group,
57  const unsigned int condition,
58  const std::string& containerSGKey,
59  const unsigned int featureCollectionMode,
60  const std::string& navElementLinkKey,
61  const int restrictToLegIndex) const {
62  const SG::ReadHandleKey<TrigCompositeUtils::DecisionContainer>* navRHK = cgm()->getRun3NavigationKeyPtr();
63  if (!navRHK || navRHK->empty()) {
64  ATH_MSG_ERROR("Trig::DecisionAccess::features: Run 3 Trigger Navigation ReadHandleKey not set. " << (navRHK == nullptr ? "(nullptr)." : "(empty).") << " Check that the TDT's 'NavigationFormat' property is set to 'TrigComposite' for R3, "
65  "and the 'HLTSummary' property is set to the correct HLTNav_Summary_OnlineSlimmed / HLTNav_Summary_AODSlimmed / HLTNav_Summary_DAODSlimmed collection for the given input file.");
66  return std::vector< TrigCompositeUtils::LinkInfo<CONTAINER> >();
67  }
68  return group->features<CONTAINER>(cgm()->store(), cgm()->getRun3NavigationKey(), condition, containerSGKey, featureCollectionMode, navElementLinkKey, restrictToLegIndex);
69 }
70 
71 template<class CONTAINER>
72 std::vector< TrigCompositeUtils::LinkInfo<CONTAINER> > Trig::DecisionAccess::features(const std::string& chainName,
73  const unsigned int condition,
74  const std::string& containerSGKey,
75  const unsigned int featureCollectionMode,
76  const std::string& navElementLinkKey,
77  const int restrictToLegIndex) const {
78  const Trig::ChainGroup *g = cgm()->createChainGroup(Trig::convertStringToVector(chainName));
79  return features<CONTAINER>(g, condition, containerSGKey, featureCollectionMode, navElementLinkKey, restrictToLegIndex);
80 }
81 
82 template<class CONTAINER, class FEATURE_CONTAINER>
83 std::pair< typename CONTAINER::const_iterator, typename CONTAINER::const_iterator >
84 Trig::DecisionAccess::associateToEventView(SG::ReadHandle<CONTAINER>& inViewContainer,
85  const TrigCompositeUtils::LinkInfo<FEATURE_CONTAINER> linkInfo,
86  const std::string& roiName) const {
87  return associateToEventView(inViewContainer, linkInfo.source, roiName);
88 }
89 
90 template<class CONTAINER>
91 std::pair< typename CONTAINER::const_iterator, typename CONTAINER::const_iterator >
92 Trig::DecisionAccess::associateToEventView(SG::ReadHandle<CONTAINER>& inViewContainer,
93  const TrigCompositeUtils::Decision* decisionObject,
94  const std::string& roiName) const {
95  using TrigCompositeUtils::LinkInfo;
96  using TrigCompositeUtils::findLink;
97  LinkInfo<TrigRoiDescriptorCollection> roiLI = findLink<TrigRoiDescriptorCollection>(decisionObject, roiName);
98  // We don't actually need to be able to resolve the ElementLink, but we should check that one was returned from the Navigation.
99  if (roiLI.link.key() == 0) {
100  ATH_MSG_ERROR("Unable to locate an ElementLink with name " << roiName << " from given Decision object.");
101  throw std::runtime_error("Trig::DecisionAccess::associateToEventView Unable to locate an ElementLink with name "+roiName+
102  " from given Decision object.");
103  }
104  return associateToEventView(inViewContainer, roiLI.link);
105 }
106 
107 template<class CONTAINER>
108 std::pair< typename CONTAINER::const_iterator, typename CONTAINER::const_iterator >
109 Trig::DecisionAccess::associateToEventView(SG::ReadHandle<CONTAINER>& inViewContainer,
110  const ElementLink<TrigRoiDescriptorCollection>& matchROI) const {
111  // If we can resolve the link, then we can also check the fullscan flag.
112  bool isFullscan = false;
113  if (matchROI.isValid()) {
114  isFullscan = (*matchROI)->isFullscan();
115  }
116  return associateToEventView(inViewContainer, matchROI.index(), matchROI.key(), isFullscan);
117 }
118 
119 template<class CONTAINER>
120 std::pair< typename CONTAINER::const_iterator, typename CONTAINER::const_iterator >
121 Trig::DecisionAccess::associateToEventView(SG::ReadHandle<CONTAINER>& inViewContainer,
122  const uint32_t matchIndex,
123  const uint32_t matchKey,
124  const bool isFullscan) const {
125  if (!inViewContainer.isValid()) {
126  std::stringstream ss;
127  ss << "Supplied ReadHandle '" << inViewContainer.key() << "' of type '" << ClassID_traits<CONTAINER>::typeName() << "' is not valid.";
128  ATH_MSG_ERROR(ss.str());
129  throw std::runtime_error("Trig::DecisionAccess::associateToEventView "+ss.str());
130  }
131  const CONTAINER* container = inViewContainer.cptr();
132  const typename CONTAINER::const_iterator end = container->end();
133  typename CONTAINER::const_iterator foundStartIt = end, foundEndIt = end;
134  static const SG::AuxElement::ConstAccessor< ElementLink<TrigRoiDescriptorCollection> > accessor("viewIndex");
135  for (typename CONTAINER::const_iterator it = container->begin(); it != end; ++it) {
136  if (!accessor.isAvailable(**it)) { // iterator dereferences to an OBJECT*, OBJECT* dereferences to an OBJECT
137  if (isFullscan) {
138  ATH_MSG_DEBUG("Supplied container has no viewIndex decoration. But isFullscan flag is TRUE. "
139  << "Returning a pair of iterators over the whole of the container.");
140  return std::make_pair(container->begin(), end);
141  } else {
142  ATH_MSG_WARNING("Unable to read the viewIndex decoration from the supplied container. Was it created inside an EventView? "
143  << "Returning a pair of iterators from the end of the container.");
144  return std::make_pair(end, end);
145  }
146  }
147  const ElementLink<TrigRoiDescriptorCollection> objectROI = accessor( **it );
148  bool match = true;
149  if (objectROI.index() != matchIndex) { // Always match on the Index
150  match = false;
151  }
152  if (matchKey != 0 && objectROI.key() != matchKey ) { // Matching on the Key is optional
153  match = false;
154  }
155  if (match && foundStartIt == end) { // Found the start of this ROI's objects
156  foundStartIt = it;
157  }
158  if (!match && foundStartIt != end) { // Found the end of this ROI's objects
159  foundEndIt = it;
160  break;
161  }
162  }
163  return std::make_pair(foundStartIt, foundEndIt);
164 }
165