Added task for CDB connection, loading magnetic field and geometry.
[u/mrichter/AliRoot.git] / PWG1 / AliTaskCDBconnect.cxx
... / ...
CommitLineData
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
30ClassImp(AliTaskCDBconnect)
31
32//______________________________________________________________________________
33AliTaskCDBconnect::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//______________________________________________________________________________
45AliTaskCDBconnect::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//______________________________________________________________________________
62AliTaskCDBconnect::~AliTaskCDBconnect()
63{
64// Destructor
65 if (fGRPManager) delete fGRPManager;
66// if (gGeoManager) delete gGeoManager;
67}
68
69//______________________________________________________________________________
70void AliTaskCDBconnect::LocalInit()
71{
72// Init CDB locally if run number is defined.
73 if (!fRun) {
74 AliWarning("AliTaskCDBconnect::LocalInit Run number not defined yet");
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//______________________________________________________________________________
89void AliTaskCDBconnect::ConnectInputData(Option_t* /*option*/)
90{
91// Connect the input data, create CDB manager.
92 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
93 if (!mgr) AliFatal("No analysis manager");
94 fESDhandler = dynamic_cast<AliESDInputHandler *>(mgr->GetInputEventHandler());
95
96 if (fESDhandler) {
97 fESD = fESDhandler->GetEvent();
98 } else {
99 AliFatal("No ESD input event handler connected") ;
100 }
101 // Create CDB manager
102 AliCDBManager *cdb = AliCDBManager::Instance();
103 // SetDefault storage. Specific storages must be set by TaskCDBconnectSupply::Init()
104// cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
105 cdb->SetDefaultStorage("raw://");
106 Int_t run = fESD->GetRunNumber();
107 if (run != fRun) fRunChanged = kTRUE;
108 else fRunChanged = kFALSE;
109 // Set run
110 if (fRunChanged) cdb->SetRun(fRun);
111 // Initialize GRP manager only once
112 InitGRP();
113}
114
115//______________________________________________________________________________
116void AliTaskCDBconnect::InitGRP()
117{
118// Initialize geometry and mag. field
119 if (!fGRPManager) {
120 // magnetic field
121 if (!TGeoGlobalMagField::Instance()->GetField()) {
122 printf("Loading field map...\n");
123 fGRPManager = new AliGRPManager();
124 if(!fGRPManager->ReadGRPEntry()) {
125 printf("Cannot get GRP entry\n");
126 }
127 if( !fGRPManager->SetMagField() ) {
128 printf("Problem with magnetic field setup\n");
129 }
130 }
131
132 // geometry
133 printf("Loading geometry...\n");
134 AliGeomManager::LoadGeometry();
135 if( !AliGeomManager::ApplyAlignObjsFromCDB("GRP ITS TPC") ) {
136 printf("Problem with align objects\n");
137 }
138 }
139}
140
141//______________________________________________________________________________
142void AliTaskCDBconnect::CreateOutputObjects()
143{
144// Nothing for the moment, but we may need ESD event replication here.
145}
146
147//______________________________________________________________________________
148void AliTaskCDBconnect::Exec(Option_t* /*option*/)
149{
150//
151// Execute all supplied analysis of one event. Notify run change via RunChanged().
152 fESD = fESDhandler->GetEvent();
153
154 // Intercept when the run number changed
155 if (fRun != fESD->GetRunNumber()) {
156 fRunChanged = kTRUE;
157 fRun = fESD->GetRunNumber();
158 AliCDBManager::Instance()->SetRun(fRun);
159 }
160// PostData(0, fESD);
161}