ATLAS Offline Software
SegmentRetriever.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "TrkSegment/Segment.h"
10 
11 #include "JiveXML/DataType.h"
12 
13 namespace JiveXML {
14 
21  SegmentRetriever::SegmentRetriever(const std::string& type,const std::string& name,const IInterface* parent):
23 
24 
26  ATH_CHECK(m_keys.initialize());
27  return StatusCode::SUCCESS;
28  }
29 
30 
38  StatusCode SegmentRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
39 
40  ATH_MSG_DEBUG("Retrieving " << dataTypeName());
41 
42  for( const auto& key : m_keys ) {
44  if (cont.isValid()) {
45 
46  //Get number of segments in this collection
48 
49  //Define the data vectors we want to fill and create space
50  DataVect x; x.reserve(NSegs);
51  DataVect y; y.reserve(NSegs);
52  DataVect z; z.reserve(NSegs);
53  DataVect phi; phi.reserve(NSegs);
54  DataVect theta; theta.reserve(NSegs);
55  DataVect numHits; numHits.reserve(NSegs);
56  DataVect hits;
57 
58  //Loop over the segments
60  for (SegmentItr=cont.cptr()->begin(); SegmentItr!=cont.cptr()->end(); ++SegmentItr) {
61 
62  //Retrive primite variabels
63  x.emplace_back((*SegmentItr)->globalPosition().x()/10.);
64  y.emplace_back((*SegmentItr)->globalPosition().y()/10.);
65  z.emplace_back((*SegmentItr)->globalPosition().z()/10.);
66  phi.emplace_back((*SegmentItr)->localParameters()[Trk::phi]);
67  theta.emplace_back((*SegmentItr)->localParameters()[Trk::theta]);
68 
69  //Count number of valid (non-null) RIO_OnTracks
70  int NRoTs = 0;
71  //Reserve space for expected number
72  hits.reserve(hits.size()+(*SegmentItr)->containedMeasurements().size());
73 
74  //Loop over segment measurments
75  std::vector< const Trk::MeasurementBase * >::const_iterator measItr, measEnd;
76  measItr=(*SegmentItr)->containedMeasurements().begin();
77  measEnd=(*SegmentItr)->containedMeasurements().end();
78 
79  //Now loop over measurements
80  for (; measItr!=measEnd; ++measItr) {
81 
82  //dynamic_cast to RIO_OnTrack - will return NULL if not a RIO_OnTrack object
83  const Trk::RIO_OnTrack *RoT = dynamic_cast<const Trk::RIO_OnTrack*>(*measItr);
84 
85  //Ignore failed dynamic_casts
86  if (!RoT) continue ;
87 
88  //Add the hit
89  hits.emplace_back(RoT->identify().get_compact() );
90  //count as valid
91  NRoTs++;
92  }
93 
94  //Store number of hits for this segement
95  numHits.emplace_back(NRoTs);
96  }
97 
98  //Add data to our map
100  DataMap["x"] = x;
101  DataMap["y"] = y;
102  DataMap["z"] = z;
103  DataMap["phi"] = phi;
104  DataMap["theta"] = theta;
105  DataMap["numHits"] = numHits;
106 
107  //Hits are stored as multiple with average size given in XML header
108  if (NSegs > 0) {
109  std::string multiple = "hits multiple=\"" + DataType( hits.size()*1./numHits.size()).toString() + "\"";
110  DataMap[multiple] = hits;
111  }
112 
113  //forward data to formating tool
114  if ( FormatTool->AddToEvent(dataTypeName(), key.key(), &DataMap).isFailure())
115  return StatusCode::RECOVERABLE;
116 
117  ATH_MSG_DEBUG(dataTypeName() << " collection " << key << " retrieved with " << NSegs << " entries");
118 
119  }
120  else{
121  ATH_MSG_WARNING("Collection " << key << " not found in SG ");
122  }
123  }
124 
125  //All collections retrieved - done
126  return StatusCode::SUCCESS;
127 
128  } // retrive
129 } //namespace
DataType.h
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
JiveXML::SegmentRetriever::dataTypeName
virtual std::string dataTypeName() const
Return the name of the data type.
Definition: SegmentRetriever.h:42
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
JiveXML::DataVect
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition: DataType.h:58
DataType
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
Definition: RoIBResultByteStreamTool.cxx:25
JiveXML::SegmentRetriever::m_keys
SG::ReadHandleKeyArray< Trk::SegmentCollection > m_keys
Definition: SegmentRetriever.h:48
Identifier::get_compact
value_type get_compact() const
Get the compact id.
Trk::RIO_OnTrack
Definition: RIO_OnTrack.h:70
JiveXML::DataMap
std::map< std::string, DataVect > DataMap
Definition: DataType.h:59
JiveXML::SegmentRetriever::initialize
virtual StatusCode initialize()
Definition: SegmentRetriever.cxx:25
x
#define x
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
TrackSegment.h
SegmentRetriever.h
z
#define z
Trk::theta
@ theta
Definition: ParamDefs.h:66
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
test_pyathena.parent
parent
Definition: test_pyathena.py:15
JiveXML::SegmentRetriever::SegmentRetriever
SegmentRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
Definition: SegmentRetriever.cxx:21
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
JiveXML
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
Definition: BadLArRetriever.cxx:22
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
RIO_OnTrack.h
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
JiveXML::SegmentRetriever::retrieve
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
Definition: SegmentRetriever.cxx:38
y
#define y
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::RIO_OnTrack::identify
Identifier identify() const
return the identifier -extends MeasurementBase
Definition: RIO_OnTrack.h:152
Trk::phi
@ phi
Definition: ParamDefs.h:75
AthAlgTool
Definition: AthAlgTool.h:26
DataVector< Trk::Segment >::size_type
BASE::size_type size_type
Definition: DataVector.h:813
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Segment.h
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37