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 19 of file TrackInformationExtractor.h.

Member Function Documentation

◆ missing()

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

Definition at line 27 of file TrackInformationExtractor.cc.

Referenced by operator()().

27  {
28  G4Exception(
29  "SimG4Core/Notification", "mc001", FatalException, "TrackInformationExtractor: G4Track has no TrackInformation");
30 }

◆ 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.

References missing(), and wrongType().

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

◆ operator()() [2/4]

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

Definition at line 25 of file TrackInformationExtractor.h.

References operator()().

Referenced by operator()().

25 { return operator()(*gtk); }
const TrackInformation & operator()(const G4Track &gtk) const

◆ 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 16 of file TrackInformationExtractor.cc.

References missing(), and wrongType().

16  {
17  G4VUserTrackInformation *gui = gtk.GetUserInformation();
18  TrackInformation *tkInfo = dynamic_cast<TrackInformation *>(gui);
19  if (gui == nullptr) {
20  missing(gtk);
21  } else if (tkInfo == nullptr) {
22  wrongType();
23  }
24  return *tkInfo;
25 }
void missing(const G4Track &gtk) const

◆ operator()() [4/4]

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

Definition at line 30 of file TrackInformationExtractor.h.

References operator()().

Referenced by operator()().

30 { return operator()(*gtk); }
const TrackInformation & operator()(const G4Track &gtk) const

◆ wrongType()

void TrackInformationExtractor::wrongType ( ) const
private

Definition at line 32 of file TrackInformationExtractor.cc.

Referenced by operator()().

32  {
33  G4Exception(
34  "SimG4Core/Notification", "mc001", FatalException, "User information in G4Track is not of TrackInformation type");
35 }