AliPhysics  7c9d977 (7c9d977)
AliTaskCDBconnect.cxx
Go to the documentation of this file.
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 <TRegexp.h>
21 #include <TGeoGlobalMagField.h>
22 #include "TGeoManager.h"
23 #include <TInterpreter.h>
24 
25 #include "AliAnalysisManager.h"
26 #include "AliGeomManager.h"
27 #include "AliCDBManager.h"
28 #include "AliGRPManager.h"
29 #include "AliVEvent.h"
30 #include "AliInputEventHandler.h"
31 #include "AliLog.h"
32 
33 ClassImp(AliTaskCDBconnect)
34 
35 //______________________________________________________________________________
38  fFallBackToRaw(kFALSE),
39  fRun(0),
40  fLock(0),
41  fStorage(),
42  fSpecCDBUri(),
43  fGRPManager(NULL)
44 {
45  // Dummy constructor
46  fSpecCDBUri.SetOwner();
47 }
48 
49 //______________________________________________________________________________
50 AliTaskCDBconnect::AliTaskCDBconnect(const char* name, const char *storage, Int_t run, Bool_t fallback)
51  :AliAnalysisTask(name, "ESD analysis tender car"),
52  fFallBackToRaw(fallback),
53  fRun(run),
54  fLock(0),
55  fStorage(storage),
56  fSpecCDBUri(),
57  fGRPManager(NULL)
58 {
59  // Default constructor
60  fSpecCDBUri.SetOwner();
61  DefineInput (0, TChain::Class());
62  if (run>0) InitGRP();
63 }
64 
65 //______________________________________________________________________________
67 {
68  // Destructor
69  delete fGRPManager;
70 }
71 
72 //______________________________________________________________________________
74 {
75  // Initialize geometry and mag. field
76  AliCDBManager *cdb = AliCDBManager::Instance();
77 
78  if (!cdb->IsDefaultStorageSet()) {
79  //
80  // automatic setting of year
81  Int_t year = -1;
82  if (fRun<139674) year = 2010;
83  else if (fRun<170718) year = 2011;
84  else if (fRun<194479) year = 2012;
85  else if (fRun<199999) year = 2013;
86  else if (fRun<208504) year = 2014;
87  else if (fRun<247170) year = 2015;
88  else if (fRun<267255) year = 2016;
89  else if (fRun<282901) year = 2017;
90  else {
91  year = 2018;
92  TDatime today;
93  if (today.GetYear()!=year) AliErrorF("Adjust CDB connect, we are now in %d!",today.GetYear());
94  }
95  //
96  Bool_t useCVMFS = kFALSE;
97  TString inpStor = fStorage.Strip(TString::kTrailing,'/');
98  if (inpStor == "cvmfs:") {
99  fStorage = Form("local:///cvmfs/alice.cern.ch/calibration/data/%4d/OCDB",year);
100  useCVMFS = kTRUE;
101  }
102  else if (inpStor.BeginsWith("local:///cvmfs") && inpStor.EndsWith("/OCDB")) {
103  TString tmp = inpStor;
104  tmp.ReplaceAll("local://","");
105  TString strYold = tmp(TRegexp("/[0-9][0-9][0-9][0-9]/OCDB"));
106  TString strYnew = Form("/%4d/OCDB",year);
107  if (strYold.IsNull()) tmp += strYnew;
108  else tmp.ReplaceAll(strYold,strYnew);
109  useCVMFS = kTRUE;
110  fStorage = Form("local://%s", tmp.Data());
111  }
112  // check if cvfms is linked
113  if (useCVMFS) {
114  TString cvmfspath = fStorage;
115  cvmfspath = cvmfspath.ReplaceAll("local://", "");
116  if(gSystem->AccessPathName(cvmfspath.Data(),kFileExists)) {
117  if (fFallBackToRaw) {
118  AliErrorF("could not access %s, switching to raw://",fStorage.Data());
119  fStorage = "raw://";
120  }
121  else AliFatalF("could not access %s, fallback to raw:// disabled",fStorage.Data());
122  }
123  }
124  AliInfoF("Setting default storage to %s",fStorage.Data());
125  cdb->SetDefaultStorage(fStorage);
126  //
127  // set specific storages
128  for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
129  TNamed* obj = (TNamed*)fSpecCDBUri[i];
130  if (!obj) continue;
131  UInt_t vsv = obj->GetUniqueID();
132  Int_t ver = int(vsv>>16)-1;
133  Int_t subver = int(vsv&0xffff)-1;
134  cdb->SetSpecificStorage(obj->GetName(), obj->GetTitle(), ver, subver);
135  }
136  }
137  if (cdb->GetRun()!=fRun) {
138  fLock = cdb->SetLock(kFALSE,fLock);
139  cdb->SetRun(fRun);
140  if (gSystem->AccessPathName("localOCDBaccessConfig.C", kFileExists)==0) {
141  // If we are using a specific storage override, this is the place to load it
142  gInterpreter->ProcessLine("localOCDBaccessConfig()");
143  }
144  fLock = cdb->SetLock(kTRUE,fLock);
145  }
146  if (gSystem->AccessPathName("OCDB.root",kFileExists)==0) cdb->SetSnapshotMode("OCDB.root");
147  //
148  if (!fGRPManager) fGRPManager = new AliGRPManager();
149  AliInfo("AliCDBconnect: #### Loading GRP to init B-field...");
150  if(!fGRPManager->ReadGRPEntry()) AliFatal("Cannot get GRP entry");
151  if(!fGRPManager->SetMagField()) AliFatal("Problem with magnetic field setup");
152  //
153  // geometry
154  if (!gGeoManager) {
155  AliInfo("AliCDBconnect: #### Loading geometry...");
156  AliGeomManager::LoadGeometry("geometry.root");
157  if(!AliGeomManager::ApplyAlignObjsFromCDB("GRP ITS TPC TRD TOF EMCAL PHOS MUON")) AliWarning("Problem with align objects");
158  }
159 }
160 
161 //______________________________________________________________________________
163 {
164  // Init CDB locally if run number is defined.
165  //
166  // try to init before the analysis set
167  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
168  if (!mgr) AliFatal("No analysis manager");
169  if (fRun>0 && !fGRPManager) {
170  // in the proof or plugin mode the initialization done in the constructor is not available
171  InitGRP();
172  }
173  else {
174  AliInfo("Run number is not available at this stage, InitGRP will be called in the execution loop");
175  }
176 }
177 
178 //______________________________________________________________________________
180 {
181  // Connect the input data, create CDB manager.
182  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
183  if (!mgr) AliFatal("No analysis manager");
184  AliAnalysisTask::ConnectInputData(option);
185  Int_t run = AliAnalysisManager::GetAnalysisManager()->GetRunFromPath();
186  if (run<=0) {
187  AliWarning("AliTaskCDBconnect: Could not set run from path");
188  return;
189  }
190  if (fRun != run) {
191  fRun = run;
192  InitGRP();
193  }
194 }
195 
196 
197 //______________________________________________________________________________
199 {
200  // Execute all supplied analysis of one event. Notify run change via RunChanged().
201  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
202  if (!mgr) AliFatal("No analysis manager");
203  AliInputEventHandler* inp = (AliInputEventHandler*)mgr->GetInputEventHandler();
204  if (!inp) AliFatal("No input event handler connected");
205  AliVEvent* ev = inp->GetEvent();
206  if (!ev) AliFatal("No event returned");
207  int run = ev->GetRunNumber();
208  // Intercept when the run number changed
209  if (fRun != run && run>0) {
210  fRun = run;
211  InitGRP();
212  }
213 }
214 
215 //______________________________________________________________________________
216 void AliTaskCDBconnect::SetSpecificStorage(const char* calibType, const char* dbString, Int_t version, Int_t subVersion)
217 {
218  // Set a specific storage
219  TNamed *nmpath = new TNamed(calibType,dbString);
220  if (version<0) version = -1;
221  if (subVersion<0) subVersion = -1;
222  nmpath->SetUniqueID((UInt_t(version+1)<<16)+UInt_t(subVersion+1));
223  fSpecCDBUri.AddLast(nmpath);
224 }
virtual void CreateOutputObjects()
TSystem * gSystem
virtual void Exec(Option_t *option)
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
AliGRPManager * fGRPManager
void SetSpecificStorage(const char *calibType, const char *dbString, Int_t version=-1, Int_t subVersion=-1)
virtual void ConnectInputData(Option_t *option="")
const char Option_t
Definition: External.C:48
bool Bool_t
Definition: External.C:53