ROOT logo
/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/////////////////////////////////////////////////////////////////////
//                                                                 //
//  class AliCDBPath						   //
//  Path string identifying the object:  			   //
//  "level0/level1/level2" 					   //
//  (was: "Detector/DBType/DetSpecType") 		           //
//  (example: "ZDC/Calib/Pedestals") 		         	   //
//                                                                 //
/////////////////////////////////////////////////////////////////////

#include "AliCDBPath.h"

#include <TObjArray.h>
#include <TObjString.h>
#include <TRegexp.h>

#include "AliLog.h"

ClassImp(AliCDBPath)

//_____________________________________________________________________________
AliCDBPath::AliCDBPath() :
  TObject(),
  fPath(""),
  fLevel0(""),
  fLevel1(""),
  fLevel2(""),
  fIsValid(kTRUE),
  fIsWildcard(kFALSE)
{
  // default constructor

}

//_____________________________________________________________________________
AliCDBPath::AliCDBPath(const AliCDBPath& other):
  TObject(other),
  fPath(other.fPath),
  fLevel0(""),
  fLevel1(""),
  fLevel2(""),
  fIsValid(other.fIsValid),
  fIsWildcard(other.fIsWildcard)
{
  // constructor
  Init();
  InitPath();

}

//_____________________________________________________________________________
AliCDBPath::AliCDBPath(const char* level0, const char* level1,
    const char* level2):
  TObject(),
  fPath(""),
  fLevel0(level0), 
  fLevel1(level1), 
  fLevel2(level2),
  fIsValid(kTRUE),
  fIsWildcard(kFALSE)
{
  // constructor

  fPath += level0;
  fPath += '/';
  fPath += level1;
  fPath += '/';
  fPath += level2;

  if ((IsWord(fLevel0) || fLevel0 == "*")
      && (IsWord(fLevel1) || fLevel1 == "*")
      && (IsWord(fLevel2) || fLevel2 == "*")) {

    fIsValid = kTRUE;
  } else {
    fIsValid = kFALSE;
    AliError(Form("Invalid AliCDBPath <%s/%s/%s>!", 
          level0, level1, level2));
  }

  Init();
}

//_____________________________________________________________________________
AliCDBPath::AliCDBPath(const char* path):
  TObject(),
  fPath(path),
  fLevel0(""),
  fLevel1(""),
  fLevel2(""),
  fIsValid(kTRUE),
  fIsWildcard(kFALSE)
{
  // constructor

  Init();
  InitPath();	
}

//_____________________________________________________________________________
AliCDBPath::AliCDBPath(const TString& path):
  TObject(),
  fPath(path),
  fLevel0(""),
  fLevel1(""),
  fLevel2(""),
  fIsValid(kTRUE),
  fIsWildcard(kFALSE)
{
  Init();
  InitPath();
}

//_____________________________________________________________________________
void AliCDBPath::InitPath() {
  // sets fLevel0, fLevel1, fLevel2, validity flagss from fPath

  TSubString strippedString = fPath.Strip(TString::kBoth);
  TString aString(strippedString);
  strippedString = aString.Strip(TString::kBoth, '/');

  TObjArray* anArray = TString(strippedString).Tokenize("/");
  Int_t paramCount = anArray->GetEntriesFast();

  if (paramCount == 1) {
    if (fPath == "*") {
      fLevel0 = "*";
      fLevel1 = "*";
      fLevel2 = "*";

      fIsValid = kTRUE;
    } else {
      fIsValid = kFALSE;
    }

  } else if (paramCount == 2) {
    fLevel0 = ((TObjString*) anArray->At(0))->GetString();
    TString bString =  ((TObjString*) anArray->At(1))->GetString();

    if (IsWord(fLevel0) && bString == "*") {
      fLevel1 = "*";
      fLevel2 = "*";

      fIsValid = kTRUE;			

    } else {
      fIsValid = kFALSE;
    }

  } else if (paramCount == 3) {
    fLevel0 = ((TObjString*) anArray->At(0))->GetString();
    fLevel1 = ((TObjString*) anArray->At(1))->GetString();
    fLevel2 = ((TObjString*) anArray->At(2))->GetString();

    if ((IsWord(fLevel0) || fLevel0 == "*")
        && (IsWord(fLevel1) || fLevel1 == "*")
        && (IsWord(fLevel2) || fLevel2 == "*")) {

      fIsValid = kTRUE;
    } else {
      fIsValid = kFALSE;
    }

  } else {
    fIsValid = kFALSE;

  }

  if (!fIsValid) {
    AliInfo(Form("Invalid AliCDBPath <%s>!", fPath.Data()));
  } else {	
    fPath = Form("%s/%s/%s", fLevel0.Data(), fLevel1.Data(), fLevel2.Data());
  }

  delete anArray;

  Init();
}

//_____________________________________________________________________________
AliCDBPath::~AliCDBPath() {
  // destructor

}

//_____________________________________________________________________________
Bool_t AliCDBPath::IsWord(const TString& str) {
  // check if string is a word

  TRegexp pattern("^[a-zA-Z0-9_.-]+$");

  return str.Contains(pattern);	
}

//_____________________________________________________________________________
void AliCDBPath::Init() {
  // set fIsWildcard flag

  fIsWildcard = fPath.MaybeWildcard();	
}

//_____________________________________________________________________________
Bool_t AliCDBPath::Level0Comprises(const TString& str) const {
  // check if Level0 is wildcard or is equal to str

  if (fLevel0 == "*") {
    return kTRUE;
  }

  return fLevel0 == str;
}

//_____________________________________________________________________________
Bool_t AliCDBPath::Level1Comprises(const TString& str) const {
  // check if Level1 is wildcard or is equal to str

  if (fLevel1 == "*") {
    return kTRUE;
  }

  return fLevel1 == str;
}

//_____________________________________________________________________________
Bool_t AliCDBPath::Level2Comprises(const TString& str) const {
  // check if Level2 is wildcard or is equal to str

  if (fLevel2 == "*") {
    return kTRUE;
  }

  return fLevel2 == str;
}

//_____________________________________________________________________________
Bool_t AliCDBPath::Comprises(const AliCDBPath& other) const {
  // check if path is wildcard and comprises other

  return Level0Comprises(other.fLevel0)
    && Level1Comprises(other.fLevel1)
    && Level2Comprises(other.fLevel2);
}

//_____________________________________________________________________________
const char* AliCDBPath::GetLevel(Int_t i) const {
  // return level i of the path

  switch (i) {
    case 0:
      return fLevel0.Data();
      break;
    case 1:
      return fLevel1.Data();
      break;
    case 2:
      return fLevel2.Data();
      break;
    default:
      return 0;
  }

}
 AliCDBPath.cxx:1
 AliCDBPath.cxx:2
 AliCDBPath.cxx:3
 AliCDBPath.cxx:4
 AliCDBPath.cxx:5
 AliCDBPath.cxx:6
 AliCDBPath.cxx:7
 AliCDBPath.cxx:8
 AliCDBPath.cxx:9
 AliCDBPath.cxx:10
 AliCDBPath.cxx:11
 AliCDBPath.cxx:12
 AliCDBPath.cxx:13
 AliCDBPath.cxx:14
 AliCDBPath.cxx:15
 AliCDBPath.cxx:16
 AliCDBPath.cxx:17
 AliCDBPath.cxx:18
 AliCDBPath.cxx:19
 AliCDBPath.cxx:20
 AliCDBPath.cxx:21
 AliCDBPath.cxx:22
 AliCDBPath.cxx:23
 AliCDBPath.cxx:24
 AliCDBPath.cxx:25
 AliCDBPath.cxx:26
 AliCDBPath.cxx:27
 AliCDBPath.cxx:28
 AliCDBPath.cxx:29
 AliCDBPath.cxx:30
 AliCDBPath.cxx:31
 AliCDBPath.cxx:32
 AliCDBPath.cxx:33
 AliCDBPath.cxx:34
 AliCDBPath.cxx:35
 AliCDBPath.cxx:36
 AliCDBPath.cxx:37
 AliCDBPath.cxx:38
 AliCDBPath.cxx:39
 AliCDBPath.cxx:40
 AliCDBPath.cxx:41
 AliCDBPath.cxx:42
 AliCDBPath.cxx:43
 AliCDBPath.cxx:44
 AliCDBPath.cxx:45
 AliCDBPath.cxx:46
 AliCDBPath.cxx:47
 AliCDBPath.cxx:48
 AliCDBPath.cxx:49
 AliCDBPath.cxx:50
 AliCDBPath.cxx:51
 AliCDBPath.cxx:52
 AliCDBPath.cxx:53
 AliCDBPath.cxx:54
 AliCDBPath.cxx:55
 AliCDBPath.cxx:56
 AliCDBPath.cxx:57
 AliCDBPath.cxx:58
 AliCDBPath.cxx:59
 AliCDBPath.cxx:60
 AliCDBPath.cxx:61
 AliCDBPath.cxx:62
 AliCDBPath.cxx:63
 AliCDBPath.cxx:64
 AliCDBPath.cxx:65
 AliCDBPath.cxx:66
 AliCDBPath.cxx:67
 AliCDBPath.cxx:68
 AliCDBPath.cxx:69
 AliCDBPath.cxx:70
 AliCDBPath.cxx:71
 AliCDBPath.cxx:72
 AliCDBPath.cxx:73
 AliCDBPath.cxx:74
 AliCDBPath.cxx:75
 AliCDBPath.cxx:76
 AliCDBPath.cxx:77
 AliCDBPath.cxx:78
 AliCDBPath.cxx:79
 AliCDBPath.cxx:80
 AliCDBPath.cxx:81
 AliCDBPath.cxx:82
 AliCDBPath.cxx:83
 AliCDBPath.cxx:84
 AliCDBPath.cxx:85
 AliCDBPath.cxx:86
 AliCDBPath.cxx:87
 AliCDBPath.cxx:88
 AliCDBPath.cxx:89
 AliCDBPath.cxx:90
 AliCDBPath.cxx:91
 AliCDBPath.cxx:92
 AliCDBPath.cxx:93
 AliCDBPath.cxx:94
 AliCDBPath.cxx:95
 AliCDBPath.cxx:96
 AliCDBPath.cxx:97
 AliCDBPath.cxx:98
 AliCDBPath.cxx:99
 AliCDBPath.cxx:100
 AliCDBPath.cxx:101
 AliCDBPath.cxx:102
 AliCDBPath.cxx:103
 AliCDBPath.cxx:104
 AliCDBPath.cxx:105
 AliCDBPath.cxx:106
 AliCDBPath.cxx:107
 AliCDBPath.cxx:108
 AliCDBPath.cxx:109
 AliCDBPath.cxx:110
 AliCDBPath.cxx:111
 AliCDBPath.cxx:112
 AliCDBPath.cxx:113
 AliCDBPath.cxx:114
 AliCDBPath.cxx:115
 AliCDBPath.cxx:116
 AliCDBPath.cxx:117
 AliCDBPath.cxx:118
 AliCDBPath.cxx:119
 AliCDBPath.cxx:120
 AliCDBPath.cxx:121
 AliCDBPath.cxx:122
 AliCDBPath.cxx:123
 AliCDBPath.cxx:124
 AliCDBPath.cxx:125
 AliCDBPath.cxx:126
 AliCDBPath.cxx:127
 AliCDBPath.cxx:128
 AliCDBPath.cxx:129
 AliCDBPath.cxx:130
 AliCDBPath.cxx:131
 AliCDBPath.cxx:132
 AliCDBPath.cxx:133
 AliCDBPath.cxx:134
 AliCDBPath.cxx:135
 AliCDBPath.cxx:136
 AliCDBPath.cxx:137
 AliCDBPath.cxx:138
 AliCDBPath.cxx:139
 AliCDBPath.cxx:140
 AliCDBPath.cxx:141
 AliCDBPath.cxx:142
 AliCDBPath.cxx:143
 AliCDBPath.cxx:144
 AliCDBPath.cxx:145
 AliCDBPath.cxx:146
 AliCDBPath.cxx:147
 AliCDBPath.cxx:148
 AliCDBPath.cxx:149
 AliCDBPath.cxx:150
 AliCDBPath.cxx:151
 AliCDBPath.cxx:152
 AliCDBPath.cxx:153
 AliCDBPath.cxx:154
 AliCDBPath.cxx:155
 AliCDBPath.cxx:156
 AliCDBPath.cxx:157
 AliCDBPath.cxx:158
 AliCDBPath.cxx:159
 AliCDBPath.cxx:160
 AliCDBPath.cxx:161
 AliCDBPath.cxx:162
 AliCDBPath.cxx:163
 AliCDBPath.cxx:164
 AliCDBPath.cxx:165
 AliCDBPath.cxx:166
 AliCDBPath.cxx:167
 AliCDBPath.cxx:168
 AliCDBPath.cxx:169
 AliCDBPath.cxx:170
 AliCDBPath.cxx:171
 AliCDBPath.cxx:172
 AliCDBPath.cxx:173
 AliCDBPath.cxx:174
 AliCDBPath.cxx:175
 AliCDBPath.cxx:176
 AliCDBPath.cxx:177
 AliCDBPath.cxx:178
 AliCDBPath.cxx:179
 AliCDBPath.cxx:180
 AliCDBPath.cxx:181
 AliCDBPath.cxx:182
 AliCDBPath.cxx:183
 AliCDBPath.cxx:184
 AliCDBPath.cxx:185
 AliCDBPath.cxx:186
 AliCDBPath.cxx:187
 AliCDBPath.cxx:188
 AliCDBPath.cxx:189
 AliCDBPath.cxx:190
 AliCDBPath.cxx:191
 AliCDBPath.cxx:192
 AliCDBPath.cxx:193
 AliCDBPath.cxx:194
 AliCDBPath.cxx:195
 AliCDBPath.cxx:196
 AliCDBPath.cxx:197
 AliCDBPath.cxx:198
 AliCDBPath.cxx:199
 AliCDBPath.cxx:200
 AliCDBPath.cxx:201
 AliCDBPath.cxx:202
 AliCDBPath.cxx:203
 AliCDBPath.cxx:204
 AliCDBPath.cxx:205
 AliCDBPath.cxx:206
 AliCDBPath.cxx:207
 AliCDBPath.cxx:208
 AliCDBPath.cxx:209
 AliCDBPath.cxx:210
 AliCDBPath.cxx:211
 AliCDBPath.cxx:212
 AliCDBPath.cxx:213
 AliCDBPath.cxx:214
 AliCDBPath.cxx:215
 AliCDBPath.cxx:216
 AliCDBPath.cxx:217
 AliCDBPath.cxx:218
 AliCDBPath.cxx:219
 AliCDBPath.cxx:220
 AliCDBPath.cxx:221
 AliCDBPath.cxx:222
 AliCDBPath.cxx:223
 AliCDBPath.cxx:224
 AliCDBPath.cxx:225
 AliCDBPath.cxx:226
 AliCDBPath.cxx:227
 AliCDBPath.cxx:228
 AliCDBPath.cxx:229
 AliCDBPath.cxx:230
 AliCDBPath.cxx:231
 AliCDBPath.cxx:232
 AliCDBPath.cxx:233
 AliCDBPath.cxx:234
 AliCDBPath.cxx:235
 AliCDBPath.cxx:236
 AliCDBPath.cxx:237
 AliCDBPath.cxx:238
 AliCDBPath.cxx:239
 AliCDBPath.cxx:240
 AliCDBPath.cxx:241
 AliCDBPath.cxx:242
 AliCDBPath.cxx:243
 AliCDBPath.cxx:244
 AliCDBPath.cxx:245
 AliCDBPath.cxx:246
 AliCDBPath.cxx:247
 AliCDBPath.cxx:248
 AliCDBPath.cxx:249
 AliCDBPath.cxx:250
 AliCDBPath.cxx:251
 AliCDBPath.cxx:252
 AliCDBPath.cxx:253
 AliCDBPath.cxx:254
 AliCDBPath.cxx:255
 AliCDBPath.cxx:256
 AliCDBPath.cxx:257
 AliCDBPath.cxx:258
 AliCDBPath.cxx:259
 AliCDBPath.cxx:260
 AliCDBPath.cxx:261
 AliCDBPath.cxx:262
 AliCDBPath.cxx:263
 AliCDBPath.cxx:264
 AliCDBPath.cxx:265
 AliCDBPath.cxx:266
 AliCDBPath.cxx:267
 AliCDBPath.cxx:268
 AliCDBPath.cxx:269
 AliCDBPath.cxx:270
 AliCDBPath.cxx:271
 AliCDBPath.cxx:272
 AliCDBPath.cxx:273
 AliCDBPath.cxx:274
 AliCDBPath.cxx:275
 AliCDBPath.cxx:276
 AliCDBPath.cxx:277