]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliRunAction.cxx
Functions renamed to get a prefix PHOS
[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   : AliVerbose("runAction"),
31     fRunID(-1) 
32 {
33 //
34   fTimer = new G4Timer;
35 }
36
37 //_____________________________________________________________________________
38 AliRunAction::AliRunAction(const AliRunAction& right) 
39   : AliVerbose("runAction") {
40 //
41   AliGlobals::Exception("AliRunAction is protected from copying.");
42 }
43
44 //_____________________________________________________________________________
45 AliRunAction::~AliRunAction() {
46 //
47   delete fTimer;
48 }
49
50 // operators
51
52 //_____________________________________________________________________________
53 AliRunAction& AliRunAction::operator=(const AliRunAction &right)
54 {
55   // check assignement to self
56   if (this == &right) return *this;
57   
58   AliGlobals::Exception("AliRunAction is protected from assigning.");
59
60   return *this;
61 }
62
63 // private methods
64
65 //_____________________________________________________________________________
66 AliSDConstruction* AliRunAction::GetSDConstruction() const
67 {
68 // Gets sensitive detectors construction and checks type.
69 // ---
70
71   TG4VSDConstruction* tg4SDConstruction 
72      = TG4SDManager::Instance()->GetSDConstruction();
73
74   AliSDConstruction* aliSDConstruction
75      = dynamic_cast<AliSDConstruction*>(tg4SDConstruction);
76
77   if (!aliSDConstruction) {
78      G4String text = "AliRunAction::GetSDConstruction:\n";
79      text = text + "    Unknown type.";
80      AliGlobals::Exception(text);
81      return 0;
82   }
83   
84   return aliSDConstruction;
85 }
86
87 // public methods
88
89 //_____________________________________________________________________________
90 void AliRunAction::BeginOfRunAction(const G4Run* run)
91 {
92 // Called by G4 kernel at the beginning of run.
93 // ---
94
95   fRunID++;
96   
97   // aliroot
98   // store runID in the event header
99   gAlice->GetHeader()->SetRun(fRunID);
100
101   // create lego sensitive detectors 
102   // if lego is instantiated
103   AliLego* lego = gAlice->Lego();
104   if (lego) {
105     GetSDConstruction()->SetLego(lego);
106     G4UImanager::GetUIpointer()->ApplyCommand("/aliVerbose/eventAction 0");
107     G4UImanager::GetUIpointer()->ApplyCommand("/aliGenerator/set AliGenerator");
108   }  
109
110   // notify graphics 
111   if (G4VVisManager::GetConcreteInstance()) {
112     G4UImanager::GetUIpointer()->ApplyCommand("/vis/scene/notifyHandlers");
113   } 
114
115   if (VerboseLevel() > 0) {
116     G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
117   }
118     
119   fTimer->Start();
120 }
121
122 //_____________________________________________________________________________
123 void AliRunAction::EndOfRunAction(const G4Run* run)
124 {
125 // Called by G4 kernel at the end of run.
126 // ---
127
128   fTimer->Stop();
129
130   // delete lego sensitive detectors 
131   // if lego is instantiated
132   AliLego* lego = gAlice->Lego();
133   if (lego) {
134     GetSDConstruction()->UnsetLego();
135     G4UImanager::GetUIpointer()->ApplyCommand("/aliVerbose/eventAction 0");
136   }  
137
138   // update graphics 
139   if (G4VVisManager::GetConcreteInstance()) {
140      G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
141   }
142
143   if (VerboseLevel() > 0) {
144     G4cout << "Time of this run:   " << *fTimer << G4endl;
145     G4cout << "Number of events processed: " << run->GetNumberOfEvent() << G4endl;
146   }    
147 }