#include "AliDCSGenDB.h"
#include "AliLog.h"
#include "ARVersion.h"
const Int_t kBeamPeriod=2;
ClassImp(AliDCSGenDB)
AliDCSGenDB::AliDCSGenDB():
fFirstRun(0),
fLastRun(0),
fSpecificStorage(0),
fDefaultStorage(0),
fSensor(0),
fStorLoc(0),
fMetaData(0),
fConfTree(0)
{}
AliDCSGenDB::AliDCSGenDB(const char* defaultStorage, const char* specificStorage):
fFirstRun(0),
fLastRun(0),
fSpecificStorage(specificStorage),
fDefaultStorage(defaultStorage),
fSensor(0),
fStorLoc(0),
fMetaData(0),
fConfTree(0)
{}
AliDCSGenDB::AliDCSGenDB(const AliDCSGenDB& org):
TObject(org),
fFirstRun(org.fFirstRun),
fLastRun(org.fLastRun),
fSpecificStorage(org.fSpecificStorage),
fDefaultStorage(org.fDefaultStorage),
fSensor(0),
fStorLoc(0),
fMetaData(0),
fConfTree(0)
{
AliError("copy constructor not implemented");
}
AliDCSGenDB::~AliDCSGenDB(){
delete fSensor;
delete fMetaData;
delete fConfTree;
}
AliDCSGenDB& AliDCSGenDB::operator= (const AliDCSGenDB& )
{
AliError("assignment operator not implemented");
return *this;
}
void AliDCSGenDB::MakeCalib(const char *list, const char *mapDCS,
const TTimeStamp& startTime,
const TTimeStamp& endTime,
Int_t firstRun, Int_t lastRun, const char *calibDir )
{
TClonesArray *arr = ReadList(list);
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 )
{
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(ALIROOT_BRANCH);
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,
const char *sensorClass)
{
fMetaData = CreateMetaObject(sensorClass);
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;
AliCDBManager::Instance()->GetCacheFlag();
AliCDBManager::Instance()->SetCacheFlag(kTRUE);
}
TMap* AliDCSGenDB::SetGraphFile(const char *fname)
{
TFile file(fname);
TMap * map = (TMap*)file.Get("DCSMap");
return map;
}
TClonesArray * AliDCSGenDB::ReadList(const char *fname, const char *title) {
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) {
TTree* tree = new TTree(title,title);
tree->ReadFile(fname,"");
TClonesArray *arr = AliDCSSensor::ReadTree(tree);
arr->Delete();
delete arr;
return tree;
}