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 "AliTaskConfigOCDB.h"
20 #include <TGeoGlobalMagField.h>
21 #include "TGeoManager.h"
24 #include "AliAnalysisManager.h"
25 #include "AliGeomManager.h"
26 #include "AliCDBManager.h"
27 #include "AliGRPManager.h"
28 #include "AliESDEvent.h"
29 #include "AliESDInputHandler.h"
32 ClassImp(AliTaskConfigOCDB)
34 //______________________________________________________________________________
35 AliTaskConfigOCDB::AliTaskConfigOCDB():
47 //______________________________________________________________________________
48 AliTaskConfigOCDB::AliTaskConfigOCDB(const char* name, const char *storage, Int_t run)
49 :AliAnalysisTask(name, "configure OCDB field geom"),
51 fOCDBstorage(storage),
57 // Default constructor
58 AliCDBManager *cdb = AliCDBManager::Instance();
59 cdb->SetDefaultStorage(storage);
61 DefineInput (0, TChain::Class());
64 //______________________________________________________________________________
65 AliTaskConfigOCDB::~AliTaskConfigOCDB()
71 //______________________________________________________________________________
72 void AliTaskConfigOCDB::LocalInit()
74 // Init CDB locally if run number is defined.
77 //______________________________________________________________________________
78 void AliTaskConfigOCDB::ConnectInputData(Option_t* /*option*/)
80 // Connect the input data, create CDB manager.
83 //______________________________________________________________________________
84 void AliTaskConfigOCDB::InitGRP()
86 // Initialize geometry and mag. field
89 if (!TGeoGlobalMagField::Instance()->GetField()) {
90 printf("AliCDBconnect: #### Loading field map...\n");
91 fGRPManager = new AliGRPManager();
92 if(!fGRPManager->ReadGRPEntry()) {
93 AliError("Cannot get GRP entry");
95 if( !fGRPManager->SetMagField() ) {
96 AliError("Problem with magnetic field setup");
102 printf("AliCDBconnect: #### Loading geometry...\n");
103 AliGeomManager::LoadGeometry();
104 if( !AliGeomManager::ApplyAlignObjsFromCDB("GRP ITS TPC TRD") ) {
105 AliError("Problem with align objects");
111 //______________________________________________________________________________
112 void AliTaskConfigOCDB::CreateOutputObjects()
114 // Init CDB locally if run number is defined.
115 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
116 if (!mgr) AliFatal("No analysis manager");
117 fESDhandler = dynamic_cast<AliESDInputHandler *>(mgr->GetInputEventHandler());
120 AliFatal("No ESD input event handler connected");
123 // Try to get event number before the first event is read (this has precedence
124 // over existing fRun)
125 TTree* inputTree = mgr->GetTree();
126 if (!inputTree) { AliError("no input tree"); return; }
127 TFile* inputFile = inputTree->GetCurrentFile();
128 if (!inputFile) { AliError("no input file"); return; }
129 TString inputFileName(inputFile->GetName());
130 Int_t run = guessRunNumber(inputFileName);
131 mgr->SetRunFromPath(run);
134 AliError("AliTaskConfigOCDB: Run not set - no CDB connection");
137 // Create CDB manager
138 AliCDBManager *cdb = AliCDBManager::Instance();
139 // If CDB is unlocked, set the def storage
142 cdb->SetDefaultStorage(fOCDBstorage);
145 if (run && (run != fRun)) {
149 fRunChanged = kFALSE;
152 if (fRunChanged || !fGRPManager) {
153 printf("AliCDBconnect: #### Setting run to: %d\n", fRun);
155 // Initialize GRP manager only once
160 //______________________________________________________________________________
161 Bool_t AliTaskConfigOCDB::Notify()
163 // Init CDB locally if run number is defined.
164 CreateOutputObjects();
168 //______________________________________________________________________________
169 void AliTaskConfigOCDB::Exec(Option_t* /*option*/)
172 // Execute all supplied analysis of one event. Notify run change via RunChanged().
173 fESD = fESDhandler->GetEvent();
174 // Intercept when the run number changed
175 if (fRun != fESD->GetRunNumber()) {
177 fRun = fESD->GetRunNumber();
178 CreateOutputObjects();
182 //______________________________________________________________________________
183 void AliTaskConfigOCDB::Terminate(Option_t *)
185 // Initialize CDB also in Terminate
186 // CreateOutputObjects();
189 Int_t AliTaskConfigOCDB::guessRunNumber(TString path)
191 //guess the runnumber from datapath
192 //works also on the LEGO train where the data path looks like this:
193 //workdir/testdata/__alice__data__2010__LHC10b__000114924__ESDs__pass2_root_archive_AliESDs_2/10000114924018.100/root_archive.zip
194 TObjArray* a = path.Tokenize("/_");
195 TRegexp r("^000[0-9][0-9][0-9][0-9][0-9][0-9]$");
197 for (Int_t i=0; i<a->GetEntries();i++)
199 TObjString* subobj = (TObjString*)a->At(i);
200 TString subtmp = subobj->GetString();
201 if (subtmp.Contains(r))
207 Int_t runNumber=sub.Atoi();
208 AliInfo(Form("guessed run: %i\n",runNumber));