ATLAS Offline Software
Loading...
Searching...
No Matches
AlignTrackCollSplitter.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
8
9
10namespace Trk {
11
12//___________________________________________________________________________
13AlignTrackCollSplitter::AlignTrackCollSplitter(const std::string& name, ISvcLocator* pSvcLocator)
14 : AthAlgorithm(name, pSvcLocator)
15 , m_trackTypeCounter(AlignTrack::NTrackTypes+1,0)
16{
17}
18
19//___________________________________________________________________________
21{
22 ATH_MSG_DEBUG("AlignTrackCollSplitter destructor");
23}
24
25//___________________________________________________________________________
27{
28 ATH_MSG_DEBUG("AlignTrackCollSplitter::initialize()");
29
30 // set the track collection names
31 ATH_MSG_INFO("Splitting "<<m_inputCol<<" into:");
32 for(int icol=0; icol<AlignTrack::NTrackTypes+1; ++icol) {
34 ATH_MSG_INFO(" - "<<m_outColNames[icol]);
35 }
36
37 return StatusCode::SUCCESS;
38}
39
40//___________________________________________________________________________
42{
43 ATH_MSG_DEBUG("AlignTrackCollSplitter::execute()");
44
45 // increment number of events
46 m_nevents++;
47
48 // loop over tracks
49 const TrackCollection * originalTracks = nullptr;
50
51 // check if m_inputCol is a TrackCollection and exists for this event
52 // perhaps this can be done in a much nicer way on the python side ala PyUtils/checkFile.py
53 // do it here for now
55 evtStore()->retrieve(originalTracks,m_inputCol).isFailure() ) {
56 ATH_MSG_DEBUG("input track collection \'"<<m_inputCol<<"\' not found for this event");
57
61 msg(MSG::FATAL)<<"Input track collection \'"<<m_inputCol<<"\' not found in first "
62 <<m_nRetrievalErrors<<" events. Aborting."<<endmsg;
63 msg(MSG::FATAL)<<"Maximum allowed number of events without the track collection "
64 <<"can be changed using the \'MaxRetrievalErrors\' option (-1 for infinite)."
65 <<endmsg;
66 return StatusCode::FAILURE;
67 }
68 }
69 return StatusCode::SUCCESS;
70 }
71
72 // if we're here it means that the track collection m_inputCol exists in the file
73 // (it can be empty) so we change the error cutoff to process the whole file
76
77 if(originalTracks->empty())
78 return StatusCode::SUCCESS;
79
80 // increment number of processed tracks
81 m_ntracks += originalTracks->size();
82
83 // vector to keep all different AlignTrack collections
84 // +1 is for undefined AlignTrack type
85 std::vector<TrackCollection *> alignTracks;
86 alignTracks.reserve(AlignTrack::NTrackTypes+1);
87
88for(int i=0;i<AlignTrack::NTrackTypes+1;i++)
89 alignTracks.push_back(new TrackCollection);
90
91 // loop over AlignTracks and fill the corresponding track collections
92 int itrk = 0;
93 DataVector<Track>::const_iterator it = originalTracks->begin();
94 DataVector<Track>::const_iterator it_end = originalTracks->end();
95 for ( ;it != it_end ; ++it, ++itrk) {
96
97 ATH_MSG_DEBUG("Processing AlignTrack "<<itrk);
98
99 // each track in the collection HAS to be an AlignTrack
100 const AlignTrack * alignTrack = dynamic_cast<const AlignTrack*>(*it);
101 if(!alignTrack) {
102 msg(MSG::FATAL)<<"Track is not an AlignTrack. The code only works with TrackCollection"
103 <<" filled with AlignTracks."<<endmsg;
104 return StatusCode::FAILURE;
105 }
106
107 int type = alignTrack->type();
108 ATH_MSG_DEBUG("type of AlignTrack: "<<alignTrack->type());
109
110 //previously this check was always returning true (type>=0 || type<AlignTrack::NTrackTypes), meaning that in principle you could try
111 //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
112 // is for undefined tracks? (Nick Styles, 04/02/15)
114
115 ATH_MSG_DEBUG("collection index is "<<colIndex);
116 alignTracks[colIndex]->push_back(new AlignTrack(*alignTrack));
117 ATH_MSG_DEBUG("pushback ok");
118
119 ++m_trackTypeCounter[colIndex];
120 }
121
122 // record the collections in the StoreGate that takes care of deletion
123 // only record collection to storegate if it's not empty
124 for(int icol=0;icol<AlignTrack::NTrackTypes+1;++icol) {
125 ATH_MSG_DEBUG(icol<<": recording "<<m_outColNames[icol]<<" size "<<alignTracks[icol]->size());
126 if(!alignTracks[icol]->empty()) {
127 if(evtStore()->record(alignTracks[icol],m_outColNames[icol],false).isFailure()) {
128 ATH_MSG_ERROR("Unable to record "<<m_outColNames[icol]<<" in the StoreGate");
129 delete alignTracks[icol];
130 }
131 ATH_MSG_DEBUG("Recorded \'"<<m_outColNames[icol]<<"\' with size "<<alignTracks[icol]->size()<<" to StoreGate");
132 }
133 else {
134 ATH_MSG_DEBUG("not recording "<<m_outColNames[icol]);
135 delete alignTracks[icol];
136 }
137 }
138
139 ATH_MSG_DEBUG("returning SUCCESS");
140 return StatusCode::SUCCESS;
141}
142
143//___________________________________________________________________________
145{
146 ATH_MSG_DEBUG("AlignTrackCollSplitter::stop()");
147
148 ATH_MSG_INFO("Processed "<<m_nevents<<" with "<<m_ntracks<<" AlignTracks");
149 ATH_MSG_INFO("Track collections recorded in StoreGate:");
150 ATH_MSG_INFO("----------------------------------------------");
151 for(int icol=0;icol<AlignTrack::NTrackTypes+1;++icol)
153 ATH_MSG_INFO("----------------------------------------------");
154
155 return StatusCode::SUCCESS;
156}
157
158//___________________________________________________________________________
160{
161 ATH_MSG_DEBUG("AlignTrackCollSplitter::finalize()");
162 return StatusCode::SUCCESS;
163}
164
165}
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
static const Attributes_t empty
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
MsgStream & msg() const
DataModel_detail::const_iterator< DataVector > const_iterator
Standard const_iterator.
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
virtual StatusCode execute()
loops over tracks in event, and accumulates information necessary for alignmnet
int m_ntracks
number of processed tracks
virtual StatusCode stop()
stop method
virtual ~AlignTrackCollSplitter()
destructor
std::vector< int > m_trackTypeCounter
counter for different types of tracks
int m_nRetrievalErrors
number of retrieval errors at the beginning of the job
virtual StatusCode finalize()
finalize method
virtual StatusCode initialize()
initialize method
AlignTrackCollSplitter(const std::string &name, ISvcLocator *pSvcLocator)
constructor
std::vector< std::string > m_outColNames
Names of output track collections.
int m_nevents
number of processed events
@ NTrackTypes
total number of track types
Definition AlignTrack.h:53
AlignTrackType type() const
get and set the refit type
Definition AlignTrack.h:96
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
Ensure that the ATLAS eigen extensions are properly loaded.
std::string dumpAlignTrackType(const AlignTrack::AlignTrackType type)