]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/Macros/AliTRDWriteIntoDataBase.C
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / TRD / Macros / AliTRDWriteIntoDataBase.C
1 #if !defined( __CINT__) || defined(__MAKECINT__)
2
3 #include <iostream>
4
5 #include <vector>
6 #include <TChain.h>
7 #include <TFile.h>
8 #include <TTree.h>
9 #include <TString.h>
10 #include <TObject.h>
11 #include <TSystem.h>
12 #include <TH1F.h>
13
14 #include "AliCDBManager.h"
15 #include "AliCDBId.h"
16 #include "AliCDBStorage.h"
17 #include "AliCDBMetaData.h"
18 #include "AliTRDCalibra.h"
19 #include "AliTRDCalDet.h"
20
21 #endif
22 const Int_t firstrun = 0;
23 const Int_t lastrun = 0;
24 AliCDBStorage* gStorLoc = 0;
25 AliCDBMetaData* CreateMetaObject(const char* objectClassName);
26 void StoreObject(const char* cdbPath, TObject* object, AliCDBMetaData* metaData);
27 Bool_t WriteIntoDataBase(TTree *tree, Int_t i);
28
29
30 AliCDBMetaData* CreateMetaObject(const char* objectClassName)
31 {
32   AliCDBMetaData *md1= new AliCDBMetaData(); 
33   md1->SetObjectClassName(objectClassName);
34   md1->SetResponsible("Raphaelle Bailhache");
35   md1->SetBeamPeriod(1);
36   md1->SetAliRootVersion("05-06-00"); //root version
37   md1->SetComment("The dummy values in this calibration file are for testing only");
38   
39   return md1;
40 }
41
42 void StoreObject(const char* cdbPath, TObject* object, AliCDBMetaData* metaData)
43 {
44   AliCDBId id1(cdbPath, firstrun, lastrun); 
45   id1.SetVersion(0);
46   gStorLoc->Put(object, id1, metaData); 
47 }
48
49
50 Bool_t AliTRDWriteIntoDataBase(TTree *tree, Int_t i){
51   //
52   // To use this macro, you have first to write the coefficients in a file
53   // To take the resulted tree from the file and to give it to this macro
54   // The macro will write the coefficient into a local database
55   // in the directory where you run it
56   //
57
58
59   AliTRDCalDet* obj1 = 0;
60   TObject* obj2 = 0;
61   AliCDBMetaData *metadata = 0;
62  
63  
64   
65   //Single instance of AliCDBManager and AliTRDCalibra 
66   AliCDBManager *man = AliCDBManager::Instance();
67   if (!man) {
68     printf("Could not get CDB Manager");
69     return kFALSE;
70   }
71   gStorLoc = man->GetDefaultStorage();
72   if (!gStorLoc) {
73     printf("Could not get default Storage");
74     return kFALSE;
75   }
76   AliTRDCalibra *calibra = AliTRDCalibra::Instance();
77
78
79  
80   // Create the new database object Det
81   if(i != 2) {
82     obj1 = calibra->CreateDetObjectTree(tree, i);
83     obj2 = calibra->CreatePadObjectTree(tree, i, obj1);
84   }
85   if(i == 2) obj2 = calibra->CreatePadObjectTree(tree);
86   
87
88   //Store the info for the detector
89   if(i != 2) {
90     metadata = CreateMetaObject("AliTRDCalDet");
91     if(i == 0) StoreObject("TRD/Calib/ChamberGainFactor",(TObject *) obj1, metadata);
92     if(i == 1) StoreObject("TRD/Calib/ChamberVdrift",(TObject *) obj1, metadata);
93     if(i == 3) StoreObject("TRD/Calib/ChamberT0",(TObject *) obj1, metadata);
94     
95   }
96
97  
98   //Store the info for the pad
99   metadata = CreateMetaObject("AliTRDCalPad");
100   if(i == 0) StoreObject("TRD/Calib/LocalGainFactor",(TObject *) obj2, metadata); 
101   if(i == 1) StoreObject("TRD/Calib/LocalVdrift",(TObject *) obj2, metadata); 
102   if(i == 3) StoreObject("TRD/Calib/LocalT0",(TObject *) obj2, metadata); 
103   if(i == 2) StoreObject("TRD/Calib/PRFWidth",(TObject *) obj2, metadata); 
104
105
106   return kTRUE;
107 }