Geant4  10.01.p01
G4TrajectoriesModel.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4TrajectoriesModel.cc 87360 2014-12-01 16:07:16Z gcosmo $
28 //
29 //
30 // John Allison 26th August 1998.
31 // Model which knows how to draw GEANT4 trajectories.
32 
33 #include "G4TrajectoriesModel.hh"
34 
35 #include "G4ModelingParameters.hh"
36 #include "G4VGraphicsScene.hh"
37 #include "G4RunManager.hh"
38 #ifdef G4MULTITHREADED
39 #include "G4MTRunManager.hh"
40 #endif
41 #include "G4Run.hh"
42 #include "G4Event.hh"
43 #include "G4AttDefStore.hh"
44 #include "G4AttValue.hh"
45 #include "G4AttDef.hh"
46 #include "G4AttCheck.hh"
47 #include "G4UIcommand.hh"
48 #include "G4VVisManager.hh"
49 
51 :fpCurrentTrajectory(0)
52 ,fRunID(-1)
53 ,fEventID(-1)
54 {
55  fType = "G4TrajectoriesModel";
56  fGlobalTag = "G4TrajectoriesModel for all trajectories.";
58 }
59 
61 
63 
65 {
67 #ifdef G4MULTITHREADED
69  { runManager = G4MTRunManager::GetMasterRunManager(); }
70 #endif
71  const G4Run* currentRun = runManager->GetCurrentRun();
72  if (currentRun) {
73  fRunID = currentRun->GetRunID();
74  } else {
75  fRunID = -1;
76  }
77 
78  const G4Event* event = fpMP->GetEvent();
79  if (event) {
80  fEventID = event->GetEventID();
81  } else {
82  fEventID = -1;
83  }
84 
85  G4TrajectoryContainer* TC = event -> GetTrajectoryContainer ();
86  if (!TC) return;
87 
89  if (!pVVisManager) return;
90 
91  pVVisManager->BeginDraw();
92  // The use of Begin/EndDraw (optional methods to improve drawing
93  // speed) assumes all trajectories are drawn with the same
94  // transformation. If not, a fatal exception with be raised in
95  // G4VisManager::DrawT.
96  for (G4int iT = 0; iT < TC->entries(); iT++) {
97  fpCurrentTrajectory = (*TC) [iT];
98  // Debug trajectory:
99  // fpCurrentTrajectory->ShowTrajectory(); G4cout << G4endl;
100  // Debug G4AttValues:
101  // G4TrajectoriesModelDebugG4AttValues(fpCurrentTrajectory);
103  sceneHandler.AddCompound (*fpCurrentTrajectory);
104  }
105  pVVisManager->EndDraw();
106 }
107 
108 const std::map<G4String,G4AttDef>* G4TrajectoriesModel::GetAttDefs() const
109 {
110  G4bool isNew;
111  std::map<G4String,G4AttDef>* store
112  = G4AttDefStore::GetInstance("G4TrajectoriesModel", isNew);
113  if (isNew) {
114  (*store)["RunID"] =
115  G4AttDef("RunID","Run ID","Physics","","G4int");
116  (*store)["EventID"] =
117  G4AttDef("EventID","Event ID","Physics","","G4int");
118  }
119  return store;
120 }
121 
122 std::vector<G4AttValue>* G4TrajectoriesModel::CreateCurrentAttValues() const
123 {
124  std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
125  values->push_back
127  values->push_back
129  return values;
130 }
131 
132 // Debug material...
133 
134 #include "G4VTrajectoryPoint.hh"
135 
137 {
138  // Trajectory attributes
139  { // Scope bracket - allows re-use of names without compiler warnings.
140  std::vector<G4AttValue>* attValues = pTraj->CreateAttValues();
141  if (attValues) {
142  G4AttCheck attCheck(attValues, pTraj->GetAttDefs());
143  G4cout << "\nProvided G4Atts:\n" << attCheck;
144  if (attCheck.Check()) G4cout << "Error" << G4endl;
145  else {
146  std::vector<G4AttValue> standardValues;
147  std::map<G4String,G4AttDef> standardDefinitions;
148  attCheck.Standard(&standardValues, &standardDefinitions);
149  G4cout << "\nStandard G4Atts:\n"
150  << G4AttCheck(&standardValues, &standardDefinitions);
151  }
152  delete attValues;
153  }
154  }
155  // Trajectory point attributes
156  for (G4int i = 0; i < pTraj->GetPointEntries(); i++) {
157  G4VTrajectoryPoint* aPoint = pTraj->GetPoint(i);
158  std::vector<G4AttValue>* attValues = aPoint->CreateAttValues();
159  if (attValues) {
160  G4AttCheck attCheck(attValues, aPoint->GetAttDefs());
161  G4cout << "\nProvided G4Atts:\n" << attCheck;
162  if (attCheck.Check()) G4cout << "Error" << G4endl;
163  else {
164  std::vector<G4AttValue> standardValues;
165  std::map<G4String,G4AttDef> standardDefinitions;
166  attCheck.Standard(&standardValues, &standardDefinitions);
167  G4cout << "\nStandard G4Atts:\n"
168  << G4AttCheck(&standardValues, &standardDefinitions);
169  }
170  delete attValues;
171  }
172  }
173 }
G4String fType
Definition: G4VModel.hh:108
static G4VVisManager * GetConcreteInstance()
std::vector< G4AttValue > * CreateCurrentAttValues() const
virtual G4VTrajectoryPoint * GetPoint(G4int i) const =0
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:371
int G4int
Definition: G4Types.hh:78
const G4Run * GetCurrentRun() const
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
G4String fGlobalTag
Definition: G4VModel.hh:109
virtual std::vector< G4AttValue > * CreateAttValues() const
virtual int GetPointEntries() const =0
G4GLOB_DLL std::ostream G4cout
const G4Event * GetEvent() const
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
bool G4bool
Definition: G4Types.hh:79
virtual void EndDraw()=0
static G4MTRunManager * GetMasterRunManager()
G4int GetRunID() const
Definition: G4Run.hh:76
Definition: G4Run.hh:46
const G4ModelingParameters * fpMP
Definition: G4VModel.hh:113
virtual void BeginDraw(const G4Transform3D &objectTransformation=G4Transform3D())=0
G4String fGlobalDescription
Definition: G4VModel.hh:110
G4bool IsMultithreadedApplication()
Definition: G4Threading.cc:134
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
virtual void DescribeYourselfTo(G4VGraphicsScene &)
virtual void AddCompound(const G4VTrajectory &)=0
void G4TrajectoriesModelDebugG4AttValues(const G4VTrajectory *)
virtual std::vector< G4AttValue > * CreateAttValues() const
const G4VTrajectory * fpCurrentTrajectory
const std::map< G4String, G4AttDef > * GetAttDefs() const
#define G4endl
Definition: G4ios.hh:61
std::map< G4String, G4AttDef > * GetInstance(const G4String &storeKey, G4bool &isNew)