General data base configuration class for DCS sensors (Haavard)
[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
32// db->Init(run,"TPC/Config/Temperature","TPC/*/*")
33// db->MakeCalib("PressureSensor.txt","DCSMap.root",startTime,endTime,firstRun,lastRun,"TPC/Calib/Temperature")
34
35
36#include "AliDCSGenDB.h"
37
38const char *kDefaultStorage="local:///afs/cern.ch/alice/tpctest/AliRoot/HEAD";
39const char *kSpecificStorage="local:///afs/cern.ch/alice/tpctest/Calib/";
40const char *kSensorClass = "AliDCSSensorArray";
41const Int_t kBeamPeriod=2;
42
43ClassImp(AliDCSGenDB)
44
45//______________________________________________________________________________________________
46
47AliDCSGenDB::AliDCSGenDB():
48 fFirstRun(0),
49 fLastRun(0),
50 fSpecificStorage(kSpecificStorage),
51 fDefaultStorage(kDefaultStorage),
52 fSensor(0),
53 fStorLoc(0),
54 fCalib(0),
55 fMetaData(0),
56 fConfTree(0)
57//
58// standard constructor
59//
60{}
61
62//______________________________________________________________________________________________
63
64AliDCSGenDB::AliDCSGenDB(const AliDCSGenDB& org):
65 TObject(org),
66 fFirstRun(org.fFirstRun),
67 fLastRun(org.fLastRun),
68 fSpecificStorage(org.fSpecificStorage),
69 fDefaultStorage(org.fDefaultStorage),
70 fSensor(0),
71 fStorLoc(0),
72 fCalib(0),
73 fMetaData(0),
74 fConfTree(0)
75{
76//
77// Copy constructor
78//
79
80 ((AliDCSGenDB &) org).Copy(*this);
81}
82
83//______________________________________________________________________________________________
84AliDCSGenDB::~AliDCSGenDB(){
85//
86// destructor
87//
88 fCalib->Terminate();
89 delete fSensor;
90 delete fMetaData;
91 delete fConfTree;
92}
93
94//______________________________________________________________________________________________
95AliDCSGenDB& AliDCSGenDB::operator= (const AliDCSGenDB& org )
96{
97 //
98 // assignment operator
99 //
100 if (&org == this) return *this;
101
102 new (this) AliDCSGenDB(org);
103 return *this;
104}
105
106//______________________________________________________________________________________________
107void AliDCSGenDB::Copy(TObject &c) const
108{
109 //
110 // Copy function
111 //
112
113 TObject::Copy(c);
114}
115
116//______________________________________________________________________________________________
117void AliDCSGenDB::MakeCalib(const char *list, const char *mapDCS,
118 const TTimeStamp& startTime,
119 const TTimeStamp& endTime,
120 Int_t firstRun, Int_t lastRun, const char *calibDir )
121{
122 // The Terminate() function is the last function to be called during
123 // a query. It always runs on the client, it can be used to present
124 // the results graphically or save the results to file.
125
126 TClonesArray *arr = ReadList(list);
127 AliDCSSensorArray *fSensor = new AliDCSSensorArray(arr);
128 fSensor->SetStartTime(startTime);
129 fSensor->SetEndTime(endTime);
130 TMap* map = SetGraphFile(mapDCS);
131 if (map) {
132 fSensor->MakeSplineFit(map);
133 }
134 delete map;
135 map=0;
136 mapDCS=0;
137
138 SetFirstRun(firstRun);
139 SetLastRun(lastRun);
140
141 StoreObject(calibDir, fSensor, fMetaData);
142}
143
144//______________________________________________________________________________________________
145void AliDCSGenDB::MakeConfig(const char *file, Int_t firstRun, Int_t lastRun, const char *confDir )
146{
147 //
148 // Store Configuration file to OCDB
149 //
150
151 TTree *tree = ReadListTree(file);
152 SetConfTree(tree);
153 SetFirstRun(firstRun);
154 SetLastRun(lastRun);
155
156 StoreObject(confDir, fConfTree, fMetaData);
157}
158
159
160
161
162//______________________________________________________________________________________________
163AliCDBMetaData* AliDCSGenDB::CreateMetaObject(const char* objectClassName)
164{
165 AliCDBMetaData *md1= new AliCDBMetaData();
166 md1->SetObjectClassName(objectClassName);
167 md1->SetResponsible("Haavard Helstrup");
168 md1->SetBeamPeriod(kBeamPeriod);
169 md1->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
170
171 return md1;
172}
173
174//______________________________________________________________________________________________
175void AliDCSGenDB::StoreObject(const char* cdbPath, TObject* object, AliCDBMetaData* metaData)
176{
177
178 AliCDBId id1(cdbPath, fFirstRun, fLastRun);
179 if (fStorLoc) fStorLoc->Put(object, id1, metaData);
180}
181
182//______________________________________________________________________________________________
183void AliDCSGenDB::Init(Int_t run, const char *configDir, const char *specificDir)
184{
185
186 fMetaData = CreateMetaObject(kSensorClass);
187 AliCDBManager *man = AliCDBManager::Instance();
188 man->SetDefaultStorage(fDefaultStorage);
189 man->SetRun(run);
190 man->SetSpecificStorage(specificDir,fSpecificStorage);
191 AliCDBEntry *config = man->Get(configDir);
192 if (config) fConfTree = (TTree*)config->GetObject();
193 fStorLoc = man->GetStorage(fSpecificStorage);
194 if (!fStorLoc) return;
195
196 fCalib = AliTPCcalibDB::Instance();
197
198}
199
200//______________________________________________________________________________________________
201
202
203//_____________________________________________________________________________
204TMap* AliDCSGenDB::SetGraphFile(const char *fname)
205{
206 //
207 // Read DCS maps from file given by fname
208 //
209 TFile file(fname);
210 TMap * map = (TMap*)file.Get("DCSMap");
211 return map;
212}
213
214//______________________________________________________________________________________________
215
216TClonesArray * AliDCSGenDB::ReadList(const char *fname, const char *title) {
217 //
218 // read values from ascii file
219 //
220 TTree* tree = new TTree(title,title);
221 tree->ReadFile(fname,"");
222 TClonesArray *arr = AliDCSSensor::ReadTree(tree);
223 delete tree;
224 return arr;
225}
226
227//______________________________________________________________________________________________
228
229TTree * AliDCSGenDB::ReadListTree(const char *fname, const char *title) {
230 //
231 // read values from ascii file
232 //
233 TTree* tree = new TTree(title,title);
234 tree->ReadFile(fname,"");
235 TClonesArray *arr = AliDCSSensor::ReadTree(tree);
236 arr->Delete();
237 delete arr;
238 return tree;
239}
240
241
242