Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 98852 2016-08-15 07:03:35Z 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  return;
77  }
78 
79  const G4Event* event = fpMP->GetEvent();
80  if (event) {
81  fEventID = event->GetEventID();
82  } else {
83  fEventID = -1;
84  return;
85  }
86 
87  G4TrajectoryContainer* TC = event -> GetTrajectoryContainer ();
88  if (!TC) return;
89 
91  if (!pVVisManager) return;
92 
93  pVVisManager->BeginDraw();
94  // The use of Begin/EndDraw (optional methods to improve drawing
95  // speed) assumes all trajectories are drawn with the same
96  // transformation. If not, a fatal exception with be raised in
97  // G4VisManager::DrawT.
98  for (G4int iT = 0; iT < TC->entries(); iT++) {
99  fpCurrentTrajectory = (*TC) [iT];
100  // Debug trajectory:
101  // fpCurrentTrajectory->ShowTrajectory(); G4cout << G4endl;
102  // Debug G4AttValues:
103  // G4TrajectoriesModelDebugG4AttValues(fpCurrentTrajectory);
104  if (fpCurrentTrajectory)
105  sceneHandler.AddCompound (*fpCurrentTrajectory);
106  }
107  pVVisManager->EndDraw();
108 }
109 
110 const std::map<G4String,G4AttDef>* G4TrajectoriesModel::GetAttDefs() const
111 {
112  G4bool isNew;
113  std::map<G4String,G4AttDef>* store
114  = G4AttDefStore::GetInstance("G4TrajectoriesModel", isNew);
115  if (isNew) {
116  (*store)["RunID"] =
117  G4AttDef("RunID","Run ID","Physics","","G4int");
118  (*store)["EventID"] =
119  G4AttDef("EventID","Event ID","Physics","","G4int");
120  }
121  return store;
122 }
123 
124 std::vector<G4AttValue>* G4TrajectoriesModel::CreateCurrentAttValues() const
125 {
126  std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
127  values->push_back
128  (G4AttValue("RunID",G4UIcommand::ConvertToString(fRunID),""));
129  values->push_back
130  (G4AttValue("EventID",G4UIcommand::ConvertToString(fEventID),""));
131  return values;
132 }
133 
134 // Debug material...
135 
136 #include "G4VTrajectoryPoint.hh"
137 
139 {
140  // Trajectory attributes
141  { // Scope bracket - allows re-use of names without compiler warnings.
142  std::vector<G4AttValue>* attValues = pTraj->CreateAttValues();
143  if (attValues) {
144  G4AttCheck attCheck(attValues, pTraj->GetAttDefs());
145  G4cout << "\nProvided G4Atts:\n" << attCheck;
146  if (attCheck.Check()) G4cout << "Error" << G4endl;
147  else {
148  std::vector<G4AttValue> standardValues;
149  std::map<G4String,G4AttDef> standardDefinitions;
150  attCheck.Standard(&standardValues, &standardDefinitions);
151  G4cout << "\nStandard G4Atts:\n"
152  << G4AttCheck(&standardValues, &standardDefinitions);
153  }
154  delete attValues;
155  }
156  }
157  // Trajectory point attributes
158  for (G4int i = 0; i < pTraj->GetPointEntries(); i++) {
159  G4VTrajectoryPoint* aPoint = pTraj->GetPoint(i);
160  std::vector<G4AttValue>* attValues = aPoint->CreateAttValues();
161  if (attValues) {
162  G4AttCheck attCheck(attValues, aPoint->GetAttDefs());
163  G4cout << "\nProvided G4Atts:\n" << attCheck;
164  if (attCheck.Check()) G4cout << "Error" << G4endl;
165  else {
166  std::vector<G4AttValue> standardValues;
167  std::map<G4String,G4AttDef> standardDefinitions;
168  attCheck.Standard(&standardValues, &standardDefinitions);
169  G4cout << "\nStandard G4Atts:\n"
170  << G4AttCheck(&standardValues, &standardDefinitions);
171  }
172  delete attValues;
173  }
174  }
175 }
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:372
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:152
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 std::map< G4String, G4AttDef > * GetAttDefs() const
#define G4endl
Definition: G4ios.hh:61
std::map< G4String, G4AttDef > * GetInstance(const G4String &storeKey, G4bool &isNew)