]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliCDBMetaData.cxx
Initialization of some arrays
[u/mrichter/AliRoot.git] / STEER / AliCDBMetaData.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 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 // Object meta data: full description of a run dependent database object     // 
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24
25 #include <TRegexp.h>
26 #include <TObjArray.h>
27 #include <TObjString.h>
28 #include <TSystem.h>
29
30 #include "AliCDBMetaData.h"
31 #include "AliLog.h"
32
33
34 ClassImp(AliCDBMetaData)
35
36
37 //_____________________________________________________________________________
38 AliCDBMetaData::AliCDBMetaData() :
39   TObject(),
40   fName(""),
41   fFirstRun(-1),
42   fLastRun(-1),
43   fVersion(-1),
44   fPeriod(-1),
45   fFormat(""),
46   fResponsible("Duck, Donald"),
47   fExtraInfo("")
48 {
49 // default constructor
50 // the default values mean no selection
51   DecodeName();
52 }
53
54 //_____________________________________________________________________________
55 AliCDBMetaData::AliCDBMetaData
56          (const char* name, Int_t firstRun, Int_t lastRun, Int_t period, 
57           const char* objFormat, const char* responsible, 
58           const char* extraInfo):
59   TObject(),
60   fName(name),
61   fFirstRun(firstRun),
62   fLastRun(lastRun),
63   fVersion(-1),
64   fPeriod(period),
65   fFormat(objFormat),
66   fResponsible(responsible),
67   fExtraInfo(extraInfo)
68 {
69 // constructor
70   DecodeName();
71 }
72
73 //_____________________________________________________________________________
74 AliCDBMetaData::AliCDBMetaData(const AliCDBMetaData& entry) :
75   TObject(entry),
76   fName(entry.fName),
77   fFirstRun(entry.fFirstRun),
78   fLastRun(entry.fLastRun),
79   fVersion(entry.fVersion),
80   fPeriod(entry.fPeriod),
81   fFormat(entry.fFormat),
82   fResponsible(entry.fResponsible),
83   fExtraInfo(entry.fExtraInfo)
84 {
85 // copy constructor
86   DecodeName();
87 }
88
89 //_____________________________________________________________________________
90 AliCDBMetaData& AliCDBMetaData::operator = (const AliCDBMetaData& entry)
91 {
92 // assignment operator
93   fName = entry.fName;
94   fFirstRun = entry.fFirstRun;
95   fLastRun = entry.fLastRun;
96   fVersion = entry.fVersion;
97   fPeriod=entry.fPeriod;
98   fFormat=entry.fFormat;
99   fResponsible=entry.fResponsible;
100   fExtraInfo=entry.fExtraInfo;
101   DecodeName();
102   return *this;
103 }
104
105 //_____________________________________________________________________________
106 void AliCDBMetaData::EncodeName(){
107 // Encode name from single elements ("Detector", "DBType", "DetSpecType" -> "Detector/DBType/DetSpecType")   
108    fName = fDetector+'/'+fDBType+'/'+fDetSpecType;
109    if(fDBType == "*" && fDetSpecType == "*") fName = fDetector+'/'+'*';
110    if(fDetector == "*" && fDBType == "*" && fDetSpecType == "*") fName = "*";
111
112 }
113
114 //_____________________________________________________________________________
115 void AliCDBMetaData::DecodeName(){
116 // Decode name into single elements ("Detector/DBType/DetSpecType" -> "Detector", "DBType", "DetSpecType")   
117
118  if(fName==""){fDetector=""; fDBType=""; fDetSpecType=""; return;}
119
120  while(fName.EndsWith("/")) fName.Remove(fName.Last('/'));
121  while(fName.BeginsWith("/")) fName.Remove(fName.First('/'),1);
122  
123  // fName= "fDetector/fDBType/fDetSpecType
124  int nslashes=fName.CountChar('/');
125  
126  if(nslashes>2){AliError("Wrong format!\n");fDetector=""; fDBType=""; fDetSpecType="";}
127
128  if(nslashes == 0){
129    if(fName == "*"){fDetector="*"; fDBType="*"; fDetSpecType="*";}
130    else{AliError("Wrong format!\n"); fDetector=""; fDBType=""; fDetSpecType="";}
131  }
132  if(nslashes == 1){
133    if(fName.EndsWith("*"))
134      {fDetector=fName(0, fName.Index('/')); fDBType="*"; fDetSpecType="*";}
135    else {AliError("Wrong format!\n"); fDetector=""; fDBType=""; fDetSpecType="";}
136  }
137
138  if(nslashes == 2){
139    int firstsl=fName.First('/'), lastsl=fName.Last('/'), lgth=fName.Length();
140    fDetector=fName(0, firstsl); 
141    fDBType=fName(firstsl+1, lastsl-(firstsl+1));
142    fDetSpecType=fName(lastsl+1, lgth-(lastsl+1)); 
143  }
144  EncodeName();
145 }
146
147 //_____________________________________________________________________________
148 Bool_t AliCDBMetaData::IsStrictlyValid(Int_t runNumber, AliCDBMetaData* metaData) const
149 {
150 // check if the object is valid for runNumber. TRUE if metaData version is equal to this's version 
151
152   if ((fFirstRun >= 0) && (runNumber < fFirstRun)) return kFALSE;
153   if ((fLastRun >= 0) && (runNumber > fLastRun)) return kFALSE;
154   if (metaData) {
155     if ((metaData->fVersion >= 0) && (metaData->fVersion != fVersion)) 
156       return kFALSE;
157   }
158   return kTRUE;
159 }
160
161 //_____________________________________________________________________________
162 Bool_t AliCDBMetaData::IsValid(Int_t runNumber, AliCDBMetaData* metaData) const
163 {
164 // check if the object is valid for runNumber. TRUE if metaData version less or equal wrt to this's
165
166   if ((fFirstRun >= 0) && (runNumber < fFirstRun)) return kFALSE;
167   if ((fLastRun >= 0) && (runNumber > fLastRun)) return kFALSE;
168   if (metaData) {
169     if ((metaData->fVersion >= 0) && (metaData->fVersion < fVersion)) 
170       return kFALSE;
171   }
172   return kTRUE;
173 }
174
175 //_____________________________________________________________________________
176 Int_t AliCDBMetaData::Compare(const TObject* object) const
177 {
178 // check whether this is preferred to object
179
180   if (!object || !object->InheritsFrom(AliCDBMetaData::Class())) return 1;
181   if (fVersion < ((AliCDBMetaData*)object)->GetVersion()) return -1;
182   if (fVersion > ((AliCDBMetaData*)object)->GetVersion()) return 1;
183   return 0;
184 }
185
186 //_____________________________________________________________________________
187 Bool_t AliCDBMetaData::Matches(const char* name, Int_t runNumber) const
188 {
189 // check whether name and run number match with this meta data
190
191   if ((fFirstRun >= 0) && (runNumber < fFirstRun)) return kFALSE;
192   if ((fLastRun >= 0) && (runNumber > fLastRun)) return kFALSE;
193   if (!TString(name).Contains(TRegexp(fName))) return kFALSE;
194   return kTRUE;
195 }
196
197
198 //_____________________________________________________________________________
199 Bool_t operator == (const AliCDBMetaData& entry1, const AliCDBMetaData& entry2)
200 {
201 // compare two DB entries
202
203   if (strcmp(entry1.GetName(), entry2.GetName()) != 0) return kFALSE;
204   if (entry1.GetFirstRun() != entry2.GetFirstRun()) return kFALSE;
205   if (entry1.GetLastRun() != entry2.GetLastRun()) return kFALSE;
206   if (entry1.GetVersion() != entry2.GetVersion()) return kFALSE;
207   return kTRUE;
208 }
209
210