AliPhysics  2c6b7ad (2c6b7ad)
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  if (gSystem->AccessPathName("OCDB.root",kFileExists)==0) {
80  cdb->SetDefaultStorage("local://");
81  cdb->SetRaw(kFALSE);
82  cdb->SetSnapshotMode("OCDB.root");
83  }
84  else {
85  //
86  // automatic setting of year
87  Int_t year = -1;
88  if (fRun<139674) year = 2010;
89  else if (fRun<170718) year = 2011;
90  else if (fRun<194479) year = 2012;
91  else if (fRun<199999) year = 2013;
92  else if (fRun<208504) year = 2014;
93  else if (fRun<247170) year = 2015;
94  else if (fRun<267255) year = 2016;
95  else if (fRun<282901) year = 2017;
96  else {
97  year = 2018;
98  // no more updates needed
99  // TDatime today;
100  // if (today.GetYear()!=year) AliErrorF("Adjust CDB connect, we are now in %d!",today.GetYear());
101  }
102  //
103  Bool_t useCVMFS = kFALSE;
104  TString inpStor = fStorage.Strip(TString::kTrailing,'/');
105  if (inpStor == "cvmfs:") {
106  fStorage = Form("local:///cvmfs/alice.cern.ch/calibration/data/%4d/OCDB",year);
107  useCVMFS = kTRUE;
108  }
109  else if (inpStor.BeginsWith("local:///cvmfs") && inpStor.EndsWith("/OCDB")) {
110  TString tmp = inpStor;
111  tmp.ReplaceAll("local://","");
112  TString strYold = tmp(TRegexp("/[0-9][0-9][0-9][0-9]/OCDB"));
113  TString strYnew = Form("/%4d/OCDB",year);
114  if (strYold.IsNull()) tmp += strYnew;
115  else tmp.ReplaceAll(strYold,strYnew);
116  useCVMFS = kTRUE;
117  fStorage = Form("local://%s", tmp.Data());
118  }
119  // check if cvfms is linked
120  if (useCVMFS) {
121  TString cvmfspath = fStorage;
122  cvmfspath = cvmfspath.ReplaceAll("local://", "");
123  if(gSystem->AccessPathName(cvmfspath.Data(),kFileExists)) {
124  if (fFallBackToRaw) {
125  AliErrorF("could not access %s, switching to raw://",fStorage.Data());
126  fStorage = "raw://";
127  }
128  else AliFatalF("could not access %s, fallback to raw:// disabled",fStorage.Data());
129  }
130  }
131  AliInfoF("Setting default storage to %s",fStorage.Data());
132  cdb->SetDefaultStorage(fStorage);
133  }
134  //
135  // set specific storages
136  for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
137  TNamed* obj = (TNamed*)fSpecCDBUri[i];
138  if (!obj) continue;
139  UInt_t vsv = obj->GetUniqueID();
140  Int_t ver = int(vsv>>16)-1;
141  Int_t subver = int(vsv&0xffff)-1;
142  cdb->SetSpecificStorage(obj->GetName(), obj->GetTitle(), ver, subver);
143  }
144  }
145  if (cdb->GetRun()!=fRun) {
146  fLock = cdb->SetLock(kFALSE,fLock);
147  cdb->SetRun(fRun);
148  if (gSystem->AccessPathName("localOCDBaccessConfig.C", kFileExists)==0) {
149  // If we are using a specific storage override, this is the place to load it
150  gInterpreter->ProcessLine("localOCDBaccessConfig()");
151  }
152  fLock = cdb->SetLock(kTRUE,fLock);
153  }
154  //
155  if (!fGRPManager) fGRPManager = new AliGRPManager();
156  AliInfo("AliCDBconnect: #### Loading GRP to init B-field...");
157  if(!fGRPManager->ReadGRPEntry()) AliFatal("Cannot get GRP entry");
158  if(!fGRPManager->SetMagField()) AliFatal("Problem with magnetic field setup");
159  //
160  // geometry
161  if (!gGeoManager) {
162  AliInfo("AliCDBconnect: #### Loading geometry...");
163  AliGeomManager::LoadGeometry("geometry.root");
164  if(!AliGeomManager::ApplyAlignObjsFromCDB("GRP ITS TPC TRD TOF EMCAL PHOS MUON")) AliWarning("Problem with align objects");
165  }
166 }
167 
168 //______________________________________________________________________________
170 {
171  // Init CDB locally if run number is defined.
172  //
173  // try to init before the analysis set
174  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
175  if (!mgr) AliFatal("No analysis manager");
176  if (fRun>0 && !fGRPManager) {
177  // in the proof or plugin mode the initialization done in the constructor is not available
178  InitGRP();
179  }
180  else {
181  AliInfo("Run number is not available at this stage, InitGRP will be called in the execution loop");
182  }
183 }
184 
185 //______________________________________________________________________________
187 {
188  // Connect the input data, create CDB manager.
189  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
190  if (!mgr) AliFatal("No analysis manager");
191  AliAnalysisTask::ConnectInputData(option);
192  Int_t run = AliAnalysisManager::GetAnalysisManager()->GetRunFromPath();
193  if (run<=0) {
194  AliWarning("AliTaskCDBconnect: Could not set run from path");
195  return;
196  }
197  if (fRun != run) {
198  fRun = run;
199  InitGRP();
200  }
201 }
202 
203 
204 //______________________________________________________________________________
206 {
207  // Execute all supplied analysis of one event. Notify run change via RunChanged().
208  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
209  if (!mgr) AliFatal("No analysis manager");
210  AliInputEventHandler* inp = (AliInputEventHandler*)mgr->GetInputEventHandler();
211  if (!inp) AliFatal("No input event handler connected");
212  AliVEvent* ev = inp->GetEvent();
213  if (!ev) AliFatal("No event returned");
214  int run = ev->GetRunNumber();
215  // Intercept when the run number changed
216  if (fRun != run && run>0) {
217  fRun = run;
218  InitGRP();
219  }
220 }
221 
222 //______________________________________________________________________________
223 void AliTaskCDBconnect::SetSpecificStorage(const char* calibType, const char* dbString, Int_t version, Int_t subVersion)
224 {
225  // Set a specific storage
226  TNamed *nmpath = new TNamed(calibType,dbString);
227  if (version<0) version = -1;
228  if (subVersion<0) subVersion = -1;
229  nmpath->SetUniqueID((UInt_t(version+1)<<16)+UInt_t(subVersion+1));
230  fSpecCDBUri.AddLast(nmpath);
231 }
232 
233 //______________________________________________________________________________
234 AliTaskCDBconnect* AliTaskCDBconnect::AddTaskCDBconnect(const char* path/*="raw://"*/, Int_t run) {
235  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
236  if (!mgr) {
237  ::Error("AddTaskCDBconnect", "No analysis manager to connect to.");
238  return NULL;
239  }
240  AliTaskCDBconnect *task= new AliTaskCDBconnect("CDBconnect", path, run);
241  mgr->AddTask(task);
242  AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
243  mgr->ConnectInput(task, 0, cinput1);
244  return task;
245 }
246 
247 //______________________________________________________________________________
249  return AliTaskCDBconnect::AddTaskCDBconnect("cvmfs://");
250 }
virtual void CreateOutputObjects()
TSystem * gSystem
virtual void Exec(Option_t *option)
int Int_t
Definition: External.C:63
static AliTaskCDBconnect * AddTaskCDBconnect()
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