1 AliCDBStorage *storLoc, *storGrid;
6 void DBAccessTutorial(){
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...
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()
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)
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");
35 //create the new object
37 TObjString str1("This is step zero"); // object that will be stored
39 AliCDBId id1("ZDC/Calib/Gain",0,10); // Id of the object: AliCDBId("name", firstRun, lastRun)
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);
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
56 // read, update, store again
57 printf("\n<< TUTORIAL >> Retrieve object from local storage...\n");
58 entry = storLoc->Get("ZDC/Calib/Gain", 5);
60 objstr = (TObjString*) entry->GetObject();
61 printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
63 objstr->SetString("This is step 0.1: slightly better!"); // update object
65 printf("\n<< TUTORIAL >> Storing object into local storage...\n");
66 storLoc->Put(entry); // store into local: filename = Run0_10_v0_s1.root
68 // read, update, store again
69 printf("\n<< TUTORIAL >> Retrieve object from local storage...\n");
70 entry = storLoc->Get("ZDC/Calib/Gain", 5);
72 objstr = (TObjString*) entry->GetObject();
73 printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
75 objstr -> SetString("This is step 0.2: much better!");
77 printf("\n<< TUTORIAL >> Storing object into local storage...\n");
78 storLoc->Put(entry); // store into local: filename = Run0_10_v0_s2.root
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");
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());
94 objstr -> SetString("This is step 1: stored into Local and into Grid!");
96 printf("\n<< TUTORIAL >> Storing object into local storage...\n");
97 storLoc->Put(entry); // store into local: filename = Run0_10_v0_s3.root
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
104 // step 2: read from Grid, update, store again (into Grid)
106 printf("\n<< TUTORIAL >> Retrieve object from Grid storage...\n");
107 entry = storGrid->Get("ZDC/Calib/Gain", 5);
109 objstr = (TObjString*) entry->GetObject();
110 printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
112 objstr -> SetString("This is step 2: update and store into Grid!");
114 printf("\n<< TUTORIAL >> Storing object into Grid storage...\n");
115 storGrid->Put(entry); // store into grid: filename = Run0_10_v2.root
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());
123 objstr = (TObjString*) entry->GetObject();
124 objstr -> SetString("This is step 3: update and store into Grid!");
126 printf("\n<< TUTORIAL >> Storing object into Grid storage...\n");
127 storGrid->Put(entry); // store into grid: filename = Run0_10_v3.root
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");
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());
141 printf("\n<< TUTORIAL >> Storing object into local storage...\n");
142 storLoc->Put(entry); // local: Run0_10_v3_s0.root
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());
150 objstr->SetString("This is step 3.1: updated locally!");
152 printf("\n<< TUTORIAL >> Storing object into local storage...\n");
153 storLoc->Put(entry); // local: Run0_10_v3_s1.root
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");
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());
168 printf("\n<< TUTORIAL >> Trying to store object into local storage...\n");
169 storLoc->Put(entry); // ERROR message!
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");
178 printf("\n<< TUTORIAL >> Setting Drain storage ...\n");
179 AliCDBManager::Instance()->SetDrain("dump://DBDrain.root"); //setting Drain storage
181 // Testing default storage behavior: let's set default storage to Local storage
182 AliCDBManager::Instance()->SetDefaultStorage(storLoc);
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());
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");
198 // Step 5.1: Store an object into four different Grid databases
200 TObjString str2("This is the TPC/Calib/Gain object valid for runs 0 to 10.");
201 AliCDBId id2("TPC/Calib/Gain",0,10);
203 TObjString str3("This is the TPC/Calib/Drift object valid for runs 0 to 20.");
204 AliCDBId id3("TPC/Calib/Drift",0,20);
206 TObjString str4("This is the TPC/Align/Angles object valid for runs 0 to 15.");
207 AliCDBId id4("TPC/Align/Angles",0,15);
209 TObjString str5("This is the TPC/Align/Position object valid for runs 0 to 8.");
210 AliCDBId id5("TPC/Align/Positions",0,8);
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);
218 // Step 5.2: Read all the TPC objects with GetAll and drain into DBDrain.root
220 printf("\n<< TUTORIAL >> Retrieve more objects from Grid storage and drain them into Dump ...\n");
221 TList *list = (TList*)storGrid->GetAll("TPC/*",5);
223 // That's all folks! Delete AliCDBManager instance and metaData object
225 printf( "<< TUTORIAL >> **** That's all folks!! ***\n");
228 AliCDBManager::Instance()->Destroy();