]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/CDB/AliCDBId.cxx
small changes to D0-h code (Fabio C.)
[u/mrichter/AliRoot.git] / STEER / CDB / AliCDBId.cxx
CommitLineData
9e1ceb13 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/////////////////////////////////////////////////////////////////////
17// //
18// class AliCDBId //
19// Identity of an object stored into a database: //
20// path, run validity range, version, subVersion //
21// //
22/////////////////////////////////////////////////////////////////////
23
24#include "AliCDBId.h"
b21e3194 25#include <Riostream.h>
a4970db9 26#include <TObjArray.h>
27#include <TObjString.h>
9e1ceb13 28
66b0310c 29using std::endl;
30using std::cout;
9e1ceb13 31ClassImp(AliCDBId)
32
33//_____________________________________________________________________________
34AliCDBId::AliCDBId():
35fPath(),
36fRunRange(-1,-1),
37fVersion(-1),
38fSubVersion(-1),
39fLastStorage("new")
40{
41// constructor
42
43}
44
45//_____________________________________________________________________________
46AliCDBId::AliCDBId(const AliCDBId& other):
47TObject(),
48fPath(other.fPath),
49fRunRange(other.fRunRange),
50fVersion(other.fVersion),
51fSubVersion(other.fSubVersion),
52fLastStorage(other.fLastStorage)
53{
54// constructor
55
56}
57
58//_____________________________________________________________________________
59AliCDBId::AliCDBId(const AliCDBPath& path, Int_t firstRun, Int_t lastRun,
60 Int_t version, Int_t subVersion):
61fPath(path),
62fRunRange(firstRun, lastRun),
63fVersion(version),
64fSubVersion(subVersion),
65fLastStorage("new")
66{
67// constructor
68
69}
70
71//_____________________________________________________________________________
72AliCDBId::AliCDBId(const AliCDBPath& path, const AliCDBRunRange& runRange,
73 Int_t version, Int_t subVersion):
74fPath(path),
75fRunRange(runRange),
76fVersion(version),
77fSubVersion(subVersion),
78fLastStorage("new")
79{
80// constructor
81
82}
83
a4970db9 84//_____________________________________________________________________________
85AliCDBId* AliCDBId::MakeFromString(const TString& idString)
86{
87// constructor from string
88// string has the format as the output of AliCDBId::ToString:
89// path: "TRD/Calib/PIDLQ"; run range: [0,999999999]; version: v0_s0
90
91 AliCDBId* id = new AliCDBId("a/b/c",-1,-1,-1,-1);
92
93 TObjArray* arr1 = idString.Tokenize(';');
94 TIter iter1(arr1);
95 TObjString *objStr1 = 0;
96 while((objStr1 = dynamic_cast<TObjString*>(iter1.Next()))) {
97 TString buff(objStr1->GetName());
98
99 if(buff.Contains("path:")) {
100 TString path(buff(buff.First('\"')+1, buff.Length()-buff.First('\"')-2));
101 id->SetPath(path.Data());
102
103 } else if (buff.Contains("run range:")) {
104 TString firstRunStr(buff(buff.Index('[')+1, buff.Index(',')-buff.Index('[')-1));
105 TString lastRunStr(buff(buff.Index(',')+1, buff.Index(']')-buff.Index(',')-1));
106 id->SetRunRange(firstRunStr.Atoi(), lastRunStr.Atoi());
107
108 } else if (buff.Contains("version:")) {
109 if (buff.Contains("_s")) {
110 TString versStr(buff(buff.Last('v')+1, buff.Index('_')-buff.Last('v')-1));
111 TString subVersStr(buff(buff.Last('s')+1, buff.Length()-buff.Last('s')-1));
112 id->SetVersion(versStr.Atoi());
113 id->SetSubVersion(subVersStr.Atoi());
114 } else {
115 TString versStr(buff(buff.Last('v')+1, buff.Length()-buff.Last('v')-1));
116 id->SetVersion(versStr.Atoi());
117 }
118 }
119
120 }
121
122 delete arr1;
123
124 return id;
125
126}
127
9e1ceb13 128//_____________________________________________________________________________
129AliCDBId::~AliCDBId() {
130//destructor
131
132}
133
134//_____________________________________________________________________________
135Bool_t AliCDBId::IsValid() const {
136// validity check
8e245d15 137
9e1ceb13 138 if (!(fPath.IsValid() && fRunRange.IsValid())) {
139 return kFALSE;
140 }
141
142 // FALSE if doesn't have version but has subVersion
143 return !(!HasVersion() && HasSubVersion());
144}
145
8e245d15 146//___________________________________________________________________________
147Bool_t AliCDBId::IsEqual(const TObject* obj) const {
148// check if this id is equal to other id (compares path, run range, versions)
149
150 if (this == obj) {
151 return kTRUE;
152 }
153
154 if (AliCDBId::Class() != obj->IsA()) {
155 return kFALSE;
156 }
157 AliCDBId* other = (AliCDBId*) obj;
158 return fPath.GetPath() == other->GetPath() && fRunRange.IsEqual(&other->GetAliCDBRunRange()) &&
159 fVersion == other->GetVersion() && fSubVersion == other->GetSubVersion();
160}
161
9e1ceb13 162//_____________________________________________________________________________
163TString AliCDBId::ToString() const {
164// returns a string of Id data
165
c3a7b59a 166 TString result = Form("path: \"%s\"; run range: [%d,%d]",
167 GetPath().Data(), GetFirstRun(), GetLastRun());
168
169 if(GetVersion() >= 0) result += Form("; version: v%d", GetVersion());
170 if(GetSubVersion() >= 0) result += Form("_s%d", GetSubVersion());
171 return result;
9e1ceb13 172}
b21e3194 173
174//_____________________________________________________________________________
175void AliCDBId::Print(Option_t* /*option*/) const {
176// Prints ToString()
177
178 cout << ToString().Data() << endl;
179
180}