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