ATLAS Offline Software
SegmentRetriever.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "TrkSegment/Segment.h"
11 
12 #include "JiveXML/DataType.h"
13 
14 namespace JiveXML {
15 
22  SegmentRetriever::SegmentRetriever(const std::string& type,const std::string& name,const IInterface* parent):
24  m_typeName("Segment"){
25 
26  //Only declare the interface
27  declareInterface<IDataRetriever>(this);
28  }
29 
37  StatusCode SegmentRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
38 
39  //be verbose
40  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Retrieving " << dataTypeName() <<endmsg;
41 
42  //Get an iterator over all segement collections
43  SG::ConstIterator<Trk::SegmentCollection> CollectionItr, CollectionsEnd;
44  if ((evtStore()->retrieve(CollectionItr, CollectionsEnd)).isFailure()){
45  if (msgLvl(MSG::ERROR)) msg(MSG::ERROR) << "Unable to retrieve iterator for Segment collection" << endmsg;
46  return StatusCode::RECOVERABLE;
47  }
48 
49  //Loop over segment collections
50  for (; CollectionItr!=CollectionsEnd; ++CollectionItr) {
51 
52  //Get number of segments in this collection
53  Trk::SegmentCollection::size_type NSegs=(*CollectionItr).size();
54 
55  //Define the data vectors we want to fill and create space
56  DataVect x; x.reserve(NSegs);
57  DataVect y; y.reserve(NSegs);
58  DataVect z; z.reserve(NSegs);
59  DataVect phi; phi.reserve(NSegs);
60  DataVect theta; theta.reserve(NSegs);
61  DataVect numHits; numHits.reserve(NSegs);
62  DataVect hits;
63 
64  //Loop over the segments
66  for (SegmentItr=(*CollectionItr).begin(); SegmentItr!=(*CollectionItr).end(); ++SegmentItr) {
67 
68  //Retrive primite variabels
69  x.emplace_back((*SegmentItr)->globalPosition().x()/10.);
70  y.emplace_back((*SegmentItr)->globalPosition().y()/10.);
71  z.emplace_back((*SegmentItr)->globalPosition().z()/10.);
72  phi.emplace_back((*SegmentItr)->localParameters()[Trk::phi]);
73  theta.emplace_back((*SegmentItr)->localParameters()[Trk::theta]);
74 
75  //Count number of valid (non-null) RIO_OnTracks
76  int NRoTs = 0;
77  //Reserve space for expected number
78  hits.reserve(hits.size()+(*SegmentItr)->containedMeasurements().size());
79 
80  //Loop over segment measurments
81  std::vector< const Trk::MeasurementBase * >::const_iterator measItr, measEnd;
82  measItr=(*SegmentItr)->containedMeasurements().begin();
83  measEnd=(*SegmentItr)->containedMeasurements().end();
84 
85  //Now loop over measurements
86  for (; measItr!=measEnd; ++measItr) {
87 
88  //dynamic_cast to RIO_OnTrack - will return NULL if not a RIO_OnTrack object
89  const Trk::RIO_OnTrack *RoT = dynamic_cast<const Trk::RIO_OnTrack*>(*measItr);
90 
91  //Ignore failed dynamic_casts
92  if (!RoT) continue ;
93 
94  //Add the hit
95  hits.emplace_back(RoT->identify().get_compact() );
96  //count as valid
97  NRoTs++;
98  }
99 
100  //Store number of hits for this segement
101  numHits.emplace_back(NRoTs);
102  }
103 
104  //Add data to our map
106  DataMap["x"] = x;
107  DataMap["y"] = y;
108  DataMap["z"] = z;
109  DataMap["phi"] = phi;
110  DataMap["theta"] = theta;
111  DataMap["numHits"] = numHits;
112 
113  //Hits are stored as multiple with average size given in XML header
114  if (NSegs > 0) {
115  std::string multiple = "hits multiple=\"" + DataType( hits.size()*1./numHits.size()).toString() + "\"";
116  DataMap[multiple] = hits;
117  }
118 
119  //forward data to formating tool
120  if ( FormatTool->AddToEvent(dataTypeName(), CollectionItr.key(), &DataMap).isFailure())
121  return StatusCode::RECOVERABLE;
122 
123  //Be verbose
124  if (msgLvl(MSG::DEBUG)) {
125  msg(MSG::DEBUG) << dataTypeName() << " collection " << CollectionItr.key();
126  msg(MSG::DEBUG) << " retrieved with " << NSegs << " entries"<< endmsg;
127  }
128 
129  }//Loop over segment collections
130 
131  //All collections retrieved - done
132  return StatusCode::SUCCESS;
133 
134  } // retrive
135 } //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:39
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
SG::detail::IteratorBase::key
const std::string & key() const
Get the key string with which the current object was stored.
Definition: SGIterator.cxx:155
JiveXML::DataVect
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition: DataType.h:58
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:71
DataType
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
Definition: RoIBResultByteStreamTool.cxx:25
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
Trk::RIO_OnTrack
Definition: RIO_OnTrack.h:70
JiveXML::DataMap
std::map< std::string, DataVect > DataMap
Definition: DataType.h:59
x
#define x
TrackSegment.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
SegmentRetriever.h
z
#define z
Trk::theta
@ theta
Definition: ParamDefs.h:72
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
LArG4ShowerLibProcessing.hits
hits
Definition: LArG4ShowerLibProcessing.py:136
Segment.h
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:22
JiveXML
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
Definition: BadLArRetriever.cxx:21
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
RIO_OnTrack.h
JiveXML::SegmentRetriever::retrieve
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
Definition: SegmentRetriever.cxx:37
y
#define y
Identifier::get_compact
value_type get_compact(void) const
Get the compact id.
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
Trk::RIO_OnTrack::identify
virtual Identifier identify() const final
return the identifier -extends MeasurementBase
Definition: RIO_OnTrack.h:155
Trk::phi
@ phi
Definition: ParamDefs.h:81
AthAlgTool
Definition: AthAlgTool.h:26
DataVector< Trk::Segment >::size_type
BASE::size_type size_type
Definition: DataVector.h:813
SG::ConstIterator
Definition: SGIterator.h:163
SegmentCollection.h