]> git.uio.no Git - u/mrichter/AliRoot.git/blame - macros/DBAccessTutorial.C
Possibility to getthe data from zip file
[u/mrichter/AliRoot.git] / macros / DBAccessTutorial.C
CommitLineData
9e1ceb13 1AliCDBStorage *storLoc, *storGrid;
2
3AliCDBEntry *entry=0;
4TObjString *objstr=0;
5
d85afa9b 6void DBAccessTutorial(){
7
9e1ceb13 8AliCDBManager *man = AliCDBManager::Instance();
9// pointer man points to the single instance of AliCDBManager.
10// This will let us avoid typing AliCDBManager::Instance every time...
d85afa9b 11
d85afa9b 12
9e1ceb13 13printf("\n<< TUTORIAL >> Activating Grid storage...\n");
14storGrid = man->GetStorage("alien://aliendb4.cern.ch:9000;colla;DBGrid;ALICE::CERN::se01"); // replace "colla" with your username!
15// The default storage is automatically set to this.
16// One can access default storage with:
17// (AliCDBStorage*) AliCDBManager::Instance()->GetDefaultStorage()
18// To check the activation of the default storage:
19// (Bool_t) AliCDBManager::Instance()->IsDefaultStorageSet()
20
21printf("\n<< TUTORIAL >> Activating Local storage...\n");
22storLoc = man->GetStorage("local://DBLocal");
23// To set the default storage to this one:
24// AliCDBMAnager::Instance()->SetDefaultStorage("local://DBLocal") or
25// AliCDBMAnager::Instance()->SetDefaultStorage(storLoc)
26
27/////////////////////////////////////////////
28// Step 0: Write/read in Local storage //
29/////////////////////////////////////////////
30printf("\n<< TUTORIAL >> ********************************************\n");
31printf( "<< TUTORIAL >> **** Step 0: write/read in local storage ***\n");
32printf( "<< TUTORIAL >> ********************************************\n");
33
34
35//create the new object
36
37TObjString str1("This is step zero"); // object that will be stored
38
39AliCDBId id1("ZDC/Calib/Gain",0,10); // Id of the object: AliCDBId("name", firstRun, lastRun)
40
41AliCDBMetaData *md1= new AliCDBMetaData(); // metaData describing the object
42md1->SetObjectClassName("TObjString");
43md1->SetResponsible("Alberto Colla");
44md1->SetBeamPeriod(1);
45md1->SetAliRootVersion("05-04-00"); //root version
46md1->SetComment("This is a test");
47TObjString str("test");
48md1->SetProperty("key1",&str);
49
50
51// Store the object into local storage
52printf("\n<< TUTORIAL >> Storing object into local storage...\n");
53storLoc->Put(&str1,id1, md1); // filename: DBLocal/ZDC/Calib/Gain/Run0_10_v0_s0.root
54
55
56// read, update, store again
57printf("\n<< TUTORIAL >> Retrieve object from local storage...\n");
58entry = storLoc->Get("ZDC/Calib/Gain", 5);
59
60objstr = (TObjString*) entry->GetObject();
61printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
62
63objstr->SetString("This is step 0.1: slightly better!"); // update object
64
65printf("\n<< TUTORIAL >> Storing object into local storage...\n");
66storLoc->Put(entry); // store into local: filename = Run0_10_v0_s1.root
67
68// read, update, store again
69printf("\n<< TUTORIAL >> Retrieve object from local storage...\n");
70entry = storLoc->Get("ZDC/Calib/Gain", 5);
71
72objstr = (TObjString*) entry->GetObject();
73printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
74
75objstr -> SetString("This is step 0.2: much better!");
76
77printf("\n<< TUTORIAL >> Storing object into local storage...\n");
78storLoc->Put(entry); // store into local: filename = Run0_10_v0_s2.root
79
80///////////////////////////////////////////////////////////////////////
81// Step 1: read from Local, update, store locally and into Grid //
82///////////////////////////////////////////////////////////////////////
83printf("\n<< TUTORIAL >> ********************************************\n");
84printf( "<< TUTORIAL >> **** Step 1: write/read in Grid storage ***\n");
85printf( "<< TUTORIAL >> ********************************************\n");
86
87// read from local
88printf("\n<< TUTORIAL >> Retrieve object from local storage...\n");
89entry = storLoc->Get("ZDC/Calib/Gain", 5);
90objstr = (TObjString*) entry->GetObject();
91printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
92
93
94objstr -> SetString("This is step 1: stored into Local and into Grid!");
95
96printf("\n<< TUTORIAL >> Storing object into local storage...\n");
97storLoc->Put(entry); // store into local: filename = Run0_10_v0_s3.root
98
99printf("\n<< TUTORIAL >> Storing object into Grid storage...\n");
100storGrid->Put(entry); // store into grid: filename = DBGrid/ZDC/Calib/Gain/Run0_10_v1.root
101
102
103
104// step 2: read from Grid, update, store again (into Grid)
d85afa9b 105
9e1ceb13 106printf("\n<< TUTORIAL >> Retrieve object from Grid storage...\n");
107entry = storGrid->Get("ZDC/Calib/Gain", 5);
d85afa9b 108
9e1ceb13 109objstr = (TObjString*) entry->GetObject();
110printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
d85afa9b 111
9e1ceb13 112objstr -> SetString("This is step 2: update and store into Grid!");
d85afa9b 113
9e1ceb13 114printf("\n<< TUTORIAL >> Storing object into Grid storage...\n");
115storGrid->Put(entry); // store into grid: filename = Run0_10_v2.root
d85afa9b 116
9e1ceb13 117// step 3: read, update, store again (into Grid)
118printf("\n<< TUTORIAL >> Retrieve object from Grid storage...\n");
119entry = storGrid->Get("ZDC/Calib/Gain", 5);
120objstr = (TObjString*) entry->GetObject();
121printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
d85afa9b 122
9e1ceb13 123objstr = (TObjString*) entry->GetObject();
124objstr -> SetString("This is step 3: update and store into Grid!");
d85afa9b 125
9e1ceb13 126printf("\n<< TUTORIAL >> Storing object into Grid storage...\n");
127storGrid->Put(entry); // store into grid: filename = Run0_10_v3.root
d85afa9b 128
9e1ceb13 129 ////////////////////////////////////////////////
130 // Step 3.0: read from Grid, store locally! //
131////////////////////////////////////////////////
132printf("\n<< TUTORIAL >> **********************************************\n");
133printf( "<< TUTORIAL >> **** Step 3: read from Grid, store locally ***\n");
134printf( "<< TUTORIAL >> **********************************************\n");
d85afa9b 135
9e1ceb13 136printf("\n<< TUTORIAL >> Retrieve object from Grid storage...\n");
137entry = storGrid->Get("ZDC/Calib/Gain", 5);
138objstr = (TObjString*) entry->GetObject();
139printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
d85afa9b 140
9e1ceb13 141printf("\n<< TUTORIAL >> Storing object into local storage...\n");
142storLoc->Put(entry); // local: Run0_10_v3_s0.root
d85afa9b 143
9e1ceb13 144// Step 3.1: read from Local, update, store again into Local
145printf("\n<< TUTORIAL >> Retrieve object from local storage...\n");
146entry = storLoc->Get("ZDC/Calib/Gain", 5);
147objstr = (TObjString*) entry->GetObject();
148printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
d85afa9b 149
9e1ceb13 150objstr->SetString("This is step 3.1: updated locally!");
d85afa9b 151
9e1ceb13 152printf("\n<< TUTORIAL >> Storing object into local storage...\n");
153storLoc->Put(entry); // local: Run0_10_v3_s1.root
d85afa9b 154
9e1ceb13 155/////////////////////////////////////////////////////////////
156// Step 3.2: read again from Grid version 3, store locally //
157// -> ERROR, local update already present!! //
158/////////////////////////////////////////////////////////////
159printf("\n<< TUTORIAL >> **********************************************\n");
160printf( "<< TUTORIAL >> **** Step 3.2: error test ***\n");
161printf( "<< TUTORIAL >> **********************************************\n");
d85afa9b 162
9e1ceb13 163printf("\n<< TUTORIAL >> Retrieve object from Grid storage...\n");
164entry = (AliCDBEntry*) storGrid->Get("ZDC/Calib/Gain",5);
165objstr = (TObjString*) entry->GetObject();
166printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
d85afa9b 167
9e1ceb13 168printf("\n<< TUTORIAL >> Trying to store object into local storage...\n");
169storLoc->Put(entry); // ERROR message!
d85afa9b 170
9e1ceb13 171/////////////////////////////////////////////////////////////
172// Step 4: read from local, DRAIN to a dump storage: DBDrain.root! //
173/////////////////////////////////////////////////////////////
174printf("\n<< TUTORIAL >> ************************************************************\n");
175printf( "<< TUTORIAL >> **** Step 4: Read from local and DRAIN to a dump storage ***\n");
176printf( "<< TUTORIAL >> ************************************************************\n");
d85afa9b 177
9e1ceb13 178printf("\n<< TUTORIAL >> Setting Drain storage ...\n");
179AliCDBManager::Instance()->SetDrain("dump://DBDrain.root"); //setting Drain storage
d85afa9b 180
9e1ceb13 181// Testing default storage behavior: let's set default storage to Local storage
182AliCDBManager::Instance()->SetDefaultStorage(storLoc);
d85afa9b 183
9e1ceb13 184// read from local (default) storage. The object is automatically drained into the drain storage!
185printf("\n<< TUTORIAL >> Retrieve object from local storage...\n");
186entry = man->GetDefaultStorage()->Get("ZDC/Calib/Gain",5);
187objstr = (TObjString*) entry->GetObject();
188printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
d85afa9b 189
9e1ceb13 190/////////////////////////////////////////////////////////////
191// Step 5: READ AND DRAIN multiple objects (with GetAll) //
192/////////////////////////////////////////////////////////////
193printf("\n<< TUTORIAL >> *******************************************************\n");
194printf( "<< TUTORIAL >> **** Step 5: Read and Drain multiple objects ***\n");
195printf( "<< TUTORIAL >> *******************************************************\n");
d85afa9b 196
d85afa9b 197
9e1ceb13 198// Step 5.1: Store an object into four different Grid databases
d85afa9b 199
9e1ceb13 200TObjString str2("This is the TPC/Calib/Gain object valid for runs 0 to 10.");
201AliCDBId id2("TPC/Calib/Gain",0,10);
d85afa9b 202
9e1ceb13 203TObjString str3("This is the TPC/Calib/Drift object valid for runs 0 to 20.");
204AliCDBId id3("TPC/Calib/Drift",0,20);
d85afa9b 205
9e1ceb13 206TObjString str4("This is the TPC/Align/Angles object valid for runs 0 to 15.");
207AliCDBId id4("TPC/Align/Angles",0,15);
d85afa9b 208
9e1ceb13 209TObjString str5("This is the TPC/Align/Position object valid for runs 0 to 8.");
210AliCDBId id5("TPC/Align/Positions",0,8);
d85afa9b 211
9e1ceb13 212printf("\n<< TUTORIAL >> Storing more objects into Grid storage...\n");
213storGrid->Put(&str2,id2,md1);
214storGrid->Put(&str3,id3,md1);
215storGrid->Put(&str4,id4,md1);
216storGrid->Put(&str5,id5,md1);
d85afa9b 217
9e1ceb13 218// Step 5.2: Read all the TPC objects with GetAll and drain into DBDrain.root
d85afa9b 219
9e1ceb13 220printf("\n<< TUTORIAL >> Retrieve more objects from Grid storage and drain them into Dump ...\n");
221TList *list = (TList*)storGrid->GetAll("TPC/*",5);
d85afa9b 222
9e1ceb13 223// That's all folks! Delete AliCDBManager instance and metaData object
d85afa9b 224
9e1ceb13 225printf( "<< TUTORIAL >> **** That's all folks!! ***\n");
d85afa9b 226
d85afa9b 227
9e1ceb13 228AliCDBManager::Instance()->Destroy();
229delete entry;
230delete md1;
d85afa9b 231
232}