]>
Commit | Line | Data |
---|---|---|
f902e6f2 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | #include "AliTaskCDBconnect.h" | |
17 | ||
18 | #include <TChain.h> | |
19 | #include <TFile.h> | |
20 | #include <TGeoGlobalMagField.h> | |
125ba988 | 21 | #include "TGeoManager.h" |
f902e6f2 | 22 | |
23 | #include "AliAnalysisManager.h" | |
24 | #include "AliGeomManager.h" | |
25 | #include "AliCDBManager.h" | |
26 | #include "AliGRPManager.h" | |
27 | #include "AliESDEvent.h" | |
28 | #include "AliESDInputHandler.h" | |
29 | #include "AliLog.h" | |
30 | ||
31 | ClassImp(AliTaskCDBconnect) | |
32 | ||
33 | //______________________________________________________________________________ | |
34 | AliTaskCDBconnect::AliTaskCDBconnect(): | |
35 | AliAnalysisTask(), | |
36 | fRun(0), | |
37 | fRunChanged(kFALSE), | |
38 | fESDhandler(NULL), | |
39 | fESD(NULL), | |
40 | fGRPManager(NULL) | |
41 | { | |
42 | // Dummy constructor | |
43 | } | |
44 | ||
45 | //______________________________________________________________________________ | |
46 | AliTaskCDBconnect::AliTaskCDBconnect(const char* name): | |
47 | AliAnalysisTask(name, "ESD analysis tender car"), | |
48 | fRun(0), | |
49 | fRunChanged(kFALSE), | |
50 | fESDhandler(NULL), | |
51 | fESD(NULL), | |
52 | fGRPManager(NULL) | |
53 | { | |
54 | // Default constructor | |
55 | AliCDBManager *cdb = AliCDBManager::Instance(); | |
56 | cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB"); | |
57 | cdb->SetRun(0); | |
58 | DefineInput (0, TChain::Class()); | |
59 | // DefineOutput(0, AliESDEvent::Class()); | |
60 | } | |
61 | ||
62 | //______________________________________________________________________________ | |
63 | AliTaskCDBconnect::~AliTaskCDBconnect() | |
64 | { | |
65 | // Destructor | |
66 | if (fGRPManager) delete fGRPManager; | |
67 | // if (gGeoManager) delete gGeoManager; | |
68 | } | |
69 | ||
70 | //______________________________________________________________________________ | |
71 | void AliTaskCDBconnect::LocalInit() | |
72 | { | |
73 | // Init CDB locally if run number is defined. | |
f902e6f2 | 74 | } |
75 | ||
76 | //______________________________________________________________________________ | |
77 | void AliTaskCDBconnect::ConnectInputData(Option_t* /*option*/) | |
78 | { | |
79 | // Connect the input data, create CDB manager. | |
f902e6f2 | 80 | } |
81 | ||
82 | //______________________________________________________________________________ | |
83 | void AliTaskCDBconnect::InitGRP() | |
84 | { | |
85 | // Initialize geometry and mag. field | |
86 | if (!fGRPManager) { | |
87 | // magnetic field | |
88 | if (!TGeoGlobalMagField::Instance()->GetField()) { | |
2251e21b | 89 | printf("AliCDBconnect: #### Loading field map...\n"); |
f902e6f2 | 90 | fGRPManager = new AliGRPManager(); |
91 | if(!fGRPManager->ReadGRPEntry()) { | |
2251e21b | 92 | AliError("Cannot get GRP entry"); |
f902e6f2 | 93 | } |
94 | if( !fGRPManager->SetMagField() ) { | |
2251e21b | 95 | AliError("Problem with magnetic field setup"); |
f902e6f2 | 96 | } |
97 | } | |
98 | ||
99 | // geometry | |
125ba988 | 100 | if (!gGeoManager) { |
101 | printf("AliCDBconnect: #### Loading geometry...\n"); | |
25cf73e9 | 102 | AliGeomManager::LoadGeometry("geometry.root"); |
36f9cda1 | 103 | if( !AliGeomManager::ApplyAlignObjsFromCDB("GRP ITS TPC TRD") ) { |
125ba988 | 104 | AliError("Problem with align objects"); |
105 | } | |
106 | } | |
f902e6f2 | 107 | } |
108 | } | |
109 | ||
110 | //______________________________________________________________________________ | |
111 | void AliTaskCDBconnect::CreateOutputObjects() | |
112 | { | |
2251e21b | 113 | // Init CDB locally if run number is defined. |
114 | AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); | |
115 | if (!mgr) AliFatal("No analysis manager"); | |
116 | fESDhandler = dynamic_cast<AliESDInputHandler *>(mgr->GetInputEventHandler()); | |
117 | ||
118 | if (!fESDhandler) { | |
119 | AliFatal("No ESD input event handler connected"); | |
120 | return; | |
121 | } | |
b121056d | 122 | // Try to get event number before the first event is read (this has precedence |
123 | // over existing fRun) | |
2251e21b | 124 | Int_t run = mgr->GetRunFromPath(); |
d9fd89a6 | 125 | if (!run && !fRun) { |
126 | AliError("AliTaskCDBconnect: Run not set - no CDB connection"); | |
127 | return; | |
2251e21b | 128 | } |
2251e21b | 129 | // Create CDB manager |
130 | AliCDBManager *cdb = AliCDBManager::Instance(); | |
b121056d | 131 | // If CDB is already locked, return |
132 | if (cdb->GetLock()) return; | |
2251e21b | 133 | // SetDefault storage. Specific storages must be set by TaskCDBconnectSupply::Init() |
b121056d | 134 | // cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB"); |
f665d14d | 135 | if (!cdb->GetRaw()) { |
b23713ce | 136 | cdb->SetDefaultStorage("raw://"); |
b121056d | 137 | } |
2251e21b | 138 | if (run && (run != fRun)) { |
139 | fRunChanged = kTRUE; | |
140 | fRun = run; | |
141 | } else { | |
142 | fRunChanged = kFALSE; | |
b121056d | 143 | } |
2251e21b | 144 | // Set run |
d9fd89a6 | 145 | if (fRunChanged || !fGRPManager) { |
146 | printf("AliCDBconnect: #### Setting run to: %d\n", fRun); | |
147 | cdb->SetRun(fRun); | |
148 | // Initialize GRP manager only once | |
149 | if (fRun) InitGRP(); | |
150 | } | |
2251e21b | 151 | } |
152 | ||
153 | //______________________________________________________________________________ | |
154 | Bool_t AliTaskCDBconnect::Notify() | |
155 | { | |
156 | // Init CDB locally if run number is defined. | |
157 | CreateOutputObjects(); | |
158 | return kTRUE; | |
f902e6f2 | 159 | } |
160 | ||
161 | //______________________________________________________________________________ | |
162 | void AliTaskCDBconnect::Exec(Option_t* /*option*/) | |
163 | { | |
164 | // | |
165 | // Execute all supplied analysis of one event. Notify run change via RunChanged(). | |
166 | fESD = fESDhandler->GetEvent(); | |
f902e6f2 | 167 | // Intercept when the run number changed |
168 | if (fRun != fESD->GetRunNumber()) { | |
169 | fRunChanged = kTRUE; | |
170 | fRun = fESD->GetRunNumber(); | |
d9fd89a6 | 171 | CreateOutputObjects(); |
f902e6f2 | 172 | } |
f902e6f2 | 173 | } |
b121056d | 174 | |
175 | //______________________________________________________________________________ | |
176 | void AliTaskCDBconnect::Terminate(Option_t *) | |
177 | { | |
178 | // Initialize CDB also in Terminate | |
219eb55e | 179 | // CreateOutputObjects(); |
b121056d | 180 | } |