]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/CDB/AliDCSGenDB.cxx
CMake: Retrieve Git information
[u/mrichter/AliRoot.git] / STEER / CDB / AliDCSGenDB.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16
17 ///////////////////////////////////////////////////////////////////////////////
18 //                                                                           //
19 //  Class to generate DCS data base entries                                  //
20 //  Author: Haavard Helstrup                                                 //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24
25
26
27
28 // TTimeStamp startTime(2006,10,18,0,0,0,0,kFALSE)
29 // TTimeStamp endTime(2006,10,19,0,0,0,0,kFALSE)
30 // Int_t run=2546
31 // AliDCSGenDB db
32 // db->SetDefaultStorage("local:///afs/cern.ch/alice/tpctest/AliRoot/HEAD");
33 // db->SetSpecificStorage("local:///afs/cern.ch/alice/tpctest/Calib/");
34 // db->Init(run,"TPC/Config/Pressure","TPC/*/*")
35 // db->MakeCalib("PressureSensor.txt","DCSMap.root",startTime,endTime,firstRun,lastRun,"TPC/Calib/Pressure")
36
37
38 #include "AliDCSGenDB.h"
39 #include "AliLog.h"
40 #include "ARVersion.h"
41
42 const Int_t kBeamPeriod=2;
43
44 ClassImp(AliDCSGenDB)
45
46 //______________________________________________________________________________________________
47
48 AliDCSGenDB::AliDCSGenDB():
49   fFirstRun(0),
50   fLastRun(0),
51   fSpecificStorage(0),
52   fDefaultStorage(0),
53   fSensor(0),
54   fStorLoc(0),
55   fMetaData(0),
56   fConfTree(0)
57   //
58   //  standard constructor
59   //
60 {}
61
62 //______________________________________________________________________________________________
63
64 AliDCSGenDB::AliDCSGenDB(const char* defaultStorage, const char* specificStorage):
65   fFirstRun(0),
66   fLastRun(0),
67   fSpecificStorage(specificStorage),
68   fDefaultStorage(defaultStorage),
69   fSensor(0),
70   fStorLoc(0),
71   fMetaData(0),
72   fConfTree(0)
73   //
74   //  special constructor
75   //
76 {}
77
78 //______________________________________________________________________________________________
79
80 AliDCSGenDB::AliDCSGenDB(const AliDCSGenDB& org):
81   TObject(org),
82   fFirstRun(org.fFirstRun),
83   fLastRun(org.fLastRun),
84   fSpecificStorage(org.fSpecificStorage),
85   fDefaultStorage(org.fDefaultStorage),
86   fSensor(0),
87   fStorLoc(0),
88   fMetaData(0),
89   fConfTree(0)
90 {
91   //
92   //  Copy constructor
93   //
94
95   AliError("copy constructor not implemented");
96
97 }
98
99 //______________________________________________________________________________________________
100 AliDCSGenDB::~AliDCSGenDB(){
101   //
102   // destructor
103   //
104   delete fSensor;
105   delete fMetaData;
106   delete fConfTree;
107 }
108
109 //______________________________________________________________________________________________
110 AliDCSGenDB& AliDCSGenDB::operator= (const AliDCSGenDB& /*org*/ )
111 {
112   //
113   // assignment operator
114   //
115   AliError("assignment operator not implemented");
116   return *this;
117
118 }
119
120 //______________________________________________________________________________________________
121
122 void AliDCSGenDB::MakeCalib(const char *list, const char *mapDCS,
123     const TTimeStamp& startTime,
124     const TTimeStamp& endTime,
125     Int_t firstRun, Int_t lastRun, const char *calibDir )
126 {
127
128   // Generate calibration entry from DCS map
129   // Configuration read from ASCII file specified by list
130
131   TClonesArray *arr = ReadList(list);
132   fSensor = new AliDCSSensorArray(arr);
133   fSensor->SetStartTime(startTime);
134   fSensor->SetEndTime(endTime);
135   TMap* map = SetGraphFile(mapDCS);
136   if (map) {
137     fSensor->MakeSplineFit(map);
138   }
139   delete map;
140   map=0;
141   mapDCS=0;
142
143   SetFirstRun(firstRun);
144   SetLastRun(lastRun);
145
146   StoreObject(calibDir, fSensor, fMetaData);
147 }
148
149 //______________________________________________________________________________________________
150 void AliDCSGenDB::MakeConfig(const char *file, Int_t firstRun, Int_t lastRun, const char *confDir )
151 {
152   //
153   // Store Configuration file to OCDB
154   //
155
156   TTree *tree = ReadListTree(file);
157   SetConfTree(tree);
158   SetFirstRun(firstRun);
159   SetLastRun(lastRun);
160
161   StoreObject(confDir, fConfTree, fMetaData);
162 }
163
164
165
166
167 //______________________________________________________________________________________________
168 AliCDBMetaData* AliDCSGenDB::CreateMetaObject(const char* objectClassName)
169 {
170   AliCDBMetaData *md1= new AliCDBMetaData();
171   md1->SetObjectClassName(objectClassName);
172   md1->SetResponsible("Haavard Helstrup");
173   md1->SetBeamPeriod(kBeamPeriod);
174   md1->SetAliRootVersion(ALIROOT_VERSION);
175
176   return md1;
177 }
178
179 //______________________________________________________________________________________________
180 void AliDCSGenDB::StoreObject(const char* cdbPath, TObject* object, AliCDBMetaData* metaData)
181 {
182
183   AliCDBId id1(cdbPath, fFirstRun, fLastRun);
184   if (fStorLoc) fStorLoc->Put(object, id1, metaData);
185 }
186
187 //______________________________________________________________________________________________
188 void AliDCSGenDB::Init(Int_t run, const char *configDir, 
189     const char *specificDir,
190     const char *sensorClass)
191 {
192
193   fMetaData = CreateMetaObject(sensorClass);
194   AliCDBManager *man = AliCDBManager::Instance();
195   man->SetDefaultStorage(fDefaultStorage);
196   man->SetRun(run);
197   man->SetSpecificStorage(specificDir,fSpecificStorage);
198   AliCDBEntry *config = man->Get(configDir);
199   if (config) fConfTree = (TTree*)config->GetObject();
200   fStorLoc = man->GetStorage(fSpecificStorage);
201   if (!fStorLoc)    return;
202
203   /*Bool_t cdbCache = */AliCDBManager::Instance()->GetCacheFlag(); // save cache status
204   AliCDBManager::Instance()->SetCacheFlag(kTRUE); // activate CDB cache
205
206
207 }
208
209 //______________________________________________________________________________________________
210
211
212 //_____________________________________________________________________________
213 TMap* AliDCSGenDB::SetGraphFile(const char *fname)
214 {
215   //
216   // Read DCS maps from file given by fname
217   //
218   TFile file(fname);
219   TMap * map = (TMap*)file.Get("DCSMap");
220   return map;
221 }
222
223 //______________________________________________________________________________________________
224
225 TClonesArray * AliDCSGenDB::ReadList(const char *fname, const char *title) {
226   //
227   // read values from ascii file
228   //
229   TTree* tree = new TTree(title,title);
230   tree->ReadFile(fname,"");
231   TClonesArray *arr = AliDCSSensor::ReadTree(tree);
232   delete tree;
233   return arr;
234 }
235
236 //______________________________________________________________________________________________
237
238 TTree * AliDCSGenDB::ReadListTree(const char *fname, const char *title) {
239   //
240   // read values from ascii file
241   //
242   TTree* tree = new TTree(title,title);
243   tree->ReadFile(fname,"");
244   TClonesArray *arr = AliDCSSensor::ReadTree(tree);
245   arr->Delete();
246   delete arr;
247   return tree;
248 }
249
250
251