]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliCDBDump.cxx
Updated version of the CDB classes. Bug fix in AliCDBGrid. New AliCDBStorage function...
[u/mrichter/AliRoot.git] / STEER / AliCDBDump.cxx
index 552c6da8f9164b48fd00990032a807b49f7bf0b4..d40bb51f981fb0db87d0236f44b085223e77c68a 100644 (file)
@@ -46,6 +46,9 @@ fFile(NULL), fReadOnly(readOnly) {
                AliDebug(2,Form("File <%s> opened",dbFile));
                if(fReadOnly) AliDebug(2,Form("in read-only mode"));
        }
+
+       fType="dump";
+       fBaseFolder = dbFile;
 }
 
 //_____________________________________________________________________________
@@ -97,18 +100,18 @@ Bool_t AliCDBDump::IdToKeyName(const AliCDBRunRange& runRange, Int_t version,
 // build key name from AliCDBId data (run range, version, subVersion)
 
         if (!runRange.IsValid()) {
-                AliWarning(Form("Invalid run range <%d, %d>.",
+                AliDebug(2,Form("Invalid run range <%d, %d>.",
                         runRange.GetFirstRun(), runRange.GetLastRun()));
                 return kFALSE;
         }
 
         if (version < 0) {
-                AliWarning(Form("Invalid version <%d>.", version));
+                AliDebug(2,Form("Invalid version <%d>.", version));
                 return kFALSE;
         }
 
        if (subVersion < 0) {
-               AliWarning(Form("Invalid subversion <%s>.", subVersion));
+               AliDebug(2,Form("Invalid subversion <%s>.", subVersion));
                return kFALSE;
        }
     
@@ -181,7 +184,7 @@ Bool_t AliCDBDump::PrepareId(AliCDBId& id) {
        
                        if (!KeyNameToId(keyName, aRunRange, aVersion, 
                           aSubVersion)) {
-                               AliWarning(Form(
+                               AliDebug(2,Form(
                                        "Bad keyname <%s>!I'll skip it.", keyName));
                                continue;
                        }
@@ -206,7 +209,7 @@ Bool_t AliCDBDump::PrepareId(AliCDBId& id) {
        
                        if (!KeyNameToId(keyName, aRunRange, aVersion, 
                           aSubVersion)) {
-                               AliWarning(Form(
+                               AliDebug(2,Form(
                                        "Bad keyname <%s>!I'll skip it.", keyName));
                                continue;
                        }
@@ -233,9 +236,9 @@ Bool_t AliCDBDump::PrepareId(AliCDBId& id) {
 
        if(lastStorage.Contains(TString("new"), TString::kIgnoreCase) &&
           id.GetSubVersion() > 0 ){
-               AliWarning(Form("*** WARNING! a NEW object is being stored with version v%d_s%d",
+               AliDebug(2, Form("A NEW object is being stored with version v%d_s%d",
                                        id.GetVersion(),id.GetSubVersion()));
-               AliWarning(Form("and it will hide previously stored object with v%d_s%d!",
+               AliDebug(2, Form("and it will hide previously stored object with v%d_s%d!",
                                        id.GetVersion(),id.GetSubVersion()-1));
        }
 
@@ -250,10 +253,9 @@ Bool_t AliCDBDump::PrepareId(AliCDBId& id) {
 
 
 //_____________________________________________________________________________
-AliCDBId AliCDBDump::GetId(const AliCDBId& query) {
+Bool_t AliCDBDump::GetId(const AliCDBId& query, AliCDBId& result) {
 // look for filename matching query (called by GetEntry)
 
-        AliCDBId result(query.GetAliCDBPath(), -1, -1, -1, -1);
 
         AliCDBRunRange aRunRange; // the runRange got from filename
         Int_t aVersion, aSubVersion; // the version and subVersion got from filename
@@ -292,10 +294,10 @@ AliCDBId AliCDBDump::GetId(const AliCDBId& query) {
                                        aRunRange.GetLastRun());
                        } else if (result.GetVersion() == aVersion
                                && result.GetSubVersion() == aSubVersion){
-                               AliError(Form("More than one object valid for run %d, version %d_%d!", 
+                               AliDebug(2,Form("More than one object valid for run %d, version %d_%d!", 
                                        query.GetFirstRun(), aVersion, aSubVersion));
                                result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1);
-                               return result
+                               return kFALSE
                                }
                }
                
@@ -315,10 +317,10 @@ AliCDBId AliCDBDump::GetId(const AliCDBId& query) {
                        // aVersion is requested version!
                        
                        if(result.GetSubVersion() == aSubVersion){
-                               AliError(Form("More than one object valid for run %d, version %d_%d!", 
+                               AliDebug(2,Form("More than one object valid for run %d, version %d_%d!", 
                                        query.GetFirstRun(), aVersion, aSubVersion));
                                result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1);
-                               return result
+                               return kFALSE
                        }
                        if( result.GetSubVersion() < aSubVersion) {
 
@@ -345,10 +347,10 @@ AliCDBId AliCDBDump::GetId(const AliCDBId& query) {
                        // aVersion and aSubVersion are requested version and subVersion!
 
                        if(result.GetVersion() == aVersion && result.GetSubVersion() == aSubVersion){
-                               AliError(Form("More than one object valid for run %d, version %d_%d!", 
+                               AliDebug(2,Form("More than one object valid for run %d, version %d_%d!", 
                                        query.GetFirstRun(), aVersion, aSubVersion));
                                result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1);
-                               return result
+                               return kFALSE
                        }
                        result.SetVersion(aVersion);
                        result.SetSubVersion(aSubVersion);
@@ -358,11 +360,11 @@ AliCDBId AliCDBDump::GetId(const AliCDBId& query) {
                }
        }
 
-       return result;
+       return kTRUE;
 }
 
 //_____________________________________________________________________________
-AliCDBEntry* AliCDBDump::GetEntry(const AliCDBId& query) {
+AliCDBEntry* AliCDBDump::GetEntry(const AliCDBId& queryId) {
 // get AliCDBEntry from the database
 
        TDirectory::TContext context(gDirectory, fFile);
@@ -372,28 +374,31 @@ AliCDBEntry* AliCDBDump::GetEntry(const AliCDBId& query) {
                 return NULL;
         }
 
-        if (!gDirectory->cd(query.GetPath())) {
+        if (!gDirectory->cd(queryId.GetPath())) {
                 return NULL;
         }
 
-       AliCDBId dataId;
+       AliCDBId dataId(queryId.GetAliCDBPath(), -1, -1, -1, -1);
+        Bool_t result;
 
        // look for a filename matching query requests (path, runRange, version, subVersion)
-       if (!query.HasVersion()) {
+       if (!queryId.HasVersion()) {
                // if version is not specified, first check the selection criteria list
-               dataId = GetId(GetSelection(query));
+               AliCDBId selectedId(queryId);
+               GetSelection(&selectedId);
+               result = GetId(selectedId, dataId);
        } else {
-               dataId = GetId(query);
+               result = GetId(queryId, dataId);
        }
 
-       if (!dataId.IsSpecified()) {
+       if (!result || !dataId.IsSpecified()) {
                return NULL;
        }
        
        TString keyname;
        if (!IdToKeyName(dataId.GetAliCDBRunRange(), dataId.GetVersion(), 
                dataId.GetSubVersion(), keyname)) {
-               AliError("Bad ID encountered! Subnormal error!");
+               AliDebug(2,Form("Bad ID encountered! Subnormal error!"));
                return NULL;
        }
 
@@ -403,12 +408,12 @@ AliCDBEntry* AliCDBDump::GetEntry(const AliCDBId& query) {
 
        TObject* anObject = gDirectory->Get(keyname);
        if (!anObject) {
-               AliError("Bad storage data: NULL entry object!");
+               AliDebug(2,Form("Bad storage data: NULL entry object!"));
                return NULL;
        } 
 
        if (AliCDBEntry::Class() != anObject->IsA()) {
-               AliError("Bad storage data: Invalid entry object!");
+               AliDebug(2,Form("Bad storage data: Invalid entry object!"));
                return NULL;
        }
 
@@ -540,17 +545,118 @@ Bool_t AliCDBDump::PutEntry(AliCDBEntry* entry) {
        // write object (key name: Run#firstRun_#lastRun_v#version_s#subVersion)
        Bool_t result = gDirectory->WriteTObject(entry, keyname);
        if (!result) {
-               AliError(Form("Can't write entry to file: %s", 
+               AliError(Form("Can't write entry to file: %s",
                                fFile->GetName()));
        }
 
         if(result) {
-               AliInfo(Form("AliCDBEntry stored into file %s",fFile->GetName()));
+               AliInfo(Form("CDB object stored into file %s",fFile->GetName()));
                AliInfo(Form("TDirectory/key name: %s/%s",id.GetPath().Data(),keyname.Data()));
         }
 
        return result;
 }
+//_____________________________________________________________________________
+TList* AliCDBDump::GetIdListFromFile(const char* fileName){
+
+       TString turl(fileName);
+       if (turl[0] != '/') {
+               turl.Prepend(TString(gSystem->WorkingDirectory()) + '/');
+       }
+       TFile *file = TFile::Open(turl);
+       if (!file) {
+               AliError(Form("Can't open selection file <%s>!", turl.Data()));
+               return NULL;
+       }
+       file->cd();
+
+       TList *list = new TList();
+       list->SetOwner();
+       int i=0;
+       TString keycycle;
+       
+       AliCDBId *id;
+       while(1){
+               i++;
+               keycycle = "AliCDBId;";
+               keycycle+=i;
+               
+               id = (AliCDBId*) file->Get(keycycle);
+               if(!id) break;
+               list->AddFirst(id);
+       }
+       file->Close(); delete file; file=0;     
+       return list;
+}
+
+//_____________________________________________________________________________
+Bool_t AliCDBDump::Contains(const char* path) const{
+// check for path in storage
+
+       TDirectory::TContext context(gDirectory, fFile);
+       if (!(fFile && fFile->IsOpen())) {
+                AliError("AliCDBDump storage is not initialized properly");
+                return kFALSE;
+        }
+       
+       return gDirectory->cd(path);
+
+}
+
+//_____________________________________________________________________________
+void AliCDBDump::QueryValidFiles()
+{
+// Query the CDB for files valid for AliCDBStorage::fRun
+// fills list fValidFileIds with AliCDBId objects created from file name
+
+       AliError("Not yet (and maybe never) implemented");
+}
+
+//_____________________________________________________________________________
+Bool_t AliCDBDump::IdToFilename(const AliCDBId& /*id*/, TString& /*filename*/) const {
+// build file name from AliCDBId (path, run range, version) and fDBFolder
+
+       AliError("Not implemented");
+        return kFALSE;
+}
+
+//_____________________________________________________________________________
+Int_t AliCDBDump::GetLatestVersion(const char* path, Int_t run){
+// get last version found in the database valid for run and path
+
+       AliCDBPath aCDBPath(path);
+       if(!aCDBPath.IsValid() || aCDBPath.IsWildcard()) {
+               AliError(Form("Invalid path in request: %s", path));
+               return -1;
+       }
+
+       AliCDBId query(path, run, run, -1, -1);
+       AliCDBId dataId;
+
+       GetId(query,dataId);
+
+       return dataId.GetVersion();
+}
+
+//_____________________________________________________________________________
+Int_t AliCDBDump::GetLatestSubVersion(const char* path, Int_t run, Int_t version){
+// get last version found in the database valid for run and path
+
+       AliCDBPath aCDBPath(path);
+       if(!aCDBPath.IsValid() || aCDBPath.IsWildcard()) {
+               AliError(Form("Invalid path in request: %s", path));
+               return -1;
+       }
+
+       AliCDBId query(path, run, run, version, -1);
+       AliCDBId dataId;
+
+       GetId(query,dataId);
+
+       return dataId.GetSubVersion();
+
+}
+
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //                                                                                             //
@@ -594,8 +700,6 @@ AliCDBParam* AliCDBDumpFactory::CreateParameter(const char* dbString) {
                pathname.Prepend(TString(gSystem->WorkingDirectory()) + '/');
        }
 
-        AliInfo(pathname);
-
         return new AliCDBDumpParam(pathname, readOnly);
 }
 
@@ -624,7 +728,9 @@ AliCDBStorage* AliCDBDumpFactory::Create(const AliCDBParam* param) {
 ClassImp(AliCDBDumpParam)
 
 //_____________________________________________________________________________
-AliCDBDumpParam::AliCDBDumpParam() {
+AliCDBDumpParam::AliCDBDumpParam():
+fDBPath(), fReadOnly(kFALSE)
+{
 // default constructor
 
 }