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