]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliDCSGenDB.cxx
Handle missing rec-point tree in a uniform way: return null pointer to TEvePointSet.
[u/mrichter/AliRoot.git] / STEER / 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
41 const Int_t kBeamPeriod=2;
42
43 ClassImp(AliDCSGenDB)
44
45 //______________________________________________________________________________________________
46
47 AliDCSGenDB::AliDCSGenDB():
48    fFirstRun(0),
49    fLastRun(0),
50    fSpecificStorage(0),
51    fDefaultStorage(0),
52    fSensor(0),
53    fStorLoc(0),
54    fMetaData(0),
55    fConfTree(0)
56 //
57 //  standard constructor
58 //
59 {}
60
61 //______________________________________________________________________________________________
62
63 AliDCSGenDB::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
79 AliDCSGenDB::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),
87   fMetaData(0),
88   fConfTree(0)
89 {
90 //
91 //  Copy constructor
92 //
93
94  AliError("copy constructor not implemented");
95
96 }
97
98 //______________________________________________________________________________________________
99 AliDCSGenDB::~AliDCSGenDB(){
100 //
101 // destructor
102 //
103    delete fSensor;
104    delete fMetaData;
105    delete fConfTree;
106 }
107
108 //______________________________________________________________________________________________
109 AliDCSGenDB& AliDCSGenDB::operator= (const AliDCSGenDB& /*org*/ )
110 {
111  //
112  // assignment operator
113  //
114  AliError("assignment operator not implemented");
115  return *this;
116
117 }
118
119 //______________________________________________________________________________________________
120
121 void 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 {
126
127    // Generate calibration entry from DCS map
128    // Configuration read from ASCII file specified by list
129    
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 //______________________________________________________________________________________________
149 void 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 //______________________________________________________________________________________________
167 AliCDBMetaData* 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 //______________________________________________________________________________________________
179 void 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 //______________________________________________________________________________________________
187 void AliDCSGenDB::Init(Int_t run, const char *configDir, 
188                                   const char *specificDir,
189                                   const char *sensorClass)
190 {
191
192    fMetaData = CreateMetaObject(sensorClass);
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
202    /*Bool_t cdbCache = */AliCDBManager::Instance()->GetCacheFlag(); // save cache status
203    AliCDBManager::Instance()->SetCacheFlag(kTRUE); // activate CDB cache
204    
205
206 }
207
208 //______________________________________________________________________________________________
209
210
211 //_____________________________________________________________________________
212 TMap* 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
224 TClonesArray * 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
237 TTree * 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