ATLAS Offline Software
AlignTrackCollSplitter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
9 
10 namespace Trk {
11 
12 //___________________________________________________________________________
13 AlignTrackCollSplitter::AlignTrackCollSplitter(const std::string& name, ISvcLocator* pSvcLocator)
14  : AthAlgorithm(name, pSvcLocator)
15  , m_nevents(0)
16  , m_ntracks(0)
17  , m_trackTypeCounter(AlignTrack::NTrackTypes+1,0)
18  , m_nRetrievalErrors(0)
19 {
20  declareProperty("InputTrkCol", m_inputCol = "AlignTracks");
21  declareProperty("OutputColPrefix", m_outColPrefix = "AlignTracks");
22  declareProperty("MaxRetrievalErrors", m_maxRetrievalErrors = -1);
23 }
24 
25 //___________________________________________________________________________
27 {
28  ATH_MSG_DEBUG("AlignTrackCollSplitter destructor");
29 }
30 
31 //___________________________________________________________________________
33 {
34  ATH_MSG_DEBUG("AlignTrackCollSplitter::initialize()");
35 
36  // set the track collection names
37  ATH_MSG_INFO("Splitting "<<m_inputCol<<" into:");
38  for(int icol=0; icol<AlignTrack::NTrackTypes+1; ++icol) {
41  }
42 
43  return StatusCode::SUCCESS;
44 }
45 
46 //___________________________________________________________________________
48 {
49  ATH_MSG_DEBUG("AlignTrackCollSplitter::execute()");
50 
51  // increment number of events
52  m_nevents++;
53 
54  // loop over tracks
55  const TrackCollection * originalTracks = nullptr;
56 
57  // check if m_inputCol is a TrackCollection and exists for this event
58  // perhaps this can be done in a much nicer way on the python side ala PyUtils/checkFile.py
59  // do it here for now
60  if( !evtStore()->contains<TrackCollection>(m_inputCol) ||
61  evtStore()->retrieve(originalTracks,m_inputCol).isFailure() ) {
62  ATH_MSG_DEBUG("input track collection \'"<<m_inputCol<<"\' not found for this event");
63 
64  if(m_maxRetrievalErrors>=0) {
67  msg(MSG::FATAL)<<"Input track collection \'"<<m_inputCol<<"\' not found in first "
68  <<m_nRetrievalErrors<<" events. Aborting."<<endmsg;
69  msg(MSG::FATAL)<<"Maximum allowed number of events without the track collection "
70  <<"can be changed using the \'MaxRetrievalErrors\' option (-1 for infinite)."
71  <<endmsg;
72  return StatusCode::FAILURE;
73  }
74  }
75  return StatusCode::SUCCESS;
76  }
77 
78  // if we're here it means that the track collection m_inputCol exists in the file
79  // (it can be empty) so we change the error cutoff to process the whole file
82 
83  if(originalTracks->empty())
84  return StatusCode::SUCCESS;
85 
86  // increment number of processed tracks
87  m_ntracks += originalTracks->size();
88 
89  // vector to keep all different AlignTrack collections
90  // +1 is for undefined AlignTrack type
91  std::vector<TrackCollection *> alignTracks;
92  alignTracks.reserve(AlignTrack::NTrackTypes+1);
93 
94 for(int i=0;i<AlignTrack::NTrackTypes+1;i++)
95  alignTracks.push_back(new TrackCollection);
96 
97  // loop over AlignTracks and fill the corresponding track collections
98  int itrk = 0;
99  DataVector<Track>::const_iterator it = originalTracks->begin();
100  DataVector<Track>::const_iterator it_end = originalTracks->end();
101  for ( ;it != it_end ; ++it, ++itrk) {
102 
103  ATH_MSG_DEBUG("Processing AlignTrack "<<itrk);
104 
105  // each track in the collection HAS to be an AlignTrack
106  const AlignTrack * alignTrack = dynamic_cast<const AlignTrack*>(*it);
107  if(!alignTrack) {
108  msg(MSG::FATAL)<<"Track is not an AlignTrack. The code only works with TrackCollection"
109  <<" filled with AlignTracks."<<endmsg;
110  return StatusCode::FAILURE;
111  }
112 
113  int type = alignTrack->type();
114  ATH_MSG_DEBUG("type of AlignTrack: "<<alignTrack->type());
115 
116  //previously this check was always returning true (type>=0 || type<AlignTrack::NTrackTypes), meaning that in principle you could try
117  //to access an invalid vector element if type was negative. Assume that what we have below is what was meant, as last entry in vector
118  // is for undefined tracks? (Nick Styles, 04/02/15)
119  int colIndex = (type>=0 && type<AlignTrack::NTrackTypes) ? type : AlignTrack::NTrackTypes;
120 
121  ATH_MSG_DEBUG("collection index is "<<colIndex);
122  alignTracks[colIndex]->push_back(new AlignTrack(*alignTrack));
123  ATH_MSG_DEBUG("pushback ok");
124 
125  ++m_trackTypeCounter[colIndex];
126  }
127 
128  // record the collections in the StoreGate that takes care of deletion
129  // only record collection to storegate if it's not empty
130  for(int icol=0;icol<AlignTrack::NTrackTypes+1;++icol) {
131  ATH_MSG_DEBUG(icol<<": recording "<<m_outColNames[icol]<<" size "<<alignTracks[icol]->size());
132  if(!alignTracks[icol]->empty()) {
133  if(evtStore()->record(alignTracks[icol],m_outColNames[icol],false).isFailure()) {
134  ATH_MSG_ERROR("Unable to record "<<m_outColNames[icol]<<" in the StoreGate");
135  delete alignTracks[icol];
136  }
137  ATH_MSG_DEBUG("Recorded \'"<<m_outColNames[icol]<<"\' with size "<<alignTracks[icol]->size()<<" to StoreGate");
138  }
139  else {
140  ATH_MSG_DEBUG("not recording "<<m_outColNames[icol]);
141  delete alignTracks[icol];
142  }
143  }
144 
145  ATH_MSG_DEBUG("returning SUCCESS");
146  return StatusCode::SUCCESS;
147 }
148 
149 //___________________________________________________________________________
151 {
152  ATH_MSG_DEBUG("AlignTrackCollSplitter::stop()");
153 
154  ATH_MSG_INFO("Processed "<<m_nevents<<" with "<<m_ntracks<<" AlignTracks");
155  ATH_MSG_INFO("Track collections recorded in StoreGate:");
156  ATH_MSG_INFO("----------------------------------------------");
157  for(int icol=0;icol<AlignTrack::NTrackTypes+1;++icol)
159  ATH_MSG_INFO("----------------------------------------------");
160 
161  return StatusCode::SUCCESS;
162 }
163 
164 //___________________________________________________________________________
166 {
167  ATH_MSG_DEBUG("AlignTrackCollSplitter::finalize()");
168  return StatusCode::SUCCESS;
169 }
170 
171 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
Trk::AlignTrackCollSplitter::m_outColNames
std::vector< std::string > m_outColNames
Names of output track collections.
Definition: AlignTrackCollSplitter.h:52
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AlignTrackCollSplitter.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::AlignTrackCollSplitter::m_ntracks
int m_ntracks
number of processed tracks
Definition: AlignTrackCollSplitter.h:55
Trk::AlignTrackCollSplitter::m_nRetrievalErrors
int m_nRetrievalErrors
number of retrieval errors at the beginning of the job
Definition: AlignTrackCollSplitter.h:59
Trk::AlignTrackCollSplitter::AlignTrackCollSplitter
AlignTrackCollSplitter(const std::string &name, ISvcLocator *pSvcLocator)
constructor
Definition: AlignTrackCollSplitter.cxx:13
skel.it
it
Definition: skel.GENtoEVGEN.py:396
Trk::AlignTrackCollSplitter::~AlignTrackCollSplitter
virtual ~AlignTrackCollSplitter()
destructor
Definition: AlignTrackCollSplitter.cxx:26
Trk::dumpAlignTrackType
std::string dumpAlignTrackType(const AlignTrack::AlignTrackType type)
Definition: AlignTrack.cxx:410
Trk::AlignTrack::AlignTrackType
AlignTrackType
Definition: AlignTrack.h:45
Trk::AlignTrackCollSplitter::m_maxRetrievalErrors
int m_maxRetrievalErrors
maximum allowed number of retrieval errors at the beginning of the job (-1 for infinite)
Definition: AlignTrackCollSplitter.h:60
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
atlasStyleMacro.icol
int icol
Definition: atlasStyleMacro.py:13
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
Trk::AlignTrackCollSplitter::execute
virtual StatusCode execute()
loops over tracks in event, and accumulates information necessary for alignmnet
Definition: AlignTrackCollSplitter.cxx:47
AlignTrack.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TrackCollection.h
Trk::AlignTrackCollSplitter::finalize
virtual StatusCode finalize()
finalize method
Definition: AlignTrackCollSplitter.cxx:165
DataVector< Trk::Track >
AthAlgorithm
Definition: AthAlgorithm.h:47
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::AlignTrackCollSplitter::initialize
virtual StatusCode initialize()
initialize method
Definition: AlignTrackCollSplitter.cxx:32
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
Trk::AlignTrack
Definition: AlignTrack.h:41
Trk::AlignTrackCollSplitter::m_nevents
int m_nevents
number of processed events
Definition: AlignTrackCollSplitter.h:54
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
Trk::AlignTrackCollSplitter::stop
virtual StatusCode stop()
stop method
Definition: AlignTrackCollSplitter.cxx:150
Trk::AlignTrackCollSplitter::m_trackTypeCounter
std::vector< int > m_trackTypeCounter
counter for different types of tracks
Definition: AlignTrackCollSplitter.h:57
Trk::AlignTrackCollSplitter::m_outColPrefix
std::string m_outColPrefix
Prefix for names of output track collections.
Definition: AlignTrackCollSplitter.h:50
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
Trk::AlignTrackCollSplitter::m_inputCol
std::string m_inputCol
Name of input track collection.
Definition: AlignTrackCollSplitter.h:49
Trk::AlignTrack::NTrackTypes
@ NTrackTypes
total number of track types
Definition: AlignTrack.h:53
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Trk::AlignTrack::type
AlignTrackType type() const
get and set the refit type
Definition: AlignTrack.h:96