]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliCDBId.cxx
Fix fixed-string length bug
[u/mrichter/AliRoot.git] / STEER / AliCDBId.cxx
index a5053da1cd9cf6800b442d91bada4f8854aec3c0..85bd2883d07bf931661241052d234d8b6570e4f6 100644 (file)
@@ -22,6 +22,9 @@
 /////////////////////////////////////////////////////////////////////
 
 #include "AliCDBId.h"
+#include <Riostream.h>
+#include <TObjArray.h>
+#include <TObjString.h>
 
 ClassImp(AliCDBId)
 
@@ -76,6 +79,50 @@ fLastStorage("new")
 
 }
 
+//_____________________________________________________________________________
+AliCDBId* AliCDBId::MakeFromString(const TString& idString)
+{
+// constructor from string 
+// string has the format as the output of AliCDBId::ToString:
+// path: "TRD/Calib/PIDLQ"; run range: [0,999999999]; version: v0_s0
+
+       AliCDBId* id = new AliCDBId("a/b/c",-1,-1,-1,-1);
+       
+       TObjArray* arr1 = idString.Tokenize(';');
+       TIter iter1(arr1);
+       TObjString *objStr1 = 0;
+       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->SetRunRange(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;
+
+}
+
 //_____________________________________________________________________________
 AliCDBId::~AliCDBId() {
 //destructor
@@ -121,3 +168,11 @@ TString AliCDBId::ToString() const {
        if(GetSubVersion() >= 0) result += Form("_s%d", GetSubVersion());
        return result;
 }
+
+//_____________________________________________________________________________
+void AliCDBId::Print(Option_t* /*option*/) const {
+// Prints ToString()
+
+       cout << ToString().Data() << endl;
+
+}