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