Updates according to recent changes in AliPHOSCalibData: splitting EMC and CPV calibr...
[u/mrichter/AliRoot.git] / PHOS / macros / CalibrationDB / AliPHOSCalibDataTest.C
CommitLineData
2f398679 1void AliPHOSCalibDataTest(){
2
3
4 /***************************************************************************************************************
5 Prelude(0): if it doesn't exist, create DB directory: $ALICE_ROOT/DB
6 ***************************************************************************************************************/
7 TString DBFolder="PhosCalibDB";
8 gSystem->ExpandPathName(DBFolder);
9
10 if(!gSystem->OpenDirectory(DBFolder)){
11 printf("Warning: folder PhosCalibDB does not exist, I will create it!");
12 TString command = "mkdir "+ DBFolder;
13 gSystem->Exec(command.Data());
14 }
15
16 /***************************************************************************************************************
17 Prelude(1): create a DB object. We'll take AliPHOSCalibData
18 (container class for PHOS Calibration data) as an example
19 ***************************************************************************************************************/
20
21 AliPHOSCalibData *calibda=new AliPHOSCalibData("PHOS");
22
23 // Fill array of PHOS energy calibration factors (4 float's) with some numbers
24 Float_t EnFactorsArray[5][64][56];
25 for(Int_t module=0; module<5; module++) {
26 for(Int_t column=0; column<64; column++) {
27 for(Int_t row=0; row<56; row++) {
28 calibda->SetADCchannelEmc(module,column,row,1.1);
29 calibda->SetADCpedestalEmc(module,column,row,0.5);
30 }
31 }
32 }
33
34 printf("\nI am in Prelude(1). PHOS Energy calibration factors: \n");
35 calibda->Print("ped gain");
36
37 /***************************************************************************************************************
38 Part 1: Store the calibration object in the database, using
39 the "Organized" storage system
40 (i.e. a well defined directory structure, defined by the
41 object's metadata and set in the DBFodler above specified)
42 ***************************************************************************************************************/
43
44 // a. Define the object's metadata (set of information which describes the object)
45 // AliObjectMetaData(char* name, int firstRun, int lastRun,int Period,char* ObjectFormat, char* ResponsibleName, char* extraInfo)
46 //
47 // name: Object's name ("Detector/DBType/DetSpecType")
48 // firstRun: first run for which the object is valid
49 // lastRun: last run for which the object is valid
50 // period: beam period (to be better specified in future)
51 // objectFormat: a string which describes the object's format
52 // ResponsibleName: name of the person who created and stored the object
53 // extraInfo: anything else you may want to know
54
55 AliObjectMetaData omd("PHOS/Calib/GainFactors",1,10,1,"AliPHOSCalibData: Pedestals and ADC channels (5x64x56 floats)","Yuri Kharlov", "PHOS calibration test");
56
57 // b. Create the specific AliRunDataStorage instance (AliRunDataOrganizedFile in this case)
58
59 AliRunDataOrganizedFile *orgf = new AliRunDataOrganizedFile(DBFolder.Data());
60
61 // c. Put the object in the database. Use Put method: AliRunDataStorage::Put(TObject object, AliObjectMetaData& metaData)
62 //
63 // the object will be stored in the file DBFolder/PHOS/Calib/GainFactors/Run1-10_v0.root
64 // Note that the version is automatically determined.
65
66 AliRunDataStorage::Instance()->Put(calibda, omd); // we could also type: orgf->Put(calibda, omd)
67
68 // delete the AliRunDataStorage instance and the object (optional)
69 AliRunDataStorage::Instance()->Delete();
70
71
72 /***************************************************************************************************************
73 Part 2: Now we want to retrieve the object valid, say, for run 5 from the database folder.
74 We will dump it in a local file called "dummyDBTutorail.root", for later usage.
75 ***************************************************************************************************************/
76
77 // a. Create the specific AliRunDataStorage instance (AliRunDataOrganizedFile in this case)
78 AliRunDataOrganizedFile *orgf = new AliRunDataOrganizedFile(DBFolder.Data());
79
80 // b. Prepare AliRunDataStorage to save the object in the local file
81 AliRunDataStorage::Instance()->RecordToFile("dummyPhosCalibDB.root");
82
83 // c. Get the object!
84 // TObject *AliRunDataStorage::Get(char* name, int runNumber)
85 // if no selection criteria are specified, the highest version found is retrieved.
86
87 AliPHOSCalibData *calibda2 = (AliPHOSCalibData*) AliRunDataStorage::Instance()->Get("PHOS/Calib/GainFactors",5);
88
89 printf("\nI am in Part2. PHOS Energy calibration factors: \n");
90 calibda2->Print("gain");
91
92 AliRunDataStorage::Instance()->Delete();
93
94
95 /***************************************************************************************************************
96 Part 3: Now we will retrieve the object from the local file.
97 We will tune the energy calibration factors and we suppose that the new object is valid from run 1 to run 15.
98 Finally we will store the object in DBFolder again with the new run range specified in the object's metadata.
99 ***************************************************************************************************************/
100
101 // a. Create the specific AliRunDataStorage instance (AliRunDataFile in this case)
102 AliRunDataFile *df = new AliRunDataFile("dummyPhosCalibDB.root");
103 //AliRunDataOrganizedFile *orgf = new AliRunDataOrganizedFile(DBFolder.Data());
104
105 // b. Get the object.
106 AliPHOSCalibData *calibda3 = (AliPHOSCalibData*) AliRunDataStorage::Instance()->Get("PHOS/Calib/GainFactors",5);
107
108 //AliPHOSCalibData calibda3copy=*calibda3;
109
110 // c. Tune the energy calibration factors in the 5th module
111 for(Int_t module=4; module<5; module++) {
112 for(Int_t column=0; column<64; column++) {
113 for(Int_t row=0; row<56; row++) {
114 calibda3->SetADCchannelEmc(module,column,row,1.2);
115 }
116 }
117 }
118
119 printf("\nI am in Part3. New PHOS Energy calibration factors: \n");
120 calibda3->Print("gain");
121
122 // d. Get the object's metadata, set the new run range
123 AliObjectMetaData omd2 = AliRunDataStorage::Instance()->GetObjectMetaData("PHOS/Calib/GainFactors");
124 omd2.SetRunRange(1,15);
125
126 // e. Store the object in the "organized" database.
127 // the object will be stored in the file DBFolder/PHOS/Calib/GainFactors/Run1-15_v1.root
128 // Note that, since there is an "overlap" of the new run range with the one specified
129 // in the previous version, the version is automatically increased.
130
131 AliRunDataOrganizedFile *orgf = new AliRunDataOrganizedFile(DBFolder.Data());
132 AliRunDataStorage::Instance()->Put(calibda3, omd2);
133
134 /***************************************************************************************************************
135 Part 3: Last act.
136 We want to retrieve the object from the "organized" database folder again.
137 This time, anyway, we don't want the highest version but version 0 instead.
138 Therefore we have to specify the version wanted using the "Select" method of AliRunDataStorage
139 and the aliSelectionMetaData object.
140 ***************************************************************************************************************/
141
142 // a. Create the specific AliRunDataStorage instance (AliRunDataOrganizedFile in this case)
143 orgf = new AliRunDataOrganizedFile(DBFolder.Data());
144
145 // b. Specify the selection criterion. We want version 0 for the object valid for run range (1,100)
146 // NOTE(1): TRegexp expression are valid! E.g. we could type "PHOS/Calib/*" if we want to specify version
147 // for all the "PHOS/Calib" subsamples...
148 // Note(2): we could also not specify the run range, if we want version 0 for any retrieved object
149 AliSelectionMetaData smd("PHOS/Calib/GainFactors",1,100,0);
150 AliRunDataStorage::Instance()->Select(smd);
151
152 // c. Get the object
153 AliPHOSCalibData *calibda4 = (AliPHOSCalibData*) AliRunDataStorage::Instance()->Get("PHOS/Calib/GainFactors",5);
154 printf("\nI am in Part4. I've just got \"PHOS/Calib/GainFactors\" object valid for run 5, version 0.\n");
155 printf("PHOS Energy calibration factors: \n");
156 calibda4->Print("gain");
157
158 printf("\nEnd of tutorial. Bye bye!! \n");
159
160
161}