]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliRunAction.cxx
update to geant4 4.0 (not yet released) - removal of old vis~ commands
[u/mrichter/AliRoot.git] / AliGeant4 / AliRunAction.cxx
1 // $Id$
2 // Category: run
3 //
4 // Author: I. Hrivnacova
5 //
6 // Class AliRunAction
7 // ------------------
8 // See the class description in the header file.
9
10 #include <G4Timer.hh>
11    // in order to avoid the odd dependency for the
12    // times system function this include must be the first
13
14 #include "AliRunAction.h"
15 #include "AliSDConstruction.h"
16 #include "AliGlobals.h"
17 #include "AliRun.h"
18 #include "AliHeader.h"
19 #include "AliLego.h"
20
21 #include "TG4SDManager.h"
22 #include "TG4VSDConstruction.h"
23
24 #include <G4Run.hh>
25 #include <G4VVisManager.hh>
26 #include <G4UImanager.hh>
27
28 //_____________________________________________________________________________
29 AliRunAction::AliRunAction()
30   : fMessenger(this),
31     fRunID(-1),
32     fVerboseLevel(0)
33 {
34 //
35   fTimer = new G4Timer;
36 }
37
38 //_____________________________________________________________________________
39 AliRunAction::AliRunAction(const AliRunAction& right) 
40   : fMessenger(this) {
41 //
42   AliGlobals::Exception("AliRunAction is protected from copying.");
43 }
44
45 //_____________________________________________________________________________
46 AliRunAction::~AliRunAction() {
47 //
48   delete fTimer;
49 }
50
51 // operators
52
53 //_____________________________________________________________________________
54 AliRunAction& AliRunAction::operator=(const AliRunAction &right)
55 {
56   // check assignement to self
57   if (this == &right) return *this;
58   
59   AliGlobals::Exception("AliRunAction is protected from assigning.");
60
61   return *this;
62 }
63
64 // private methods
65
66 //_____________________________________________________________________________
67 AliSDConstruction* AliRunAction::GetSDConstruction() const
68 {
69 // Gets sensitive detectors construction and checks type.
70 // ---
71
72   TG4VSDConstruction* tg4SDConstruction 
73      = TG4SDManager::Instance()->GetSDConstruction();
74
75   AliSDConstruction* aliSDConstruction
76      = dynamic_cast<AliSDConstruction*>(tg4SDConstruction);
77
78   if (!aliSDConstruction) {
79      G4String text = "AliRunAction::GetSDConstruction:\n";
80      text = text + "    Unknown type.";
81      AliGlobals::Exception(text);
82      return 0;
83   }
84   
85   return aliSDConstruction;
86 }
87
88 // public methods
89
90 //_____________________________________________________________________________
91 void AliRunAction::BeginOfRunAction(const G4Run* run)
92 {
93 // Called by G4 kernel at the beginning of run.
94 // ---
95
96   fRunID++;
97   
98   // aliroot
99   // store runID in the event header
100   gAlice->GetHeader()->SetRun(fRunID);
101
102   // create lego sensitive detectors 
103   // if lego is instantiated
104   AliLego* lego = gAlice->Lego();
105   if (lego) {
106     GetSDConstruction()->SetLego(lego);
107     G4UImanager::GetUIpointer()->ApplyCommand("/aliEvent/verbose 0");
108     G4UImanager::GetUIpointer()->ApplyCommand("/aliGenerator/set AliGenerator");
109   }  
110
111   // notify graphics 
112   if (G4VVisManager::GetConcreteInstance()) {
113     G4UImanager::GetUIpointer()->ApplyCommand("/vis/scene/notifyHandlers");
114   } 
115
116   G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
117   fTimer->Start();
118 }
119
120 //_____________________________________________________________________________
121 void AliRunAction::EndOfRunAction(const G4Run* run)
122 {
123 // Called by G4 kernel at the end of run.
124 // ---
125
126   fTimer->Stop();
127
128   // delete lego sensitive detectors 
129   // if lego is instantiated
130   AliLego* lego = gAlice->Lego();
131   if (lego) {
132     GetSDConstruction()->UnsetLego();
133     G4UImanager::GetUIpointer()->ApplyCommand("/aliEvent/verbose 1");
134   }  
135
136   // update graphics 
137   if (G4VVisManager::GetConcreteInstance()) {
138      G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
139   }
140
141   G4cout << "Time of this run:   " << *fTimer << G4endl;
142   G4cout << "Number of events processed: " << run->GetNumberOfEvent() << G4endl;
143 }