AliPhysics  vAN-20150723 (baea2bf)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
AliEmcalSetupTask.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2013, 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 #include "AliEmcalSetupTask.h"
16 #include <TClonesArray.h>
17 #include <TGeoGlobalMagField.h>
18 #include <TGeoManager.h>
19 #include <TRandom.h>
20 #include "AliAODEvent.h"
21 #include "AliAnalysisManager.h"
22 #include "AliCDBManager.h"
23 #include "AliEMCALGeometry.h"
24 #include "AliESDEvent.h"
25 #include "AliGRPManager.h"
26 #include "AliGeomManager.h"
27 #include "AliMagF.h"
28 #include "AliOADBContainer.h"
29 #include "AliTender.h"
30 
34 
43  AliAnalysisTaskSE(),
44  fOcdbPath("uselocal"),
45  fOadbPath("$ALICE_PHYSICS/OADB/EMCAL"),
46  fGeoPath("$ALICE_PHYSICS/OADB/EMCAL"),
47  fObjs("GRP ITS TPC TRD EMCAL"),
48  fNoOCDB(kFALSE),
49  fIsInit(kFALSE),
50  fLocalOcdb(),
51  fLocalOcdbStor()
52 {
53 }
54 
64  AliAnalysisTaskSE(name),
65  fOcdbPath("uselocal"),
66  fOadbPath("$ALICE_PHYSICS/OADB/EMCAL"),
67  fGeoPath("$ALICE_PHYSICS/OADB/EMCAL"),
68  fObjs("GRP ITS TPC TRD EMCAL"),
69  fNoOCDB(kFALSE),
70  fIsInit(kFALSE),
71  fLocalOcdb(),
72  fLocalOcdbStor()
73 {
74  fBranchNames = "ESD:AliESDHeader.,AliESDRun.";
75 }
76 
81 {
82 }
83 
89 {
90  // Connect input data
91 
92  AliAnalysisTaskSE::ConnectInputData(option);
93 
94  if (fOcdbPath.Length()==0)
95  return;
96 
97  AliCDBManager *man = AliCDBManager::Instance();
98  if (man->IsDefaultStorageSet())
99  return;
100 
101  if (fIsInit)
102  return;
103 
104  AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
105  if (!am)
106  return;
107 
108  TObjArray *tasks = am->GetTasks();
109  if (!tasks)
110  return;
111 
112  AliTender *tender = 0;
113  for (Int_t i=0; i<tasks->GetEntries(); ++i) {
114  tender = dynamic_cast<AliTender*>(tasks->At(i));
115  if (tender)
116  break;
117  }
118 
119  if (!tender)
120  return;
121 
122  if (fOcdbPath != "uselocal") {
123  tender->SetDefaultCDBStorage(fOcdbPath);
124  return;
125  }
126 
127  Int_t runno = AliAnalysisManager::GetAnalysisManager()->GetRunFromPath();
128  if (runno<=0) {
129  AliWarning(Form("Disabling tender, ignore possible message from tender below"));
130  tender->SetDefaultCDBStorage("donotuse");
131  return;
132  }
133 
134  AliWarning(Form("Intercepting tender for run %d, ignore possible message from tender below", runno));
135  Setup(runno);
136  tender->SetDefaultCDBStorage(fLocalOcdbStor);
137 }
138 
146 {
147  if (fIsInit)
148  return;
149 
150  AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
151  if (!am) {
152  AliError("Manager zero, returning");
153  return;
154  }
155 
156  am->LoadBranch("AliESDRun.");
157  am->LoadBranch("AliESDHeader.");
158 
159  Int_t runno = InputEvent()->GetRunNumber();
160  Setup(runno);
161 }
170 void AliEmcalSetupTask::Setup(Int_t runno)
171 {
172  // Setup everything
173 
174  if ( runno < 0 ) // Run number 0 can occur for MC
175  return;
176 
177  AliEMCALGeometry *geom = AliEMCALGeometry::GetInstanceFromRunNumber(runno);
178 
179  if (!geom) {
180  AliFatal("Can not create geometry!");
181  return;
182  }
183 
184  // Setup AliEMCALGeometry corresponding to year
185  Int_t year = 2013;
186  if (runno>0 && runno<=139517) {
187  year = 2010;
188  } else if ((runno > 139517) && (runno <= 170593)) {
189  year = 2011;
190  } else if ((runno > 170593) && (runno <= 193766)) {
191  year = 2012;
192  } else if ((runno > 193766) && (runno <= 199161)) {
193  year = 2013;
194  } else if ( runno > 199161) { //MV: is this the last run of run 1?
195  year = 2015;
196  }
197 
198  // Setup CDB manager
199  AliCDBManager *man = 0;
200  if (!fNoOCDB) {
201  man = AliCDBManager::Instance();
202  if (!man)
203  AliFatal(Form("Did not get pointer to CDB manager"));
204 
205  if (man->IsDefaultStorageSet()) {
206  AliInfo(Form("Default OCDB storage already set"));
207  } else {
208  if (fOcdbPath.Length()==0) {
209  man = 0; // do not use OCDB
210  } else if (fOcdbPath != "uselocal") {
211  AliInfo(Form("Setting up OCDB to point to %s",fOcdbPath.Data()));
212  man->SetDefaultStorage(fOcdbPath);
213  } else { // use local copy of OCDB
214  TString tmpdir=gSystem->WorkingDirectory();
215  if (gSystem->AccessPathName(tmpdir))
216  tmpdir = "/tmp";
217  tmpdir+="/";
218  tmpdir+=gSystem->GetUid();
219  tmpdir+="-";
220  TDatime t;
221  tmpdir+=t.Get();
222  tmpdir+="-";
223  Int_t counter = 0;
224  fLocalOcdb = tmpdir;
225  fLocalOcdb += Form("%d%d%d",gRandom->Integer(999999999),gRandom->Integer(999999999),gRandom->Integer(999999999));
226  while (!gSystem->AccessPathName(fLocalOcdb)) {
227  fLocalOcdb = tmpdir;
228  fLocalOcdb += Form("%d%d%d",gRandom->Integer(999999999),gRandom->Integer(999999999),gRandom->Integer(999999999));
229  counter++;
230  if (counter>100) {
231  AliFatal(Form("Could not create local directory for OCDB at %s",tmpdir.Data()));
232  }
233  }
234  gSystem->MakeDirectory(fLocalOcdb);
235  TString filename(Form("$ALICE_PHYSICS/PWG/EMCAL/data/%d.dat",year));
236  TString cmd(Form("cd %s && tar -xf %s",fLocalOcdb.Data(),filename.Data()));
237  Int_t ret = gSystem->Exec(cmd);
238  if (ret==0) {
239  TString locdb("local://");
240  locdb+=fLocalOcdb;
241  locdb+="/";
242  locdb+=year;
243  AliInfo(Form("Setting up local OCDB at %s",locdb.Data()));
244  man->SetDefaultStorage(locdb);
245  fLocalOcdbStor = locdb;
246  } else {
247  AliFatal(Form("Could not set up local OCDB at %s",fLocalOcdb.Data()));
248  }
249  }
250  }
251  }
252 
253  // Load geometry from OCDB
254  if (man) {
255  if (man->GetRun()!=runno)
256  man->SetRun(runno);
257  AliInfo(Form("Loading grp data from OCDB for run %d", runno));
258  AliGRPManager GRPManager;
259  GRPManager.ReadGRPEntry();
260  GRPManager.SetMagField();
261  AliInfo(Form("Loading geometry from OCDB"));
262  AliGeomManager::LoadGeometry();
263  if (!fObjs.IsNull())
264  AliGeomManager::ApplyAlignObjsFromCDB(fObjs);
265  }
266 
267  // Load geometry from file (does not use misalignment of ITS/TPC!)
268  TGeoManager *geo = AliGeomManager::GetGeometry();
269  if (!geo && fGeoPath.Length()>0) {
270  TString fname(gSystem->ExpandPathName(Form("%s/geometry_%d.root", fGeoPath.Data(), year)));
271  if (gSystem->AccessPathName(fname)==0) {
272  AliInfo(Form("Loading geometry from file %s (should be avoided!)", fname.Data()));
273  AliGeomManager::LoadGeometry(fname);
274  geo = AliGeomManager::GetGeometry();
275  }
276  }
277 
278  // Lock geometry
279  if (geo) {
280  AliInfo(Form("Locking geometry"));
281  geo->LockGeometry();
282  }
283 
284  // Construct field map
285  if (!TGeoGlobalMagField::Instance()->GetField()) {
286  InputEvent()->InitMagneticField();
287  }
288 
289  // Apply mis-alignment matrices from OADB
290  if (fOadbPath.Length()>0) {
291  AliOADBContainer emcalgeoCont(Form("emcal"));
292  emcalgeoCont.InitFromFile(Form("%s/EMCALlocal2master.root",fOadbPath.Data()),
293  Form("AliEMCALgeo"));
294  TObjArray *mobj=dynamic_cast<TObjArray*>(emcalgeoCont.GetObject(runno,"EmcalMatrices"));
295  if (mobj) {
296  for(Int_t mod=0; mod < (geom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
297  //AliInfo(Form("Misalignment matrix %d", mod));
298  geom->SetMisalMatrix((TGeoHMatrix*) mobj->At(mod),mod);
299  }
300  }
301  }
302 
303  fIsInit = kTRUE;
304 }
305 
311 {
312  if (fLocalOcdb.Length()>0) {
313  TString cmd(Form("rm -rf %s", fLocalOcdb.Data()));
314  gSystem->Exec(cmd);
315  }
316 }
Bool_t fIsInit
!=true then already initialized
ClassImp(AliAnalysisTaskTriggerRates) AliAnalysisTaskTriggerRates
TString fObjs
string of objects for alignment to apply
TString fGeoPath
path to geometry
Declaration of the EMCAL setup task.
TString fOcdbPath
path to ocdb (def=uselocal)
TString fLocalOcdbStor
!storage path to local ocdb
void ConnectInputData(Option_t *option="")
void Terminate(Option_t *option)
void Setup(Int_t runno)
Bool_t fNoOCDB
if true then do not mess with OCDB
TString fOadbPath
path to oadb
Simple task setting up connections to databases for the EMCAL train.
void UserExec(Option_t *option)
TString fLocalOcdb
!directory path to local ocdb