AliPhysics  9fe175b (9fe175b)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  TGeoManager *geo(nullptr);
255  if (man) {
256  if (man->GetRun()!=runno)
257  man->SetRun(runno);
258  AliInfo(Form("Loading grp data from OCDB for run %d", runno));
259  AliGRPManager GRPManager;
260  GRPManager.ReadGRPEntry();
261  GRPManager.SetMagField();
262  if(!AliGeomManager::GetGeometry() && man){
263  AliInfo(Form("Loading geometry from OCDB"));
264  AliGeomManager::LoadGeometry();
265  geo = AliGeomManager::GetGeometry();
266  if (!fObjs.IsNull())
267  AliGeomManager::ApplyAlignObjsFromCDB(fObjs);
268  // Lock geometry
269  if (geo) {
270  AliInfo(Form("Locking geometry"));
271  geo->LockGeometry();
272  }
273  }
274  }
275 
276  // Load geometry from file (does not use misalignment of ITS/TPC!)
277  geo = AliGeomManager::GetGeometry();
278  if (!geo && fGeoPath.Length()>0) {
279  TString fname(gSystem->ExpandPathName(Form("%s/geometry_%d.root", fGeoPath.Data(), year)));
280  if (gSystem->AccessPathName(fname)==0) {
281  AliInfo(Form("Loading geometry from file %s (should be avoided!)", fname.Data()));
282  AliGeomManager::LoadGeometry(fname);
283  geo = AliGeomManager::GetGeometry();
284  // Lock geometry
285  if (geo) {
286  AliInfo(Form("Locking geometry"));
287  geo->LockGeometry();
288  }
289  }
290  }
291 
292 
293  // Construct field map
294  if (!TGeoGlobalMagField::Instance()->GetField()) {
295  InputEvent()->InitMagneticField();
296  }
297 
298  // Apply mis-alignment matrices from OADB
299  if (fOadbPath.Length()>0) {
300  AliOADBContainer emcalgeoCont(Form("emcal"));
301  emcalgeoCont.InitFromFile(Form("%s/EMCALlocal2master.root",fOadbPath.Data()),
302  Form("AliEMCALgeo"));
303  TObjArray *mobj=dynamic_cast<TObjArray*>(emcalgeoCont.GetObject(runno,"EmcalMatrices"));
304  if (mobj) {
305  for(Int_t mod=0; mod < (geom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
306  //AliInfo(Form("Misalignment matrix %d", mod));
307  if(mobj->At(mod))
308  {
309  geom->SetMisalMatrix((TGeoHMatrix*) mobj->At(mod),mod);
310  }
311  else if(gGeoManager)
312  {
313  AliWarning(Form("Set matrix for SM %d from gGeoManager\n",mod));
314  geom->SetMisalMatrix(geom->GetMatrixForSuperModuleFromGeoManager(mod),mod);
315  }
316  else
317  {
318  AliError(Form("Matrix for SM %d is not available\n",mod));
319  }
320  }
321  }
322  }
323 
324  fIsInit = kTRUE;
325 }
326 
332 {
333  if (fLocalOcdb.Length()>0) {
334  TString cmd(Form("rm -rf %s", fLocalOcdb.Data()));
335  gSystem->Exec(cmd);
336  }
337 }
Bool_t fIsInit
!=true then already initialized
TString fObjs
string of objects for alignment to apply
TString fGeoPath
path to geometry
TSystem * gSystem
Declaration of the EMCAL setup task.
TRandom * gRandom
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
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
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