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>
22 #include "AliAnalysisManager.h"
23 #include "AliGeomManager.h"
24 #include "AliCDBManager.h"
25 #include "AliGRPManager.h"
26 #include "AliESDEvent.h"
27 #include "AliESDInputHandler.h"
30 ClassImp(AliTaskCDBconnect)
32 //______________________________________________________________________________
33 AliTaskCDBconnect::AliTaskCDBconnect():
44 //______________________________________________________________________________
45 AliTaskCDBconnect::AliTaskCDBconnect(const char* name):
46 AliAnalysisTask(name, "ESD analysis tender car"),
53 // Default constructor
54 AliCDBManager *cdb = AliCDBManager::Instance();
55 cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
57 DefineInput (0, TChain::Class());
58 // DefineOutput(0, AliESDEvent::Class());
61 //______________________________________________________________________________
62 AliTaskCDBconnect::~AliTaskCDBconnect()
65 if (fGRPManager) delete fGRPManager;
66 // if (gGeoManager) delete gGeoManager;
69 //______________________________________________________________________________
70 void AliTaskCDBconnect::LocalInit()
72 // Init CDB locally if run number is defined.
74 Info("LocalInit","AliTaskCDBconnect::LocalInit Run number not defined yet");
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://");
84 // Initialize GRP manager only once
88 //______________________________________________________________________________
89 void AliTaskCDBconnect::ConnectInputData(Option_t* /*option*/)
91 // Connect the input data, create CDB manager.
94 //______________________________________________________________________________
95 void AliTaskCDBconnect::InitGRP()
97 // Initialize geometry and mag. field
100 if (!TGeoGlobalMagField::Instance()->GetField()) {
101 printf("AliCDBconnect: #### Loading field map...\n");
102 fGRPManager = new AliGRPManager();
103 if(!fGRPManager->ReadGRPEntry()) {
104 AliError("Cannot get GRP entry");
106 if( !fGRPManager->SetMagField() ) {
107 AliError("Problem with magnetic field setup");
112 printf("AliCDBconnect: #### Loading geometry...\n");
113 AliGeomManager::LoadGeometry();
114 if( !AliGeomManager::ApplyAlignObjsFromCDB("GRP ITS TPC") ) {
115 AliError("Problem with align objects");
120 //______________________________________________________________________________
121 void AliTaskCDBconnect::CreateOutputObjects()
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());
129 AliFatal("No ESD input event handler connected");
132 // Try to get event number before the first event is read
133 Int_t run = mgr->GetRunFromPath();
134 if (!run) run = fESD->GetRunNumber();
136 AliWarning("AliTaskCDBconnect: Could not set run from path");
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)) {
149 fRunChanged = kFALSE;
152 if (fRunChanged) cdb->SetRun(fRun);
153 // Initialize GRP manager only once
157 //______________________________________________________________________________
158 Bool_t AliTaskCDBconnect::Notify()
160 // Init CDB locally if run number is defined.
161 CreateOutputObjects();
165 //______________________________________________________________________________
166 void AliTaskCDBconnect::Exec(Option_t* /*option*/)
169 // Execute all supplied analysis of one event. Notify run change via RunChanged().
170 fESD = fESDhandler->GetEvent();
171 // Intercept when the run number changed
172 if (fRun != fESD->GetRunNumber()) {
174 fRun = fESD->GetRunNumber();
175 Warning("Exec", "Run number changed in ESDEvent to %d", fRun);
176 AliCDBManager::Instance()->SetRun(fRun);
178 // PostData(0, fESD);