1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 #include "AliTaskCDBconnect.h"
20 #include <TGeoGlobalMagField.h>
21 #include "TGeoManager.h"
23 #include "AliAnalysisManager.h"
24 #include "AliGeomManager.h"
25 #include "AliCDBManager.h"
26 #include "AliGRPManager.h"
27 #include "AliESDEvent.h"
28 #include "AliESDInputHandler.h"
31 ClassImp(AliTaskCDBconnect)
33 //______________________________________________________________________________
34 AliTaskCDBconnect::AliTaskCDBconnect():
45 //______________________________________________________________________________
46 AliTaskCDBconnect::AliTaskCDBconnect(const char* name, const char *storage, Int_t run)
47 :AliAnalysisTask(name, "ESD analysis tender car"),
54 // Default constructor
55 AliCDBManager *cdb = AliCDBManager::Instance();
56 cdb->SetDefaultStorage(storage);
58 DefineInput (0, TChain::Class());
61 //______________________________________________________________________________
62 AliTaskCDBconnect::~AliTaskCDBconnect()
68 //______________________________________________________________________________
69 void AliTaskCDBconnect::LocalInit()
71 // Init CDB locally if run number is defined.
74 //______________________________________________________________________________
75 void AliTaskCDBconnect::ConnectInputData(Option_t* /*option*/)
77 // Connect the input data, create CDB manager.
80 //______________________________________________________________________________
81 void AliTaskCDBconnect::InitGRP()
83 // Initialize geometry and mag. field
86 if (!TGeoGlobalMagField::Instance()->GetField()) {
87 printf("AliCDBconnect: #### Loading field map...\n");
88 fGRPManager = new AliGRPManager();
89 if(!fGRPManager->ReadGRPEntry()) {
90 AliError("Cannot get GRP entry");
92 if( !fGRPManager->SetMagField() ) {
93 AliError("Problem with magnetic field setup");
99 printf("AliCDBconnect: #### Loading geometry...\n");
100 AliGeomManager::LoadGeometry("geometry.root");
101 if( !AliGeomManager::ApplyAlignObjsFromCDB("GRP ITS TPC TRD") ) {
102 AliError("Problem with align objects");
108 //______________________________________________________________________________
109 void AliTaskCDBconnect::CreateOutputObjects()
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());
117 AliFatal("No ESD input event handler connected");
120 // Try to get event number before the first event is read (this has precedence
121 // over existing fRun)
122 Int_t run = mgr->GetRunFromPath();
124 AliError("AliTaskCDBconnect: Run not set - no CDB connection");
127 // Create CDB manager
128 AliCDBManager *cdb = AliCDBManager::Instance();
129 // If CDB is already locked, return
130 if (cdb->GetLock()) return;
131 // SetDefault storage. Specific storages must be set by TaskCDBconnectSupply::Init()
132 // cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
133 // if (!cdb->GetRaw()) {
134 // cdb->SetDefaultStorage("raw://");
136 if (run && (run != fRun)) {
140 fRunChanged = kFALSE;
143 if (fRunChanged || !fGRPManager) {
144 printf("AliCDBconnect: #### Setting run to: %d\n", fRun);
146 // Initialize GRP manager only once
151 //______________________________________________________________________________
152 Bool_t AliTaskCDBconnect::Notify()
154 // Init CDB locally if run number is defined.
155 CreateOutputObjects();
159 //______________________________________________________________________________
160 void AliTaskCDBconnect::Exec(Option_t* /*option*/)
163 // Execute all supplied analysis of one event. Notify run change via RunChanged().
164 fESD = fESDhandler->GetEvent();
165 // Intercept when the run number changed
166 if (fRun != fESD->GetRunNumber()) {
168 fRun = fESD->GetRunNumber();
169 CreateOutputObjects();
173 //______________________________________________________________________________
174 void AliTaskCDBconnect::Terminate(Option_t *)
176 // Initialize CDB also in Terminate
177 // CreateOutputObjects();