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