LCOV - code coverage report
Current view: top level - STEER/CDB - AliCDBPath.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 116 132 87.9 %
Date: 2016-06-14 17:26:59 Functions: 20 22 90.9 %

          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 AliCDBPath                                               //
      19             : //  Path string identifying the object:                            //
      20             : //  "level0/level1/level2"                                       //
      21             : //  (was: "Detector/DBType/DetSpecType")                         //
      22             : //  (example: "ZDC/Calib/Pedestals")                             //
      23             : //                                                                 //
      24             : /////////////////////////////////////////////////////////////////////
      25             : 
      26             : #include "AliCDBPath.h"
      27             : 
      28             : #include <TObjArray.h>
      29             : #include <TObjString.h>
      30             : #include <TRegexp.h>
      31             : 
      32             : #include "AliLog.h"
      33             : 
      34         128 : ClassImp(AliCDBPath)
      35             : 
      36             : //_____________________________________________________________________________
      37             : AliCDBPath::AliCDBPath() :
      38        2746 :   TObject(),
      39        2746 :   fPath(""),
      40        2746 :   fLevel0(""),
      41        2746 :   fLevel1(""),
      42        2746 :   fLevel2(""),
      43        2746 :   fIsValid(kTRUE),
      44        2746 :   fIsWildcard(kFALSE)
      45       13730 : {
      46             :   // default constructor
      47             : 
      48        5492 : }
      49             : 
      50             : //_____________________________________________________________________________
      51             : AliCDBPath::AliCDBPath(const AliCDBPath& other):
      52       24084 :   TObject(other),
      53       24084 :   fPath(other.fPath),
      54       24084 :   fLevel0(""),
      55       24084 :   fLevel1(""),
      56       24084 :   fLevel2(""),
      57       24084 :   fIsValid(other.fIsValid),
      58       24084 :   fIsWildcard(other.fIsWildcard)
      59      120420 : {
      60             :   // constructor
      61       24084 :   Init();
      62       24084 :   InitPath();
      63             : 
      64       48168 : }
      65             : 
      66             : //_____________________________________________________________________________
      67             : AliCDBPath::AliCDBPath(const char* level0, const char* level1,
      68             :     const char* level2):
      69        1726 :   TObject(),
      70        1726 :   fPath(""),
      71        1726 :   fLevel0(level0), 
      72        1726 :   fLevel1(level1), 
      73        1726 :   fLevel2(level2),
      74        1726 :   fIsValid(kTRUE),
      75        1726 :   fIsWildcard(kFALSE)
      76        8630 : {
      77             :   // constructor
      78             : 
      79        1726 :   fPath += level0;
      80        1726 :   fPath += '/';
      81        1726 :   fPath += level1;
      82        1726 :   fPath += '/';
      83        1726 :   fPath += level2;
      84             : 
      85        3452 :   if ((IsWord(fLevel0) || fLevel0 == "*")
      86        3452 :       && (IsWord(fLevel1) || fLevel1 == "*")
      87        3452 :       && (IsWord(fLevel2) || fLevel2 == "*")) {
      88             : 
      89        1726 :     fIsValid = kTRUE;
      90        1726 :   } else {
      91           0 :     fIsValid = kFALSE;
      92           0 :     AliError(Form("Invalid AliCDBPath <%s/%s/%s>!", 
      93             :           level0, level1, level2));
      94             :   }
      95             : 
      96        1726 :   Init();
      97        3452 : }
      98             : 
      99             : //_____________________________________________________________________________
     100             : AliCDBPath::AliCDBPath(const char* path):
     101        2299 :   TObject(),
     102        2299 :   fPath(path),
     103        2299 :   fLevel0(""),
     104        2299 :   fLevel1(""),
     105        2299 :   fLevel2(""),
     106        2299 :   fIsValid(kTRUE),
     107        2299 :   fIsWildcard(kFALSE)
     108       11495 : {
     109             :   // constructor
     110             : 
     111        2299 :   Init();
     112        2299 :   InitPath();   
     113        4598 : }
     114             : 
     115             : //_____________________________________________________________________________
     116             : AliCDBPath::AliCDBPath(const TString& path):
     117         917 :   TObject(),
     118         917 :   fPath(path),
     119         917 :   fLevel0(""),
     120         917 :   fLevel1(""),
     121         917 :   fLevel2(""),
     122         917 :   fIsValid(kTRUE),
     123         917 :   fIsWildcard(kFALSE)
     124        4585 : {
     125         917 :   Init();
     126         917 :   InitPath();
     127        1834 : }
     128             : 
     129             : //_____________________________________________________________________________
     130             : void AliCDBPath::InitPath() {
     131             :   // sets fLevel0, fLevel1, fLevel2, validity flagss from fPath
     132             : 
     133       57184 :   TSubString strippedString = fPath.Strip(TString::kBoth);
     134       28592 :   TString aString(strippedString);
     135       57184 :   strippedString = aString.Strip(TString::kBoth, '/');
     136             : 
     137      114368 :   TObjArray* anArray = TString(strippedString).Tokenize("/");
     138       28592 :   Int_t paramCount = anArray->GetEntriesFast();
     139             : 
     140       28592 :   if (paramCount == 1) {
     141          20 :     if (fPath == "*") {
     142          10 :       fLevel0 = "*";
     143          10 :       fLevel1 = "*";
     144          10 :       fLevel2 = "*";
     145             : 
     146          10 :       fIsValid = kTRUE;
     147          10 :     } else {
     148           0 :       fIsValid = kFALSE;
     149             :     }
     150             : 
     151       28582 :   } else if (paramCount == 2) {
     152          12 :     fLevel0 = ((TObjString*) anArray->At(0))->GetString();
     153           6 :     TString bString =  ((TObjString*) anArray->At(1))->GetString();
     154             : 
     155          12 :     if (IsWord(fLevel0) && bString == "*") {
     156           0 :       fLevel1 = "*";
     157           0 :       fLevel2 = "*";
     158             : 
     159           0 :       fIsValid = kTRUE;                 
     160             : 
     161           0 :     } else {
     162           3 :       fIsValid = kFALSE;
     163             :     }
     164             : 
     165       28582 :   } else if (paramCount == 3) {
     166      114316 :     fLevel0 = ((TObjString*) anArray->At(0))->GetString();
     167      114316 :     fLevel1 = ((TObjString*) anArray->At(1))->GetString();
     168      114316 :     fLevel2 = ((TObjString*) anArray->At(2))->GetString();
     169             : 
     170       57418 :     if ((IsWord(fLevel0) || fLevel0 == "*")
     171       57176 :         && (IsWord(fLevel1) || fLevel1 == "*")
     172       57432 :         && (IsWord(fLevel2) || fLevel2 == "*")) {
     173             : 
     174       28579 :       fIsValid = kTRUE;
     175       28579 :     } else {
     176           0 :       fIsValid = kFALSE;
     177             :     }
     178             : 
     179             :   } else {
     180           0 :     fIsValid = kFALSE;
     181             : 
     182             :   }
     183             : 
     184       28592 :   if (!fIsValid) {
     185          12 :     AliInfo(Form("Invalid AliCDBPath <%s>!", fPath.Data()));
     186             :   } else {      
     187      142945 :     fPath = Form("%s/%s/%s", fLevel0.Data(), fLevel1.Data(), fLevel2.Data());
     188             :   }
     189             : 
     190       57184 :   delete anArray;
     191             : 
     192       28592 :   Init();
     193       28592 : }
     194             : 
     195             : //_____________________________________________________________________________
     196      117580 : AliCDBPath::~AliCDBPath() {
     197             :   // destructor
     198             : 
     199       58790 : }
     200             : 
     201             : //_____________________________________________________________________________
     202             : Bool_t AliCDBPath::IsWord(const TString& str) {
     203             :   // check if string is a word
     204      181851 :   static const TRegexp pattern("^[a-zA-Z0-9_.-]+$");
     205             : 
     206       90918 :   return str.Contains(pattern); 
     207           0 : }
     208             : 
     209             : //_____________________________________________________________________________
     210             : void AliCDBPath::Init() {
     211             :   // set fIsWildcard flag
     212             : 
     213      115236 :   fIsWildcard = fPath.MaybeWildcard();  
     214       57618 : }
     215             : 
     216             : //_____________________________________________________________________________
     217             : Bool_t AliCDBPath::Level0Comprises(const TString& str) const {
     218             :   // check if Level0 is wildcard or is equal to str
     219             : 
     220       44612 :   if (fLevel0 == "*") {
     221         152 :     return kTRUE;
     222             :   }
     223             : 
     224       22154 :   return fLevel0 == str;
     225       22306 : }
     226             : 
     227             : //_____________________________________________________________________________
     228             : Bool_t AliCDBPath::Level1Comprises(const TString& str) const {
     229             :   // check if Level1 is wildcard or is equal to str
     230             : 
     231        3338 :   if (fLevel1 == "*") {
     232         435 :     return kTRUE;
     233             :   }
     234             : 
     235        1234 :   return fLevel1 == str;
     236        1669 : }
     237             : 
     238             : //_____________________________________________________________________________
     239             : Bool_t AliCDBPath::Level2Comprises(const TString& str) const {
     240             :   // check if Level2 is wildcard or is equal to str
     241             : 
     242        4450 :   if (fLevel2 == "*") {
     243        2202 :     return kTRUE;
     244             :   }
     245             : 
     246          23 :   return fLevel2 == str;
     247        2225 : }
     248             : 
     249             : //_____________________________________________________________________________
     250             : Bool_t AliCDBPath::Comprises(const AliCDBPath& other) const {
     251             :   // check if path is wildcard and comprises other
     252             : 
     253       64773 :   return Level0Comprises(other.fLevel0)
     254       22961 :     && Level1Comprises(other.fLevel1)
     255        1956 :     && Level2Comprises(other.fLevel2);
     256             : }
     257             : 
     258             : //_____________________________________________________________________________
     259             : const char* AliCDBPath::GetLevel(Int_t i) const {
     260             :   // return level i of the path
     261             : 
     262           0 :   switch (i) {
     263             :     case 0:
     264           0 :       return fLevel0.Data();
     265             :       break;
     266             :     case 1:
     267           0 :       return fLevel1.Data();
     268             :       break;
     269             :     case 2:
     270           0 :       return fLevel2.Data();
     271             :       break;
     272             :     default:
     273           0 :       return 0;
     274             :   }
     275             : 
     276           0 : }

Generated by: LCOV version 1.11