Line data Source code
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"
25 : #include <Riostream.h>
26 : #include <TObjArray.h>
27 : #include <TObjString.h>
28 :
29 : using std::endl;
30 : using std::cout;
31 128 : ClassImp(AliCDBId)
32 :
33 : //_____________________________________________________________________________
34 2734 : AliCDBId::AliCDBId():
35 2734 : fPath(),
36 2734 : fRunRange(-1,-1),
37 2734 : fVersion(-1),
38 2734 : fSubVersion(-1),
39 2734 : fLastStorage("new")
40 13670 : {
41 : // constructor
42 :
43 5468 : }
44 :
45 : //_____________________________________________________________________________
46 : AliCDBId::AliCDBId(const AliCDBId& other):
47 945 : TObject(),
48 945 : fPath(other.fPath),
49 945 : fRunRange(other.fRunRange),
50 945 : fVersion(other.fVersion),
51 945 : fSubVersion(other.fSubVersion),
52 945 : fLastStorage(other.fLastStorage)
53 4725 : {
54 : // constructor
55 :
56 1890 : }
57 :
58 : //_____________________________________________________________________________
59 715 : AliCDBId::AliCDBId(const AliCDBPath& path, Int_t firstRun, Int_t lastRun,
60 : Int_t version, Int_t subVersion):
61 715 : fPath(path),
62 715 : fRunRange(firstRun, lastRun),
63 715 : fVersion(version),
64 715 : fSubVersion(subVersion),
65 715 : fLastStorage("new")
66 3575 : {
67 : // constructor
68 :
69 1430 : }
70 :
71 : //_____________________________________________________________________________
72 1624 : AliCDBId::AliCDBId(const AliCDBPath& path, const AliCDBRunRange& runRange,
73 : Int_t version, Int_t subVersion):
74 1624 : fPath(path),
75 1624 : fRunRange(runRange),
76 1624 : fVersion(version),
77 1624 : fSubVersion(subVersion),
78 1624 : fLastStorage("new")
79 8120 : {
80 : // constructor
81 :
82 3248 : }
83 :
84 : //_____________________________________________________________________________
85 : AliCDBId* 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 0 : AliCDBId* id = new AliCDBId("a/b/c",-1,-1,-1,-1);
92 :
93 0 : TObjArray* arr1 = idString.Tokenize(';');
94 0 : TIter iter1(arr1);
95 : TObjString *objStr1 = 0;
96 0 : while((objStr1 = dynamic_cast<TObjString*>(iter1.Next()))) {
97 0 : TString buff(objStr1->GetName());
98 :
99 0 : if(buff.Contains("path:")) {
100 0 : TString path(buff(buff.First('\"')+1, buff.Length()-buff.First('\"')-2));
101 0 : id->SetPath(path.Data());
102 :
103 0 : } else if (buff.Contains("run range:")) {
104 0 : TString firstRunStr(buff(buff.Index('[')+1, buff.Index(',')-buff.Index('[')-1));
105 0 : TString lastRunStr(buff(buff.Index(',')+1, buff.Index(']')-buff.Index(',')-1));
106 0 : id->SetRunRange(firstRunStr.Atoi(), lastRunStr.Atoi());
107 :
108 0 : } else if (buff.Contains("version:")) {
109 0 : if (buff.Contains("_s")) {
110 0 : TString versStr(buff(buff.Last('v')+1, buff.Index('_')-buff.Last('v')-1));
111 0 : TString subVersStr(buff(buff.Last('s')+1, buff.Length()-buff.Last('s')-1));
112 0 : id->SetVersion(versStr.Atoi());
113 0 : id->SetSubVersion(subVersStr.Atoi());
114 0 : } else {
115 0 : TString versStr(buff(buff.Last('v')+1, buff.Length()-buff.Last('v')-1));
116 0 : id->SetVersion(versStr.Atoi());
117 0 : }
118 : }
119 :
120 0 : }
121 :
122 0 : delete arr1;
123 :
124 : return id;
125 :
126 0 : }
127 :
128 : //_____________________________________________________________________________
129 17162 : AliCDBId::~AliCDBId() {
130 : //destructor
131 :
132 8581 : }
133 :
134 : //_____________________________________________________________________________
135 : Bool_t AliCDBId::IsValid() const {
136 : // validity check
137 :
138 2949 : if (!(fPath.IsValid() && fRunRange.IsValid())) {
139 0 : return kFALSE;
140 : }
141 :
142 : // FALSE if doesn't have version but has subVersion
143 2948 : return !(!HasVersion() && HasSubVersion());
144 983 : }
145 :
146 : //___________________________________________________________________________
147 : Bool_t AliCDBId::IsEqual(const TObject* obj) const {
148 : // check if this id is equal to other id (compares path, run range, versions)
149 :
150 191052 : if (this == obj) {
151 0 : return kTRUE;
152 : }
153 :
154 95526 : if (AliCDBId::Class() != obj->IsA()) {
155 0 : return kFALSE;
156 : }
157 95526 : AliCDBId* other = (AliCDBId*) obj;
158 96284 : return fPath.GetPath() == other->GetPath() && fRunRange.IsEqual(&other->GetAliCDBRunRange()) &&
159 1513 : fVersion == other->GetVersion() && fSubVersion == other->GetSubVersion();
160 95526 : }
161 :
162 : //_____________________________________________________________________________
163 : TString AliCDBId::ToString() const {
164 : // returns a string of Id data
165 :
166 2644 : TString result = Form("path: \"%s\"; run range: [%d,%d]",
167 5288 : GetPath().Data(), GetFirstRun(), GetLastRun());
168 :
169 7396 : if(GetVersion() >= 0) result += Form("; version: v%d", GetVersion());
170 7508 : if(GetSubVersion() >= 0) result += Form("_s%d", GetSubVersion());
171 : return result;
172 5288 : }
173 :
174 : //_____________________________________________________________________________
175 : void AliCDBId::Print(Option_t* /*option*/) const {
176 : // Prints ToString()
177 :
178 0 : cout << ToString().Data() << endl;
179 :
180 0 : }
181 :
182 :
183 :
184 : Int_t AliCDBId::Compare(const TObject* obj) const
185 : {
186 : //
187 : // compare according y
188 0 : AliCDBId * o2 = (AliCDBId*)obj;
189 0 : return TString(this->GetPath()).CompareTo((o2->GetPath()));
190 :
191 0 : }
192 :
193 : Bool_t AliCDBId::IsSortable() const {
194 0 : return kTRUE;
195 : }
|