Coverity fix
[u/mrichter/AliRoot.git] / PHOS / AliPHOSGridFile.cxx
CommitLineData
7f06a34f 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/* $Id$ */
16
702ab87e 17/* History of cvs commits:
18 *
19 * $Log$
43fbaae1 20 * Revision 1.5 2005/05/28 14:19:04 schutz
21 * Compilation warnings fixed by T.P.
22 *
702ab87e 23 */
24
7f06a34f 25//_________________________________________________________________________
26// To navigate in the Grid catalogue (very elementary)
43073eba 27// check here : /afs/cern.ch/user/p/peters/public/README.ALIEN
7f06a34f 28//-- Author: Yves Schutz (CERN)
29
30// --- ROOT system ---
43073eba 31#include "TObjString.h"
32#include "TGrid.h"
7f06a34f 33#include "TGridResult.h"
34
35// --- Standard library ---
36
37// --- AliRoot header files ---
351dd634 38#include "AliLog.h"
43073eba 39#include "AliPHOSGridFile.h"
7f06a34f 40
925e6570 41ClassImp(AliPHOSGridFile)
7f06a34f 42
43//____________________________________________________________________________
43fbaae1 44AliPHOSGridFile::AliPHOSGridFile(TString grid):
45 fGrid(0),
46 fRoot("/alice/production/aliprod"),
47 fYear(""),
48 fProd(""),
49 fVers(""),
50 fType(""),
51 fRun(""),
52 fEvt(""),
53 fPath("")
7f06a34f 54{
43073eba 55 // default ctor; Doing initialisation ;
43073eba 56 if (grid == "alien")
7f06a34f 57 fGrid = TGrid::Connect("alien://aliendb1.cern.ch:15000/?direct") ;
43073eba 58 else
59 Error("AliPHOSGridFile", " %s is an unknown grid system", grid.Data()) ;
60 if ( !fGrid )
61 Error("ctor", "Cannot connect to alien://aliendb1.cern.ch:15000/?direct") ;
62
43073eba 63#if ROOT_VERSION_CODE < ROOT_VERSION(5,0,0)
64 if ( !fGrid->OpenDir(fRoot) )
65 Error("ctor", "Cannot find directory %s ", fRoot.Data() ) ;
66#else
67 Error("AliPHOSGridFile", "needs to be ported to new TGrid");
68#endif
43073eba 69
70 fPath += fRoot ;
43fbaae1 71}
7f06a34f 72
43fbaae1 73//____________________________________________________________________________
74AliPHOSGridFile::AliPHOSGridFile(const AliPHOSGridFile &rhs) :
75 TObject(rhs),
76 fGrid(0),
77 fRoot(""),
78 fYear(""),
79 fProd(""),
80 fVers(""),
81 fType(""),
82 fRun(""),
83 fEvt(""),
84 fPath("")
85{
86 //copy ctor
87 rhs.Copy(*this);
7f06a34f 88}
89
90//____________________________________________________________________________
91AliPHOSGridFile::~AliPHOSGridFile()
92{
93}
94
95//____________________________________________________________________________
96TString AliPHOSGridFile::GetLFN() const
97{
98 TString fileName(Pwd()) ;
43073eba 99 fileName += "galice.root" ;
100#if ROOT_VERSION_CODE < ROOT_VERSION(5,0,0)
101 if ( !fGrid->GetAccessPath(fileName) ) {
102 AliWarning(Form("file %s does not exist", fileName.Data())) ;
103 fileName = "" ;
7f06a34f 104 }
43073eba 105 else
106 fileName.Prepend("alien://") ;
107#else
108 Error("GetLFN", "needs to be ported to new TGrid");
109#endif
110 return fileName ;
7f06a34f 111}
112
113//____________________________________________________________________________
702ab87e 114void AliPHOSGridFile::Copy(TObject & obj)const
7f06a34f 115{
43073eba 116 //Copy method used by the Copy ctor
702ab87e 117 AliPHOSGridFile &lfn = static_cast<AliPHOSGridFile &>(obj);
118 /* incorrect Copy, destination is OBJ, not this.
43073eba 119 fRoot = lfn.fRoot ;
120 fYear = lfn.fYear ;
121 fProd = lfn.fProd ;
122 fVers = lfn.fVers ;
123 fType = lfn.fType ;
124 fRun = lfn.fRun ;
125 fEvt = lfn.fEvt ;
126 TObject::Copy(lfn) ;
702ab87e 127 */
128 lfn.fRoot = fRoot ;
129 lfn.fYear = fYear ;
130 lfn.fProd = fProd ;
131 lfn.fVers = fVers ;
132 lfn.fType = fType ;
133 lfn.fRun = fRun ;
134 lfn.fEvt = fEvt ;
135 TObject::Copy(lfn) ;
7f06a34f 136}
137
138//____________________________________________________________________________
139void AliPHOSGridFile::Help()
140{
141 // Prints information on available lfn's
43073eba 142
a675b8d6 143 AliInfo(Form(" ")) ;
7f06a34f 144
145}
146
147//____________________________________________________________________________
148void AliPHOSGridFile::ListEvents() const
149{
150 // list the available events for the current path and run selected
151
43073eba 152 char path[80] ;
3da0f212 153 snprintf(path,80,"%s/%s-%s/%s/%s/%s", fRoot.Data(), fYear.Data(), fProd.Data(), fVers.Data(), fType.Data(), fRun.Data()) ;
43073eba 154 AliInfo(Form("Searching %s", path)) ;
155#if ROOT_VERSION_CODE < ROOT_VERSION(5,0,0)
156 Grid_ResultHandle_t gr = fGrid->Find(path, "galice.root") ;
7f06a34f 157 TGridResult ar(gr) ;
43073eba 158 ar.Print() ;
159#else
160 Error("ListEvents", "needs to be ported to new TGrid");
161#endif
7f06a34f 162}
163
164//____________________________________________________________________________
165void AliPHOSGridFile::ListRuns() const
166{
167 // list the available runs for the current path selected
168
43073eba 169 char path[80] ;
3da0f212 170 snprintf(path,80,"%s/%s-%s/%s/%s", fRoot.Data(), fYear.Data(), fProd.Data(), fVers.Data(), fType.Data()) ;
43073eba 171 AliInfo(Form("Searching %s", path)) ;
172#if ROOT_VERSION_CODE < ROOT_VERSION(5,0,0)
173 Grid_ResultHandle_t gr = fGrid->OpenDir(path) ;
7f06a34f 174 TGridResult ar(gr) ;
43073eba 175 ar.Print() ;
176#else
177 Error("ListRuns", "needs to be ported to new TGrid");
178#endif
7f06a34f 179}
180
181//____________________________________________________________________________
182Bool_t AliPHOSGridFile::SetYearProd(TString year, TString prod)
183{
184 // set the year and verifies if the directory exists
185 Bool_t rv = kFALSE ;
43073eba 186 char tempo[80] ;
3da0f212 187 snprintf(tempo,80,"/%s-%s", year.Data(), prod.Data()) ;
43073eba 188
189 TString path(fRoot) ;
190 path += tempo ;
191#if ROOT_VERSION_CODE < ROOT_VERSION(5,0,0)
192 if ( !fGrid->OpenDir(path) ) {
193 AliError(Form("Cannot find directory %s", path.Data() )) ;
351dd634 194 } else {
43073eba 195 rv = kTRUE ;
196 fYear = year ;
197 fProd = prod ;
198 fPath = path ;
7f06a34f 199 }
43073eba 200#else
201 Error("SetYearProd", "needs to be ported to new TGrid");
202#endif
203 return rv ;
7f06a34f 204}
205
206//____________________________________________________________________________
43073eba 207Bool_t AliPHOSGridFile::SetVers(TString vers)
7f06a34f 208{
209 // set the year and verifies if the directory exists
210 Bool_t rv = kFALSE ;
43073eba 211 char tempo[80] ;
3da0f212 212 snprintf(tempo,80,"/%s-%s/%s", fYear.Data(), fProd.Data(), vers.Data()) ;
43073eba 213 fVers = tempo ;
214
215 TString path(fRoot) ;
216 path += tempo ;
217#if ROOT_VERSION_CODE < ROOT_VERSION(5,0,0)
218 if ( !fGrid->OpenDir(path) ) {
219 AliError(Form("Cannot find directory %s ", path.Data() )) ;
351dd634 220 } else {
43073eba 221 rv = kTRUE ;
222 fVers = vers ;
7f06a34f 223 fPath = path ;
224 }
43073eba 225#else
226 Error("SetVers", "needs to be ported to new TGrid");
227#endif
228 return rv ;
7f06a34f 229}
230
231//____________________________________________________________________________
43073eba 232Bool_t AliPHOSGridFile::SetType(TString type)
7f06a34f 233{
234 // set the year and verifies if the directory exists
235 Bool_t rv = kFALSE ;
43073eba 236 char tempo[80] ;
3da0f212 237 snprintf(tempo,80,"/%s-%s/%s/%s", fYear.Data(), fProd.Data(), fVers.Data(), type.Data()) ;
43073eba 238
7f06a34f 239 TString path(fRoot) ;
43073eba 240 path += tempo ;
241#if ROOT_VERSION_CODE < ROOT_VERSION(5,0,0)
242 if ( !fGrid->OpenDir(path) ) {
243 AliError(Form("Cannot find directory %s ", path.Data() )) ;
351dd634 244 } else {
43073eba 245 rv = kTRUE ;
246 fType = type ;
247 fPath = path ;
7f06a34f 248 }
43073eba 249#else
250 Error("SetType", "needs to be ported to new TGrid");
251#endif
252 return rv ;
7f06a34f 253}
254
255//____________________________________________________________________________
43073eba 256Bool_t AliPHOSGridFile::SetPath(TString year, TString prod, TString vers, TString type)
7f06a34f 257{
258 // set the year and verifies if the directory exists
43073eba 259 Bool_t rv = kFALSE ;
260 char tempo[80] ;
3da0f212 261 snprintf(tempo,80,"/%s-%s/%s/%s", year.Data(), prod.Data(), vers.Data(), type.Data()) ;
43073eba 262
263 TString path(fRoot) ;
264 path += tempo ;
265#if ROOT_VERSION_CODE < ROOT_VERSION(5,0,0)
266 if ( !fGrid->OpenDir(path) ) {
267 AliError(Form("Cannot find directory %s ", path.Data() )) ;
351dd634 268 } else {
43073eba 269 rv = kTRUE ;
270 fPath = path ;
271 fYear += year ;
272 fProd += prod ;
273 fVers += vers ;
7f06a34f 274 fType += type ;
275 }
43073eba 276#else
277 Error("SetPath", "needs to be ported to new TGrid");
278#endif
279 return rv ;
7f06a34f 280}
281
282//____________________________________________________________________________
43073eba 283Bool_t AliPHOSGridFile::SetRun(Int_t run)
7f06a34f 284{
285 // set the year and verifies if the directory exists
286 Bool_t rv = kFALSE ;
287
43073eba 288 TString zero("00000") ;
289 TString srun ;
290 srun += run ;
291 Int_t nzero = zero.Length() - srun.Length() ;
7f06a34f 292 Int_t index ;
43073eba 293 for (index = 0 ; index < nzero ; index++)
294 srun.Prepend("0") ;
7f06a34f 295
43073eba 296 char tempo[80] ;
3da0f212 297 snprintf(tempo,80,"/%s-%s/%s/%s/%s", fYear.Data(), fProd.Data(), fVers.Data(), fType.Data(), srun.Data()) ;
7f06a34f 298
43073eba 299 TString path(fRoot) ;
7f06a34f 300 path += tempo ;
43073eba 301#if ROOT_VERSION_CODE < ROOT_VERSION(5,0,0)
302 if ( !fGrid->OpenDir(path) ) {
303 AliError(Form("Cannot find directory %s ", path.Data() )) ;
351dd634 304 } else {
43073eba 305 rv = kTRUE ;
306 fRun = srun ;
307 fPath = path ;
7f06a34f 308 }
43073eba 309#else
310 Error("SetRun", "needs to be ported to new TGrid");
311#endif
312 return rv ;
7f06a34f 313}
314
315//____________________________________________________________________________
43073eba 316Bool_t AliPHOSGridFile::SetEvt(Int_t evt)
7f06a34f 317{
318 // set the year and verifies if the directory exists
43073eba 319 Bool_t rv = kFALSE ;
7f06a34f 320
43073eba 321 TString zero("00000") ;
322 TString sevt ;
323 sevt += evt ;
324 Int_t nzero = zero.Length() - sevt.Length() ;
7f06a34f 325 Int_t index ;
43073eba 326 for (index = 0 ; index < nzero ; index++)
7f06a34f 327 sevt.Prepend("0") ;
43073eba 328
329 char tempo[80] ;
3da0f212 330 snprintf(tempo,80,"/%s-%s/%s/%s/%s/%s/", fYear.Data(), fProd.Data(), fVers.Data(), fType.Data(), fRun.Data(), sevt.Data()) ;
43073eba 331 TString path(fRoot) ;
7f06a34f 332 path += tempo ;
43073eba 333#if ROOT_VERSION_CODE < ROOT_VERSION(5,0,0)
334 if ( !fGrid->OpenDir(path) ) {
335 AliError(Form("Cannot find directory %s ", path.Data() )) ;
351dd634 336 } else {
43073eba 337 rv = kTRUE ;
338 fEvt = sevt ;
339 fPath = path ;
7f06a34f 340 }
43073eba 341#else
342 Error("SetEvt", "needs to be ported to new TGrid");
343#endif
344 return rv ;
7f06a34f 345}