CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions
TrackInformationExtractor Class Reference

#include <TrackInformationExtractor.h>

Public Member Functions

const TrackInformationoperator() (const G4Track &gtk) const
 
const TrackInformationoperator() (const G4Track *gtk) const
 
TrackInformationoperator() (G4Track &gtk) const
 
TrackInformationoperator() (G4Track *gtk) const
 

Private Member Functions

void missing (const G4Track &gtk) const
 
void wrongType () const
 

Detailed Description

Provides safe access to the TrackInformation part of a G4Track. If the G4Track pointer/reference is const, a const reference to the TrackInformation is returned, else a non-const reference is returned. The TrackInformationExtractor checks for the existance of TrackInformation and for the validity of the dynamic_cast; It will throw an excepton if it is not possible to return TrackInformation, but it will do it's best to satisfy the request (in some cases it may even create the TrackInformation on-the-fly).

Definition at line 20 of file TrackInformationExtractor.h.

Member Function Documentation

◆ missing()

void TrackInformationExtractor::missing ( const G4Track &  gtk) const
inlineprivate

Definition at line 34 of file TrackInformationExtractor.h.

34  {
35  throw SimG4Exception("TrackInformationExtractor: G4Track has no TrackInformation");
36  }

Referenced by operator()().

◆ operator()() [1/4]

const TrackInformation & TrackInformationExtractor::operator() ( const G4Track &  gtk) const

for a const G4Track pointer/reference a const TrackInformation& is returned.

Definition at line 5 of file TrackInformationExtractor.cc.

5  {
6  G4VUserTrackInformation *gui = gtk.GetUserInformation();
7  if (gui == nullptr)
8  missing(gtk);
9  const TrackInformation *tkInfo = dynamic_cast<const TrackInformation *>(gui);
10  if (tkInfo == nullptr)
11  wrongType();
12  return *tkInfo;
13 }

References missing(), and wrongType().

◆ operator()() [2/4]

const TrackInformation& TrackInformationExtractor::operator() ( const G4Track *  gtk) const
inline

Definition at line 26 of file TrackInformationExtractor.h.

26 { return operator()(*gtk); }

References operator()().

Referenced by operator()().

◆ operator()() [3/4]

TrackInformation & TrackInformationExtractor::operator() ( G4Track &  gtk) const

for a non-const G4Track pointer/reference the TrackInformation& is also non-const.

Definition at line 15 of file TrackInformationExtractor.cc.

15  {
16  G4VUserTrackInformation *gui = gtk.GetUserInformation();
17  if (gui == nullptr)
18  missing(gtk);
19  TrackInformation *tkInfo = dynamic_cast<TrackInformation *>(gui);
20  if (tkInfo == nullptr)
21  wrongType();
22  return *tkInfo;
23 }

References missing(), and wrongType().

◆ operator()() [4/4]

TrackInformation& TrackInformationExtractor::operator() ( G4Track *  gtk) const
inline

Definition at line 31 of file TrackInformationExtractor.h.

31 { return operator()(*gtk); }

References operator()().

Referenced by operator()().

◆ wrongType()

void TrackInformationExtractor::wrongType ( ) const
inlineprivate

Definition at line 37 of file TrackInformationExtractor.h.

37 { throw SimG4Exception("User information in G4Track is not of TrackInformation type"); }

Referenced by operator()().

TrackInformationExtractor::operator()
const TrackInformation & operator()(const G4Track &gtk) const
Definition: TrackInformationExtractor.cc:5
SimG4Exception
Definition: SimG4Exception.h:13
TrackInformation
Definition: TrackInformation.h:12
TrackInformationExtractor::wrongType
void wrongType() const
Definition: TrackInformationExtractor.h:37
TrackInformationExtractor::missing
void missing(const G4Track &gtk) const
Definition: TrackInformationExtractor.h:34