]>
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> | |
21 | ||
22 | #include "AliAnalysisManager.h" | |
23 | #include "AliGeomManager.h" | |
24 | #include "AliCDBManager.h" | |
25 | #include "AliGRPManager.h" | |
26 | #include "AliESDEvent.h" | |
27 | #include "AliESDInputHandler.h" | |
28 | #include "AliLog.h" | |
29 | ||
30 | ClassImp(AliTaskCDBconnect) | |
31 | ||
32 | //______________________________________________________________________________ | |
33 | AliTaskCDBconnect::AliTaskCDBconnect(): | |
34 | AliAnalysisTask(), | |
35 | fRun(0), | |
36 | fRunChanged(kFALSE), | |
37 | fESDhandler(NULL), | |
38 | fESD(NULL), | |
39 | fGRPManager(NULL) | |
40 | { | |
41 | // Dummy constructor | |
42 | } | |
43 | ||
44 | //______________________________________________________________________________ | |
45 | AliTaskCDBconnect::AliTaskCDBconnect(const char* name): | |
46 | AliAnalysisTask(name, "ESD analysis tender car"), | |
47 | fRun(0), | |
48 | fRunChanged(kFALSE), | |
49 | fESDhandler(NULL), | |
50 | fESD(NULL), | |
51 | fGRPManager(NULL) | |
52 | { | |
53 | // Default constructor | |
54 | AliCDBManager *cdb = AliCDBManager::Instance(); | |
55 | cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB"); | |
56 | cdb->SetRun(0); | |
57 | DefineInput (0, TChain::Class()); | |
58 | // DefineOutput(0, AliESDEvent::Class()); | |
59 | } | |
60 | ||
61 | //______________________________________________________________________________ | |
62 | AliTaskCDBconnect::~AliTaskCDBconnect() | |
63 | { | |
64 | // Destructor | |
65 | if (fGRPManager) delete fGRPManager; | |
66 | // if (gGeoManager) delete gGeoManager; | |
67 | } | |
68 | ||
69 | //______________________________________________________________________________ | |
70 | void AliTaskCDBconnect::LocalInit() | |
71 | { | |
72 | // Init CDB locally if run number is defined. | |
73 | if (!fRun) { | |
2251e21b | 74 | Info("LocalInit","AliTaskCDBconnect::LocalInit Run number not defined yet"); |
f902e6f2 | 75 | return; |
76 | } | |
77 | // Create CDB manager | |
78 | AliCDBManager *cdb = AliCDBManager::Instance(); | |
79 | // SetDefault storage. Specific storages must be set by TaskCDBconnectSupply::Init() | |
80 | // cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB"); | |
81 | cdb->SetDefaultStorage("raw://"); | |
82 | // Set run | |
83 | cdb->SetRun(fRun); | |
84 | // Initialize GRP manager only once | |
85 | InitGRP(); | |
86 | } | |
87 | ||
88 | //______________________________________________________________________________ | |
89 | void AliTaskCDBconnect::ConnectInputData(Option_t* /*option*/) | |
90 | { | |
91 | // Connect the input data, create CDB manager. | |
f902e6f2 | 92 | } |
93 | ||
94 | //______________________________________________________________________________ | |
95 | void AliTaskCDBconnect::InitGRP() | |
96 | { | |
97 | // Initialize geometry and mag. field | |
98 | if (!fGRPManager) { | |
99 | // magnetic field | |
100 | if (!TGeoGlobalMagField::Instance()->GetField()) { | |
2251e21b | 101 | printf("AliCDBconnect: #### Loading field map...\n"); |
f902e6f2 | 102 | fGRPManager = new AliGRPManager(); |
103 | if(!fGRPManager->ReadGRPEntry()) { | |
2251e21b | 104 | AliError("Cannot get GRP entry"); |
f902e6f2 | 105 | } |
106 | if( !fGRPManager->SetMagField() ) { | |
2251e21b | 107 | AliError("Problem with magnetic field setup"); |
f902e6f2 | 108 | } |
109 | } | |
110 | ||
111 | // geometry | |
2251e21b | 112 | printf("AliCDBconnect: #### Loading geometry...\n"); |
f902e6f2 | 113 | AliGeomManager::LoadGeometry(); |
114 | if( !AliGeomManager::ApplyAlignObjsFromCDB("GRP ITS TPC") ) { | |
2251e21b | 115 | AliError("Problem with align objects"); |
f902e6f2 | 116 | } |
117 | } | |
118 | } | |
119 | ||
120 | //______________________________________________________________________________ | |
121 | void AliTaskCDBconnect::CreateOutputObjects() | |
122 | { | |
2251e21b | 123 | // Init CDB locally if run number is defined. |
124 | AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); | |
125 | if (!mgr) AliFatal("No analysis manager"); | |
126 | fESDhandler = dynamic_cast<AliESDInputHandler *>(mgr->GetInputEventHandler()); | |
127 | ||
128 | if (!fESDhandler) { | |
129 | AliFatal("No ESD input event handler connected"); | |
130 | return; | |
131 | } | |
132 | // Try to get event number before the first event is read | |
133 | Int_t run = mgr->GetRunFromPath(); | |
7b17a36b | 134 | if (!run && fESD) run = fESD->GetRunNumber(); |
2251e21b | 135 | if (!run) { |
136 | AliWarning("AliTaskCDBconnect: Could not set run from path"); | |
137 | if (!fRun) return; | |
138 | } | |
139 | printf("AliCDBconnect: #### Setting run to #%d\n", run); | |
140 | // Create CDB manager | |
141 | AliCDBManager *cdb = AliCDBManager::Instance(); | |
142 | // SetDefault storage. Specific storages must be set by TaskCDBconnectSupply::Init() | |
143 | // cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB"); | |
144 | cdb->SetDefaultStorage("raw://"); | |
145 | if (run && (run != fRun)) { | |
146 | fRunChanged = kTRUE; | |
147 | fRun = run; | |
148 | } else { | |
149 | fRunChanged = kFALSE; | |
150 | } | |
151 | // Set run | |
152 | if (fRunChanged) cdb->SetRun(fRun); | |
153 | // Initialize GRP manager only once | |
154 | if (fRun) InitGRP(); | |
155 | } | |
156 | ||
157 | //______________________________________________________________________________ | |
158 | Bool_t AliTaskCDBconnect::Notify() | |
159 | { | |
160 | // Init CDB locally if run number is defined. | |
161 | CreateOutputObjects(); | |
162 | return kTRUE; | |
f902e6f2 | 163 | } |
164 | ||
165 | //______________________________________________________________________________ | |
166 | void AliTaskCDBconnect::Exec(Option_t* /*option*/) | |
167 | { | |
168 | // | |
169 | // Execute all supplied analysis of one event. Notify run change via RunChanged(). | |
170 | fESD = fESDhandler->GetEvent(); | |
f902e6f2 | 171 | // Intercept when the run number changed |
172 | if (fRun != fESD->GetRunNumber()) { | |
173 | fRunChanged = kTRUE; | |
174 | fRun = fESD->GetRunNumber(); | |
2251e21b | 175 | Warning("Exec", "Run number changed in ESDEvent to %d", fRun); |
f902e6f2 | 176 | AliCDBManager::Instance()->SetRun(fRun); |
177 | } | |
178 | // PostData(0, fESD); | |
179 | } |