Correcly handle centrality bins (Diego)
[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"
f37b73fe 27#include "AliVEvent.h"
28#include "AliInputEventHandler.h"
f902e6f2 29#include "AliLog.h"
30
31ClassImp(AliTaskCDBconnect)
32
33//______________________________________________________________________________
34AliTaskCDBconnect::AliTaskCDBconnect():
35 AliAnalysisTask(),
36 fRun(0),
f902e6f2 37 fGRPManager(NULL)
38{
39// Dummy constructor
40}
41
42//______________________________________________________________________________
2b30638c 43AliTaskCDBconnect::AliTaskCDBconnect(const char* name, const char *storage, Int_t run)
44 :AliAnalysisTask(name, "ESD analysis tender car"),
45 fRun(run),
f902e6f2 46 fGRPManager(NULL)
47{
48// Default constructor
49 AliCDBManager *cdb = AliCDBManager::Instance();
2b30638c 50 cdb->SetDefaultStorage(storage);
f902e6f2 51 DefineInput (0, TChain::Class());
f37b73fe 52 if (run>0) InitGRP();
f902e6f2 53}
54
55//______________________________________________________________________________
56AliTaskCDBconnect::~AliTaskCDBconnect()
57{
f37b73fe 58 // Destructor
2b30638c 59 delete fGRPManager;
f902e6f2 60}
61
62//______________________________________________________________________________
f902e6f2 63void AliTaskCDBconnect::InitGRP()
64{
5538ee85 65 // Initialize geometry and mag. field
66 AliCDBManager *cdb = AliCDBManager::Instance();
67 if (!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("raw://");
e64d92e0 68 cdb->SetRun(fRun);
f37b73fe 69 if (!fGRPManager) fGRPManager = new AliGRPManager();
70 AliInfo("AliCDBconnect: #### Loading GRP to init B-field...");
71 if(!fGRPManager->ReadGRPEntry()) AliFatal("Cannot get GRP entry");
72 if(!fGRPManager->SetMagField()) AliFatal("Problem with magnetic field setup");
73 //
74 // geometry
75 if (!gGeoManager) {
76 AliInfo("AliCDBconnect: #### Loading geometry...");
77 AliGeomManager::LoadGeometry("geometry.root");
d67ba96a 78 if(!AliGeomManager::ApplyAlignObjsFromCDB("GRP ITS TPC TRD")) AliWarning("Problem with align objects");
f902e6f2 79 }
80}
81
82//______________________________________________________________________________
83void AliTaskCDBconnect::CreateOutputObjects()
84{
f37b73fe 85 // Init CDB locally if run number is defined.
86 //
87 // try to init before the analysis set
2251e21b 88 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
89 if (!mgr) AliFatal("No analysis manager");
189edb30 90 if ( fRun>0 && !fGRPManager) {
91 // in the proof or plugin mode the initialization done in the constructor is not available
f37b73fe 92 InitGRP();
2251e21b 93 }
f37b73fe 94 else {
95 AliInfo("Run number is not available at this stage, InitGRP will be called in the execution loop");
b121056d 96 }
f37b73fe 97 //
f902e6f2 98}
99
100//______________________________________________________________________________
101void AliTaskCDBconnect::Exec(Option_t* /*option*/)
102{
103//
104// Execute all supplied analysis of one event. Notify run change via RunChanged().
f37b73fe 105 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
106 if (!mgr) AliFatal("No analysis manager");
107 AliInputEventHandler* inp = (AliInputEventHandler*)mgr->GetInputEventHandler();
108 if (!inp) AliFatal("No input event handler connected");
109 //
110 AliVEvent* ev = inp->GetEvent();
111 if (!ev) AliFatal("No event returned");
112 int run = ev->GetRunNumber();
f902e6f2 113 // Intercept when the run number changed
f37b73fe 114 if (fRun != run) {
115 fRun = run;
f37b73fe 116 InitGRP();
f902e6f2 117 }
f902e6f2 118}
1c3f0b5d 119
120//______________________________________________________________________________
121void AliTaskCDBconnect::SetSpecificStorage(const char* calibType, const char* dbString)
122{
123 AliCDBManager *cdb = AliCDBManager::Instance();
124 cdb->SetSpecificStorage(calibType,dbString);
125 }