1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////////
19 // Class to generate DCS data base entries //
20 // Author: Haavard Helstrup //
22 ///////////////////////////////////////////////////////////////////////////////
28 // TTimeStamp startTime(2006,10,18,0,0,0,0,kFALSE)
29 // TTimeStamp endTime(2006,10,19,0,0,0,0,kFALSE)
32 // db->Init(run,"TPC/Config/Pressure","TPC/*/*")
33 // db->MakeCalib("PressureSensor.txt","DCSMap.root",startTime,endTime,firstRun,lastRun,"TPC/Calib/Pressure")
36 #include "AliDCSGenDB.h"
39 const char *kDefaultStorage="local:///afs/cern.ch/alice/tpctest/AliRoot/HEAD";
40 const char *kSpecificStorage="local:///afs/cern.ch/alice/tpctest/Calib/";
41 const char *kSensorClass = "AliDCSSensorArray";
42 const Int_t kBeamPeriod=2;
46 //______________________________________________________________________________________________
48 AliDCSGenDB::AliDCSGenDB():
51 fSpecificStorage(kSpecificStorage),
52 fDefaultStorage(kDefaultStorage),
58 // standard constructor
62 //______________________________________________________________________________________________
64 AliDCSGenDB::AliDCSGenDB(const AliDCSGenDB& org):
66 fFirstRun(org.fFirstRun),
67 fLastRun(org.fLastRun),
68 fSpecificStorage(org.fSpecificStorage),
69 fDefaultStorage(org.fDefaultStorage),
79 AliError("copy constructor not implemented");
83 //______________________________________________________________________________________________
84 AliDCSGenDB::~AliDCSGenDB(){
93 //______________________________________________________________________________________________
94 AliDCSGenDB& AliDCSGenDB::operator= (const AliDCSGenDB& org )
97 // assignment operator
99 AliError("assignment operator not implemented");
103 //______________________________________________________________________________________________
105 void AliDCSGenDB::MakeCalib(const char *list, const char *mapDCS,
106 const TTimeStamp& startTime,
107 const TTimeStamp& endTime,
108 Int_t firstRun, Int_t lastRun, const char *calibDir )
110 // The Terminate() function is the last function to be called during
111 // a query. It always runs on the client, it can be used to present
112 // the results graphically or save the results to file.
114 TClonesArray *arr = ReadList(list);
115 AliDCSSensorArray *fSensor = new AliDCSSensorArray(arr);
116 fSensor->SetStartTime(startTime);
117 fSensor->SetEndTime(endTime);
118 TMap* map = SetGraphFile(mapDCS);
120 fSensor->MakeSplineFit(map);
126 SetFirstRun(firstRun);
129 StoreObject(calibDir, fSensor, fMetaData);
132 //______________________________________________________________________________________________
133 void AliDCSGenDB::MakeConfig(const char *file, Int_t firstRun, Int_t lastRun, const char *confDir )
136 // Store Configuration file to OCDB
139 TTree *tree = ReadListTree(file);
141 SetFirstRun(firstRun);
144 StoreObject(confDir, fConfTree, fMetaData);
150 //______________________________________________________________________________________________
151 AliCDBMetaData* AliDCSGenDB::CreateMetaObject(const char* objectClassName)
153 AliCDBMetaData *md1= new AliCDBMetaData();
154 md1->SetObjectClassName(objectClassName);
155 md1->SetResponsible("Haavard Helstrup");
156 md1->SetBeamPeriod(kBeamPeriod);
157 md1->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
162 //______________________________________________________________________________________________
163 void AliDCSGenDB::StoreObject(const char* cdbPath, TObject* object, AliCDBMetaData* metaData)
166 AliCDBId id1(cdbPath, fFirstRun, fLastRun);
167 if (fStorLoc) fStorLoc->Put(object, id1, metaData);
170 //______________________________________________________________________________________________
171 void AliDCSGenDB::Init(Int_t run, const char *configDir, const char *specificDir)
174 fMetaData = CreateMetaObject(kSensorClass);
175 AliCDBManager *man = AliCDBManager::Instance();
176 man->SetDefaultStorage(fDefaultStorage);
178 man->SetSpecificStorage(specificDir,fSpecificStorage);
179 AliCDBEntry *config = man->Get(configDir);
180 if (config) fConfTree = (TTree*)config->GetObject();
181 fStorLoc = man->GetStorage(fSpecificStorage);
182 if (!fStorLoc) return;
184 Bool_t cdbCache = AliCDBManager::Instance()->GetCacheFlag(); // save cache status
185 AliCDBManager::Instance()->SetCacheFlag(kTRUE); // activate CDB cache
190 //______________________________________________________________________________________________
193 //_____________________________________________________________________________
194 TMap* AliDCSGenDB::SetGraphFile(const char *fname)
197 // Read DCS maps from file given by fname
200 TMap * map = (TMap*)file.Get("DCSMap");
204 //______________________________________________________________________________________________
206 TClonesArray * AliDCSGenDB::ReadList(const char *fname, const char *title) {
208 // read values from ascii file
210 TTree* tree = new TTree(title,title);
211 tree->ReadFile(fname,"");
212 TClonesArray *arr = AliDCSSensor::ReadTree(tree);
217 //______________________________________________________________________________________________
219 TTree * AliDCSGenDB::ReadListTree(const char *fname, const char *title) {
221 // read values from ascii file
223 TTree* tree = new TTree(title,title);
224 tree->ReadFile(fname,"");
225 TClonesArray *arr = AliDCSSensor::ReadTree(tree);