From 45f03c4dbc248744f8baa56235b2e89425f13936 Mon Sep 17 00:00:00 2001 From: hristov Date: Wed, 18 Jul 2007 10:18:29 +0000 Subject: [PATCH] General data base configuration class for DCS sensors (Haavard) --- STEER/AliDCSGenDB.cxx | 242 ++++++++++++++++++++++++++++++++++++++++++ STEER/AliDCSGenDB.h | 83 +++++++++++++++ 2 files changed, 325 insertions(+) create mode 100644 STEER/AliDCSGenDB.cxx create mode 100644 STEER/AliDCSGenDB.h diff --git a/STEER/AliDCSGenDB.cxx b/STEER/AliDCSGenDB.cxx new file mode 100644 index 00000000000..ce3d56f9019 --- /dev/null +++ b/STEER/AliDCSGenDB.cxx @@ -0,0 +1,242 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + + +/////////////////////////////////////////////////////////////////////////////// +// // +// Class to generate DCS data base entries // +// Author: Haavard Helstrup // +// // +/////////////////////////////////////////////////////////////////////////////// + + + + + +// TTimeStamp startTime(2006,10,18,0,0,0,0,kFALSE) +// TTimeStamp endTime(2006,10,19,0,0,0,0,kFALSE) +// Int_t run=2546 +// AliDCSGenDB db +// db->Init(run,"TPC/Config/Temperature","TPC/*/*") +// db->MakeCalib("PressureSensor.txt","DCSMap.root",startTime,endTime,firstRun,lastRun,"TPC/Calib/Temperature") + + +#include "AliDCSGenDB.h" + +const char *kDefaultStorage="local:///afs/cern.ch/alice/tpctest/AliRoot/HEAD"; +const char *kSpecificStorage="local:///afs/cern.ch/alice/tpctest/Calib/"; +const char *kSensorClass = "AliDCSSensorArray"; +const Int_t kBeamPeriod=2; + +ClassImp(AliDCSGenDB) + +//______________________________________________________________________________________________ + +AliDCSGenDB::AliDCSGenDB(): + fFirstRun(0), + fLastRun(0), + fSpecificStorage(kSpecificStorage), + fDefaultStorage(kDefaultStorage), + fSensor(0), + fStorLoc(0), + fCalib(0), + fMetaData(0), + fConfTree(0) +// +// standard constructor +// +{} + +//______________________________________________________________________________________________ + +AliDCSGenDB::AliDCSGenDB(const AliDCSGenDB& org): + TObject(org), + fFirstRun(org.fFirstRun), + fLastRun(org.fLastRun), + fSpecificStorage(org.fSpecificStorage), + fDefaultStorage(org.fDefaultStorage), + fSensor(0), + fStorLoc(0), + fCalib(0), + fMetaData(0), + fConfTree(0) +{ +// +// Copy constructor +// + + ((AliDCSGenDB &) org).Copy(*this); +} + +//______________________________________________________________________________________________ +AliDCSGenDB::~AliDCSGenDB(){ +// +// destructor +// + fCalib->Terminate(); + delete fSensor; + delete fMetaData; + delete fConfTree; +} + +//______________________________________________________________________________________________ +AliDCSGenDB& AliDCSGenDB::operator= (const AliDCSGenDB& org ) +{ + // + // assignment operator + // + if (&org == this) return *this; + + new (this) AliDCSGenDB(org); + return *this; +} + +//______________________________________________________________________________________________ +void AliDCSGenDB::Copy(TObject &c) const +{ + // + // Copy function + // + + TObject::Copy(c); +} + +//______________________________________________________________________________________________ +void AliDCSGenDB::MakeCalib(const char *list, const char *mapDCS, + const TTimeStamp& startTime, + const TTimeStamp& endTime, + Int_t firstRun, Int_t lastRun, const char *calibDir ) +{ + // The Terminate() function is the last function to be called during + // a query. It always runs on the client, it can be used to present + // the results graphically or save the results to file. + + TClonesArray *arr = ReadList(list); + AliDCSSensorArray *fSensor = new AliDCSSensorArray(arr); + fSensor->SetStartTime(startTime); + fSensor->SetEndTime(endTime); + TMap* map = SetGraphFile(mapDCS); + if (map) { + fSensor->MakeSplineFit(map); + } + delete map; + map=0; + mapDCS=0; + + SetFirstRun(firstRun); + SetLastRun(lastRun); + + StoreObject(calibDir, fSensor, fMetaData); +} + +//______________________________________________________________________________________________ +void AliDCSGenDB::MakeConfig(const char *file, Int_t firstRun, Int_t lastRun, const char *confDir ) +{ + // + // Store Configuration file to OCDB + // + + TTree *tree = ReadListTree(file); + SetConfTree(tree); + SetFirstRun(firstRun); + SetLastRun(lastRun); + + StoreObject(confDir, fConfTree, fMetaData); +} + + + + +//______________________________________________________________________________________________ +AliCDBMetaData* AliDCSGenDB::CreateMetaObject(const char* objectClassName) +{ + AliCDBMetaData *md1= new AliCDBMetaData(); + md1->SetObjectClassName(objectClassName); + md1->SetResponsible("Haavard Helstrup"); + md1->SetBeamPeriod(kBeamPeriod); + md1->SetAliRootVersion(gSystem->Getenv("ARVERSION")); + + return md1; +} + +//______________________________________________________________________________________________ +void AliDCSGenDB::StoreObject(const char* cdbPath, TObject* object, AliCDBMetaData* metaData) +{ + + AliCDBId id1(cdbPath, fFirstRun, fLastRun); + if (fStorLoc) fStorLoc->Put(object, id1, metaData); +} + +//______________________________________________________________________________________________ +void AliDCSGenDB::Init(Int_t run, const char *configDir, const char *specificDir) +{ + + fMetaData = CreateMetaObject(kSensorClass); + AliCDBManager *man = AliCDBManager::Instance(); + man->SetDefaultStorage(fDefaultStorage); + man->SetRun(run); + man->SetSpecificStorage(specificDir,fSpecificStorage); + AliCDBEntry *config = man->Get(configDir); + if (config) fConfTree = (TTree*)config->GetObject(); + fStorLoc = man->GetStorage(fSpecificStorage); + if (!fStorLoc) return; + + fCalib = AliTPCcalibDB::Instance(); + +} + +//______________________________________________________________________________________________ + + +//_____________________________________________________________________________ +TMap* AliDCSGenDB::SetGraphFile(const char *fname) +{ + // + // Read DCS maps from file given by fname + // + TFile file(fname); + TMap * map = (TMap*)file.Get("DCSMap"); + return map; +} + +//______________________________________________________________________________________________ + +TClonesArray * AliDCSGenDB::ReadList(const char *fname, const char *title) { + // + // read values from ascii file + // + TTree* tree = new TTree(title,title); + tree->ReadFile(fname,""); + TClonesArray *arr = AliDCSSensor::ReadTree(tree); + delete tree; + return arr; +} + +//______________________________________________________________________________________________ + +TTree * AliDCSGenDB::ReadListTree(const char *fname, const char *title) { + // + // read values from ascii file + // + TTree* tree = new TTree(title,title); + tree->ReadFile(fname,""); + TClonesArray *arr = AliDCSSensor::ReadTree(tree); + arr->Delete(); + delete arr; + return tree; +} + + + diff --git a/STEER/AliDCSGenDB.h b/STEER/AliDCSGenDB.h new file mode 100644 index 00000000000..a4fb0d8cab5 --- /dev/null +++ b/STEER/AliDCSGenDB.h @@ -0,0 +1,83 @@ +///////////////////////////////////////////////////////////////// +// Class to generate temperature sensor data base entries. +// +// Existing data base structure read at start of processsing. +// 20/12-2006 HH. +// Modification log: +///////////////////////////////////////////////////////////////// + +#ifndef AliDCSGenDB_h +#define AliDCSGenDB_h + +#include +#include +#include +#include +#include +#include + +#include "AliTPCcalibDB.h" +#include "AliCDBMetaData.h" +#include "AliCDBManager.h" +#include "AliCDBId.h" +#include "AliCDBStorage.h" +#include "AliDCSSensorArray.h" +#include "AliLog.h" +#include "TSystem.h" + +class AliDCSGenDB : public TObject { + +public: + +// Constructors + + AliDCSGenDB(); + AliDCSGenDB(const AliDCSGenDB& org); + ~AliDCSGenDB(); + AliDCSGenDB& operator= (const AliDCSGenDB& org); + void Copy(TObject &c) const; + +// Functionality + + void MakeCalib(const char *file, const char *fMap, + const TTimeStamp& startTime, + const TTimeStamp& endTime, + Int_t firstRun, Int_t lastRun, const char *calibDir); + void MakeConfig(const char *file, Int_t firstRun, Int_t lastRun, const char *confDir); + AliCDBMetaData* CreateMetaObject(const char *objectClassName); + void StoreObject(const char* cdbPath, TObject* object, AliCDBMetaData* metaData); + void Init(Int_t run, const char *configDir, const char *specificDir); + static TClonesArray * ReadList(const char* fname, const char *title="dcsConf"); + static TTree * ReadListTree(const char* fname, const char *title="dcsConf"); + +// Getters/Setters + + void SetFirstRun(Int_t frun){fFirstRun=frun;} + void SetLastRun(Int_t lrun) {fLastRun=lrun;} + TMap* SetGraphFile(const char* fname); + void SetConfTree(TTree *tree) {fConfTree=tree;} + TTree* GetConfTree() const {return fConfTree;} + const TString& GetSpecificStorage() const { return fSpecificStorage;} + void SetSpecificStorage (const TString& specificStorage) { fSpecificStorage=specificStorage; } + const TString& GetDefaultStorage() const { return fDefaultStorage;} + void SetDefaultStorage (const TString& defaultStorage) { fDefaultStorage=defaultStorage; } + const AliDCSSensorArray* GetSensorArray() const {return fSensor;} + void SetSensorArray(AliDCSSensorArray *arr) { fSensor=arr; } + + +protected: + + Int_t fFirstRun; // first run in validity period + Int_t fLastRun; // last run in validity period + TString fSpecificStorage; // specific storage for data base + TString fDefaultStorage; // default storage for data base + AliDCSSensorArray *fSensor; // array of DCS sensors + AliCDBStorage *fStorLoc; // pointer to CDB storage + AliTPCcalibDB *fCalib; // calibration object + AliCDBMetaData *fMetaData; // data base metadata + TTree *fConfTree; // configuration tree + + ClassDef(AliDCSGenDB,1) + }; +#endif + -- 2.39.3