LCOV - code coverage report
Current view: top level - STEER/CDB - AliOCDBtoolkit.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 405 0.0 %
Date: 2016-06-14 17:26:59 Functions: 0 19 0.0 %

          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             :   Primary goal of the proposal was to provide functionality to browse and compare the content of the OCDB
      19             :   specified by different means.
      20             : 
      21             :   a.) galice.root               - as currently implemented by Ruben in MC (or any file with cdbMap, and cdbList)
      22             :   b.) AliESDs.root              - for the reconstructed data
      23             :   c.) ocdb snapshot             - as used for grid productions
      24             :   d.) TMap(s)                   - as used internally in galice.root and AliESDs,root  
      25             :   e.) log file (if possible)    - looks logs aways used similar syntax, tested and working
      26             :   f.) C macro                   - custom macro
      27             : 
      28             :   Content comparison should be done:
      29             :   a.) on the level of symbolic links 
      30             :   b.) on the level of content itself 
      31             :   - by by byte comparison dif
      32             :   - data member by data member comparison
      33             : 
      34             :   Implementation assumption:
      35             :   All input formats (a .. f) will  be converted to the TMap storages and TList if AliCDBIds 
      36             : 
      37             :   Example usage:
      38             :   AliOCDBtoolkit::MakeDiffExampleUseCase();
      39             :   or from the AliOCDBtoolkit.sh in propmpt
      40             :   ocdbMakeTable AliESDs.root ESD OCDBrec.list
      41             :   ocdbMakeTable galice.root MC OCDBsim.list
      42             : 
      43             :   
      44             :    
      45             : 
      46             : 
      47             : 
      48             :   //=============================================================================
      49             :   // Functionality to dump content of  objects in human readable format
      50             :   //=============================================================================
      51             :   Use case examples 
      52             :   1.) compare oontent of alignent OCDB files for differnt yers
      53             :   2.) compare ClusterParam for different periods
      54             :   
      55             :   
      56             :    
      57             :   =================================================================================================================
      58             :   // 1.)
      59             :   // Compare alignment example:
      60             :   // Compare TPC alignemnt 2013 and 2010
      61             :   //
      62             :   AliOCDBtoolkit::DumpOCDBFile("/cvmfs/alice.gsi.de/alice/data/2013/OCDB/TPC/Align/Data/Run0_999999999_v1_s0.root","TPCalign2013.dump",1,1);
      63             :   AliOCDBtoolkit::DumpOCDBFile("/cvmfs/alice.gsi.de/alice/data/2010/OCDB/TPC/Align/Data/Run0_999999999_v1_s0.root","TPCalign2010.dump",1,1);
      64             :   diff  TPCalign2013.dump TPCalign2010.dump > TPCalign2013_TPCalign2010.diff
      65             :   //
      66             :   //    
      67             :   =================================================================================================================
      68             :   //  2.) 
      69             :   // Compare CluterParam OCDB etry
      70             :   //
      71             :   AliOCDBtoolkit::DumpOCDBFile("/cvmfs/alice.gsi.de/alice/data/2010/OCDB/TPC/Calib/ClusterParam/Run131541_999999999_v2_s0.root","2010_TPC_Calib_ClusterParam_Run131541_999999999_v2_s0.dump",1);
      72             :   AliOCDBtoolkit:: AliOCDBtoolkit::DumpOCDBFile("/cvmfs/alice.gsi.de/alice/data/2010/OCDB/TPC/Calib/ClusterParam/Run0_999999999_v1_s0.root","2010_TPC_Calib_ClusterParam_Run0_999999999_v1_s0.dump",1);
      73             :   AliOCDBtoolkit::DumpOCDBFile("/cvmfs/alice.gsi.de/alice/data/2013/OCDB/TPC/Calib/ClusterParam/Run0_999999999_v1_s0.root","2013_TPC_Calib_ClusterParam_Run0_999999999_v1_s0.dump",1);
      74             :   diff 2010_TPC_Calib_ClusterParam_Run131541_999999999_v2_s0.dump 2010_TPC_Calib_ClusterParam_Run0_999999999_v1_s0.dump
      75             :  
      76             : 
      77             : */
      78             : 
      79             : /*
      80             :   To check:
      81             :   1.) Verify hash value uasge as and MD5 sum - 
      82             : 
      83             :  */
      84             : 
      85             : 
      86             : // STD
      87             : #include <iostream>
      88             : #include <algorithm>
      89             : #include <sstream>
      90             : #include <stdexcept>
      91             : #include <functional>
      92             : #include "TRealData.h"
      93             : #include "TDataMember.h"
      94             : #include "TClass.h"
      95             : #include "TROOT.h"
      96             : #include <TVectorD.h>
      97             : //
      98             : #include "TSystem.h"
      99             : #include "TObjArray.h"
     100             : #include "TString.h"
     101             : #include "TTree.h"
     102             : #include "TMessage.h"
     103             : #include <TGrid.h>
     104             : //
     105             : #include "AliCDBManager.h"
     106             : #include "AliCDBEntry.h"
     107             : #include "AliOCDBtoolkit.h"
     108             : #include "AliCDBStorage.h"
     109             : #include "TRegexp.h"
     110             : 
     111             : using std::cout;
     112             : using std::cerr;
     113             : using std::endl;
     114             : using std::exception;
     115             : 
     116             : void AliOCDBtoolkit::MakeDiffExampleUseCase(){
     117             :   //
     118             :   // Example usage for the MC 
     119             :   // To run example case, assuming presence of following files in working directory: 
     120             :   //    - rec.log        
     121             :   //    - galice.root   
     122             :   //    - AliESDs.root
     123             :   //
     124           0 :   AliCDBManager * man = AliCDBManager::Instance();
     125           0 :   AliOCDBtoolkit::LoadOCDBFromLog("rec.log",0);
     126           0 :   const TMap *cdbMapLog= man->GetStorageMap();        // this is map of 
     127           0 :   const TList *cdbListLog=man->GetRetrievedIds();     // this is list of AliCDBId
     128             :   //  TList *cdbListLog0=man->GetRetrievedIds();     // this is list of AliCDBId
     129             :   //
     130           0 :   TFile *fmc = TFile::Open("galice.root");
     131           0 :   TMap *cdbMapMC= (TMap*)fmc->Get("cdbMap");          // 
     132           0 :   TList *cdbListMC0= (TList*)fmc->Get("cdbList");     // this is list of TObjStrings
     133           0 :   TList *cdbListMC = AliOCDBtoolkit::ConvertListStringToCDBId(cdbListMC0);        // convert to the TObjArray of AliCDBids
     134             :   //
     135           0 :   TFile *fesd = TFile::Open("AliESDs.root");
     136           0 :   TList *listESD = ((TTree*)fesd->Get("esdTree"))->GetUserInfo();
     137           0 :   TMap *cdbMapESD= (TMap*)listESD->FindObject("cdbMap");  
     138           0 :   TList *cdbListESD0= (TList*)listESD->FindObject("cdbList"); // this is list of TObjStrings
     139           0 :   TList *cdbListESD = AliOCDBtoolkit::ConvertListStringToCDBId(cdbListESD0);              // convert to the TObjArray  of AliCDBids
     140             :   //
     141             :   //
     142             :   //
     143           0 :   printf("\n\n");
     144           0 :   printf("Diff log>>>ESD\n\n:");
     145           0 :   MakeDiff(cdbMapLog, cdbListLog, cdbMapESD, cdbListESD,0);
     146           0 :   printf("\n\n");
     147           0 :   printf("Diff ESD>>>log\n\n:");
     148           0 :   MakeDiff(cdbMapESD, cdbListESD,cdbMapLog, cdbListLog,0);
     149             :   // 
     150           0 :   printf("\n\n");
     151           0 :   printf("Diff ESD>>>MC\n\n:");
     152           0 :   MakeDiff(cdbMapMC, cdbListMC, cdbMapESD, cdbListESD,0);
     153           0 : }
     154             : 
     155             : 
     156             : void AliOCDBtoolkit::DumpOCDBAsTxt(const TString fInput, const TString fType, const TString outfile){
     157             :   //
     158             :   //
     159             :   //
     160             :   TFile *file;
     161             :   const TMap *cdbMap=0;
     162             :   const TList *cdbList=0;
     163             :   //
     164             :   //
     165           0 :   AliCDBManager * man = AliCDBManager::Instance();
     166           0 :   if (fInput.Contains("alien://") && gGrid==0){
     167           0 :     TGrid *myGrid = TGrid::Connect("alien://");            //Oddly this will return also a pointer if connection fails
     168           0 :     if(myGrid->GetPort()==0){                       //if connection fails port 0 is saved, using this to check for successful connection
     169           0 :       cerr << "Cannot connect to grid!" << endl;
     170           0 :       return;
     171             :     }
     172           0 :   }
     173           0 :   if(fType.EqualTo("MC",TString::kIgnoreCase)){
     174           0 :         file = TFile::Open(fInput.Data());
     175           0 :         cdbMap = (TMap*)file->Get("cdbMap");
     176           0 :         if (!cdbMap){
     177           0 :           printf("cdbMap does not exist in input file\t%s. Exiting\n",fInput.Data());
     178           0 :           return;
     179             :         }
     180             :         // 
     181           0 :         man->SetDefaultStorage(((TPair*)cdbMap->FindObject("default"))->Value()->GetName());
     182           0 :         TList *cdbListMC0 = (TList*)file->Get("cdbList");     // this is list of TObjStrings
     183           0 :         cdbList = AliOCDBtoolkit::ConvertListStringToCDBId(cdbListMC0);        // convert to the TObjArray of AliCDBids
     184           0 :   } 
     185           0 :     else if(fType.EqualTo("ESD",TString::kIgnoreCase)){
     186           0 :       file = TFile::Open(fInput.Data());
     187           0 :       if (!file) {
     188           0 :         printf("Input file  does not exist %s. Exiting\n",fInput.Data());
     189           0 :         return;
     190             :       }
     191           0 :       TList *listESD = ((TTree*)file->Get("esdTree"))->GetUserInfo();
     192           0 :       cdbMap = (TMap*)listESD->FindObject("cdbMap");  
     193           0 :       if (!cdbMap){
     194           0 :         printf("cdbMap does not exist in input file\t%s. Exiting\n",fInput.Data());
     195           0 :         return;
     196             :       }
     197           0 :       AliOCDBtoolkit::SetStorage(cdbMap);
     198           0 :       TList *cdbListESD0= (TList*)listESD->FindObject("cdbList"); // this is list of TObjStrings
     199           0 :       cdbList = ConvertListStringToCDBId(cdbListESD0);              // convert to the TObjArray  of AliCDBids
     200           0 :     }
     201           0 :     else if(fType.EqualTo("log",TString::kIgnoreCase)){
     202           0 :         LoadOCDBFromLog(fInput.Data(),0);
     203           0 :         cdbMap = man->GetStorageMap();        // this is map of 
     204           0 :         cdbList =man->GetRetrievedIds();     // this is list of AliCDBId
     205             :     }
     206             :     else{
     207           0 :         printf("unsupported option: %s",fType.Data());
     208           0 :         return;
     209             :     }
     210           0 :   cout <<"BEGINDUMP:" << endl;
     211           0 :   DumpOCDB(cdbMap,cdbList,outfile);
     212           0 : }
     213             : 
     214             : 
     215             : Bool_t AliOCDBtoolkit::ParseInfoFromOcdbString(TString ocdbString, TString &ocdbPath, Int_t &run0, Int_t &run1, Int_t &version, Int_t &subVersion){
     216             :   // Functionalit
     217             :   // Parse OCDB id string and provide basic ocdb information
     218             :   //
     219             :   //  a.) parse ocdbPath
     220           0 :   Int_t indexBeginPath= ocdbString.Index("path: ")+7;
     221           0 :   if (indexBeginPath<0) return kFALSE;
     222           0 :   Int_t indexEndPath=ocdbString.Index(";",indexBeginPath);
     223           0 :   if (indexEndPath<0) return kFALSE;
     224           0 :   ocdbPath=TString(&(ocdbString.Data()[indexBeginPath]), indexEndPath-indexBeginPath-1);
     225             :   // b.) parse runRange
     226           0 :   Int_t indexRun0= ocdbString.Index(": [",indexEndPath)+3;
     227           0 :   if (indexRun0<0) return kFALSE;
     228           0 :   Int_t indexRun1= ocdbString.Index(",",indexRun0)+1;
     229           0 :   if (indexRun1<0) return kFALSE;
     230           0 :   run0=atoi(&(ocdbString.Data()[indexRun0]));
     231           0 :   run1=atoi(&(ocdbString.Data()[indexRun1]));
     232           0 :   AliCDBRunRange runRange(run0,run1);
     233             :   //c.) parse version, subversion
     234           0 :   Int_t indexVersion= ocdbString.Index("version: v",indexRun1)+10;
     235           0 :   if (indexVersion<0) return kFALSE;
     236           0 :   Int_t indexSubVersion= ocdbString.Index("_s",indexVersion)+2;
     237           0 :   if (indexSubVersion<0) return kFALSE;
     238           0 :   version=atoi(&(ocdbString.Data()[indexVersion]));
     239           0 :   subVersion=atoi(&(ocdbString.Data()[indexSubVersion]));
     240           0 :   return kTRUE;
     241           0 : }
     242             : 
     243             : Bool_t AliOCDBtoolkit::ParseInfoFromOcdbString(TString ocdbString, AliCDBId &cdbId){
     244             :   //
     245             :   // Parse OCDB id string and provide basic ocdb information and fillcdbID object
     246             :   //
     247           0 :   TString ocdbPath;
     248           0 :   Int_t run0=0, run1=0;
     249           0 :   Int_t version=0, subVersion=0;
     250           0 :   Bool_t parseStatus = ParseInfoFromOcdbString(ocdbString, ocdbPath, run0,run1,version,subVersion); 
     251           0 :   if (parseStatus) {
     252           0 :     AliCDBRunRange runRange(run0,run1);
     253           0 :     cdbId=AliCDBId(ocdbPath.Data(),runRange,version,subVersion);
     254           0 :     AliCDBId* id = AliCDBId::MakeFromString(ocdbString);
     255           0 :     cdbId=*id;
     256           0 :     delete id;
     257           0 :   }
     258             :   //
     259             :   return parseStatus;
     260           0 : }
     261             : 
     262             : TList  * AliOCDBtoolkit::ConvertListStringToCDBId(const TList *cdbList0){
     263             :   //
     264             :   // Convert input  list of the TObjString to list to AliCDBid 
     265             :   //
     266           0 :   Int_t entriesList0=cdbList0->GetEntries();
     267           0 :   TList * array0 = new TList();
     268           0 :   AliCDBId tmp0;
     269           0 :   for (Int_t ientry0=0; ientry0<entriesList0; ientry0++){
     270           0 :     if (cdbList0->At(ientry0)==0) continue;
     271           0 :     Bool_t isId =  cdbList0->At(ientry0)->IsA()->InheritsFrom("AliCDBId");
     272           0 :     if (isId){
     273           0 :       array0->AddLast(cdbList0->At(ientry0));
     274             :     }else{
     275           0 :       Bool_t isString =  cdbList0->At(ientry0)->IsA()->InheritsFrom("TObjString");
     276           0 :       if (isString){
     277           0 :         TObjString* sid0 = dynamic_cast<TObjString*> (cdbList0->At(ientry0));
     278           0 :         Bool_t status =  ParseInfoFromOcdbString(sid0->String(), tmp0);
     279           0 :         if (!status) continue; 
     280           0 :         array0->AddLast(new AliCDBId(tmp0));
     281           0 :       }
     282           0 :     }
     283           0 :   }
     284             :   return array0;  
     285           0 : }
     286             : 
     287             : 
     288             : 
     289             : void AliOCDBtoolkit::LoadOCDBFromLog(const char *logName, Int_t verbose){
     290             :   //
     291             :   // Initilaize OCDB
     292             :   // Load OCDB setting as specified in log
     293             :   // Assuming fixed version of the log 
     294             :   // AliCDBManager is initilaized - ocdbMap and ID list can be exported
     295             :   //
     296             : 
     297             :   // Parsing/loading sequence:
     298             :   //    0.) SetDefault storage  *** Default Storage URI:
     299             :   //    1.) SetSpecific storage  *** Specific storage
     300             :   //    2.) SetRunNumber  Run number:
     301             :   //    3.) Set used IDs
     302             :   //
     303           0 :   AliCDBManager * man = AliCDBManager::Instance();
     304             :   //
     305             :   // 0.) SetDefault storage  *** Default Storage URI:
     306             :   // 
     307           0 :   TString  defaultOCDB = gSystem->GetFromPipe(TString::Format("cat %s| grep \"Storage URI:\"",logName).Data());
     308           0 :   TObjArray *array = defaultOCDB.Tokenize("\"");
     309           0 :   man->SetDefaultStorage(array->Last()->GetName());
     310           0 :   delete array;
     311             :   //
     312             :   // 1.) SetSpecific storage  *** Specific storage
     313             :   //
     314           0 :   TString  specificStorage  = gSystem->GetFromPipe(TString::Format("cat %s| grep \"Specific storage\"",logName).Data());
     315           0 :   array = specificStorage.Tokenize("\"");
     316           0 :   Int_t entries = array->GetEntries();
     317           0 :   for (Int_t i=1; i<entries-2; i+=4){    
     318             :     // add protection here line shuld be in expected format
     319           0 :     if ((verbose&2)>0) printf("%s\t%s\n",array->At(i)->GetName(),array->At(i+2)->GetName());    
     320           0 :     man->SetSpecificStorage(array->At(i)->GetName(),array->At(i+2)->GetName());
     321             :   }
     322           0 :   delete array;
     323             :   //
     324             :   // 2.) SetRunNumber  Run number:
     325             :   //
     326           0 :   TString  runLine  = gSystem->GetFromPipe(TString::Format("cat %s| grep \"I-AliCDBManager::Print: Run number =\"",logName).Data());
     327           0 :   array = runLine.Tokenize("=");
     328             :   Int_t run = 0;
     329           0 :   if (array->GetEntries()>1) run=atoi(array->At(1)->GetName()); 
     330           0 :   delete array;
     331           0 :   man->SetRun(run);  
     332             :   //
     333             :   // 3.) Set used IDs
     334             :   //   
     335           0 :   TString  ids =   gSystem->GetFromPipe(TString::Format("cat %s| grep I-AliCDB | grep path| grep range | grep version", logName).Data());
     336           0 :   array= ids.Tokenize("\n");
     337           0 :   entries = array->GetEntries();
     338             :   //
     339           0 :   for (Int_t i=0; i<entries; i++){
     340             :     //
     341           0 :     TString ocdbString = array->At(i)->GetName();
     342           0 :     TString ocdbEntry;
     343           0 :     TString ocdbPath;
     344           0 :     Int_t run0=0, run1=0;
     345           0 :     Int_t version=0, subVersion=0;
     346           0 :     Bool_t parseStatus = ParseInfoFromOcdbString(ocdbString, ocdbPath, run0,run1,version,subVersion); 
     347           0 :     if (!parseStatus) continue;
     348           0 :     AliCDBRunRange runRange(run0,run1);
     349             :     //
     350           0 :     if ((verbose&2)!=0) {
     351           0 :       printf("%s/Run%d_%d_v%d_s%d.root\n",ocdbPath.Data(),run0,run1,version,subVersion); 
     352             :     }
     353             :     try {
     354           0 :       man->Get(ocdbPath.Data(),runRange,version,subVersion);      
     355           0 :     } catch(const exception &e){
     356           0 :       cerr << "OCDB retrieval failed!" << endl;
     357           0 :       cerr << "Detailes: " << e.what() << endl;
     358           0 :     }    
     359           0 :   }  
     360           0 :   if ((verbose&1)!=0){
     361           0 :     man->Print();
     362           0 :     man->GetStorageMap()->Print();
     363           0 :     man->GetRetrievedIds()->Print(); 
     364             :   }
     365           0 : }
     366             : 
     367             : void  AliOCDBtoolkit::SetStorage(const TMap *cdbMap){
     368             :   //
     369             :   //  Set storages as specified in the map - TO CHECK.. 
     370             :   //  Should go to the AliCDBmanager if not alreadyhhere +++MI
     371             :   //   
     372             :   //  In case OCDB_PATH local variable is defined
     373             :   //  alien storage is replaced by OCDB_PATH prefix: e.g:  local:///cvmfs/alice.gsi.de/
     374             :   //
     375             :   //  Regexp extensivelly used - see documentation in ????
     376             :   //       http://wwwacs.gantep.edu.tr/guides/programming/root/htmldoc/examples/tstring.C.html
     377           0 :   AliCDBManager * man = AliCDBManager::Instance();  
     378           0 :   TIter iter(cdbMap->GetTable());
     379             :   TPair* aPair=0;
     380           0 :   while ((aPair = (TPair*) iter.Next())) {
     381             :     //    aPair->Value();
     382             :     //aPair->Print();
     383           0 :     TString urlOrig = aPair->Value()->GetName();
     384           0 :     TString url=urlOrig; // e.g TString  url="alien://?User=?DBFolder=/alice/data/2010/OCDB?SE=default?CacheFolder=?OperateDisconnected=1?CacheSize=1073741824?CleanupInterval=0"
     385           0 :     man->ExtractBaseFolder(url); // url==alien://Folder=/alice/data/2010/OCDB"
     386           0 :     TString ocdbPrefix(gSystem->Getenv("OCDB_PATHTEST"));
     387           0 :     if (ocdbPrefix.Length()>0){
     388           0 :       TRegexp alienPrefix("^alien://Folder=");      
     389           0 :       url(alienPrefix)=ocdbPrefix+"";
     390           0 :     }
     391             : 
     392           0 :     printf("%s\t%s\t%s\n", aPair->GetName(), urlOrig.Data(), url.Data());
     393           0 :     if (TString(aPair->GetName())=="default") man->SetDefaultStorage(url);
     394             :     else
     395           0 :       man->SetSpecificStorage(aPair->GetName(), url);
     396           0 :   }  
     397           0 : }
     398             :  
     399             : void AliOCDBtoolkit::LoadOCDBFromMap(const TMap *cdbMap, const TList *cdbList){
     400             :   //
     401             :   // Initilaize OCDB
     402             :   // Load OCDB setting as specified in maps
     403             :   // Or Do we have already implementation in AliCDBanager?  TO CHECK.. Should go to the AliCDBmanager if not alreadyhhere
     404           0 :   AliCDBManager * man = AliCDBManager::Instance();  
     405           0 :   AliOCDBtoolkit::SetStorage(cdbMap);  
     406           0 :   TIter iter(cdbList);
     407             :   TObjString *ocdbString=0;
     408           0 :   while (( ocdbString= (TObjString*) iter.Next())) {
     409           0 :     AliCDBId* cdbId = AliCDBId::MakeFromString(ocdbString->String());
     410             :     try {
     411             :       //      AliCDBEntry * cdbEntry = (AliCDBEntry*) man->Get(*cdbId,kTRUE);
     412           0 :       man->Get(*cdbId,kTRUE);
     413           0 :     } catch(const exception &e){
     414           0 :       cerr << "OCDB retrieval failed!" << endl;
     415           0 :       cerr << "Detailes: " << e.what() << endl;
     416           0 :     }   
     417             :   }    
     418           0 : }
     419             : 
     420             : void AliOCDBtoolkit::LoadOCDBFromESD(const char *fname){
     421             :   //
     422             :   // Load OCDB setup from the ESD file
     423             :   // 
     424           0 :   TFile * fesd = TFile::Open(fname);
     425           0 :   TList *listESD = ((TTree*)fesd->Get("esdTree"))->GetUserInfo();
     426           0 :   TMap *cdbMapESD= (TMap*)listESD->FindObject("cdbMap");  
     427           0 :   TList *cdbListESD0= (TList*)listESD->FindObject("cdbList"); // this is list of TObjStrings
     428           0 :   AliOCDBtoolkit::SetStorage(cdbMapESD); 
     429           0 :   AliOCDBtoolkit::LoadOCDBFromMap(cdbMapESD, cdbListESD0);
     430           0 : }
     431             : 
     432             : 
     433             : void AliOCDBtoolkit::MakeDiff(const TMap *cdbMap0, const TList *cdbList0, const TMap */*cdbMap1*/, const TList *cdbList1, Int_t /*verbose*/){
     434             :   //
     435             :   //
     436             :   // Print difference between the 2 ocdb maps
     437             :   // Input:
     438             :   //   maps and list charactireizing OCDB setup  
     439             :   // Output:
     440             :   //   To be decided.
     441             :   //
     442           0 :   AliOCDBtoolkit::SetStorage(cdbMap0);
     443           0 :   Int_t entriesList0=cdbList0->GetEntries();
     444           0 :   Int_t entriesList1=cdbList1->GetEntries();
     445             :   //
     446           0 :   for (Int_t ientry0=0; ientry0<entriesList0; ientry0++){
     447           0 :     AliCDBId *id0    = dynamic_cast<AliCDBId*> (cdbList0->At(ientry0));
     448             :     AliCDBId *id1=0;
     449           0 :     for (Int_t ientry1=0; ientry1<entriesList1; ientry1++){
     450           0 :       AliCDBId *cid1    = dynamic_cast<AliCDBId*> (cdbList1->At(ientry1));
     451             :       //id0.Print();
     452             :       //cid1.Print();
     453           0 :       if (cid1->GetPath().Contains(id0->GetPath().Data())==0) continue;
     454             :       id1=cid1;
     455           0 :     }
     456           0 :     if (!id1) {
     457           0 :       printf("Missing entry\t");
     458           0 :       id0->Print();
     459           0 :       continue;
     460             :     }
     461             :     //   Bool_t isOK=kTRUE;
     462           0 :     if (id0->GetFirstRun()!= id1->GetFirstRun() ||id0->GetLastRun()!= id1->GetLastRun()){
     463           0 :       printf("Differrent run range\n");
     464           0 :       id0->Print();
     465           0 :       id1->Print();
     466           0 :     }    
     467           0 :     if (id0->GetVersion()!= id1->GetVersion() ||id0->GetSubVersion()!= id1->GetSubVersion()){
     468           0 :       printf("Differrent version\n");
     469           0 :       id0->Print();
     470           0 :       id1->Print();
     471           0 :     }    
     472           0 :   }
     473           0 : }
     474             : 
     475             : void AliOCDBtoolkit::DumpOCDB(const TMap *cdbMap0, const TList *cdbList0, const TString outfile){
     476             :   //
     477             :   // Dump the OCDB configuatation as formated text file 
     478             :   // with following collumns
     479             :   // cdb name  prefix cdb path
     480             :   // OCDB entries are sorted alphabetically
     481             :   // e.g:
     482             :   // TPC/Calib/RecoParam /hera/alice/jwagner/software/aliroot/AliRoot_TPCdev/OCDB/ TPC/Calib/RecoParam/Run0_999999999_v0_s0.root $SIZE_AliCDBEntry_Object $HASH_AliCDBEntry_Object
     483             :   
     484           0 :   AliCDBManager * man = AliCDBManager::Instance();
     485           0 :   AliOCDBtoolkit::SetStorage(cdbMap0);  
     486             :   TList * cdbList = (TList*) cdbList0;   // sorted array
     487           0 :   cdbList->Sort();
     488             : 
     489           0 :   TIter next(cdbList);
     490             :   AliCDBId *CDBId=0;
     491           0 :   TString cdbName="";
     492           0 :   TString cdbPath="";
     493             :   TObjString *ostr;
     494             :   AliCDBEntry *cdbEntry=0;
     495             :   TGrid *myGrid = NULL;
     496             :   UInt_t hash;
     497             :   TMessage * file;
     498             :   Int_t size; 
     499           0 :   FILE *ofs = fopen(outfile.Data(),"w");
     500             :   
     501           0 :   while ((CDBId  =(AliCDBId*) next())){
     502           0 :     cdbName = CDBId->GetPath();
     503           0 :     ostr = (TObjString*)cdbMap0->GetValue(cdbName.Data());
     504           0 :     if(!ostr) ostr = (TObjString*)cdbMap0->GetValue("default");
     505           0 :     cdbPath = ostr->GetString();
     506           0 :     if(cdbPath.Contains("local://"))cdbPath=cdbPath(8,cdbPath.Length()).Data();
     507           0 :     if(!myGrid && cdbPath.Contains("alien://")){        //check if connection to alien is initialized
     508           0 :         myGrid = TGrid::Connect("alien://");            //Oddly this will return also a pointer if connection fails
     509           0 :         if(myGrid->GetPort()==0){                       //if connection fails port 0 is saved, using this to check for successful connection
     510           0 :             cerr << "Cannot connect to grid!" << endl;
     511             :             continue;
     512             :         }
     513             :     }
     514             :     try {
     515           0 :       cdbEntry = (AliCDBEntry*) man->Get(*CDBId,kTRUE);
     516           0 :     }catch(const exception &e){
     517           0 :       cerr << "OCDB retrieval failed!" << endl;
     518           0 :       cerr << "Detailes: " << e.what() << endl;
     519             :       hash=0;
     520             :       size=-1;
     521           0 :     }  
     522           0 :     if (!cdbEntry) {
     523           0 :       printf("Object not avaliable\n");
     524           0 :       CDBId->Print();
     525             :       continue;
     526             :     }
     527           0 :     TObject *obj = cdbEntry->GetObject();
     528           0 :     file = new TMessage(TBuffer::kWrite);
     529           0 :     file->WriteObject(obj);
     530           0 :     size = file->Length();
     531           0 :     if(!obj){
     532           0 :       fprintf(ofs,"object %s empty!\n",cdbName.Data());
     533           0 :       continue;
     534             :     }
     535           0 :     hash = TString::Hash(file->Buffer(),size);
     536           0 :     fprintf(ofs,"%s\t%s\t%s/Run%d_%d_v%d_s%d.root\t%d\t%u\n",
     537           0 :            cdbName.Data(),
     538           0 :            cdbPath.Data(),
     539           0 :            cdbName.Data(),
     540           0 :            CDBId->GetFirstRun(),
     541           0 :            CDBId->GetLastRun(),
     542           0 :            CDBId->GetVersion(),
     543           0 :            CDBId->GetSubVersion(),
     544             :            size,
     545             :            hash
     546             :            );
     547             :     //if(!(CDBId->GetPathLevel(0)).Contains("TPC")) continue;
     548             :     //cout << CDBId.ToString() << endl;
     549           0 :     delete file;
     550           0 :   }
     551           0 :   fclose(ofs);
     552           0 : }
     553             : 
     554             : 
     555             : //====================================================================================================
     556             : //  Dump object part
     557             : //==================================================================================================== 
     558             : 
     559             : 
     560             : 
     561             : 
     562             : 
     563             : void AliOCDBtoolkit::DumpOCDBFile(const char *finput , const char *foutput, Bool_t dumpMetaData, Bool_t xml){
     564             :   //
     565             :   //  
     566             :   //  DumpOCDBFile("$ALICE_ROOT/OCDB/ITS/Align/Data/Run0_999999999_v0_s0.root", "ITS_Align_Data_Run0_999999999_v0_s0.dump")
     567             :   //
     568           0 :   if (finput==0) return ;
     569           0 :   if (TString(finput).Contains("alien://") && gGrid==0){
     570           0 :     TGrid *myGrid = TGrid::Connect("alien://");            //Oddly this will return also a pointer if connection fails
     571           0 :     if(myGrid->GetPort()==0){                       //if connection fails port 0 is saved, using this to check for successful connection
     572           0 :       cerr << "Cannot connect to grid!" << endl;
     573           0 :       return;
     574             :     }
     575           0 :   }
     576           0 :   TFile *falignITS  = TFile::Open(finput);
     577           0 :   AliCDBEntry *entry  = (AliCDBEntry*)falignITS->Get("AliCDBEntry");
     578           0 :   if (!entry) return; 
     579           0 :   TObject *obj = ((AliCDBEntry*)falignITS->Get("AliCDBEntry"))->GetObject();  
     580             : 
     581             :   //
     582           0 :   if (!xml){
     583           0 :     if (dumpMetaData) gROOT->ProcessLine(TString::Format("((TObject*)%p)->Dump(); >%s",entry, foutput).Data());
     584           0 :     if (!obj) return;
     585           0 :     gROOT->ProcessLine(TString::Format("AliOCDBtoolkit::DumpObjectRecursive((TObject*)%p); >>%s",obj, foutput).Data());
     586           0 :   }
     587           0 :   if (xml){
     588           0 :     TFile * f = TFile::Open(TString::Format("%s.xml",foutput).Data(),"recreate");
     589           0 :     if (dumpMetaData) entry->Write("AliCDBEntry");
     590           0 :     else obj->Write("AliCDBEntry");
     591           0 :     f->Close();
     592           0 :   }
     593           0 : }
     594             : 
     595             : 
     596             : 
     597             : void AliOCDBtoolkit::DumpObjectRecursive(TObject *obj){
     598             :   //
     599             :   //
     600             :   //
     601           0 :   Int_t counterRec=0;
     602           0 :   printf("==> Dumping object at: %p, name=%s, class=%s)\n", obj, obj->GetName(), (obj->IsA()->GetName()));
     603           0 :   DumpObjectRecursive(obj, TString(obj->IsA()->GetName())+".",counterRec);
     604           0 : }
     605             :  
     606             : //
     607             : //
     608             : //
     609             : void AliOCDBtoolkit::DumpObjectRecursive(TObject *obj, TString prefix, Int_t &counterRec){
     610             :   //
     611             :   // Recursive dump of the TObject
     612             :   // Dump all basic types and follow pointers to the objects
     613             :   // current limitation:
     614             :   //    a.) clases and structures not derived from TObject not followed (to fix)
     615             :   //    b.) dynamic arrays not followed
     616             :   //    c.) std maps,array ....  not followed
     617             :   //    
     618             :   //
     619           0 :   if (!obj) return;
     620             :   //
     621             :   // Special case of Collection classes
     622             :   //
     623           0 :   if (obj->IsA()->InheritsFrom(TCollection::Class())) {
     624           0 :     TIter myiter((TCollection*)obj);
     625             :     TObject  *arObject=0;
     626             :     Int_t counter=0;
     627           0 :     while ((arObject = (TObject*)myiter.Next())) {
     628           0 :       TString prefixArr = TString::Format("%s[%d]",prefix.Data(),counter);
     629           0 :       DumpObjectRecursive(arObject,prefixArr,counterRec);
     630           0 :       counter++;
     631           0 :     } 
     632           0 :     counterRec++;
     633             :     return;
     634           0 :   }
     635             : 
     636           0 :   TClass * cl = obj->IsA();
     637           0 :   if (!(cl->GetListOfRealData())) cl->BuildRealData();
     638             :   TRealData* rd = 0;
     639           0 :   TIter next(cl->GetListOfRealData());  
     640           0 :   while ((rd = (TRealData*) next())) {
     641           0 :     counterRec++;
     642           0 :     TDataMember* dm = rd->GetDataMember();
     643           0 :     TDataType* dtype = dm->GetDataType();
     644           0 :     Int_t offset = rd->GetThisOffset();
     645           0 :     char* pointer = ((char*) obj) + offset;
     646             :     
     647           0 :     if (dm->IsaPointer()) {
     648             :       // We have a pointer to an object or a pointer to an array of basic types.
     649             :       TClass* clobj = 0;
     650           0 :       if (!dm->IsBasic()) {
     651           0 :         clobj = TClass::GetClass(dm->GetTypeName());
     652           0 :       }
     653           0 :       if (clobj) {
     654             :         // We have a pointer to an object.
     655             :         //
     656           0 :         if (!clobj->InheritsFrom(TObject::Class())) {
     657             :           // It must be a TObject object.
     658           0 :           continue; 
     659             :         }
     660           0 :         char** apointer = (char**) pointer;
     661           0 :         TObject* robj = (TObject*) *apointer;
     662             :         //      
     663           0 :         if(!robj)
     664           0 :           printf("M:%s%s\n",prefix.Data(),dm->GetName()); // Missing - 0 pointer
     665             :         else{
     666           0 :           printf("T:%s\t%s%s\n", clobj->GetName(),prefix.Data(), dm->GetName());
     667           0 :           TString prefixNew=prefix;
     668           0 :           prefixNew+=dm->GetName();
     669           0 :           prefixNew+=".";
     670           0 :           if (robj!=obj) DumpObjectRecursive(robj,prefixNew,counterRec);  // trivial check 
     671           0 :           if (robj==obj){
     672           0 :             printf("R:%s\t%s%s\n",clobj->GetName(),prefix.Data(), dm->GetName());
     673             :           }
     674           0 :         }
     675           0 :       }
     676           0 :     } else if (dm->IsBasic()) {
     677             :       //
     678             :       // Basic data type
     679             :       //
     680           0 :       const char* index = dm->GetArrayIndex();
     681           0 :       if (dm->GetArrayDim()==0){
     682           0 :         printf("B:\t%s%s\t%s\n", prefix.Data(),rd->GetName(), dtype->AsString(pointer));
     683             :       }
     684             :       //
     685             :       // Basic array - fixed length
     686             :       //
     687             :       //      if (dm->GetArrayDim()>0 && strlen(index) != 0){
     688           0 :       if (dm->GetArrayDim()>0 ){
     689           0 :         printf("A:\t%s%s\t",prefix.Data(),rd->GetName());
     690             :         Int_t counter=0;
     691           0 :         for  (Int_t idim=0; idim<dm->GetArrayDim(); idim++){
     692             :           //printf("A:%d\t%d\n", dm->GetArrayDim(),dm->GetMaxIndex(idim));
     693           0 :           for (Int_t j=0; j<dm->GetMaxIndex(idim); j++){
     694           0 :             printf("%s\t",dtype->AsString(pointer+dm->GetUnitSize()*counter));
     695           0 :             counter++;
     696           0 :             if (counter%5==0) printf("\nA:\t%s%s\t",prefix.Data(),rd->GetName());
     697             :           }
     698             :         }
     699           0 :         printf("\n");
     700           0 :       }
     701             :       //
     702             :       // Basic array - dynamic length
     703             :       //
     704           0 :       if (dm->GetArrayDim()>0 && strlen(index) != 0){
     705             :         //
     706             :         // Dump first only for the moment
     707             :         //  
     708           0 :         printf("B:\t%s%s\t%s\n",prefix.Data(),rd->GetName(), dtype->AsString(pointer));
     709             :       }
     710           0 :     } else {
     711             :     }
     712           0 :   }
     713           0 : }  
     714             : 
     715             : //
     716             : // Small checks to test the TRealData and TDataType
     717             : //
     718             : 
     719             : 
     720             : 
     721             : void DumpDataSimple(){
     722             :   //
     723             :   // Dump example for elenatr data types 
     724             :   //
     725           0 :   TObject *obj = new TVectorD(20);
     726           0 :   TClass * cl = obj->IsA();
     727           0 :   if (!cl->GetListOfRealData()) cl->BuildRealData();
     728             :   //
     729             :   TRealData* rd = 0;
     730           0 :   rd = (TRealData*)(cl->GetListOfRealData()->FindObject("fNrows"));
     731           0 :   TDataMember* dm = rd->GetDataMember();
     732           0 :   TDataType* dtype = dm->GetDataType();
     733             :   //
     734           0 :   Int_t offset = rd->GetThisOffset();
     735           0 :   char* pointer = ((char*) obj) + offset;
     736           0 :   printf("%s\n",dtype->AsString(pointer));
     737           0 : }
     738             : 
     739             : void DumpDataArray(){
     740             :   //
     741             :   // print array example
     742             :   // 
     743           0 :   TObject *obj = new TVectorD(20);
     744           0 :   TClass * cl = obj->IsA();
     745           0 :   if (!cl->GetListOfRealData()) cl->BuildRealData();
     746             :   TRealData* rd = 0;
     747           0 :   rd = (TRealData*)(cl->GetListOfRealData()->FindObject("*fElements"));
     748           0 :   TDataMember* dm = rd->GetDataMember();
     749           0 :   TDataType* dtype = dm->GetDataType();
     750           0 :   dtype->Print();
     751             :   //
     752           0 :   Int_t offset = rd->GetThisOffset();
     753           0 :   char* pointer = ((char*) obj) + offset; 
     754           0 :   printf("%s\n",dtype->AsString(pointer));
     755           0 : }
     756             : 
     757             : void DumpTObjectArray(){
     758             :   //
     759             :   //
     760             :   //
     761           0 :   TObjArray *array = new TObjArray(10);
     762           0 :   for (Int_t i=0; i<10; i++) array->AddLast(new TNamed(Form("n%d",i), Form("n%d",i)));  
     763           0 :    AliOCDBtoolkit::DumpObjectRecursive(array);
     764             :   //
     765             :   //
     766             :   TObject *obj = array;
     767           0 :   TClass * cl = obj->IsA();
     768           0 :   if (!cl->GetListOfRealData()) cl->BuildRealData();
     769             :   TRealData* rd = 0;
     770           0 :   rd = (TRealData*)(cl->GetListOfRealData()->FindObject("*fCont"));
     771           0 :   TDataMember* dm = rd->GetDataMember();
     772           0 :   TDataType* dtype = dm->GetDataType();
     773             :   //
     774           0 :   Int_t offset = rd->GetThisOffset();
     775           0 :   char* pointer = ((char*) obj) + offset;
     776           0 :   char** apointer = (char**) pointer;
     777             :   //we have pointer to pointer here
     778           0 :   TObject** ppobj = (TObject**) *apointer;
     779           0 :   (*ppobj)->Print();
     780             :   //
     781           0 :   TIter myiter(array);
     782             :   TObject  *arObject; 
     783           0 :   dtype->Print();
     784           0 :   while ((arObject = (TObject*)myiter.Next())) {
     785           0 :     AliOCDBtoolkit::DumpObjectRecursive(arObject);
     786             :   } 
     787           0 : }
     788             : 
     789             : 
     790             : Bool_t AliOCDBtoolkit::AddoptOCDBEntry( const char *finput, const char *output,  Int_t ustartRun, Int_t uendRun){
     791             :   //
     792             :   // Addopt OCDB entry - keeping all of the CDBentry quantities
     793             :   // // Example usage: 
     794             :   //  AliOCDBtoolkit::AddoptOCDBEntry("/cvmfs/alice.gsi.de/alice/simulation/2008/v4-15-Release/Residual/TPC/Calib/ClusterParam/Run127712_130850_v4_s0.root",0,0,AliCDBRunRange::Infinity())
     795           0 :   TFile * fin = TFile::Open(finput);
     796           0 :   if (!fin) return kFALSE;
     797           0 :   AliCDBEntry * entry = (AliCDBEntry*) fin->Get("AliCDBEntry");
     798           0 :   if (!entry) return kFALSE;
     799             :   
     800             :   AliCDBStorage* pocdbStorage = 0;
     801           0 :   if (output!=0) AliCDBManager::Instance()->GetStorage(output);
     802             :   else{
     803           0 :     TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
     804           0 :     pocdbStorage = AliCDBManager::Instance()->GetStorage(localStorage.Data());
     805           0 :   }
     806             :   //
     807           0 :   AliCDBId  idIn = entry->GetId();
     808           0 :   AliCDBMetaData *metaDataIn = entry->GetMetaData();
     809             : 
     810           0 :   AliCDBMetaData *metaData= new AliCDBMetaData();
     811           0 :   metaData->SetObjectClassName(metaDataIn->GetObjectClassName());
     812           0 :   metaData->SetResponsible(TString::Format("%s: copy",metaDataIn->GetResponsible()).Data());
     813           0 :   metaData->SetBeamPeriod(metaDataIn->GetBeamPeriod());
     814             :   //
     815           0 :   metaData->SetAliRootVersion(metaDataIn->GetAliRootVersion()); //root version
     816           0 :   metaData->SetComment((TString::Format("%s: copy",metaDataIn->GetComment()).Data()));
     817             :   AliCDBId* id1=NULL;
     818           0 :   id1=new AliCDBId(idIn.GetPath(), ustartRun, uendRun);
     819           0 :   pocdbStorage->Put(entry->GetObject(), (*id1), metaData);
     820             :   return kTRUE;
     821           0 : }
     822             : 
     823             : 
     824             : void AliOCDBtoolkit::MakeSnapshotFromTxt(const TString fInput, const TString outfile, Bool_t singleKeys){
     825             :   //
     826             :   // Make snasphot form the txt file
     827             :   //
     828           0 :   AliCDBManager * man = AliCDBManager::Instance();
     829           0 :   LoadOCDBFromList(fInput.Data());
     830           0 :   man->DumpToSnapshotFile(outfile.Data(), singleKeys);
     831             : 
     832           0 : }
     833             : 

Generated by: LCOV version 1.11