Bug fix. Removed delete statement
[u/mrichter/AliRoot.git] / STEER / AliDCSGenDB.cxx
CommitLineData
45f03c4d 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
9f016d99 32// db->SetDefaultStorage("local:///afs/cern.ch/alice/tpctest/AliRoot/HEAD");
33// db->SetSpecificStorage("local:///afs/cern.ch/alice/tpctest/Calib/");
820e68e8 34// db->Init(run,"TPC/Config/Pressure","TPC/*/*")
35// db->MakeCalib("PressureSensor.txt","DCSMap.root",startTime,endTime,firstRun,lastRun,"TPC/Calib/Pressure")
45f03c4d 36
37
38#include "AliDCSGenDB.h"
820e68e8 39#include "AliLog.h"
d33faa69 40#include "ARVersion.h"
45f03c4d 41
45f03c4d 42const Int_t kBeamPeriod=2;
43
44ClassImp(AliDCSGenDB)
45
46//______________________________________________________________________________________________
47
48AliDCSGenDB::AliDCSGenDB():
49 fFirstRun(0),
50 fLastRun(0),
9f016d99 51 fSpecificStorage(0),
52 fDefaultStorage(0),
45f03c4d 53 fSensor(0),
54 fStorLoc(0),
45f03c4d 55 fMetaData(0),
56 fConfTree(0)
57//
58// standard constructor
59//
60{}
61
62//______________________________________________________________________________________________
63
9f016d99 64AliDCSGenDB::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
45f03c4d 80AliDCSGenDB::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),
45f03c4d 88 fMetaData(0),
89 fConfTree(0)
90{
91//
92// Copy constructor
93//
94
820e68e8 95 AliError("copy constructor not implemented");
96
45f03c4d 97}
98
99//______________________________________________________________________________________________
100AliDCSGenDB::~AliDCSGenDB(){
101//
102// destructor
103//
45f03c4d 104 delete fSensor;
105 delete fMetaData;
106 delete fConfTree;
107}
108
109//______________________________________________________________________________________________
2972d4eb 110AliDCSGenDB& AliDCSGenDB::operator= (const AliDCSGenDB& /*org*/ )
45f03c4d 111{
112 //
113 // assignment operator
114 //
820e68e8 115 AliError("assignment operator not implemented");
45f03c4d 116 return *this;
9f016d99 117
45f03c4d 118}
119
120//______________________________________________________________________________________________
45f03c4d 121
45f03c4d 122void 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{
45f03c4d 127
9f016d99 128 // Generate calibration entry from DCS map
129 // Configuration read from ASCII file specified by list
130
45f03c4d 131 TClonesArray *arr = ReadList(list);
f0daf312 132 fSensor = new AliDCSSensorArray(arr);
45f03c4d 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//______________________________________________________________________________________________
150void 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//______________________________________________________________________________________________
168AliCDBMetaData* AliDCSGenDB::CreateMetaObject(const char* objectClassName)
169{
170 AliCDBMetaData *md1= new AliCDBMetaData();
171 md1->SetObjectClassName(objectClassName);
172 md1->SetResponsible("Haavard Helstrup");
173 md1->SetBeamPeriod(kBeamPeriod);
d33faa69 174 md1->SetAliRootVersion(ALIROOT_SVN_BRANCH);
45f03c4d 175
176 return md1;
177}
178
179//______________________________________________________________________________________________
180void 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//______________________________________________________________________________________________
9f016d99 188void AliDCSGenDB::Init(Int_t run, const char *configDir,
189 const char *specificDir,
190 const char *sensorClass)
45f03c4d 191{
192
9f016d99 193 fMetaData = CreateMetaObject(sensorClass);
45f03c4d 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
2972d4eb 203 /*Bool_t cdbCache = */AliCDBManager::Instance()->GetCacheFlag(); // save cache status
820e68e8 204 AliCDBManager::Instance()->SetCacheFlag(kTRUE); // activate CDB cache
205
45f03c4d 206
207}
208
209//______________________________________________________________________________________________
210
211
212//_____________________________________________________________________________
213TMap* 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
225TClonesArray * 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
238TTree * 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