X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=STEER%2FCDB%2FAliCDBGrid.cxx;h=7c4a1adab6f3f63a709816eda0188892b850da17;hb=15e24252901bea35f225097c9a23086df5bdc2d4;hp=f2066f3db06707f84b526d256cbe2309b2f700ab;hpb=efeb899928399b3796d9f82fdf8c42d87f524192;p=u%2Fmrichter%2FAliRoot.git diff --git a/STEER/CDB/AliCDBGrid.cxx b/STEER/CDB/AliCDBGrid.cxx index f2066f3db06..7c4a1adab6f 100644 --- a/STEER/CDB/AliCDBGrid.cxx +++ b/STEER/CDB/AliCDBGrid.cxx @@ -727,7 +727,7 @@ Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry, const char* mirrors) { // build filename from entry's id TString filename; if (!IdToFilename(id, filename)) { - AliError("Bad ID encountered! Subnormal error!"); + AliError("Bad ID encountered, cannot make a file name out of it!"); return kFALSE; } @@ -754,25 +754,26 @@ Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry, const char* mirrors) { } // open file - TFile *file=0; + TFile *file = 0; + TFile *reopenedFile = 0; AliDebug(2, Form("fNretry = %d, fInitRetrySeconds = %d",fNretry,fInitRetrySeconds)); TString targetSE(""); Bool_t result = kFALSE; Bool_t reOpenResult = kFALSE; Int_t reOpenAttempts=0; - while( !reOpenResult && reOpenAttempts<2){ //loop to check the file after closing it, to catch the unlikely but possible case when the file + while( !reOpenResult && reOpenAttempts<2 ) { //loop to check the file after closing it, to catch the unlikely but possible case when the file // is cleaned up by alien just before closing as a consequence of a network disconnection while writing - while( !file && remainingSEs>0){ + while( !file && remainingSEs>0 ) { if(nSEs!=0){ TObjString *target = (TObjString*) arraySEs->At(nSEs-remainingSEs); targetSE=target->String(); if ( !(targetSE.BeginsWith("ALICE::") && targetSE.CountChar(':')==4) ) { - AliError(Form("\"%s\" is an invalid storage element identifier.",targetSE.Data())); + AliError( Form("\"%s\" is an invalid storage element identifier.",targetSE.Data()) ); continue; } - if(fullFilename.Contains('?')) fullFilename.Remove(fullFilename.Last('?')); + if ( fullFilename.Contains('?')) fullFilename.Remove(fullFilename.Last('?') ); fullFilename += Form("?se=%s",targetSE.Data()); } Int_t remainingAttempts=fNretry; @@ -783,7 +784,9 @@ Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry, const char* mirrors) { remainingAttempts--; file = TFile::Open(fullFilename,"CREATE"); if(!file || !file->IsWritable()){ - if(file) file->Close(); delete file; file=0; // file is not writable + if(file) { // file is not writable + file->Close(); delete file; file=0; + } TString message(TString::Format("Attempt %d failed.",fNretry-remainingAttempts)); if(remainingAttempts>0) { message += " Sleeping for "; message += nsleep; message += " seconds"; @@ -811,14 +814,13 @@ Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry, const char* mirrors) { // write object (key name: "AliCDBEntry") result = (file->WriteTObject(entry, "AliCDBEntry") != 0); - if (!result) AliError(Form("Can't write entry to file <%s>!", filename.Data())); file->Close(); - - if(result) - { + if (!result) { + AliError(Form("Can't write entry to file <%s>!", filename.Data())); + } else { AliDebug(2, Form("Reopening file %s for checking its correctness",fullFilename.Data())); - TFile* ffile = TFile::Open(fullFilename.Data(),"READ"); - if(!ffile){ + reopenedFile = TFile::Open(fullFilename.Data(),"READ"); + if(!reopenedFile){ reOpenResult = kFALSE; AliInfo(Form("The file %s was closed successfully but cannot be reopened. Trying now to regenerate it (regeneration attempt number %d)", fullFilename.Data(),++reOpenAttempts)); @@ -829,9 +831,11 @@ Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry, const char* mirrors) { remainingSEs++; }else{ reOpenResult = kTRUE; - ffile->Close(); + if ( ! AliCDBManager::Instance()->IsOCDBUploadMode() ) { + reopenedFile->Close(); + delete reopenedFile; reopenedFile=0; + } } - delete ffile; ffile=0; } } @@ -849,7 +853,7 @@ Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry, const char* mirrors) { TagFileMetaData(filename, entry->GetMetaData()); }else{ - AliError("The file could not be opend or the object could not be written"); + AliError("The file could not be opened or the object could not be written."); if(!gGrid->Rm(filename.Data())) AliError("Can't delete file!"); return kFALSE; @@ -876,6 +880,81 @@ Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry, const char* mirrors) { } arraySEs->Delete(); arraySEs=0; + if ( AliCDBManager::Instance()->IsOCDBUploadMode() ) { // if uploading to OCDBs, add to cvmfs too + if ( !filename.BeginsWith("/alice/data") && !filename.BeginsWith("/alice/simulation/2008/v4-15-Release") ) { + AliError ( Form ( "Cannot upload to CVMFS OCDBs a non official CDB object: \"%s\"!", filename.Data() ) ); + } else { + if ( !PutInCvmfs( filename, reopenedFile) ) + AliError( Form( "Could not upload AliEn file \"%s\" to CVMFS OCDB!", filename.Data() ) ); + } + reopenedFile->Close(); + delete reopenedFile; reopenedFile=0; + } + + return kTRUE; +} + +//_____________________________________________________________________________ +Bool_t AliCDBGrid::PutInCvmfs( TString& filename, TFile* cdbFile ) const +{ + // Add the CDB object to cvmfs OCDB + + TString cvmfsFilename( filename ); + // cvmfsFilename.Remove(TString::kTrailing, '/'); + TString basename = ( cvmfsFilename( cvmfsFilename.Last( '/' ) + 1, cvmfsFilename.Length() ) ); + TString cvmfsDirname = cvmfsFilename.Remove( cvmfsFilename.Last( '/' ), cvmfsFilename.Length() ); + TRegexp threeLevelsRE( "[^/]+/[^/]+/[^/]+$" ); + TString threeLevels = cvmfsDirname( threeLevelsRE ); + + TRegexp re_RawFolder("^/alice/data/20[0-9]+/OCDB"); + TRegexp re_MCFolder("^/alice/simulation/2008/v4-15-Release"); + TString rawFolder = cvmfsDirname(re_RawFolder); + TString mcFolder = cvmfsDirname(re_MCFolder); + if ( !rawFolder.IsNull() ) { + cvmfsDirname.Replace(0, 6, "/cvmfs/alice-ocdb.cern.ch/calibration"); + } else if ( !mcFolder.IsNull() ){ + cvmfsDirname.Replace(0,36,"/cvmfs/alice-ocdb.cern.ch/calibration/MC"); + } else { + AliError(Form("OCDB folder set for an invalid OCDB storage:\n %s", cvmfsDirname.Data())); + return kFALSE; + } + // now cvmfsDirname is the full dirname in cvmfs + AliDebug(3, Form("Publishing \"%s\" in \"%s\"", basename.Data(), cvmfsDirname.Data())); + + // Tar the file with the right prefix path. Include the directory structure in the tarball + // to cover the case of a containing directory being new in cvmfs, plus a container directory + // to avoid clashing with stuff present in the local directory + TString firstLevel(threeLevels(0, threeLevels.First('/'))); + TString tempDir("tmpToCvmfsOcdbs"); + gSystem->Exec( Form("rm -r %s > /dev/null 2>&1", tempDir.Data()) ); //to be sure not to publish other stuff in cvmfs + Int_t result = gSystem->Exec( Form("mkdir -p %s/%s", tempDir.Data(), threeLevels.Data()) ); + if ( result != 0 ) { + AliError ( Form ( "Could not create the directory \"%s/%s\"", tempDir.Data(), threeLevels.Data() ) ); + return kFALSE; + } + cdbFile->Cp(Form("%s/%s/%s", tempDir.Data(), threeLevels.Data(), basename.Data() )); + TString tarFileName("cdbObjectToAdd.tar.gz"); + TString cvmfsBaseFolder(cvmfsDirname(0, cvmfsDirname.Last('/'))); + cvmfsBaseFolder = cvmfsBaseFolder(0, cvmfsBaseFolder.Last('/')); + cvmfsBaseFolder = cvmfsBaseFolder(0, cvmfsBaseFolder.Last('/')); + // tarCommand should be e.g.: tar --transform 's,^,/cvmfs/alice-ocdb.cern.ch/calibration/data/2010/OCDB/,S' -cvzf objecttoadd.tar.gz basename + result = gSystem->Exec ( Form( "tar --transform 's,^%s,%s,S' -cvzf %s %s", tempDir.Data(), cvmfsBaseFolder.Data(), tarFileName.Data(), tempDir.Data() ) ); + if ( result != 0 ) { + AliError ( Form ( "Could not create the tarball for the object \"%s\"", filename.Data() ) ); + return kFALSE; + } + + // Copy the file to cvmfs (requires to have the executable in the path and access to the server) + result = gSystem->Exec( Form( "ocdb-cvmfs %s", tarFileName.Data() ) ); + if ( result != 0 ) { + AliError ( Form ( "Could not execute \"ocdb-cvmfs %s\"", filename.Data() ) ); + return kFALSE; + } + + // Remove the local file and the tar-file + gSystem->Exec( Form( "rm -r %s", tempDir.Data() ) ); + gSystem->Exec( Form( "rm %s", tarFileName.Data() ) ); + return kTRUE; }