ROOT logo
// This macro transfers OCDB data of one single ("detName") or all ALICE detectors from one location to another, 
// It is possible to set new run range, path etc... 
// draining "align" objects is in general to be avoided, since those present in the repository might not be updated
// some paths might be missing hereafter: this can be checked in advance by means of "listCdbEntries.sh" run on the
// starting OCDB folder
#if !defined(__CINT__) || defined(__MAKECINT__)
#include "AliCDBManager.h"
#include "AliCDBStorage.h"
#include "AliCDBEntry.h"
#include "AliCDBId.h"
#include <TString.h>
#include <TList.h>
#endif

void CDBToGrid(const char *detName="", const char* fromUri="local://$ALICE_ROOT/OCDB", 
	const char* toUri="local://newOCDB")
{

	AliCDBManager *man = AliCDBManager::Instance();
	man->SetDefaultStorage(fromUri);
	AliCDBStorage *dest = man->GetStorage(toUri);
	man->SetRun(0);

	TList* calib=0;
	TList* align=0;
	TList* config=0;

	if(detName == "")
	{
		// drain by cdb-path
		calib = man->GetAll("*/Calib/*");
		//align = man->GetAll("*/Align/Data");
		config = man->GetAll("*/Config/*");

		// drain everything, really!
		//calib = man->GetAll("*");

	} else {
		// drain calibration and alignment for detector "detName"

		TString calibPath = detName;
		TString alignPath = calibPath;
		calibPath+="/Calib/*";	
		alignPath+="/Align/Data";

		//calib = man->GetAll(calibPath);
		//align = man->GetAll(alignPath);

		// drain everything, really!
		calib = man->GetAll(Form("%s/*",detName));
	}

	AliCDBEntry *entry;

	Int_t ok=0; TString failed="";
	if(calib){
		ok=0; failed="";
		for(int i=0;i<calib->GetEntries();i++){

			entry = (AliCDBEntry*) calib->At(i);
			entry->GetId().SetRunRange(0,AliCDBRunRange::Infinity());

			TString path=entry->GetId().GetPath();

			printf("%s\n",path.Data());

			if (path == "ITS/Resp/RespSDD") entry->GetId().SetPath("ITS/Calib/RespSDD"); // bug in ITS/Resp/RespSDD

			if(path == "TOF/Calib/Par" || path == "TOF/Calib/SimPar" || path.Contains("TOF/CDB")) continue;

			if (dest->Put(entry)) {
				ok++;
			} else {
				failed += path.Data(); failed += " "; 
			}
		}
		printf("\n************ CALIB *********** \n");
		printf("************ Stored %d objects over %d *********** \n", ok, calib->GetEntries());
		if(failed != ""){
			printf("***** List of failed objects: %s \n", failed.Data());
		}
	}


	if(align){
		ok=0; failed="";
		for(int i=0;i<align->GetEntries();i++){

			entry = (AliCDBEntry*) align->At(i);
			entry->GetId().SetRunRange(0,AliCDBRunRange::Infinity());
			TString path=entry->GetId().GetPath();

			if (dest->Put(entry)) {
				ok++;
			} else {
				failed += path.Data(); failed += " "; 
			}
		}
		printf("\n************ ALIGN *********** \n");
		printf("************ Stored %d objects over %d *********** \n", ok, align->GetEntries());
		if(failed != ""){
			printf("***** List of failed objects: %s \n", failed.Data());
		}
	}

	if(config){
		ok=0; failed = "";
		for(int i=0;i<config->GetEntries();i++){

			entry = (AliCDBEntry*) config->At(i);
			entry->GetId().SetRunRange(0,AliCDBRunRange::Infinity());
			TString path=entry->GetId().GetPath();

			if (dest->Put(entry)) {
				ok++;
			} else {
				failed += path.Data(); failed += " "; 
			}
		}
		printf("\n************ CONFIG *********** \n");
		printf("************ Stored %d objects over %d *********** \n", ok, config->GetEntries());
		if(failed != ""){
			printf("***** List of failed objects: %s \n", failed.Data());
		}
	}

	man->Destroy();

}
 CDBToGrid.C:1
 CDBToGrid.C:2
 CDBToGrid.C:3
 CDBToGrid.C:4
 CDBToGrid.C:5
 CDBToGrid.C:6
 CDBToGrid.C:7
 CDBToGrid.C:8
 CDBToGrid.C:9
 CDBToGrid.C:10
 CDBToGrid.C:11
 CDBToGrid.C:12
 CDBToGrid.C:13
 CDBToGrid.C:14
 CDBToGrid.C:15
 CDBToGrid.C:16
 CDBToGrid.C:17
 CDBToGrid.C:18
 CDBToGrid.C:19
 CDBToGrid.C:20
 CDBToGrid.C:21
 CDBToGrid.C:22
 CDBToGrid.C:23
 CDBToGrid.C:24
 CDBToGrid.C:25
 CDBToGrid.C:26
 CDBToGrid.C:27
 CDBToGrid.C:28
 CDBToGrid.C:29
 CDBToGrid.C:30
 CDBToGrid.C:31
 CDBToGrid.C:32
 CDBToGrid.C:33
 CDBToGrid.C:34
 CDBToGrid.C:35
 CDBToGrid.C:36
 CDBToGrid.C:37
 CDBToGrid.C:38
 CDBToGrid.C:39
 CDBToGrid.C:40
 CDBToGrid.C:41
 CDBToGrid.C:42
 CDBToGrid.C:43
 CDBToGrid.C:44
 CDBToGrid.C:45
 CDBToGrid.C:46
 CDBToGrid.C:47
 CDBToGrid.C:48
 CDBToGrid.C:49
 CDBToGrid.C:50
 CDBToGrid.C:51
 CDBToGrid.C:52
 CDBToGrid.C:53
 CDBToGrid.C:54
 CDBToGrid.C:55
 CDBToGrid.C:56
 CDBToGrid.C:57
 CDBToGrid.C:58
 CDBToGrid.C:59
 CDBToGrid.C:60
 CDBToGrid.C:61
 CDBToGrid.C:62
 CDBToGrid.C:63
 CDBToGrid.C:64
 CDBToGrid.C:65
 CDBToGrid.C:66
 CDBToGrid.C:67
 CDBToGrid.C:68
 CDBToGrid.C:69
 CDBToGrid.C:70
 CDBToGrid.C:71
 CDBToGrid.C:72
 CDBToGrid.C:73
 CDBToGrid.C:74
 CDBToGrid.C:75
 CDBToGrid.C:76
 CDBToGrid.C:77
 CDBToGrid.C:78
 CDBToGrid.C:79
 CDBToGrid.C:80
 CDBToGrid.C:81
 CDBToGrid.C:82
 CDBToGrid.C:83
 CDBToGrid.C:84
 CDBToGrid.C:85
 CDBToGrid.C:86
 CDBToGrid.C:87
 CDBToGrid.C:88
 CDBToGrid.C:89
 CDBToGrid.C:90
 CDBToGrid.C:91
 CDBToGrid.C:92
 CDBToGrid.C:93
 CDBToGrid.C:94
 CDBToGrid.C:95
 CDBToGrid.C:96
 CDBToGrid.C:97
 CDBToGrid.C:98
 CDBToGrid.C:99
 CDBToGrid.C:100
 CDBToGrid.C:101
 CDBToGrid.C:102
 CDBToGrid.C:103
 CDBToGrid.C:104
 CDBToGrid.C:105
 CDBToGrid.C:106
 CDBToGrid.C:107
 CDBToGrid.C:108
 CDBToGrid.C:109
 CDBToGrid.C:110
 CDBToGrid.C:111
 CDBToGrid.C:112
 CDBToGrid.C:113
 CDBToGrid.C:114
 CDBToGrid.C:115
 CDBToGrid.C:116
 CDBToGrid.C:117
 CDBToGrid.C:118
 CDBToGrid.C:119
 CDBToGrid.C:120
 CDBToGrid.C:121
 CDBToGrid.C:122
 CDBToGrid.C:123
 CDBToGrid.C:124
 CDBToGrid.C:125
 CDBToGrid.C:126
 CDBToGrid.C:127
 CDBToGrid.C:128
 CDBToGrid.C:129
 CDBToGrid.C:130