ROOT logo
#include "AliCDBManager.h"
#include "AliCDBId.h"
#include "TCollection.h"
#include "TMap.h"
#include "TKey.h"
#include "TString.h"
#include "TObjString.h"
#include "TFile.h"
#include "TSystem.h"

void MakeSnapshot(Int_t run, const char* defStorage, TMap* specStorages, const char* snapshotFileName)
{
    AliCDBManager *cdb = AliCDBManager::Instance();
    cdb->SetDefaultStorage(defStorage);
    cdb->SetRun(run);

    TIter iter(specStorages->GetTable());
    TPair *pair = 0;
    while((pair = dynamic_cast<TPair*> (iter.Next()))){
	TObjString* caltype = dynamic_cast<TObjString*> (pair->Key());
	TObjString* specstor= dynamic_cast<TObjString*> (pair->Value());
	if (caltype && specstor)
	    //TString calType = caltype->GetString();
	    //TString specStor = specstor->GetString();
	    //cdb->SetSpecificStorage(calType.Data(),specStor.Data());
	    cdb->SetSpecificStorage(caltype->GetString().Data(),specstor->GetString().Data());
	else
	    //AliFatal("Error reading info for specific storage")
	    Printf("Error reading info for specific storage");
    }

    // ********************************** GRP ******************************************
    cdb->Get("GRP/CTP/Config");
    cdb->Get("GRP/Calib/LHCClockPhase");
    cdb->Get("GRP/GRP/Data");
    cdb->Get("GRP/Align/Data");
    cdb->Get("GRP/Calib/MeanVertexSPD");
    cdb->Get("GRP/Calib/MeanVertex");
    cdb->Get("GRP/Calib/MeanVertexTPC");
    cdb->Get("GRP/Calib/CosmicTriggers");
    cdb->Get("GRP/CTP/Scalers");
    cdb->Get("GRP/CTP/CTPtiming");
    cdb->Get("GRP/CTP/TimeAlign");
    cdb->Get("GRP/GRP/LHCData");
    cdb->Get("GRP/Calib/RecoParam");

    // ********************************** ALL ******************************************
    TString detStr = ("ITS TPC TRD TOF PHOS HMPID EMCAL MUON ZDC PMD T0 VZERO");
    //TString detStr = ("ITS MUON TPC");
    TObjArray *arr = detStr.Tokenize(' ');
    for (Int_t iDet=0; iDet<arr->GetEntries(); iDet++) {
	TObjString *detOStr = dynamic_cast<TObjString*>(arr->At(iDet));
	AliCDBManager::Instance()->GetAll(Form("%s/Calib/*",detOStr->GetString().Data()));
	AliCDBManager::Instance()->Get(Form("%s/Align/Data",detOStr->GetString().Data()));
    }

    // ******************************** TRIGGER ****************************************
    // Temporary fix - one has to define the correct policy in order
    // to load the trigger OCDB entries only for the detectors that
    // in the trigger or that are needed in order to put correct
    // information in ESD
    AliCDBManager::Instance()->GetAll("TRIGGER/*/*");

    // ********************************** HLT ******************************************
    // cdb->Get("HLT/ConfigHLT/esdLayout");
    // cdb->Get("HLT/Calib/StreamerInfo");

    TMap* entriesMap = const_cast<TMap*>(cdb->GetEntryCache());
    Printf("\nentriesMap has %d entries!\n", entriesMap->GetEntries());

    TList* entriesList = const_cast<TList*>(cdb->GetRetrievedIds());
    Printf("\nentriesList has %d entries!\n", entriesList->GetEntries());

    //TString filename(TString::Format("CDBsnapshot_Run%d.root",run));
    TString filename(snapshotFileName);
    TFile *f = new TFile(filename.Data(),"recreate");
    f->cd();
    f->WriteObject(entriesMap,"entriesMap");
    f->WriteObject(entriesList,"entriesList");
    f->Close();
    entriesMap->SetOwnerKeyValue(kFALSE,kFALSE);
    entriesList->SetOwner(kFALSE);
}

void MakeCDBSnapshot()
{
    //TMap *specMap = new TMap(10);
    TMap *specMap = new TMap(30);
    specMap->SetName("mapOfSpecificStorages");
    specMap->SetOwner(1);
    specMap->Add(new TObjString("ITS/Align/Data"), new TObjString("alien://folder=/alice/simulation/2008/v4-15-Release/Residual"));

    specMap->Add(new TObjString("MUON/Align/Data"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("MUON/Calib/Gains"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    //      MTR
    specMap->Add(new TObjString("MUON/Calib/GlobalTriggerCrateConfig"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Full"));
    specMap->Add(new TObjString("MUON/Calib/LocalTriggerBoardMasks"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Full"));
    specMap->Add(new TObjString("MUON/Calib/RegionalTriggerConfig"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Full"));
    specMap->Add(new TObjString("MUON/Calib/TriggerEfficiency"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Full"));
    // TPC (23 total) 
    specMap->Add(new TObjString("TPC/Calib/PadGainFactor"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/TimeGain"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/GainFactorDedx"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/PadTime0"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/Distortion"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/PadNoise"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/PadNoise"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/Pedestals"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/Temperature"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/Parameters"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/ClusterParam"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/AltroConfig"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/Pulser"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/Pulser"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/CE"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/Mapping"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/Correction"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Align/Data"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/Goofie"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/TimeDrift"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/Raw"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/QA"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
    specMap->Add(new TObjString("TPC/Calib/HighVoltage"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/")); 


    MakeSnapshot(139517,"alien://folder=/alice/data/2010/OCDB",specMap,"cdbSnapshot.root");

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