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