2nd =operator removed.
[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"
45f03c4d 40
45f03c4d 41const Int_t kBeamPeriod=2;
42
43ClassImp(AliDCSGenDB)
44
45//______________________________________________________________________________________________
46
47AliDCSGenDB::AliDCSGenDB():
48 fFirstRun(0),
49 fLastRun(0),
9f016d99 50 fSpecificStorage(0),
51 fDefaultStorage(0),
45f03c4d 52 fSensor(0),
53 fStorLoc(0),
45f03c4d 54 fMetaData(0),
55 fConfTree(0)
56//
57// standard constructor
58//
59{}
60
61//______________________________________________________________________________________________
62
9f016d99 63AliDCSGenDB::AliDCSGenDB(const char* defaultStorage, const char* specificStorage):
64 fFirstRun(0),
65 fLastRun(0),
66 fSpecificStorage(specificStorage),
67 fDefaultStorage(defaultStorage),
68 fSensor(0),
69 fStorLoc(0),
70 fMetaData(0),
71 fConfTree(0)
72//
73// special constructor
74//
75{}
76
77//______________________________________________________________________________________________
78
45f03c4d 79AliDCSGenDB::AliDCSGenDB(const AliDCSGenDB& org):
80 TObject(org),
81 fFirstRun(org.fFirstRun),
82 fLastRun(org.fLastRun),
83 fSpecificStorage(org.fSpecificStorage),
84 fDefaultStorage(org.fDefaultStorage),
85 fSensor(0),
86 fStorLoc(0),
45f03c4d 87 fMetaData(0),
88 fConfTree(0)
89{
90//
91// Copy constructor
92//
93
820e68e8 94 AliError("copy constructor not implemented");
95
45f03c4d 96}
97
98//______________________________________________________________________________________________
99AliDCSGenDB::~AliDCSGenDB(){
100//
101// destructor
102//
45f03c4d 103 delete fSensor;
104 delete fMetaData;
105 delete fConfTree;
106}
107
108//______________________________________________________________________________________________
109AliDCSGenDB& AliDCSGenDB::operator= (const AliDCSGenDB& org )
110{
111 //
112 // assignment operator
113 //
820e68e8 114 AliError("assignment operator not implemented");
45f03c4d 115 return *this;
9f016d99 116
45f03c4d 117}
118
119//______________________________________________________________________________________________
45f03c4d 120
45f03c4d 121void AliDCSGenDB::MakeCalib(const char *list, const char *mapDCS,
122 const TTimeStamp& startTime,
123 const TTimeStamp& endTime,
124 Int_t firstRun, Int_t lastRun, const char *calibDir )
125{
45f03c4d 126
9f016d99 127 // Generate calibration entry from DCS map
128 // Configuration read from ASCII file specified by list
129
45f03c4d 130 TClonesArray *arr = ReadList(list);
131 AliDCSSensorArray *fSensor = new AliDCSSensorArray(arr);
132 fSensor->SetStartTime(startTime);
133 fSensor->SetEndTime(endTime);
134 TMap* map = SetGraphFile(mapDCS);
135 if (map) {
136 fSensor->MakeSplineFit(map);
137 }
138 delete map;
139 map=0;
140 mapDCS=0;
141
142 SetFirstRun(firstRun);
143 SetLastRun(lastRun);
144
145 StoreObject(calibDir, fSensor, fMetaData);
146}
147
148//______________________________________________________________________________________________
149void AliDCSGenDB::MakeConfig(const char *file, Int_t firstRun, Int_t lastRun, const char *confDir )
150{
151 //
152 // Store Configuration file to OCDB
153 //
154
155 TTree *tree = ReadListTree(file);
156 SetConfTree(tree);
157 SetFirstRun(firstRun);
158 SetLastRun(lastRun);
159
160 StoreObject(confDir, fConfTree, fMetaData);
161}
162
163
164
165
166//______________________________________________________________________________________________
167AliCDBMetaData* AliDCSGenDB::CreateMetaObject(const char* objectClassName)
168{
169 AliCDBMetaData *md1= new AliCDBMetaData();
170 md1->SetObjectClassName(objectClassName);
171 md1->SetResponsible("Haavard Helstrup");
172 md1->SetBeamPeriod(kBeamPeriod);
173 md1->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
174
175 return md1;
176}
177
178//______________________________________________________________________________________________
179void AliDCSGenDB::StoreObject(const char* cdbPath, TObject* object, AliCDBMetaData* metaData)
180{
181
182 AliCDBId id1(cdbPath, fFirstRun, fLastRun);
183 if (fStorLoc) fStorLoc->Put(object, id1, metaData);
184}
185
186//______________________________________________________________________________________________
9f016d99 187void AliDCSGenDB::Init(Int_t run, const char *configDir,
188 const char *specificDir,
189 const char *sensorClass)
45f03c4d 190{
191
9f016d99 192 fMetaData = CreateMetaObject(sensorClass);
45f03c4d 193 AliCDBManager *man = AliCDBManager::Instance();
194 man->SetDefaultStorage(fDefaultStorage);
195 man->SetRun(run);
196 man->SetSpecificStorage(specificDir,fSpecificStorage);
197 AliCDBEntry *config = man->Get(configDir);
198 if (config) fConfTree = (TTree*)config->GetObject();
199 fStorLoc = man->GetStorage(fSpecificStorage);
200 if (!fStorLoc) return;
201
820e68e8 202 Bool_t cdbCache = AliCDBManager::Instance()->GetCacheFlag(); // save cache status
203 AliCDBManager::Instance()->SetCacheFlag(kTRUE); // activate CDB cache
204
45f03c4d 205
206}
207
208//______________________________________________________________________________________________
209
210
211//_____________________________________________________________________________
212TMap* AliDCSGenDB::SetGraphFile(const char *fname)
213{
214 //
215 // Read DCS maps from file given by fname
216 //
217 TFile file(fname);
218 TMap * map = (TMap*)file.Get("DCSMap");
219 return map;
220}
221
222//______________________________________________________________________________________________
223
224TClonesArray * AliDCSGenDB::ReadList(const char *fname, const char *title) {
225 //
226 // read values from ascii file
227 //
228 TTree* tree = new TTree(title,title);
229 tree->ReadFile(fname,"");
230 TClonesArray *arr = AliDCSSensor::ReadTree(tree);
231 delete tree;
232 return arr;
233}
234
235//______________________________________________________________________________________________
236
237TTree * AliDCSGenDB::ReadListTree(const char *fname, const char *title) {
238 //
239 // read values from ascii file
240 //
241 TTree* tree = new TTree(title,title);
242 tree->ReadFile(fname,"");
243 TClonesArray *arr = AliDCSSensor::ReadTree(tree);
244 arr->Delete();
245 delete arr;
246 return tree;
247}
248
249
250