From: rgrosso Date: Thu, 13 Dec 2012 15:01:59 +0000 (+0000) Subject: method DiffObjects introduced, returning kTRUE only if the object contained in the... X-Git-Url: http://git.uio.no/git/?a=commitdiff_plain;h=a37a1dfce85c4b16610cd0322ffaf68ce9bdfaf3;p=u%2Fmrichter%2FAliRoot.git method DiffObjects introduced, returning kTRUE only if the object contained in the CDB entry of two files are exactly the same (Marian) --- diff --git a/STEER/CDB/AliCDBManager.cxx b/STEER/CDB/AliCDBManager.cxx index 045a09995f4..5d4c00e6fec 100644 --- a/STEER/CDB/AliCDBManager.cxx +++ b/STEER/CDB/AliCDBManager.cxx @@ -35,6 +35,8 @@ #include #include #include +#include "TMessage.h" +#include "TObject.h" ClassImp(AliCDBParam) @@ -1553,6 +1555,73 @@ const char* AliCDBManager::GetDataTypeName(DataType type) } +//______________________________________________________________________________________________ +Bool_t AliCDBManager::DiffObjects(const char *cdbFile1, const char *cdbFile2) const +{ + // Compare byte-by-byte the objects contained in the CDB entry in two different files, + // whose name is passed as input + // Return value: + // kTRUE - in case the content of the OCDB object (persistent part) is exactly the same + // kFALSE - otherwise + + TString f1Str(cdbFile1); + TString f2Str(cdbFile2); + if (!gGrid && ( f1Str.BeginsWith("alien://") || f2Str.BeginsWith("alien://") )) + TGrid::Connect("alien://"); + + TFile * f1 = TFile::Open(cdbFile1); + if (!f1){ + Printf("Cannot open file \"%s\"",cdbFile1); + return kFALSE; + } + TFile * f2 = TFile::Open(cdbFile2); + if (!f2){ + Printf("Cannot open file \"%s\"",cdbFile2); + return kFALSE; + } + + AliCDBEntry * entry1 = (AliCDBEntry*)f1->Get("AliCDBEntry"); + if (!entry1){ + Printf("Cannot get CDB entry from file \"%s\"",cdbFile1); + return kFALSE; + } + AliCDBEntry * entry2 = (AliCDBEntry*)f2->Get("AliCDBEntry"); + if (!entry2){ + Printf("Cannot get CDB entry from file \"%s\"",cdbFile2); + return kFALSE; + } + + // stream the two objects in the buffer of two TMessages + TObject* object1 = entry1->GetObject(); + TObject* object2 = entry2->GetObject(); + TMessage * file1 = new TMessage(TBuffer::kWrite); + file1->WriteObject(object1); + Int_t size1 = file1->Length(); + TMessage * file2 = new TMessage(TBuffer::kWrite); + file2->WriteObject(object2); + Int_t size2 = file2->Length(); + if (size1!=size2){ + Printf("Problem 2: OCDB entry of different size (%d,%d)",size1,size2); + return kFALSE; + } + + // if the two buffers have the same size, check that they are the same byte-by-byte + Int_t countDiff=0; + char* buf1 = file1->Buffer(); + char* buf2 = file2->Buffer(); + //for (Int_t i=0; iBuffer()[i]!=file2->Buffer()[i]) countDiff++; + for(Int_t i=0; i0){ + Printf("The CDB objects differ by %d bytes.", countDiff); + return kFALSE; + } + + Printf("The CDB objects are the same in the two files."); + return kTRUE; +} + //______________________________________________________________________________________________ void AliCDBManager::InitShortLived() { diff --git a/STEER/CDB/AliCDBManager.h b/STEER/CDB/AliCDBManager.h index 58eaa325522..eb11b8acb04 100644 --- a/STEER/CDB/AliCDBManager.h +++ b/STEER/CDB/AliCDBManager.h @@ -135,6 +135,8 @@ class AliCDBManager: public TObject { Int_t GetEndRunLHCPeriod(); TString GetLHCPeriod(); + Bool_t DiffObjects(const char *cdbFile1, const char *cdbFile2) const; + protected: static TString fgkCondUri; // URI of the Conditions data base folder