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 element, typename list, int index>
106 struct get_strictly_feat {
107 static constexpr bool result = HLT::TypeInformation::at<list,index>::type::list_of_features::template has<element>::result;
108 };
109
111 template<typename T>
112 constexpr int getCLID() {
113
115 constexpr bool known = !std::is_same_v<search_result, HLT::TypeInformation::ERROR_THE_FOLLOWING_TYPE_IS_NOT_KNOWN_TO_THE_EDM<T>>;
116
117 if constexpr (known) return ClassID_traits<T>::ID();
118 else return -1;
119 }
120}
121
123
124 //Helper class providing interface for conversion and some convenient access to SG and Msg Services
125 class IHelper{
126 public:
127 virtual ~IHelper(){;}
128 virtual StatusCode initialize(MsgStream& m, StoreGateSvc& s){
129 m_msg = &m;
130 m_sg = &s;
131 return StatusCode::SUCCESS;
132 };
133
134 virtual StatusCode help(const std::string& label, const std::string& newLabel) = 0;
135
136 //we need this method, because for creating converted xAOD::TrigPassBits, one needs access to the corresponding xaod container
137 //with physics objects. This leads to a partial duplication of the code for the muon helper
138 virtual StatusCode help_fillTrigPassBits(const std::string& label, const std::string& newLabel, const TrigPassBits* tpb_aod, xAOD::TrigPassBits*& tpb_xaod) = 0;
139
140 virtual CLID AODContainerClid() = 0;
141 virtual CLID xAODContainerClid() = 0;
142 virtual CLID AODElementClid() = 0;
143 virtual CLID xAODElementClid() = 0;
144
145 MsgStream& msg(MSG::Level l){return *m_msg << l;}
146 bool msgLvl (const MSG::Level l){
147 if(m_msg->level() <= l){
148 *m_msg << l; return true;
149 } else {
150 return false;
151 };
152 }
153
154 template<typename T>
155 std::string format(const std::string& label){
157 }
158 protected:
159 MsgStream* m_msg{nullptr};
161 const std::string m_AODprefix = "HLT";
162 };
163
164 //class holding a tool, since this is what all helpers will need to do.
165 template<typename T>
166 class ToolHolder : public IHelper {
167 protected:
168 const ToolHandle<T>& m_tool;
169 ToolHandle<T>& tool(){return m_tool;}
170 public:
171 ToolHolder(const ToolHandle<T>& tool) : m_tool(tool){;}
172 virtual ~ToolHolder(){;}
173 virtual StatusCode initialize(MsgStream& m, StoreGateSvc& s){
175 CHECK(m_tool.retrieve());
176 return StatusCode::SUCCESS;
177 }
178 };
179
180 //this is the most vanilla case
181 template<typename AOD,typename XAOD, typename CnvTool>
182 struct DefaultHelper : public ToolHolder<CnvTool> {
184
185 DefaultHelper(const ToolHandle<CnvTool>& tool) : ToolHolder<CnvTool>(tool){;}
186
187 CLID AODContainerClid(){return getCLID<AOD>();}
188 CLID xAODContainerClid(){return getCLID<XAOD>();}
189
190 CLID AODElementClid(){return getCLID<Container2Object_t<AOD>>();}
191 CLID xAODElementClid(){return getCLID<Container2Object_t<XAOD>>();}
192
193 virtual StatusCode help(const std::string& label, const std::string& newLabel){
194 typedef IHelper IH;
195 std::string fmtkey_AOD = IH::template format<AOD>(label);
196 std::string fmtkey_xAOD = IH::template format<XAOD>(newLabel);
197 std::string fmtkey_xAODAux = IH::template format<xAODAux>(newLabel+"Aux.");
198
199 const AOD* aod = this->m_sg->template tryConstRetrieve<AOD>(fmtkey_AOD);
200 if(!aod){
201 ATH_MSG_WARNING("AOD key: " << fmtkey_AOD << " not found for xAOD conversion");
202 return StatusCode::SUCCESS;
203 }
204
205 ATH_MSG_DEBUG("attempting to convert " << fmtkey_AOD << " of size " << aod->size() << " to " << fmtkey_xAOD);
206
207 XAOD* xaod = this->m_sg->template tryRetrieve<XAOD>(fmtkey_xAOD);
208 if(!xaod){
209 ATH_MSG_WARNING("xAOD key: " << fmtkey_xAOD << " not found for xAOD conversion");
210 return StatusCode::SUCCESS;
211 }
212 CHECK( this->m_tool->convert(aod,xaod));
213 ATH_MSG_DEBUG("AOD container has size: " << aod->size());
214 ATH_MSG_DEBUG("xAOD container has size: " << xaod->size());
215 if(aod->size() != xaod->size()){
216 ATH_MSG_ERROR("conversion resulted in differently sized containers");
217 return StatusCode::FAILURE;
218 }
219 return StatusCode::SUCCESS;
220 }
221
222 virtual StatusCode help_fillTrigPassBits(const std::string& label, const std::string& newLabel, const TrigPassBits* tpb_aod, xAOD::TrigPassBits*& tpb_xaod){
223 typedef IHelper IH;
224 std::string fmtkey_AOD = IH::template format<AOD>(label);
225 std::string fmtkey_xAOD = IH::template format<XAOD>(newLabel);
226 std::string fmtkey_xAODAux = IH::template format<xAODAux>(newLabel+"Aux.");
227
228 const AOD* aod = this->m_sg->template tryConstRetrieve<AOD>(fmtkey_AOD);
229 if(!aod){
230 ATH_MSG_WARNING("AOD key: " << fmtkey_AOD << " not found");
231 return StatusCode::SUCCESS;
232 }
233 ATH_MSG_DEBUG( "AOD container " << fmtkey_AOD << " extracted of size " << aod->size() );
234 // it was found out that in Run 1 data for some containers the size of the TrigPassBits object differs from
235 // the size of the corresponding container. It was decided to not convert TrigPassBits->xAOD::TrigPassBits for such cases,
236 // so xAOD::TrigPassBits will be nullptr
237 if( aod->size() != tpb_aod->size() ) {
238 ATH_MSG_WARNING( "sizes of the container " << fmtkey_AOD << " and the corresponding (?) trigpassbits object are different: "
239 << aod->size() << " vs " << tpb_aod->size() << ", will not convert TrigPassBits for this container" );
240 return StatusCode::SUCCESS;
241 }
242
243 XAOD* xaod = this->m_sg->template tryRetrieve<XAOD>(fmtkey_xAOD);
244 if(!xaod){
245 ATH_MSG_WARNING("xAOD key: " << fmtkey_xAOD << " not found");
246 return StatusCode::SUCCESS;
247 }
248 ATH_MSG_DEBUG("xAOD container " << fmtkey_xAOD << " extracted of size " << xaod->size());
249
250 if(aod->size() != xaod->size()) {
251 ATH_MSG_ERROR("containers before and after the conversion are of different sizes");
252 return StatusCode::FAILURE;
253 }
254
255 ATH_MSG_DEBUG( "setting xaod passbits size to " << tpb_aod->size() );
256 std::unique_ptr<xAOD::TrigPassBits> xBits = xAOD::makeTrigPassBits(xaod);
257
258 for(uint i=0; i<aod->size(); i++) {
259 // if(i < tpb_aod->size() ){
260 ATH_MSG_DEBUG( "looking at object " << i+1 << " of " << aod->size() );
261 bool passed = HLT::isPassing( tpb_aod, aod->at(i), aod );
262 ATH_MSG_DEBUG( "aod ispassing = " << passed );
263 ATH_MSG_DEBUG( "xaod ispassing = " << xBits->isPassing( i ) );
264 if(passed)
265 xBits->markPassing( i );
266 ATH_MSG_DEBUG( "xaod ispassing (after update) = " << xBits->isPassing( i ) );
267 /* } else {
268 ATH_MSG_DEBUG( "skipping object " << i+1 << " as it is outside of the array range of the corresponding aod TrigPassBits object" );
269 }*/
270 }
271 tpb_xaod = xBits.release();
272 return StatusCode::SUCCESS;
273 }
274 };
275
276 struct MuonHelper : public ToolHolder<ITrigMuonEFInfoToMuonCnvTool> {
277 MuonHelper(const ToolHandle<ITrigMuonEFInfoToMuonCnvTool>& tool) : ToolHolder(tool){;}
278
279 CLID AODContainerClid(){return getCLID<TrigMuonEFInfoContainer>();}
280 CLID xAODContainerClid(){return getCLID<xAOD::MuonContainer>();}
281
282 CLID AODElementClid(){return getCLID<Container2Object_t<TrigMuonEFInfoContainer>>();}
283 CLID xAODElementClid(){return getCLID<Container2Object_t<xAOD::MuonContainer>>();}
284
285 virtual StatusCode help(const std::string& label, const std::string& newLabel){
286 xAOD::MuonContainer* xaodMuon = this->m_sg->tryRetrieve<xAOD::MuonContainer>(format<xAOD::MuonContainer>(newLabel));
287 if(!xaodMuon){
288 ATH_MSG_WARNING("muon label: " << format<xAOD::MuonContainer>(newLabel) << " not found for xAOD conversion");
289 return StatusCode::SUCCESS;
290 }
291
292 xAOD::TrackParticleContainer* xaodCombTrackParticles = this->m_sg->tryRetrieve<xAOD::TrackParticleContainer>(format<xAOD::TrackParticleContainer>(newLabel+"_CombTrackParticles"));
293 if(!xaodCombTrackParticles){
294 ATH_MSG_WARNING("muon label: " << format<xAOD::TrackParticleContainer>(newLabel+"_CombTrackParticles") << " not found for xAOD conversion");
295 return StatusCode::SUCCESS;
296 }
297
298 xAOD::TrackParticleContainer* xaodExtrapTrackParticles = this->m_sg->tryRetrieve<xAOD::TrackParticleContainer>(format<xAOD::TrackParticleContainer>(newLabel+"_ExtrapTrackParticles"));
299 if(!xaodCombTrackParticles){
300 ATH_MSG_WARNING("muon label: " << format<xAOD::TrackParticleContainer>(newLabel+"_ExtrapTrackParticles") << " not found for xAOD conversion");
301 return StatusCode::SUCCESS;
302 }
303
304 const TrigMuonEFInfoContainer* aod =
306 if(!aod){
307 ATH_MSG_WARNING("muon label: " << format<TrigMuonEFInfoContainer>(label) << " not found for xAOD conversion");
308 return StatusCode::SUCCESS;
309 }
310
311 CHECK(this->m_tool->convertTrigMuonEFInfoContainer( *aod, *xaodMuon, xaodCombTrackParticles, xaodExtrapTrackParticles));
312
313 ATH_MSG_DEBUG("Muon AOD container has size: " << aod->size());
314 ATH_MSG_DEBUG("Muon xAOD container has size: " << xaodMuon->size());
315
316 return StatusCode::SUCCESS;
317 }
318
319 virtual StatusCode help_fillTrigPassBits(const std::string& label, const std::string& newLabel, const TrigPassBits* tpb_aod, xAOD::TrigPassBits*& tpb_xaod){
320
321 const TrigMuonEFInfoContainer* aod = this->m_sg->template tryConstRetrieve<TrigMuonEFInfoContainer>(label);
322 if(!aod){
323 ATH_MSG_WARNING("AOD key: " << label << " not found");
324 return StatusCode::SUCCESS;
325 }
326 ATH_MSG_DEBUG( "AOD muon container " << label << " extracted of size " << aod->size() );
327 if( aod->size() != tpb_aod->size() ) {
328 ATH_MSG_WARNING( "sizes of the muon container " << label << " and the corresponding (?) trigpassbits object are different: "
329 << aod->size() << " vs " << tpb_aod->size() << ", will not convert TrigPassBits for this container" );
330 }
331 xAOD::MuonContainer* xaodMuon = this->m_sg->template tryRetrieve<xAOD::MuonContainer>(format<xAOD::MuonContainer>(newLabel));
332 if(!xaodMuon){
333 ATH_MSG_WARNING("xAOD key: " << format<xAOD::MuonContainer>(newLabel) << " not found");
334 return StatusCode::SUCCESS;
335 }
336 ATH_MSG_DEBUG("xAOD muon container " << format<xAOD::MuonContainer>(newLabel) << " extracted of size " << xaodMuon->size());
337
338 if(aod->size() != xaodMuon->size()) {
339 ATH_MSG_ERROR("containers before and after the conversion are of different sizes");
340 return StatusCode::FAILURE;
341 }
342
343 ATH_MSG_DEBUG( "setting muon xaod passbits size to " << tpb_aod->size() );
344 std::unique_ptr<xAOD::TrigPassBits> xBits = xAOD::makeTrigPassBits(xaodMuon);
345
346 for(uint i=0; i<aod->size(); i++) {
347 // if(i < tpb_aod->size() ){
348 ATH_MSG_DEBUG( "looking at muon object " << i+1 << " of " << aod->size() );
349 bool passed = HLT::isPassing( tpb_aod, aod->at(i), aod );
350 ATH_MSG_DEBUG( "muon aod ispassing = " << passed );
351 ATH_MSG_DEBUG( "muon xaod ispassing = " << xBits->isPassing( i ) );
352 if(passed)
353 xBits->markPassing( i );
354 ATH_MSG_DEBUG( "muon xaod ispassing (after update) = " << xBits->isPassing( i ) );
355 /* } else {
356 ATH_MSG_DEBUG( "skipping object " << i+1 << " as it is outside of the array range of the corresponding aod TrigPassBits object" );
357 }*/
358 }
359 tpb_xaod = xBits.release();
360 return StatusCode::SUCCESS;
361 }
362 };
363
364} // namespace BStoXAODHelper
365
366TrigBStoxAODTool::TrigBStoxAODTool(const std::string& type, const std::string& name, const IInterface* parent)
367 : AthAlgTool(type,name,parent),
368 m_tauJetTool( "xAODMaker::TauJetCnvTool/TauJetCnvTool",this),
369 m_combMuonTool( "xAODMaker::CombinedMuonFeatureContainerCnvTool/CombinedMuonFeatureContainerCnvTool",this),
370 m_isoMuonTool( "xAODMaker::IsoMuonFeatureContainerCnvTool/IsoMuonFeatureContainerCnvTool",this),
371 m_trigMuonTool( "TrigMuonEFInfoToMuonCnvTool/TrigMuonEFInfoToMuonCnvTool",this),
372 m_jetCnvTool( "xAODMaker::JetCnvTool/JetCnvTool",this),
373 m_trigCaloClusterTool( "xAODMaker::TrigCaloClusterCnvTool/TrigCaloClusterCnvTool",this),
374 m_emClusterTool( "xAODMaker::TrigEMClusterCnvTool/TrigEMClusterCnvTool",this),
375 m_bjetTool( "xAODMaker::TrigBjetCnvTool/TrigBjetCnvTool",this),
376 m_efBphysTool( "xAODMaker::TrigEFBphysContainerCnvTool/TrigEFBphysContainerCnvTool",this),
377 m_l2BphysTool( "xAODMaker::TrigL2BphysContainerCnvTool/TrigL2BphysContainerCnvTool",this),
378 m_trigMetTool( "xAODMaker::TrigMissingETCnvTool/TrigMissingETCnvTool",this),
379 m_trigSpacePtsTool("xAODMaker::TrigSpacePointCountsCnvTool/TrigSpacePointCountsCnvTool",this),
380 m_trigMbtsBitsTool("xAODMaker::TrigT2MbtsBitsCnvTool/TrigT2MbtsBitsCnvTool",this),
381 m_trigTrackCtsTool("xAODMaker::TrigTrackCountsCnvTool/TrigTrackCountsCnvTool",this),
382 m_trigVtxCtsTool( "xAODMaker::TrigVertexCountsCnvTool/TrigVertexCountsCnvTool",this),
383 m_electronTool( "xAODMaker::ElectronCnvTool/ElectronCnvTool", this ),
384 m_photonTool( "xAODMaker::PhotonCnvTool/PhotonCnvTool", this ),
385 m_caloClusterTool( "xAODMaker::CaloClusterCnvTool/CaloClusterCnvTool", this),
386 m_trigPassBitsTool( "xAODMaker::TrigPassBitsCnvTool/TrigPassBitsCnvTool", this )
387{
388 declareInterface<ITrigBStoxAODTool>( this );
389 declareProperty("ContainersToConvert",m_containersToConvert);
390 declareProperty("NewContainers", m_newContainers);
391
392 declareProperty("tauJetTool", m_tauJetTool);
393 declareProperty("combMuonTool", m_combMuonTool);
394 declareProperty("isoMuonTool", m_isoMuonTool);
395 declareProperty("trigMuonTool", m_trigMuonTool);
396 declareProperty("jetCnvTool", m_jetCnvTool);
397
398 declareProperty("trigCaloClusterTool", m_trigCaloClusterTool);
399 declareProperty("emClusterTool", m_emClusterTool);
400 declareProperty("bjetTool", m_bjetTool);
401 declareProperty("efBphysTool", m_efBphysTool);
402 declareProperty("l2BphysTool", m_l2BphysTool);
403
404 declareProperty("trigMetTool", m_trigMetTool);
405 declareProperty("trigSpacePtsTool", m_trigSpacePtsTool);
406 declareProperty("trigMbtsBitsTool", m_trigMbtsBitsTool);
407 declareProperty("trigTrackCtsTool", m_trigTrackCtsTool);
408 declareProperty("trigVtxCtsTool", m_trigVtxCtsTool);
409 declareProperty("electronTool", m_electronTool);
410 declareProperty("photonTool", m_photonTool);
411 declareProperty("caloClusterTool", m_caloClusterTool);
412 declareProperty("trigPassBitsTool", m_trigPassBitsTool);
413
414 m_CLID_xAODPhotonContainer = getCLID<xAOD::PhotonContainer>();
415 m_CLID_xAODElectronContainer = getCLID<xAOD::ElectronContainer>();
416}
417
419 std::map<CLID,BStoXAODHelper::IHelper*>::iterator it;
420 for(it = m_helpers.begin();it!=m_helpers.end();++it){
421 delete it->second;
422 }
423}
424
426
436
437 m_helpers.insert( std::pair<CLID,BStoXAODHelper::MuonHelper*>
440
450
460
470
476
482
488
494
500
503 (getCLID<TrigTrackCountsCollection>(),
506
512
518
524
530
536
542
548
554
560
561
562 std::multimap<CLID,BStoXAODHelper::IHelper*>::iterator it;
563 for(it = m_helpers.begin();it!=m_helpers.end();++it){
564 CHECK(it->second->initialize(this->msg(),*(evtStore())));
565 }
566
567 ATH_MSG_DEBUG("containers to convert: " << m_containersToConvert);
568 ATH_MSG_DEBUG("containers will be converted to: " << m_newContainers);
570 ATH_MSG_DEBUG("extracted class IDs (" << m_clid_labels.size() << " in total): " << m_clid_labels);
571
572 if(m_clid_labels.size() != m_clid_newLabels.size()) {
573 ATH_MSG_ERROR("number of new containers names (" << m_clid_newLabels.size()
574 << ") is not the same as the number of old containers names ("
575 << m_clid_newLabels.size() << ")");
576 return StatusCode::FAILURE;
577 }
578 ATH_MSG_DEBUG("CLID CLID, old label, new label:");
579 for(uint i=0; i<m_clid_labels.size(); i++) {
580 ATH_MSG_DEBUG(m_clid_labels[i].first << " " << m_clid_newLabels[i].first << ", "
581 << m_clid_labels[i].second << ", " << m_clid_newLabels[i].second );
582 if(m_clid_labels[i].second != m_clid_newLabels[i].second) {
583 ATH_MSG_VERBOSE("Run-1 " << m_clid_labels[i].first << " label " <<
584 m_clid_labels[i].second << " differs from the equivalent Run-2 label: "
585 << m_clid_newLabels[i].second);
586 }
587 }
588
589 return StatusCode::SUCCESS;
590}
591
593 std::vector<std::pair<CLID,std::string> >::const_iterator clidlabel;
594 std::vector<std::pair<CLID,std::string> >::const_iterator clidNewLabel = m_clid_newLabels.begin();
595 for(clidlabel =m_clid_labels.begin();clidlabel!=m_clid_labels.end();++clidlabel, ++clidNewLabel){
596
597 HLTNavDetails::IHolder* holder = nav->getHolder(clidlabel->first,clidlabel->second);
598
599 if(!holder){
600 ATH_MSG_WARNING("couldn't find holder for " << clidlabel->first << " " << clidlabel->second);
601 continue;
602 }
603
604 ATH_MSG_VERBOSE("container corresponding to feature CLID " << clidlabel->first << " has CLID " << holder->containerClid());
605
606 std::multimap<CLID,BStoXAODHelper::IHelper*>::const_iterator hit;
607 hit = m_helpers.end();//find(holder->containerClid());
608
609 std::string clabel = clidlabel->second;
610 CHECK(findHelper( m_helpers, holder->containerClid(), clabel, hit ));
611
612 if(hit!=m_helpers.end()){
613 ATH_MSG_DEBUG("attempting convertion of clid " << holder->containerClid()
614 << " for label " << clidlabel->second << ", new label " << clidNewLabel->second);
615 CHECK(hit->second->help(clidlabel->second,clidNewLabel->second));//get aod container and convert
616 ATH_MSG_DEBUG("converted clid " << holder->containerClid() << " for label " << clidlabel->second);
617 }
618 else{
619 ATH_MSG_DEBUG("couldn't find converters for clid: " << clidlabel->first);
620 }
621 }
622 return StatusCode::SUCCESS;
623}
624
626 //we need to loop over all features of all TEs
627 //find the ones pointing to a AOD container that has been converted
628 //and change the holder they use to access the feature, i.e. changes CLID and subTypeIndex
629
630 std::vector<HLT::TriggerElement*>& allTEs = nav->getAllTEs();
631 //nav->getAll(allTEs,false); //false: also get inactive TEs
632 ATH_MSG_DEBUG("rewiring Navigation for xAOD. working on " << allTEs.size() << " TEs");
633 for(auto te : allTEs){
634 std::vector<HLT::TriggerElement::FeatureAccessHelper>& feats = te->getFeatureAccessHelpers();
635 for(auto& featacchelp : feats){
636 ATH_MSG_VERBOSE("this feature has CLID: " << featacchelp.getCLID());
637
638 HLTNavDetails::IHolder* oldholder = nav->getHolder(featacchelp.getCLID(),featacchelp.getIndex().subTypeIndex());
639
640 if(!oldholder){
641 ATH_MSG_WARNING("could not find old holder for CLID " << featacchelp.getCLID() << " and subTypeIndex: " << featacchelp.getIndex());
642 continue;
643 }
644
645 std::multimap<CLID,BStoXAODHelper::IHelper*>::const_iterator it = m_helpers.end();//find(oldholder->containerClid());
646 std::string old_label = oldholder->label();
647 CHECK(findHelper( m_helpers, oldholder->containerClid(), old_label, it));
648 if(it != m_helpers.end()){
649 ATH_MSG_VERBOSE("need to rewire this CLID from " << oldholder->typeClid() << "/"<< oldholder->containerClid() << " to " << it->second->xAODContainerClid());
650
651 bool iselement = (oldholder->typeClid()==it->second->AODElementClid());
652 bool iscontainer = (oldholder->typeClid()==it->second->AODContainerClid());
653
654 ATH_MSG_VERBOSE("old is element feature " << iselement << " or container feature: " << iscontainer);
655
656 if(!(iselement || iscontainer)){
657 ATH_MSG_WARNING("not clear what kind of feature we're dealing with. Skipping. Old holder is:" << *oldholder);
658 }
659
660 CLID newTypeClid = CLID_NULL;
661 if(iselement) newTypeClid = it->second->xAODElementClid();
662 if(iscontainer) newTypeClid = it->second->xAODContainerClid();
663
664 std::lock_guard<std::recursive_mutex> lock(nav->getMutex());
665 HLT::TrigHolderStructure& holderstorage = nav->getHolderStorage();
666
667 HLTNavDetails::IHolder* newholder = holderstorage.getHolder<HLTNavDetails::IHolder>(newTypeClid,oldholder->label());
668
669 if(!newholder){
670 ATH_MSG_WARNING("could not find new holder for xAOD clid " << newTypeClid << " and label " << oldholder->label());
671 continue;
672 }
673
674 ATH_MSG_VERBOSE("old holder: " << *oldholder);
675 ATH_MSG_VERBOSE("new holder: " << *newholder);
676 ATH_MSG_VERBOSE("changing CLID: " << featacchelp.getCLID() << " to " << newTypeClid);
677 ATH_MSG_VERBOSE("changing STI: " << featacchelp.getIndex().subTypeIndex() << " to " << newholder->subTypeIndex());
678
679 featacchelp.setCLIDandIndex(newTypeClid,newholder->subTypeIndex());
680 ATH_MSG_VERBOSE("clid is now: " << featacchelp.getCLID() << " sti: " << featacchelp.getIndex().subTypeIndex());
681 ATH_MSG_VERBOSE("TE is: " << *te);
682 } // end if(helper was found)
683 }//end feature loop
684 }//end TE loop
685
686
687 return StatusCode::SUCCESS;
688}
689
690
691
692//blatantly stolen from navigation code
693StatusCode TrigBStoxAODTool::classLabel2CLIDLabel(const std::vector<std::string>& property,
694 const std::vector<std::string>& newProperty,
695 std::vector<std::pair<CLID,std::string> >& decoded,
696 std::vector<std::pair<CLID,std::string> >& decodedNewNames) {
697 // translate Class names into CLID numbers
698 SmartIF<IClassIDSvc> clidSvc{service("ClassIDSvc")};
699 ATH_CHECK( clidSvc.isValid() );
700
701 if( property.size() != newProperty.size() ) {
702 ATH_MSG_ERROR("vector sizes of new and old SG labels are different: "
703 << newProperty.size() << " vs " << property.size() );
704 return StatusCode::FAILURE;
705 }
706
707 std::vector<std::string>::const_iterator it;
708 std::vector<std::string>::const_iterator itNew = newProperty.begin();
709 for ( it = property.begin(); it != property.end(); ++it, ++itNew ) {
710 CLID clid{0};
711 std::string label;
712 std::string label_new;
713 std::string type;
714
715 if ( it->find('#') != std::string::npos ) {
716 type = it->substr(0, it->find('#') );
717 label = it->substr(it->find('#')+1 );
718 } else {
719 type = *it;
720 label = "";
721 }
722
723 if ( itNew->find('#') != std::string::npos ) {
724 label_new = itNew->substr(itNew->find('#')+1 );
725 } else {
726 label_new = "";
727 }
728
729 if ( clidSvc->getIDOfTypeName(type, clid).isFailure() ) {
730 ATH_MSG_FATAL("Unable to get CLID for class: " << *it
731 << " check property");
732 return StatusCode::FAILURE;
733 }
734
735 ATH_MSG_DEBUG("Recognized CLID : " << type << " and label: " << label << ", new label will be: " << label_new);
736 decoded.push_back(std::make_pair(clid, label));
737 decodedNewNames.push_back(std::make_pair(clid, label_new));
738 }
739 return StatusCode::SUCCESS;
740}
741
743 //we need to loop over all features of all TEs
744 //find the ones pointing to a AOD container that has been converted
745 //extract the corresponding aod TrigPassBits container and set the same
746 //bits in xAOD::TrigPassBits
747
748 std::vector<HLT::TriggerElement*>& allTEs = nav->getAllTEs();
749
750 ATH_MSG_DEBUG("setting xAOD TrigPassBits. Working on " << allTEs.size() << " TEs");
751
752 for(auto te : allTEs){
753 std::vector<HLT::TriggerElement::FeatureAccessHelper>& feats = te->getFeatureAccessHelpers();
754 for(auto& featacchelp : feats){
755 ATH_MSG_VERBOSE("this feature has CLID: " << featacchelp.getCLID());
756
757 HLTNavDetails::IHolder* holder = nav->getHolder(featacchelp.getCLID(),featacchelp.getIndex().subTypeIndex());
758
759 if(!holder){
760 ATH_MSG_WARNING("could not find holder for CLID " << featacchelp.getCLID() << " and subTypeIndex: " << featacchelp.getIndex());
761 continue;
762 }
763
764 if(holder->label() == "passbits") {
765 ATH_MSG_VERBOSE( "skipping this feature, as this is the passbits object itself" );
766 continue;
767 }
768
769 std::multimap<CLID,BStoXAODHelper::IHelper*>::const_iterator it = m_helpers.end();//find(holder->containerClid());
770 std::string hlabel = holder->label();
771 CHECK(findHelper( m_helpers, holder->containerClid(), hlabel, it ));
772 if(it != m_helpers.end()){
773
774 ATH_MSG_DEBUG( "need to extract TrigPassBits for this AOD object " << holder->typeClid() << "/"<< holder->containerClid()
775 << ", label " << holder->label() << " corresponding to xAOD CLID " << it->second->xAODContainerClid() );
776
777 bool iselement = (holder->typeClid()==it->second->AODElementClid());
778 bool iscontainer = (holder->typeClid()==it->second->AODContainerClid());
779
780 ATH_MSG_VERBOSE("is element feature " << iselement << " or container feature: " << iscontainer);
781
782 if(!(iselement || iscontainer)){
783 ATH_MSG_WARNING("not clear what kind of feature we're dealing with. Skipping. The holder is:" << *holder);
784 }
785
786 ATH_MSG_VERBOSE("holder: " << *holder);
787
788 const TrigPassBitsCollection* bits_collection = evtStore()->template tryConstRetrieve<TrigPassBitsCollection>("HLT_TrigPassBitsCollection_passbits");
789 if(bits_collection != nullptr) {
790 ATH_MSG_DEBUG( "aod bits collection extracted of size " << bits_collection->size() );
791 //dump this to compare with the results from release 17
792 // for(uint i=0; i<bits_collection->size(); i++ ) {
793 // std::cout << "size of the TrigPassBits object " << i << " is " << bits_collection->at(i)->size() << std::endl;
794 // }
795 } else {
796 ATH_MSG_WARNING( "aod bits collection cannot be extracted" );
797 continue;
798 }
799
800
801 xAOD::TrigPassBitsContainer* xaod_bits_collection = evtStore()->template tryRetrieve<xAOD::TrigPassBitsContainer>("HLT_xAOD__TrigPassBitsContainer_passbits");
802 if(xaod_bits_collection != nullptr)
803 ATH_MSG_DEBUG( "xaod bits container extracted of size " << xaod_bits_collection->size() );
804 else {
805 ATH_MSG_WARNING( "xaod bits container cannot be extracted" );
806 continue;
807 }
808
809 const TrigPassBits* bits(0);
810 if ( nav->getFeature(te, bits, "passbits" ) ){
811 ATH_MSG_DEBUG( "TrigPassBits extracted for the container " << holder->label() );
812 if(bits!=nullptr) {
813 ATH_MSG_DEBUG( "it's size is " << bits->size() );
814 } else {
815 ATH_MSG_DEBUG( "it is nullptr" );
816 continue;
817 }
818 } else {
819 ATH_MSG_WARNING( "this TE has no associated TrigPassBits object" );
820 continue;
821 }
822 if(bits_collection != nullptr && xaod_bits_collection != nullptr && bits != nullptr) {
823 int bits_nr = -1;
824 for(uint i=0; i<bits_collection->size(); i++) {
825 if(bits == bits_collection->at(i)) {
826 bits_nr = i;
827 ATH_MSG_VERBOSE( "this is bits # " << bits_nr );
828 break;
829 }
830 }
831 if(bits_nr >= 0) {
832 xAOD::TrigPassBits* xaod_tpb = nullptr;
833 std::pair<CLID,std::string> pair = std::make_pair( featacchelp.getCLID(), holder->label() );
834 std::vector<std::pair<CLID,std::string> >::const_iterator it_new_label;
835 it_new_label = std::find(m_clid_newLabels.begin(), m_clid_newLabels.end(), pair);
836 std::string new_label = "";
837 if(it_new_label != m_clid_newLabels.end()) {
838 new_label = (*it_new_label).second;
839 ATH_MSG_DEBUG( "calling help_fillTrigPassBits for TE " << te << ", feature CLID " << featacchelp.getCLID()
840 << ", aod container " << holder->label() << ", new container name: " << new_label );
841 CHECK( it->second->help_fillTrigPassBits( holder->label(), new_label, bits_collection->at(bits_nr), xaod_tpb ) );
842 } else {
843 ATH_MSG_DEBUG( "new label was not found, presumably this container was not converted. Will not look for TrigPassBits" );
844 }
845
846 if(xaod_tpb != nullptr) {
847 xaod_bits_collection->at(bits_nr) = xaod_tpb;
848 ATH_MSG_VERBOSE( "after the conversion, size of xAOD::TrigPassBits is " << xaod_bits_collection->at(bits_nr)->size() );
849 }
850
851 } else {
852 ATH_MSG_WARNING( "TrigPassBits object was not identified within container!" );
853 }
854 }// if good aod and xaod passbits are available
855 } // if helper was found
856 }// feature loop
857 }// TE loop
858
859
860 return StatusCode::SUCCESS;
861}
862
863// the following function returns iterator pointing to the desired converter, based on the clid of the AOD type and label
864StatusCode TrigBStoxAODTool::findHelper( MM_CLID_IHELPER& helpers, CLID clid, std::string& label, MM_CLID_IHELPER::const_iterator& it ) {
865 auto myrange = helpers.equal_range(clid);
866 it = myrange.first;
867 //let's see how many there are converters corresponding to the same AOD input type
868 int distance = std::distance(myrange.first, myrange.second);
869 if (distance == 1) {
870 //default case, one-to-one relation of AOD and xAOD types
871 ATH_MSG_VERBOSE("helper to convert AOD CLID " << clid << " and label " << label << " found");
872 return StatusCode::SUCCESS;
873 } else if (distance == 2) {
874 //this is for the case when there is single AOD type converted to two different xAOD types,
875 //will treat this here separately. So far this only happens for egammaContainer->xAOD::ElectronContainer and
876 //egammaContainer->xAOD::PhotonContainer
877 for(;it!=myrange.second;++it) {
878 CLID myHelperxAODCLID = (*it).second->xAODContainerClid();
879 if((label == "egamma_Electrons" && myHelperxAODCLID == m_CLID_xAODElectronContainer) ||
880 (label == "egamma_Photons" && myHelperxAODCLID == m_CLID_xAODPhotonContainer)) {
881 ATH_MSG_VERBOSE("helper to convert AOD CLID " << clid << " and label " << label << " found");
882 return StatusCode::SUCCESS;
883 }
884 }
885 } else if( distance == 0) {
886 ATH_MSG_WARNING("there is no helper to convert AOD CLID " << clid << ", label " << label);
887 it = helpers.end();
888 return StatusCode::SUCCESS;
889 } else {
890 //this should not happen...
891 ATH_MSG_ERROR("found " << distance << " helpers to convert AOD type " << clid << " and label " << label
892 << ", probably you should accomodate for this change in the code above" );
893 return StatusCode::FAILURE;
894 }
895
896 //this point is not reached if everything is OK
897 return StatusCode::SUCCESS;
898
899} // 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.
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 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
virtual StatusCode help(const std::string &label, const std::string &newLabel)=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
ToolHandle< xAODMaker::IRecTrackParticleContainerCnvTool > m_recTrackParticleContTool
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
StatusCode convert(HLT::Navigation *nav)
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.
virtual StatusCode help_fillTrigPassBits(const std::string &label, const std::string &newLabel, const TrigPassBits *tpb_aod, xAOD::TrigPassBits *&tpb_xaod)
virtual StatusCode help(const std::string &label, const std::string &newLabel)
Container2Aux_t< XAOD > xAODAux
DefaultHelper(const ToolHandle< CnvTool > &tool)
virtual StatusCode help(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)