ATLAS Offline Software
Loading...
Searching...
No Matches
TrigBStoxAODTool.cxx
Go to the documentation of this file.
1// Dear emacs, this is -*- c++ -*-
2
3/*
4 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5*/
6
8
12
14#include "GaudiKernel/ClassID.h"
15
17
19
21
22
26
30
33
37
40
41
44
47
50
53
56
59
64
69
70
73
76
79
82
85
88
92
93#include "CaloEvent/CaloClusterContainer.h"
95
99
102
103namespace {
105 template <typename T, typename Element>
106 struct MatchFeaturesStrict {
107 static constexpr bool value = Element::list_of_features::template has<T>;
108 };
109
111 template<typename T>
112 constexpr int getCLID() {
113 constexpr bool known = TypeInfo_EDM::map::template has<T, MatchFeaturesStrict>;
114 if constexpr (known) return ClassID_traits<T>::ID();
115 else return -1;
116 }
117}
118
120
121 //Helper class providing interface for conversion and some convenient access to SG and Msg Services
122 class IHelper{
123 public:
124 virtual ~IHelper(){;}
125 virtual StatusCode initialize(MsgStream& m, StoreGateSvc& s){
126 m_msg = &m;
127 m_sg = &s;
128 return StatusCode::SUCCESS;
129 };
130
131 virtual StatusCode help(const EventContext& ctx, const std::string& label, const std::string& newLabel) = 0;
132
133 //we need this method, because for creating converted xAOD::TrigPassBits, one needs access to the corresponding xaod container
134 //with physics objects. This leads to a partial duplication of the code for the muon helper
135 virtual StatusCode help_fillTrigPassBits(const std::string& label, const std::string& newLabel, const TrigPassBits* tpb_aod, xAOD::TrigPassBits*& tpb_xaod) = 0;
136
137 virtual CLID AODContainerClid() = 0;
138 virtual CLID xAODContainerClid() = 0;
139 virtual CLID AODElementClid() = 0;
140 virtual CLID xAODElementClid() = 0;
141
142 MsgStream& msg(MSG::Level l){return *m_msg << l;}
143 bool msgLvl (const MSG::Level l){
144 if(m_msg->level() <= l){
145 *m_msg << l; return true;
146 } else {
147 return false;
148 };
149 }
150
151 template<typename T>
152 std::string format(const std::string& label){
154 }
155 protected:
156 MsgStream* m_msg{nullptr};
158 const std::string m_AODprefix = "HLT";
159 };
160
161 //class holding a tool, since this is what all helpers will need to do.
162 template<typename T>
163 class ToolHolder : public IHelper {
164 protected:
165 const ToolHandle<T>& m_tool;
166 ToolHandle<T>& tool(){return m_tool;}
167 public:
168 ToolHolder(const ToolHandle<T>& tool) : m_tool(tool){;}
169 virtual ~ToolHolder(){;}
170 virtual StatusCode initialize(MsgStream& m, StoreGateSvc& s){
172 CHECK(m_tool.retrieve());
173 return StatusCode::SUCCESS;
174 }
175 };
176
177 //this is the most vanilla case
178 template<typename AOD,typename XAOD, typename CnvTool, bool withCtx = false>
179 struct DefaultHelper : public ToolHolder<CnvTool> {
181
182 DefaultHelper(const ToolHandle<CnvTool>& tool) : ToolHolder<CnvTool>(tool){;}
183
184 CLID AODContainerClid(){return getCLID<AOD>();}
185 CLID xAODContainerClid(){return getCLID<XAOD>();}
186
187 CLID AODElementClid(){return getCLID<Container2Object_t<AOD>>();}
188 CLID xAODElementClid(){return getCLID<Container2Object_t<XAOD>>();}
189
190 virtual StatusCode help(const EventContext& ctx, const std::string& label, const std::string& newLabel){
191 typedef IHelper IH;
192 std::string fmtkey_AOD = IH::template format<AOD>(label);
193 std::string fmtkey_xAOD = IH::template format<XAOD>(newLabel);
194 std::string fmtkey_xAODAux = IH::template format<xAODAux>(newLabel+"Aux.");
195
196 const AOD* aod = this->m_sg->template tryConstRetrieve<AOD>(fmtkey_AOD);
197 if(!aod){
198 ATH_MSG_WARNING("AOD key: " << fmtkey_AOD << " not found for xAOD conversion");
199 return StatusCode::SUCCESS;
200 }
201
202 ATH_MSG_DEBUG("attempting to convert " << fmtkey_AOD << " of size " << aod->size() << " to " << fmtkey_xAOD);
203
204 XAOD* xaod = this->m_sg->template tryRetrieve<XAOD>(fmtkey_xAOD);
205 if(!xaod){
206 ATH_MSG_WARNING("xAOD key: " << fmtkey_xAOD << " not found for xAOD conversion");
207 return StatusCode::SUCCESS;
208 }
209 if constexpr (withCtx) CHECK( this->m_tool->convert(ctx, aod,xaod));
210 else CHECK( this->m_tool->convert(aod,xaod));
211 ATH_MSG_DEBUG("AOD container has size: " << aod->size());
212 ATH_MSG_DEBUG("xAOD container has size: " << xaod->size());
213 if(aod->size() != xaod->size()){
214 ATH_MSG_ERROR("conversion resulted in differently sized containers");
215 return StatusCode::FAILURE;
216 }
217 return StatusCode::SUCCESS;
218 }
219
220 virtual StatusCode help_fillTrigPassBits(const std::string& label, const std::string& newLabel, const TrigPassBits* tpb_aod, xAOD::TrigPassBits*& tpb_xaod){
221 typedef IHelper IH;
222 std::string fmtkey_AOD = IH::template format<AOD>(label);
223 std::string fmtkey_xAOD = IH::template format<XAOD>(newLabel);
224 std::string fmtkey_xAODAux = IH::template format<xAODAux>(newLabel+"Aux.");
225
226 const AOD* aod = this->m_sg->template tryConstRetrieve<AOD>(fmtkey_AOD);
227 if(!aod){
228 ATH_MSG_WARNING("AOD key: " << fmtkey_AOD << " not found");
229 return StatusCode::SUCCESS;
230 }
231 ATH_MSG_DEBUG( "AOD container " << fmtkey_AOD << " extracted of size " << aod->size() );
232 // it was found out that in Run 1 data for some containers the size of the TrigPassBits object differs from
233 // the size of the corresponding container. It was decided to not convert TrigPassBits->xAOD::TrigPassBits for such cases,
234 // so xAOD::TrigPassBits will be nullptr
235 if( aod->size() != tpb_aod->size() ) {
236 ATH_MSG_WARNING( "sizes of the container " << fmtkey_AOD << " and the corresponding (?) trigpassbits object are different: "
237 << aod->size() << " vs " << tpb_aod->size() << ", will not convert TrigPassBits for this container" );
238 return StatusCode::SUCCESS;
239 }
240
241 XAOD* xaod = this->m_sg->template tryRetrieve<XAOD>(fmtkey_xAOD);
242 if(!xaod){
243 ATH_MSG_WARNING("xAOD key: " << fmtkey_xAOD << " not found");
244 return StatusCode::SUCCESS;
245 }
246 ATH_MSG_DEBUG("xAOD container " << fmtkey_xAOD << " extracted of size " << xaod->size());
247
248 if(aod->size() != xaod->size()) {
249 ATH_MSG_ERROR("containers before and after the conversion are of different sizes");
250 return StatusCode::FAILURE;
251 }
252
253 ATH_MSG_DEBUG( "setting xaod passbits size to " << tpb_aod->size() );
254 std::unique_ptr<xAOD::TrigPassBits> xBits = xAOD::makeTrigPassBits(xaod);
255
256 for(uint i=0; i<aod->size(); i++) {
257 // if(i < tpb_aod->size() ){
258 ATH_MSG_DEBUG( "looking at object " << i+1 << " of " << aod->size() );
259 bool passed = HLT::isPassing( tpb_aod, aod->at(i), aod );
260 ATH_MSG_DEBUG( "aod ispassing = " << passed );
261 ATH_MSG_DEBUG( "xaod ispassing = " << xBits->isPassing( i ) );
262 if(passed)
263 xBits->markPassing( i );
264 ATH_MSG_DEBUG( "xaod ispassing (after update) = " << xBits->isPassing( i ) );
265 /* } else {
266 ATH_MSG_DEBUG( "skipping object " << i+1 << " as it is outside of the array range of the corresponding aod TrigPassBits object" );
267 }*/
268 }
269 tpb_xaod = xBits.release();
270 return StatusCode::SUCCESS;
271 }
272 };
273
274 struct MuonHelper : public ToolHolder<ITrigMuonEFInfoToMuonCnvTool> {
275 MuonHelper(const ToolHandle<ITrigMuonEFInfoToMuonCnvTool>& tool) : ToolHolder(tool){;}
276
277 CLID AODContainerClid(){return getCLID<TrigMuonEFInfoContainer>();}
278 CLID xAODContainerClid(){return getCLID<xAOD::MuonContainer>();}
279
280 CLID AODElementClid(){return getCLID<Container2Object_t<TrigMuonEFInfoContainer>>();}
281 CLID xAODElementClid(){return getCLID<Container2Object_t<xAOD::MuonContainer>>();}
282
283 virtual StatusCode help(const EventContext& /*ctx*/, const std::string& label, const std::string& newLabel){
284 xAOD::MuonContainer* xaodMuon = this->m_sg->tryRetrieve<xAOD::MuonContainer>(format<xAOD::MuonContainer>(newLabel));
285 if(!xaodMuon){
286 ATH_MSG_WARNING("muon label: " << format<xAOD::MuonContainer>(newLabel) << " not found for xAOD conversion");
287 return StatusCode::SUCCESS;
288 }
289
290 xAOD::TrackParticleContainer* xaodCombTrackParticles = this->m_sg->tryRetrieve<xAOD::TrackParticleContainer>(format<xAOD::TrackParticleContainer>(newLabel+"_CombTrackParticles"));
291 if(!xaodCombTrackParticles){
292 ATH_MSG_WARNING("muon label: " << format<xAOD::TrackParticleContainer>(newLabel+"_CombTrackParticles") << " not found for xAOD conversion");
293 return StatusCode::SUCCESS;
294 }
295
296 xAOD::TrackParticleContainer* xaodExtrapTrackParticles = this->m_sg->tryRetrieve<xAOD::TrackParticleContainer>(format<xAOD::TrackParticleContainer>(newLabel+"_ExtrapTrackParticles"));
297 if(!xaodCombTrackParticles){
298 ATH_MSG_WARNING("muon label: " << format<xAOD::TrackParticleContainer>(newLabel+"_ExtrapTrackParticles") << " not found for xAOD conversion");
299 return StatusCode::SUCCESS;
300 }
301
302 const TrigMuonEFInfoContainer* aod =
304 if(!aod){
305 ATH_MSG_WARNING("muon label: " << format<TrigMuonEFInfoContainer>(label) << " not found for xAOD conversion");
306 return StatusCode::SUCCESS;
307 }
308
309 CHECK(this->m_tool->convertTrigMuonEFInfoContainer( *aod, *xaodMuon, xaodCombTrackParticles, xaodExtrapTrackParticles));
310
311 ATH_MSG_DEBUG("Muon AOD container has size: " << aod->size());
312 ATH_MSG_DEBUG("Muon xAOD container has size: " << xaodMuon->size());
313
314 return StatusCode::SUCCESS;
315 }
316
317 virtual StatusCode help_fillTrigPassBits(const std::string& label, const std::string& newLabel, const TrigPassBits* tpb_aod, xAOD::TrigPassBits*& tpb_xaod){
318
319 const TrigMuonEFInfoContainer* aod = this->m_sg->template tryConstRetrieve<TrigMuonEFInfoContainer>(label);
320 if(!aod){
321 ATH_MSG_WARNING("AOD key: " << label << " not found");
322 return StatusCode::SUCCESS;
323 }
324 ATH_MSG_DEBUG( "AOD muon container " << label << " extracted of size " << aod->size() );
325 if( aod->size() != tpb_aod->size() ) {
326 ATH_MSG_WARNING( "sizes of the muon container " << label << " and the corresponding (?) trigpassbits object are different: "
327 << aod->size() << " vs " << tpb_aod->size() << ", will not convert TrigPassBits for this container" );
328 }
329 xAOD::MuonContainer* xaodMuon = this->m_sg->template tryRetrieve<xAOD::MuonContainer>(format<xAOD::MuonContainer>(newLabel));
330 if(!xaodMuon){
331 ATH_MSG_WARNING("xAOD key: " << format<xAOD::MuonContainer>(newLabel) << " not found");
332 return StatusCode::SUCCESS;
333 }
334 ATH_MSG_DEBUG("xAOD muon container " << format<xAOD::MuonContainer>(newLabel) << " extracted of size " << xaodMuon->size());
335
336 if(aod->size() != xaodMuon->size()) {
337 ATH_MSG_ERROR("containers before and after the conversion are of different sizes");
338 return StatusCode::FAILURE;
339 }
340
341 ATH_MSG_DEBUG( "setting muon xaod passbits size to " << tpb_aod->size() );
342 std::unique_ptr<xAOD::TrigPassBits> xBits = xAOD::makeTrigPassBits(xaodMuon);
343
344 for(uint i=0; i<aod->size(); i++) {
345 // if(i < tpb_aod->size() ){
346 ATH_MSG_DEBUG( "looking at muon object " << i+1 << " of " << aod->size() );
347 bool passed = HLT::isPassing( tpb_aod, aod->at(i), aod );
348 ATH_MSG_DEBUG( "muon aod ispassing = " << passed );
349 ATH_MSG_DEBUG( "muon xaod ispassing = " << xBits->isPassing( i ) );
350 if(passed)
351 xBits->markPassing( i );
352 ATH_MSG_DEBUG( "muon xaod ispassing (after update) = " << xBits->isPassing( i ) );
353 /* } else {
354 ATH_MSG_DEBUG( "skipping object " << i+1 << " as it is outside of the array range of the corresponding aod TrigPassBits object" );
355 }*/
356 }
357 tpb_xaod = xBits.release();
358 return StatusCode::SUCCESS;
359 }
360 };
361
362} // namespace BStoXAODHelper
363
364TrigBStoxAODTool::TrigBStoxAODTool(const std::string& type, const std::string& name, const IInterface* parent)
365 : AthAlgTool(type,name,parent),
366 m_tauJetTool( "xAODMaker::TauJetCnvTool/TauJetCnvTool",this),
367 m_combMuonTool( "xAODMaker::CombinedMuonFeatureContainerCnvTool/CombinedMuonFeatureContainerCnvTool",this),
368 m_isoMuonTool( "xAODMaker::IsoMuonFeatureContainerCnvTool/IsoMuonFeatureContainerCnvTool",this),
369 m_trigMuonTool( "TrigMuonEFInfoToMuonCnvTool/TrigMuonEFInfoToMuonCnvTool",this),
370 m_jetCnvTool( "xAODMaker::JetCnvTool/JetCnvTool",this),
371 m_trigCaloClusterTool( "xAODMaker::TrigCaloClusterCnvTool/TrigCaloClusterCnvTool",this),
372 m_emClusterTool( "xAODMaker::TrigEMClusterCnvTool/TrigEMClusterCnvTool",this),
373 m_bjetTool( "xAODMaker::TrigBjetCnvTool/TrigBjetCnvTool",this),
374 m_efBphysTool( "xAODMaker::TrigEFBphysContainerCnvTool/TrigEFBphysContainerCnvTool",this),
375 m_l2BphysTool( "xAODMaker::TrigL2BphysContainerCnvTool/TrigL2BphysContainerCnvTool",this),
376 m_trigMetTool( "xAODMaker::TrigMissingETCnvTool/TrigMissingETCnvTool",this),
377 m_trigSpacePtsTool("xAODMaker::TrigSpacePointCountsCnvTool/TrigSpacePointCountsCnvTool",this),
378 m_trigMbtsBitsTool("xAODMaker::TrigT2MbtsBitsCnvTool/TrigT2MbtsBitsCnvTool",this),
379 m_trigTrackCtsTool("xAODMaker::TrigTrackCountsCnvTool/TrigTrackCountsCnvTool",this),
380 m_trigVtxCtsTool( "xAODMaker::TrigVertexCountsCnvTool/TrigVertexCountsCnvTool",this),
381 m_electronTool( "xAODMaker::ElectronCnvTool/ElectronCnvTool", this ),
382 m_photonTool( "xAODMaker::PhotonCnvTool/PhotonCnvTool", this ),
383 m_caloClusterTool( "xAODMaker::CaloClusterCnvTool/CaloClusterCnvTool", this),
384 m_trigPassBitsTool( "xAODMaker::TrigPassBitsCnvTool/TrigPassBitsCnvTool", this )
385{
386 declareInterface<ITrigBStoxAODTool>( this );
387 declareProperty("ContainersToConvert",m_containersToConvert);
388 declareProperty("NewContainers", m_newContainers);
389
390 declareProperty("tauJetTool", m_tauJetTool);
391 declareProperty("combMuonTool", m_combMuonTool);
392 declareProperty("isoMuonTool", m_isoMuonTool);
393 declareProperty("trigMuonTool", m_trigMuonTool);
394 declareProperty("jetCnvTool", m_jetCnvTool);
395
396 declareProperty("trigCaloClusterTool", m_trigCaloClusterTool);
397 declareProperty("emClusterTool", m_emClusterTool);
398 declareProperty("bjetTool", m_bjetTool);
399 declareProperty("efBphysTool", m_efBphysTool);
400 declareProperty("l2BphysTool", m_l2BphysTool);
401
402 declareProperty("trigMetTool", m_trigMetTool);
403 declareProperty("trigSpacePtsTool", m_trigSpacePtsTool);
404 declareProperty("trigMbtsBitsTool", m_trigMbtsBitsTool);
405 declareProperty("trigTrackCtsTool", m_trigTrackCtsTool);
406 declareProperty("trigVtxCtsTool", m_trigVtxCtsTool);
407 declareProperty("electronTool", m_electronTool);
408 declareProperty("photonTool", m_photonTool);
409 declareProperty("caloClusterTool", m_caloClusterTool);
410 declareProperty("trigPassBitsTool", m_trigPassBitsTool);
411
412 m_CLID_xAODPhotonContainer = getCLID<xAOD::PhotonContainer>();
413 m_CLID_xAODElectronContainer = getCLID<xAOD::ElectronContainer>();
414}
415
417 std::map<CLID,BStoXAODHelper::IHelper*>::iterator it;
418 for(it = m_helpers.begin();it!=m_helpers.end();++it){
419 delete it->second;
420 }
421}
422
424
434
435 m_helpers.insert( std::pair<CLID,BStoXAODHelper::MuonHelper*>
438
448
458
468
474
480
486
492
498
501 (getCLID<TrigTrackCountsCollection>(),
504
510
516
517
523
529
535
541
547
553
554
555 std::multimap<CLID,BStoXAODHelper::IHelper*>::iterator it;
556 for(it = m_helpers.begin();it!=m_helpers.end();++it){
557 CHECK(it->second->initialize(this->msg(),*(evtStore())));
558 }
559
560 ATH_MSG_DEBUG("containers to convert: " << m_containersToConvert);
561 ATH_MSG_DEBUG("containers will be converted to: " << m_newContainers);
563 ATH_MSG_DEBUG("extracted class IDs (" << m_clid_labels.size() << " in total): " << m_clid_labels);
564
565 if(m_clid_labels.size() != m_clid_newLabels.size()) {
566 ATH_MSG_ERROR("number of new containers names (" << m_clid_newLabels.size()
567 << ") is not the same as the number of old containers names ("
568 << m_clid_newLabels.size() << ")");
569 return StatusCode::FAILURE;
570 }
571 ATH_MSG_DEBUG("CLID CLID, old label, new label:");
572 for(uint i=0; i<m_clid_labels.size(); i++) {
573 ATH_MSG_DEBUG(m_clid_labels[i].first << " " << m_clid_newLabels[i].first << ", "
574 << m_clid_labels[i].second << ", " << m_clid_newLabels[i].second );
575 if(m_clid_labels[i].second != m_clid_newLabels[i].second) {
576 ATH_MSG_VERBOSE("Run-1 " << m_clid_labels[i].first << " label " <<
577 m_clid_labels[i].second << " differs from the equivalent Run-2 label: "
578 << m_clid_newLabels[i].second);
579 }
580 }
581
582 return StatusCode::SUCCESS;
583}
584
585StatusCode TrigBStoxAODTool::convert(const EventContext& ctx, HLT::Navigation* nav) {
586 std::vector<std::pair<CLID,std::string> >::const_iterator clidlabel;
587 std::vector<std::pair<CLID,std::string> >::const_iterator clidNewLabel = m_clid_newLabels.begin();
588 for(clidlabel =m_clid_labels.begin();clidlabel!=m_clid_labels.end();++clidlabel, ++clidNewLabel){
589
590 HLTNavDetails::IHolder* holder = nav->getHolder(clidlabel->first,clidlabel->second);
591
592 if(!holder){
593 ATH_MSG_WARNING("couldn't find holder for " << clidlabel->first << " " << clidlabel->second);
594 continue;
595 }
596
597 ATH_MSG_VERBOSE("container corresponding to feature CLID " << clidlabel->first << " has CLID " << holder->containerClid());
598
599 std::multimap<CLID,BStoXAODHelper::IHelper*>::const_iterator hit;
600 hit = m_helpers.end();//find(holder->containerClid());
601
602 std::string clabel = clidlabel->second;
603 CHECK(findHelper( m_helpers, holder->containerClid(), clabel, hit ));
604
605 if(hit!=m_helpers.end()){
606 ATH_MSG_DEBUG("attempting convertion of clid " << holder->containerClid()
607 << " for label " << clidlabel->second << ", new label " << clidNewLabel->second);
608 CHECK(hit->second->help(ctx, clidlabel->second,clidNewLabel->second));//get aod container and convert
609 ATH_MSG_DEBUG("converted clid " << holder->containerClid() << " for label " << clidlabel->second);
610 }
611 else{
612 ATH_MSG_DEBUG("couldn't find converters for clid: " << clidlabel->first);
613 }
614 }
615 return StatusCode::SUCCESS;
616}
617
619 //we need to loop over all features of all TEs
620 //find the ones pointing to a AOD container that has been converted
621 //and change the holder they use to access the feature, i.e. changes CLID and subTypeIndex
622
623 std::vector<HLT::TriggerElement*>& allTEs = nav->getAllTEs();
624 //nav->getAll(allTEs,false); //false: also get inactive TEs
625 ATH_MSG_DEBUG("rewiring Navigation for xAOD. working on " << allTEs.size() << " TEs");
626 for(auto te : allTEs){
627 std::vector<HLT::TriggerElement::FeatureAccessHelper>& feats = te->getFeatureAccessHelpers();
628 for(auto& featacchelp : feats){
629 ATH_MSG_VERBOSE("this feature has CLID: " << featacchelp.getCLID());
630
631 HLTNavDetails::IHolder* oldholder = nav->getHolder(featacchelp.getCLID(),featacchelp.getIndex().subTypeIndex());
632
633 if(!oldholder){
634 ATH_MSG_WARNING("could not find old holder for CLID " << featacchelp.getCLID() << " and subTypeIndex: " << featacchelp.getIndex());
635 continue;
636 }
637
638 std::multimap<CLID,BStoXAODHelper::IHelper*>::const_iterator it = m_helpers.end();//find(oldholder->containerClid());
639 std::string old_label = oldholder->label();
640 CHECK(findHelper( m_helpers, oldholder->containerClid(), old_label, it));
641 if(it != m_helpers.end()){
642 ATH_MSG_VERBOSE("need to rewire this CLID from " << oldholder->typeClid() << "/"<< oldholder->containerClid() << " to " << it->second->xAODContainerClid());
643
644 bool iselement = (oldholder->typeClid()==it->second->AODElementClid());
645 bool iscontainer = (oldholder->typeClid()==it->second->AODContainerClid());
646
647 ATH_MSG_VERBOSE("old is element feature " << iselement << " or container feature: " << iscontainer);
648
649 if(!(iselement || iscontainer)){
650 ATH_MSG_WARNING("not clear what kind of feature we're dealing with. Skipping. Old holder is:" << *oldholder);
651 }
652
653 CLID newTypeClid = CLID_NULL;
654 if(iselement) newTypeClid = it->second->xAODElementClid();
655 if(iscontainer) newTypeClid = it->second->xAODContainerClid();
656
657 std::lock_guard<std::recursive_mutex> lock(nav->getMutex());
658 HLT::TrigHolderStructure& holderstorage = nav->getHolderStorage();
659
660 HLTNavDetails::IHolder* newholder = holderstorage.getHolder<HLTNavDetails::IHolder>(newTypeClid,oldholder->label());
661
662 if(!newholder){
663 ATH_MSG_WARNING("could not find new holder for xAOD clid " << newTypeClid << " and label " << oldholder->label());
664 continue;
665 }
666
667 ATH_MSG_VERBOSE("old holder: " << *oldholder);
668 ATH_MSG_VERBOSE("new holder: " << *newholder);
669 ATH_MSG_VERBOSE("changing CLID: " << featacchelp.getCLID() << " to " << newTypeClid);
670 ATH_MSG_VERBOSE("changing STI: " << featacchelp.getIndex().subTypeIndex() << " to " << newholder->subTypeIndex());
671
672 featacchelp.setCLIDandIndex(newTypeClid,newholder->subTypeIndex());
673 ATH_MSG_VERBOSE("clid is now: " << featacchelp.getCLID() << " sti: " << featacchelp.getIndex().subTypeIndex());
674 ATH_MSG_VERBOSE("TE is: " << *te);
675 } // end if(helper was found)
676 }//end feature loop
677 }//end TE loop
678
679
680 return StatusCode::SUCCESS;
681}
682
683
684
685//blatantly stolen from navigation code
686StatusCode TrigBStoxAODTool::classLabel2CLIDLabel(const std::vector<std::string>& property,
687 const std::vector<std::string>& newProperty,
688 std::vector<std::pair<CLID,std::string> >& decoded,
689 std::vector<std::pair<CLID,std::string> >& decodedNewNames) {
690 // translate Class names into CLID numbers
691 SmartIF<IClassIDSvc> clidSvc{service("ClassIDSvc")};
692 ATH_CHECK( clidSvc.isValid() );
693
694 if( property.size() != newProperty.size() ) {
695 ATH_MSG_ERROR("vector sizes of new and old SG labels are different: "
696 << newProperty.size() << " vs " << property.size() );
697 return StatusCode::FAILURE;
698 }
699
700 std::vector<std::string>::const_iterator it;
701 std::vector<std::string>::const_iterator itNew = newProperty.begin();
702 for ( it = property.begin(); it != property.end(); ++it, ++itNew ) {
703 CLID clid{0};
704 std::string label;
705 std::string label_new;
706 std::string type;
707
708 if ( it->find('#') != std::string::npos ) {
709 type = it->substr(0, it->find('#') );
710 label = it->substr(it->find('#')+1 );
711 } else {
712 type = *it;
713 label = "";
714 }
715
716 if ( itNew->find('#') != std::string::npos ) {
717 label_new = itNew->substr(itNew->find('#')+1 );
718 } else {
719 label_new = "";
720 }
721
722 if ( clidSvc->getIDOfTypeName(type, clid).isFailure() ) {
723 ATH_MSG_FATAL("Unable to get CLID for class: " << *it
724 << " check property");
725 return StatusCode::FAILURE;
726 }
727
728 ATH_MSG_DEBUG("Recognized CLID : " << type << " and label: " << label << ", new label will be: " << label_new);
729 decoded.push_back(std::make_pair(clid, label));
730 decodedNewNames.push_back(std::make_pair(clid, label_new));
731 }
732 return StatusCode::SUCCESS;
733}
734
736 //we need to loop over all features of all TEs
737 //find the ones pointing to a AOD container that has been converted
738 //extract the corresponding aod TrigPassBits container and set the same
739 //bits in xAOD::TrigPassBits
740
741 std::vector<HLT::TriggerElement*>& allTEs = nav->getAllTEs();
742
743 ATH_MSG_DEBUG("setting xAOD TrigPassBits. Working on " << allTEs.size() << " TEs");
744
745 for(auto te : allTEs){
746 std::vector<HLT::TriggerElement::FeatureAccessHelper>& feats = te->getFeatureAccessHelpers();
747 for(auto& featacchelp : feats){
748 ATH_MSG_VERBOSE("this feature has CLID: " << featacchelp.getCLID());
749
750 HLTNavDetails::IHolder* holder = nav->getHolder(featacchelp.getCLID(),featacchelp.getIndex().subTypeIndex());
751
752 if(!holder){
753 ATH_MSG_WARNING("could not find holder for CLID " << featacchelp.getCLID() << " and subTypeIndex: " << featacchelp.getIndex());
754 continue;
755 }
756
757 if(holder->label() == "passbits") {
758 ATH_MSG_VERBOSE( "skipping this feature, as this is the passbits object itself" );
759 continue;
760 }
761
762 std::multimap<CLID,BStoXAODHelper::IHelper*>::const_iterator it = m_helpers.end();//find(holder->containerClid());
763 std::string hlabel = holder->label();
764 CHECK(findHelper( m_helpers, holder->containerClid(), hlabel, it ));
765 if(it != m_helpers.end()){
766
767 ATH_MSG_DEBUG( "need to extract TrigPassBits for this AOD object " << holder->typeClid() << "/"<< holder->containerClid()
768 << ", label " << holder->label() << " corresponding to xAOD CLID " << it->second->xAODContainerClid() );
769
770 bool iselement = (holder->typeClid()==it->second->AODElementClid());
771 bool iscontainer = (holder->typeClid()==it->second->AODContainerClid());
772
773 ATH_MSG_VERBOSE("is element feature " << iselement << " or container feature: " << iscontainer);
774
775 if(!(iselement || iscontainer)){
776 ATH_MSG_WARNING("not clear what kind of feature we're dealing with. Skipping. The holder is:" << *holder);
777 }
778
779 ATH_MSG_VERBOSE("holder: " << *holder);
780
781 const TrigPassBitsCollection* bits_collection = evtStore()->template tryConstRetrieve<TrigPassBitsCollection>("HLT_TrigPassBitsCollection_passbits");
782 if(bits_collection != nullptr) {
783 ATH_MSG_DEBUG( "aod bits collection extracted of size " << bits_collection->size() );
784 //dump this to compare with the results from release 17
785 // for(uint i=0; i<bits_collection->size(); i++ ) {
786 // std::cout << "size of the TrigPassBits object " << i << " is " << bits_collection->at(i)->size() << std::endl;
787 // }
788 } else {
789 ATH_MSG_WARNING( "aod bits collection cannot be extracted" );
790 continue;
791 }
792
793
794 xAOD::TrigPassBitsContainer* xaod_bits_collection = evtStore()->template tryRetrieve<xAOD::TrigPassBitsContainer>("HLT_xAOD__TrigPassBitsContainer_passbits");
795 if(xaod_bits_collection != nullptr)
796 ATH_MSG_DEBUG( "xaod bits container extracted of size " << xaod_bits_collection->size() );
797 else {
798 ATH_MSG_WARNING( "xaod bits container cannot be extracted" );
799 continue;
800 }
801
802 const TrigPassBits* bits(0);
803 if ( nav->getFeature(te, bits, "passbits" ) ){
804 ATH_MSG_DEBUG( "TrigPassBits extracted for the container " << holder->label() );
805 if(bits!=nullptr) {
806 ATH_MSG_DEBUG( "it's size is " << bits->size() );
807 } else {
808 ATH_MSG_DEBUG( "it is nullptr" );
809 continue;
810 }
811 } else {
812 ATH_MSG_WARNING( "this TE has no associated TrigPassBits object" );
813 continue;
814 }
815 if(bits_collection != nullptr && xaod_bits_collection != nullptr && bits != nullptr) {
816 int bits_nr = -1;
817 for(uint i=0; i<bits_collection->size(); i++) {
818 if(bits == bits_collection->at(i)) {
819 bits_nr = i;
820 ATH_MSG_VERBOSE( "this is bits # " << bits_nr );
821 break;
822 }
823 }
824 if(bits_nr >= 0) {
825 xAOD::TrigPassBits* xaod_tpb = nullptr;
826 std::pair<CLID,std::string> pair = std::make_pair( featacchelp.getCLID(), holder->label() );
827 std::vector<std::pair<CLID,std::string> >::const_iterator it_new_label;
828 it_new_label = std::find(m_clid_newLabels.begin(), m_clid_newLabels.end(), pair);
829 std::string new_label = "";
830 if(it_new_label != m_clid_newLabels.end()) {
831 new_label = (*it_new_label).second;
832 ATH_MSG_DEBUG( "calling help_fillTrigPassBits for TE " << te << ", feature CLID " << featacchelp.getCLID()
833 << ", aod container " << holder->label() << ", new container name: " << new_label );
834 CHECK( it->second->help_fillTrigPassBits( holder->label(), new_label, bits_collection->at(bits_nr), xaod_tpb ) );
835 } else {
836 ATH_MSG_DEBUG( "new label was not found, presumably this container was not converted. Will not look for TrigPassBits" );
837 }
838
839 if(xaod_tpb != nullptr) {
840 xaod_bits_collection->at(bits_nr) = xaod_tpb;
841 ATH_MSG_VERBOSE( "after the conversion, size of xAOD::TrigPassBits is " << xaod_bits_collection->at(bits_nr)->size() );
842 }
843
844 } else {
845 ATH_MSG_WARNING( "TrigPassBits object was not identified within container!" );
846 }
847 }// if good aod and xaod passbits are available
848 } // if helper was found
849 }// feature loop
850 }// TE loop
851
852
853 return StatusCode::SUCCESS;
854}
855
856// the following function returns iterator pointing to the desired converter, based on the clid of the AOD type and label
857StatusCode TrigBStoxAODTool::findHelper( MM_CLID_IHELPER& helpers, CLID clid, std::string& label, MM_CLID_IHELPER::const_iterator& it ) {
858 auto myrange = helpers.equal_range(clid);
859 it = myrange.first;
860 //let's see how many there are converters corresponding to the same AOD input type
861 int distance = std::distance(myrange.first, myrange.second);
862 if (distance == 1) {
863 //default case, one-to-one relation of AOD and xAOD types
864 ATH_MSG_VERBOSE("helper to convert AOD CLID " << clid << " and label " << label << " found");
865 return StatusCode::SUCCESS;
866 } else if (distance == 2) {
867 //this is for the case when there is single AOD type converted to two different xAOD types,
868 //will treat this here separately. So far this only happens for egammaContainer->xAOD::ElectronContainer and
869 //egammaContainer->xAOD::PhotonContainer
870 for(;it!=myrange.second;++it) {
871 CLID myHelperxAODCLID = (*it).second->xAODContainerClid();
872 if((label == "egamma_Electrons" && myHelperxAODCLID == m_CLID_xAODElectronContainer) ||
873 (label == "egamma_Photons" && myHelperxAODCLID == m_CLID_xAODPhotonContainer)) {
874 ATH_MSG_VERBOSE("helper to convert AOD CLID " << clid << " and label " << label << " found");
875 return StatusCode::SUCCESS;
876 }
877 }
878 } else if( distance == 0) {
879 ATH_MSG_WARNING("there is no helper to convert AOD CLID " << clid << ", label " << label);
880 it = helpers.end();
881 return StatusCode::SUCCESS;
882 } else {
883 //this should not happen...
884 ATH_MSG_ERROR("found " << distance << " helpers to convert AOD type " << clid << " and label " << label
885 << ", probably you should accomodate for this change in the code above" );
886 return StatusCode::FAILURE;
887 }
888
889 //this point is not reached if everything is OK
890 return StatusCode::SUCCESS;
891
892} // MM_CLID_IHELPER::const_iterator findHelper( ... )
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
Container2Aux< FEATURE, EDMLIST >::type Container2Aux_t
uint32_t CLID
The Class ID type.
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
bool passed(DecisionID id, const DecisionIDContainer &)
checks if required decision ID is in the set of IDs in the container
unsigned int uint
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
const std::string m_AODprefix
bool msgLvl(const MSG::Level l)
virtual CLID xAODElementClid()=0
virtual CLID AODContainerClid()=0
virtual StatusCode help(const EventContext &ctx, const std::string &label, const std::string &newLabel)=0
virtual CLID xAODContainerClid()=0
virtual CLID AODElementClid()=0
std::string format(const std::string &label)
virtual StatusCode help_fillTrigPassBits(const std::string &label, const std::string &newLabel, const TrigPassBits *tpb_aod, xAOD::TrigPassBits *&tpb_xaod)=0
MsgStream & msg(MSG::Level l)
virtual StatusCode initialize(MsgStream &m, StoreGateSvc &s)
virtual StatusCode initialize(MsgStream &m, StoreGateSvc &s)
ToolHolder(const ToolHandle< T > &tool)
const ToolHandle< T > & m_tool
const T * at(size_type n) const
Access an element, as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
virtual CLID containerClid() const =0
const std::string & label() const
returns the label of objects stores by this holder
Definition Holder.h:86
virtual CLID typeClid() const =0
returns the CLID of objects stores by this holder
uint16_t subTypeIndex() const
returns the index (short number used when linking object to the TE) of objects stores by this holder
Definition Holder.h:112
HLTNavDetails::Holder< T > * getHolder(uint16_t subTypeIndex) const
as above but does not create holder on demand (return 0 if not found)
bool getFeature(const TriggerElement *te, const T *&features, const std::string &label="", std::string &sourcelabel=::HLT::TrigNavStructure::m_unspecifiedLabel) const
The Navigation class, organizes TriggerElements into the tree structure.
Definition Navigation.h:100
HolderType * getHolder(class_id_type clid, const std::variant< sub_index_type, std::string > &stiOrLabel) const
std::vector< TriggerElement * > & getAllTEs()
access needed by slimming tools.
std::recursive_mutex & getMutex()
TrigHolderStructure & getHolderStorage()
The Athena Transient Store API.
std::multimap< CLID, BStoXAODHelper::IHelper * > MM_CLID_IHELPER
StatusCode setTrigPassBits(HLT::Navigation *nav)
std::vector< std::pair< CLID, std::string > > m_clid_newLabels
StatusCode findHelper(MM_CLID_IHELPER &helpers, CLID clid, std::string &label, MM_CLID_IHELPER::const_iterator &it)
ToolHandle< xAODMaker::ITrigBjetCnvTool > m_bjetTool
std::vector< std::pair< CLID, std::string > > m_clid_labels
virtual StatusCode initialize()
ToolHandle< xAODMaker::IIsoMuonFeatureContainerCnvTool > m_isoMuonTool
ToolHandle< xAODMaker::ITrigEFBphysContainerCnvTool > m_efBphysTool
ToolHandle< xAODMaker::IElectronCnvTool > m_electronTool
ToolHandle< xAODMaker::ITrigL2BphysContainerCnvTool > m_l2BphysTool
ToolHandle< xAODMaker::ITrigT2MbtsBitsCnvTool > m_trigMbtsBitsTool
ToolHandle< ITrigMuonEFInfoToMuonCnvTool > m_trigMuonTool
ToolHandle< xAODMaker::ITrigCaloClusterCnvTool > m_trigCaloClusterTool
ToolHandle< xAODMaker::ITrigSpacePointCountsCnvTool > m_trigSpacePtsTool
StatusCode classLabel2CLIDLabel(const std::vector< std::string > &property, const std::vector< std::string > &newProperty, std::vector< std::pair< CLID, std::string > > &decoded, std::vector< std::pair< CLID, std::string > > &decodedNewNames)
std::vector< std::string > m_newContainers
ToolHandle< xAODMaker::ICombinedMuonFeatureContainerCnvTool > m_combMuonTool
ToolHandle< xAODMaker::ITrigTrackCountsCnvTool > m_trigTrackCtsTool
ToolHandle< xAODMaker::ITrackCollectionCnvTool > m_trackCollectionTool
StatusCode rewireNavigation(HLT::Navigation *nav)
ToolHandle< xAODMaker::IJetCnvTool > m_jetCnvTool
ToolHandle< xAODMaker::ITrigMissingETCnvTool > m_trigMetTool
ToolHandle< xAODMaker::ITrigEMClusterCnvTool > m_emClusterTool
ToolHandle< xAODMaker::IPhotonCnvTool > m_photonTool
StatusCode convert(const EventContext &ctx, HLT::Navigation *nav)
ToolHandle< xAODMaker::ICaloClusterCnvTool > m_caloClusterTool
ToolHandle< xAODMaker::ITrigPassBitsCnvTool > m_trigPassBitsTool
TrigBStoxAODTool(const std::string &type, const std::string &name, const IInterface *parent)
std::multimap< CLID, BStoXAODHelper::IHelper * > m_helpers
ToolHandle< xAODMaker::ITrigVertexCountsCnvTool > m_trigVtxCtsTool
std::vector< std::string > m_containersToConvert
ToolHandle< xAODMaker::ITauJetCnvTool > m_tauJetTool
Container of TrigEFBjet objects to be stored in POOL.
unsigned int size() const
gets size of the bits array
This is a data object, containing a collection of egamma Objects.
STL class.
Interface for the tool doing AOD->xAOD conversion for clusters.
Interface for the tool creating CombinedMuonFeatureContainer from an AOD.
Interface for the tool creating ElectronContainer from an AOD.
Interface for the tool creating JetContainer from an AOD.
Definition IJetCnvTool.h:38
Interface for the tool creating PhotonContainer from an AOD.
Interface for the tool creating TauJetContainer from an AOD.
Interface for the tool creating TrigBjetContainer from an AOD.
Interface for the tool creating TrigCaloCluster from an AOD.
Interface for the tool creating TrigBphysContainer from an AOD.
Interface for the tool creating TrigEMCluster from an AOD.
Interface for the tool creating TrigBphysContainer from an AOD.
Interface for the tool creating TrigMissingETContainer from an AOD.
Interface for the tool creating TrigPassBitsContainer from an AOD.
Interface for the tool creating TrigSpacePointCountsContainer from an AOD.
Interface for the tool creating TrigT2MbtsBitsContainer from an AOD.
Interface for the tool creating TrigTrackCountsContainer from an AOD.
Interface for the tool creating TrigVertexCountsContainer from an AOD.
std::string label(const std::string &format, int i)
Definition label.h:19
Tool used by TrigBSExtraction to convert to xAOD.
std::string formatSGkey(const std::string &prefix, const std::string &containername, const std::string &label)
declaration of formatting function.
Definition Holder.cxx:121
bool isPassing(const TrigPassBits *bits, const T *obj, const CONTAINER *container)
Check the bit for the object in the associated bits object.
TrigVertexCountsContainer_v1 TrigVertexCountsContainer
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
BTaggingContainer_v1 BTaggingContainer
Definition of the current "BTagging container version".
TrigPassBitsContainer_v1 TrigPassBitsContainer
Define the latest version of the trig pass bits container class.
TrigMissingETContainer_v1 TrigMissingETContainer
DataVector of TrigMissingET - the current version.
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
TrigCaloClusterContainer_v1 TrigCaloClusterContainer
Define the latest version of the trigger calorimeter cluster container.
TrigSpacePointCountsContainer_v1 TrigSpacePointCountsContainer
TrigEMClusterContainer_v1 TrigEMClusterContainer
Define the latest version of the trigger EM cluster container.
TrigTrackCountsContainer_v1 TrigTrackCountsContainer
L2CombinedMuonContainer_v1 L2CombinedMuonContainer
Define the latest version of the muon CB container.
TrigPassBits_v1 TrigPassBits
Define the latest version of the trigger pass bits class.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
JetContainer_v1 JetContainer
Definition of the current "jet container version".
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
TrigBphysContainer_v1 TrigBphysContainer
std::unique_ptr< TrigPassBits_v1 > makeTrigPassBits(const CONT *container, uint32_t containerKey=xAOD::TrigPassBits_v1::DEFAULT_KEY)
Helper function creating a new object to describe a target container.
Container2Aux_t< XAOD > xAODAux
DefaultHelper(const ToolHandle< CnvTool > &tool)
virtual StatusCode help(const EventContext &ctx, const std::string &label, const std::string &newLabel)
virtual StatusCode help_fillTrigPassBits(const std::string &label, const std::string &newLabel, const TrigPassBits *tpb_aod, xAOD::TrigPassBits *&tpb_xaod)
virtual StatusCode help(const EventContext &, const std::string &label, const std::string &newLabel)
MuonHelper(const ToolHandle< ITrigMuonEFInfoToMuonCnvTool > &tool)
virtual StatusCode help_fillTrigPassBits(const std::string &label, const std::string &newLabel, const TrigPassBits *tpb_aod, xAOD::TrigPassBits *&tpb_xaod)