forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConditionId.cxx
More file actions
153 lines (125 loc) · 4.48 KB
/
Copy pathConditionId.cxx
File metadata and controls
153 lines (125 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include "CCDB/ConditionId.h"
#include <TObjArray.h> // for TObjArray
#include <TObjString.h> // for TObjString
#include <Riostream.h>
// using std::endl;
// using std::cout;
using namespace o2::ccdb;
ClassImp(ConditionId)
ConditionId::ConditionId() : mPath(), mIdRunRange(-1, -1), mVersion(-1), mSubVersion(-1), mLastStorage("new")
{
// constructor
}
ConditionId::ConditionId(const ConditionId &other)
: TObject(),
mPath(other.mPath),
mIdRunRange(other.mIdRunRange),
mVersion(other.mVersion),
mSubVersion(other.mSubVersion),
mLastStorage(other.mLastStorage)
{
// constructor
}
ConditionId::ConditionId(const IdPath &path, Int_t firstRun, Int_t lastRun, Int_t version, Int_t subVersion)
: mPath(path), mIdRunRange(firstRun, lastRun), mVersion(version), mSubVersion(subVersion), mLastStorage("new")
{
// constructor
}
ConditionId::ConditionId(const IdPath &path, const IdRunRange &runRange, Int_t version, Int_t subVersion)
: mPath(path), mIdRunRange(runRange), mVersion(version), mSubVersion(subVersion), mLastStorage("new")
{
// constructor
}
ConditionId *ConditionId::makeFromString(const TString &idString)
{
// constructor from string
// string has the format as the output of ConditionId::ToString:
// path: "TRD/Calib/PIDLQ"; run range: [0,999999999]; version: v0_s0
ConditionId *id = new ConditionId("a/b/c", -1, -1, -1, -1);
TObjArray *arr1 = idString.Tokenize(';');
TIter iter1(arr1);
TObjString *objStr1 = nullptr;
while ((objStr1 = dynamic_cast<TObjString *>(iter1.Next()))) {
TString buff(objStr1->GetName());
if (buff.Contains("path:")) {
TString path(buff(buff.First('\"') + 1, buff.Length() - buff.First('\"') - 2));
id->setPath(path.Data());
} else if (buff.Contains("run range:")) {
TString firstRunStr(buff(buff.Index('[') + 1, buff.Index(',') - buff.Index('[') - 1));
TString lastRunStr(buff(buff.Index(',') + 1, buff.Index(']') - buff.Index(',') - 1));
id->setIdRunRange(firstRunStr.Atoi(), lastRunStr.Atoi());
} else if (buff.Contains("version:")) {
if (buff.Contains("_s")) {
TString versStr(buff(buff.Last('v') + 1, buff.Index('_') - buff.Last('v') - 1));
TString subVersStr(buff(buff.Last('s') + 1, buff.Length() - buff.Last('s') - 1));
id->setVersion(versStr.Atoi());
id->setSubVersion(subVersStr.Atoi());
} else {
TString versStr(buff(buff.Last('v') + 1, buff.Length() - buff.Last('v') - 1));
id->setVersion(versStr.Atoi());
}
}
}
delete arr1;
return id;
}
ConditionId::~ConditionId() = default;
Bool_t ConditionId::isValid() const
{
// validity check
if (!(mPath.isValid() && mIdRunRange.isValid())) {
return kFALSE;
}
// FALSE if doesn't have version but has subVersion
return !(!hasVersion() && hasSubVersion());
}
Bool_t ConditionId::isEqual(const TObject *obj) const
{
// check if this id is equal to other id (compares path, run range, versions)
if (this == obj) {
return kTRUE;
}
if (ConditionId::Class() != obj->IsA()) {
return kFALSE;
}
ConditionId *other = (ConditionId *) obj;
return mPath.getPathString() == other->getPathString() && mIdRunRange.isEqual(&other->getIdRunRange()) &&
mVersion == other->getVersion() && mSubVersion == other->getSubVersion();
}
TString ConditionId::ToString() const
{
// returns a string of ConditionId data
TString result = Form(R"(path: "%s"; run range: [%d,%d])", getPathString().Data(), getFirstRun(), getLastRun());
if (getVersion() >= 0) {
result += Form("; version: v%d", getVersion());
}
if (getSubVersion() >= 0) {
result += Form("_s%d", getSubVersion());
}
return result;
}
void ConditionId::print(Option_t * /*option*/) const
{
// Prints ToString()
std::cout << ToString().Data() << std::endl;
}
Int_t ConditionId::Compare(const TObject *obj) const
{
//
// compare according y
ConditionId *o2 = (ConditionId *) obj;
return TString(this->getPathString()).CompareTo((o2->getPathString()));
}
Bool_t ConditionId::IsSortable() const
{
return kTRUE;
}