Drawing coarse slats and quadrants in the MUONdisplay (Christian, Gines)
[u/mrichter/AliRoot.git] / macros / DBAccessTutorial.C
d85afa9b 1void DBAccessTutorial(){
5 Prelude(0): if it doesn't exist, create DB directory: $ALICE_ROOT/DB
6 ***************************************************************************************************************/
7TString DBFolder="$ALICE_ROOT/DBTutorial";
11 printf("Warning: folder DBTutorial does not exist, I will create it!");
12 TString command = "mkdir "+ DBFolder;
13 gSystem->Exec(command.Data());
17 Prelude(1): create a DB object. We'll take AliZDCCalibData
18 (container class for ZDC Calibration data) as an example
19 ***************************************************************************************************************/
21AliZDCCalibData *calibda=new AliZDCCalibData("ZDC");
23// Fill array of ZDC energy calibration factors (4 float's) with some numbers
24Float_t EnFactorsArray[4]={20.,25.,200.,10.};
27printf("\nI am in Prelude(1). ZDC Energy calibration factors: \n");
28printf("PM0=%f; PM1=%f; PM2=%f; PM3=%f \n",
29 calibda->GetEnCalib(0), calibda->GetEnCalib(1), calibda->GetEnCalib(2), calibda->GetEnCalib(3) );
32 Part 1: Store the calibration object in the database, using
33 the "Organized" storage system
34 (i.e. a well defined directory structure, defined by the
35 object's metadata and set in the DBFodler above specified)
36 ***************************************************************************************************************/
38// a. Define the object's metadata (set of information which describes the object)
fe913d8f 39// AliCDBMetaData(char* name, int firstRun, int lastRun,int Period,char* ObjectFormat, char* ResponsibleName, char* extraInfo)
d85afa9b 40//
41// name: Object's name ("Detector/DBType/DetSpecType")
42// firstRun: first run for which the object is valid
43// lastRun: last run for which the object is valid
44// period: beam period (to be better specified in future)
45// objectFormat: a string which describes the object's format
46// ResponsibleName: name of the person who created and stored the object
47// extraInfo: anything else you may want to know
fe913d8f 49AliCDBMetaData md("ZDC/Calib/GainFactors",1,10,1,"AliZDCCalibData: Pedestals (47 floats), En. calib factors (4 floats)","A. Colla", "Tutorial");
d85afa9b 50
fe913d8f 51// b. Create the specific AliCDBStorage instance (AliCDBLocal in this case)
d85afa9b 52
fe913d8f 53AliCDBLocal *loc = new AliCDBLocal(DBFolder.Data());
d85afa9b 54
fe913d8f 55// c. Put the object in the database. Use Put method: AliCDBStorage::Put(TObject object, AliCDBMetaData& metaData)
d85afa9b 56//
57// the object will be stored in the file DBFolder/ZDC/Calib/GainFactors/Run1-10_v0.root
58// Note that the version is automatically determined.
fe913d8f 60AliCDBStorage::Instance()->Put(calibda, md); // we could also type: loc->Put(calibda, md)
d85afa9b 61
fe913d8f 62// delete the AliCDBStorage instance and the object (optional)
d85afa9b 64
67 Part 2: Now we want to retrieve the object valid, say, for run 5 from the database folder.
fe913d8f 68 We will dump it in a dump file called "dummyDBTutorail.root", for later usage.
d85afa9b 69 ***************************************************************************************************************/
fe913d8f 71// a. Create the specific AliCDBStorage instance (AliCDBLocal in this case)
72AliCDBLocal *loc = new AliCDBLocal(DBFolder.Data());
d85afa9b 73
fe913d8f 74// b. Prepare AliCDBStorage to save the object in the dump file
d85afa9b 76
77// c. Get the object!
fe913d8f 78// TObject *AliCDBStorage::Get(char* name, int runNumber)
d85afa9b 79// if no selection criteria are specified, the highest version found is retrieved.
fe913d8f 81AliZDCCalibData *calibda2 = (AliZDCCalibData*) AliCDBStorage::Instance()->Get("ZDC/Calib/GainFactors",5);
d85afa9b 82
83printf("\nI am in Part2. ZDC Energy calibration factors: \n");
84printf("PM0=%f; PM1=%f; PM2=%f; PM3=%f \n",
85 calibda2->GetEnCalib(0), calibda2->GetEnCalib(1), calibda2->GetEnCalib(2), calibda2->GetEnCalib(3) );
fe913d8f 87AliCDBStorage::Instance()->Delete();
d85afa9b 88
fe913d8f 91 Part 3: Now we will retrieve the object from the dump file.
d85afa9b 92 We will tune the energy calibration factors and we suppose that the new object is valid from run 1 to run 15.
93 Finally we will store the object in DBFolder again with the new run range specified in the object's metadata.
94 ***************************************************************************************************************/
fe913d8f 96// a. Create the specific AliCDBStorage instance (AliCDBDump in this case)
97AliCDBDump *df = new AliCDBDump("dummyDBTutorial.root");
d85afa9b 98
99// b. Get the object.
fe913d8f 100AliZDCCalibData *calibda3 = (AliZDCCalibData*) AliCDBStorage::Instance()->Get("ZDC/Calib/GainFactors",5);
d85afa9b 101
102//AliZDCCalibData calibda3copy=*calibda3;
104// c. Tune the energy calibration factors.
105calibda3->SetEnCalib(21.5, 0); calibda3->SetEnCalib(26.3, 1);
106calibda3->SetEnCalib(201., 2); calibda3->SetEnCalib(9.45, 3);
108printf("\nI am in Part3. New ZDC Energy calibration factors: \n");
109printf("PM0=%f; PM1=%f; PM2=%f; PM3=%f \n",
110 calibda3->GetEnCalib(0), calibda3->GetEnCalib(1), calibda3->GetEnCalib(2), calibda3->GetEnCalib(3) );
112// d. Get the object's metadata, set the new run range
fe913d8f 113AliCDBMetaData md2 = AliCDBStorage::Instance()->GetCDBMetaData("ZDC/Calib/GainFactors");
d85afa9b 115
116// e. Store the object in the "organized" database.
117// the object will be stored in the file DBFolder/ZDC/Calib/GainFactors/Run1-15_v1.root
118// Note that, since there is an "overlap" of the new run range with the one specified
119// in the previous version, the version is automatically increased.
fe913d8f 121AliCDBLocal *loc = new AliCDBLocal(DBFolder.Data());
122AliCDBStorage::Instance()->Put(calibda3, md2);
d85afa9b 123
125 Part 3: Last act.
126 We want to retrieve the object from the "organized" database folder again.
127 This time, anyway, we don't want the highest version but version 0 instead.
fe913d8f 128 Therefore we have to specify the version wanted using the "Select" method of AliCDBStorage
129 and the aliCDBMetaDataSelect object.
d85afa9b 130 ***************************************************************************************************************/
fe913d8f 132// a. Create the specific AliCDBStorage instance (AliCDBLocal in this case)
133loc = new AliCDBLocal(DBFolder.Data());
d85afa9b 134
135// b. Specify the selection criterion. We want version 0 for the object valid for run range (1,100)
136// NOTE(1): TRegexp expression are valid! E.g. we could type "ZDC/Calib/*" if we want to specify version
137// for all the "ZDC/Calib" subsamples...
138// Note(2): we could also not specify the run range, if we want version 0 for any retrieved object
fe913d8f 139AliCDBMetaDataSelect smd("ZDC/Calib/GainFactors",1,100,0);
d85afa9b 141
142// c. Get the object
fe913d8f 143AliZDCCalibData *calibda4 = (AliZDCCalibData*) AliCDBStorage::Instance()->Get("ZDC/Calib/GainFactors",5);
d85afa9b 144printf("\nI am in Part4. I've just got \"ZDC/Calib/GainFactors\" object valid for run 5, version 0.\n");
145printf("ZDC Energy calibration factors: \n");
146printf("PM0=%f; PM1=%f; PM2=%f; PM3=%f \n",
147 calibda4->GetEnCalib(0), calibda4->GetEnCalib(1), calibda4->GetEnCalib(2), calibda4->GetEnCalib(3) );
149printf("\nEnd of tutorial. Bye bye!! \n");