From f05209eee226cb9180afb49cf3a07cb74a9237e8 Mon Sep 17 00:00:00 2001 From: hristov Date: Fri, 20 May 2005 07:05:03 +0000 Subject: [PATCH] New calibration classes (A.Colla) --- STEER/AliMetaData.cxx | 101 ++++++++- STEER/AliMetaData.h | 45 ++-- STEER/AliObjectMetaData.cxx | 121 ++++++++++ STEER/AliObjectMetaData.h | 52 +++++ STEER/AliRunData.cxx | 18 +- STEER/AliRunData.h | 15 +- STEER/AliRunDataFile.cxx | 52 +++-- STEER/AliRunDataFile.h | 9 +- STEER/AliRunDataOrganizedFile.cxx | 366 ++++++++++++++++++++++++++++++ STEER/AliRunDataOrganizedFile.h | 42 ++++ STEER/AliRunDataStorage.cxx | 105 +++++---- STEER/AliRunDataStorage.h | 21 +- STEER/AliRunLoader.cxx | 8 +- STEER/AliSelectionMetaData.cxx | 77 +++++++ STEER/AliSelectionMetaData.h | 30 +++ STEER/STEERLinkDef.h | 3 + STEER/libSTEER.pkg | 3 +- 17 files changed, 957 insertions(+), 111 deletions(-) create mode 100644 STEER/AliObjectMetaData.cxx create mode 100644 STEER/AliObjectMetaData.h create mode 100644 STEER/AliRunDataOrganizedFile.cxx create mode 100644 STEER/AliRunDataOrganizedFile.h create mode 100644 STEER/AliSelectionMetaData.cxx create mode 100644 STEER/AliSelectionMetaData.h diff --git a/STEER/AliMetaData.cxx b/STEER/AliMetaData.cxx index 04bd7a38cdc..06d1609f960 100644 --- a/STEER/AliMetaData.cxx +++ b/STEER/AliMetaData.cxx @@ -17,7 +17,8 @@ /////////////////////////////////////////////////////////////////////////////// // // -// meta data of run dependent objects // +// base class of the metadata of run dependent objects // +// Derived classes: AliObjectMetaData, AliSelectionMetaData // // // /////////////////////////////////////////////////////////////////////////////// @@ -25,6 +26,7 @@ #include #include "AliMetaData.h" +#include "AliLog.h" ClassImp(AliMetaData) @@ -40,7 +42,7 @@ AliMetaData::AliMetaData() : { // default constructor // the default values mean no selection - + DecodeName(); } //_____________________________________________________________________________ @@ -53,7 +55,7 @@ AliMetaData::AliMetaData(const char* name, Int_t firstRun, Int_t lastRun, fVersion(version) { // constructor - + DecodeName(); } @@ -66,7 +68,7 @@ AliMetaData::AliMetaData(const AliMetaData& entry) : fVersion(entry.fVersion) { // copy constructor - + DecodeName(); } //_____________________________________________________________________________ @@ -78,6 +80,7 @@ AliMetaData& AliMetaData::operator = (const AliMetaData& entry) fFirstRun = entry.fFirstRun; fLastRun = entry.fLastRun; fVersion = entry.fVersion; + DecodeName(); return *this; } @@ -86,16 +89,81 @@ AliMetaData& AliMetaData::operator = (const AliMetaData& entry) //_____________________________________________________________________________ const char* AliMetaData::GetName() const { -// get the name +// get the name ("Detector/DBType/DetSpecType", example: "ZDC/Calib/Pedestals") return fName.Data(); } +//_____________________________________________________________________________ +const char* AliMetaData::GetDetector() const +{ +// get the detector's name (ZDC,ITS ...) + + return fDetector.Data(); +} //_____________________________________________________________________________ -Bool_t AliMetaData::IsValid(Int_t runNumber, AliMetaData* metaData) const +const char* AliMetaData::GetDBType() const +{ +// get the database type (Calib, Align ...) + + return fDBType.Data(); +} + +//_____________________________________________________________________________ +const char* AliMetaData::GetDetSpecType() const +{ +// get the detector's specific type name (Pedestals, GainConst, DeadChannelMaps...) + + return fDetSpecType.Data(); +} + +//_____________________________________________________________________________ +void AliMetaData::EncodeName(){ +// Encode name from single elements ("Detector", "DBType", "DetSpecType" -> "Detector/DBType/DetSpecType") + fName = fDetector+'/'+fDBType+'/'+fDetSpecType; + if(fDBType == "*" && fDetSpecType == "*") fName = fDetector+'/'+'*'; + if(fDetector == "*" && fDBType == "*" && fDetSpecType == "*") fName = "*"; + +} + +//_____________________________________________________________________________ +void AliMetaData::DecodeName(){ +// Decode name into single elements ("Detector/DBType/DetSpecType" -> "Detector", "DBType", "DetSpecType") + + if(fName==""){fDetector=""; fDBType=""; fDetSpecType=""; return;} + + while(fName.EndsWith("/")) fName.Remove(fName.Last('/')); + while(fName.BeginsWith("/")) fName.Remove(fName.First('/'),1); + + // fName= "fDetector/fDBType/fDetSpecType + int nslashes=fName.CountChar('/'); + + if(nslashes>2){AliError("Wrong format!\n");fDetector=""; fDBType=""; fDetSpecType="";} + + if(nslashes == 0){ + if(fName == "*"){fDetector="*"; fDBType="*"; fDetSpecType="*";} + else{AliError("Wrong format!\n"); fDetector=""; fDBType=""; fDetSpecType="";} + } + if(nslashes == 1){ + if(fName.EndsWith("*")) + {fDetector=fName(0, fName.Index('/')); fDBType="*"; fDetSpecType="*";} + else {AliError("Wrong format!\n"); fDetector=""; fDBType=""; fDetSpecType="";} + } + + if(nslashes == 2){ + int firstsl=fName.First('/'), lastsl=fName.Last('/'), lgth=fName.Length(); + fDetector=fName(0, firstsl); + fDBType=fName(firstsl+1, lastsl-(firstsl+1)); + fDetSpecType=fName(lastsl+1, lgth-(lastsl+1)); + } + EncodeName(); +} + +//_____________________________________________________________________________ +Bool_t AliMetaData::IsStrictlyValid(Int_t runNumber, AliMetaData* metaData) const { -// check the validity of the object +// check if the object is valid for runNumber. TRUE if metaData version is equal to this's version if ((fFirstRun >= 0) && (runNumber < fFirstRun)) return kFALSE; if ((fLastRun >= 0) && (runNumber > fLastRun)) return kFALSE; @@ -106,10 +174,24 @@ Bool_t AliMetaData::IsValid(Int_t runNumber, AliMetaData* metaData) const return kTRUE; } +//_____________________________________________________________________________ +Bool_t AliMetaData::IsValid(Int_t runNumber, AliMetaData* metaData) const +{ +// check if the object is valid for runNumber. TRUE if metaData version less or equal wrt to this's + + if ((fFirstRun >= 0) && (runNumber < fFirstRun)) return kFALSE; + if ((fLastRun >= 0) && (runNumber > fLastRun)) return kFALSE; + if (metaData) { + if ((metaData->fVersion >= 0) && (metaData->fVersion < fVersion)) + return kFALSE; + } + return kTRUE; +} + //_____________________________________________________________________________ Int_t AliMetaData::Compare(const TObject* object) const { -// check whether this is prefered to object +// check whether this is preferred to object if (!object || !object->InheritsFrom(AliMetaData::Class())) return 1; if (fVersion < ((AliMetaData*)object)->GetVersion()) return -1; @@ -124,7 +206,7 @@ Bool_t AliMetaData::Matches(const char* name, Int_t runNumber) const if ((fFirstRun >= 0) && (runNumber < fFirstRun)) return kFALSE; if ((fLastRun >= 0) && (runNumber > fLastRun)) return kFALSE; - if (TString(name).Contains(TRegexp(fName))) return kTRUE; + if (!TString(name).Contains(TRegexp(fName))) return kFALSE; return kTRUE; } @@ -140,3 +222,4 @@ Bool_t operator == (const AliMetaData& entry1, const AliMetaData& entry2) if (entry1.GetVersion() != entry2.GetVersion()) return kFALSE; return kTRUE; } + diff --git a/STEER/AliMetaData.h b/STEER/AliMetaData.h index 5ec8e1013bd..3d99e08bb89 100644 --- a/STEER/AliMetaData.h +++ b/STEER/AliMetaData.h @@ -6,7 +6,8 @@ /* $Id$ */ /// -/// meta data of run dependent objects +/// base class of the meta data of run dependent objects +/// Derived classes: AliObjectMetaData, AliSelectionMetaData /// #include @@ -23,28 +24,46 @@ public: AliMetaData(const AliMetaData& entry); AliMetaData& operator = (const AliMetaData& entry); - void SetName(const char* name) {fName = name;} - void SetRunRange(Int_t firstRun = -1, Int_t lastRun = 1) + virtual void SetName(const char* name) {fName = name; DecodeName();} + /*virtual*/ void SetRunRange(Int_t firstRun = -1, Int_t lastRun = 1) {fFirstRun = firstRun; fLastRun = lastRun;} - void SetVersion(Int_t version = -1) {fVersion = version;} + /*virtual*/ void SetVersion(Int_t version = -1) {fVersion = version;} + + void SetDetector(const char* Detector) {fDetector = Detector; EncodeName();} + void SetDBType(const char* DBType) {fDBType = DBType; EncodeName();} + void SetDetSpecType(const char* DetSpecType) {fDetSpecType = DetSpecType; EncodeName();} - virtual const char* GetName() const; - Int_t GetFirstRun() const {return fFirstRun;} - Int_t GetLastRun() const {return fLastRun;} - Int_t GetVersion() const {return fVersion;} + const char* GetDetector() const; + const char* GetDBType() const; + const char* GetDetSpecType() const; + - Bool_t IsValid(Int_t runNumber, + /*virtual*/ const char* GetName() const; + /*virtual*/ Int_t GetFirstRun() const {return fFirstRun;} + /*virtual*/ Int_t GetLastRun() const {return fLastRun;} + /*virtual*/ Int_t GetVersion() const {return fVersion;} + + /*virtual*/ Bool_t IsValid(Int_t runNumber, + AliMetaData* metaData = NULL) const; + /*virtual*/ Bool_t IsStrictlyValid(Int_t runNumber, AliMetaData* metaData = NULL) const; - virtual Int_t Compare(const TObject* object) const; - Bool_t Matches(const char* name, Int_t runNumber) const; + /*virtual*/ Int_t Compare(const TObject* object) const; + /*virtual*/ Bool_t Matches(const char* name, Int_t runNumber) const; -private: +protected: TString fName; // name of the entry + TString fDetector; // name of the detector (ZDC, TPC, etc...) + TString fDBType; // name of the database type (Calib, Align) + TString fDetSpecType; // name of the detector's specific data type (pedestals, gain coeffs...) Int_t fFirstRun; // index of first valid run Int_t fLastRun; // index of last valid run Int_t fVersion; // version of the entry - ClassDef(AliMetaData, 1) // container for a data base entry object + void EncodeName(); + void DecodeName(); + + + ClassDef(AliMetaData, 2) // base class of the meta data of run dependent objects }; extern Bool_t operator == (const AliMetaData& entry1, diff --git a/STEER/AliObjectMetaData.cxx b/STEER/AliObjectMetaData.cxx new file mode 100644 index 00000000000..b10f5ba6c65 --- /dev/null +++ b/STEER/AliObjectMetaData.cxx @@ -0,0 +1,121 @@ +/************************************************************************** + * 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. * + **************************************************************************/ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// Object meta data: full description of a run dependent database object // +// // +/////////////////////////////////////////////////////////////////////////////// + + +#include +#include +#include +#include + +#include "AliObjectMetaData.h" +#include "AliMetaData.h" +#include "AliLog.h" + + +ClassImp(AliObjectMetaData) + + +//_____________________________________________________________________________ +AliObjectMetaData::AliObjectMetaData() : + AliMetaData(), + fPeriod(-1), + fFormat(""), + fResponsible("Duck, Donald"), + fExtraInfo("") +{ +// default constructor +// the default values mean no selection +} + +//_____________________________________________________________________________ +AliObjectMetaData::AliObjectMetaData + (const char* name, Int_t firstRun, Int_t lastRun, Int_t period, + const char* objFormat, const char* responsible, + const char* extraInfo): + AliMetaData(name, firstRun, lastRun), + fPeriod(period), + fFormat(objFormat), + fResponsible(responsible), + fExtraInfo(extraInfo) +{ +// constructor +} + +//_____________________________________________________________________________ +AliObjectMetaData::AliObjectMetaData(const AliObjectMetaData& entry) : + AliMetaData(entry), + fPeriod(entry.fPeriod), + fFormat(entry.fFormat), + fResponsible(entry.fResponsible), + fExtraInfo(entry.fExtraInfo) +{ +// copy constructor +} + +//_____________________________________________________________________________ +AliObjectMetaData& AliObjectMetaData::operator = (const AliObjectMetaData& entry) +{ +// assignment operator + fName = entry.fName; + fFirstRun = entry.fFirstRun; + fLastRun = entry.fLastRun; + fPeriod=entry.fPeriod; + fFormat=entry.fFormat; + fResponsible=entry.fResponsible; + fExtraInfo=entry.fExtraInfo; + DecodeName(); + return *this; +} + +//_____________________________________________________________________________ +const int AliObjectMetaData::GetPeriod() const +{ +// get the beam period + + return fPeriod; +} + +//_____________________________________________________________________________ +const char* AliObjectMetaData::GetFormat() const +{ +// get the object's format + + return fFormat.Data(); +} + +//_____________________________________________________________________________ +const char* AliObjectMetaData::GetResponsible() const +{ +// get the object's responsible (the person who made it) + + return fResponsible.Data(); +} + +//_____________________________________________________________________________ +const char* AliObjectMetaData::GetExtraInfo() const +{ +// get the object's extra info + + return fExtraInfo.Data(); +} + diff --git a/STEER/AliObjectMetaData.h b/STEER/AliObjectMetaData.h new file mode 100644 index 00000000000..c234a6a100b --- /dev/null +++ b/STEER/AliObjectMetaData.h @@ -0,0 +1,52 @@ +#ifndef ALIOBJECTMETADATA_H +#define ALIOBJECTMETADATA_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +/// +/// Object meta data: it fully describes a run dependent database object. +/// It is attached to the object to build an AliRunData object +/// +/// + +#include +#include + +#include "AliMetaData.h" + + +class AliObjectMetaData: public AliMetaData { +public: + AliObjectMetaData(); // default constructor + AliObjectMetaData + (const char* name, Int_t firstRun = -1, Int_t lastRun = -1, Int_t period=-1, + const char* objFormat="", const char* responsible="Duck, Donald", + const char* extraInfo=""); // constructor + virtual ~AliObjectMetaData() {}; // destructor + + AliObjectMetaData(const AliObjectMetaData& entry); // copy contructor + AliObjectMetaData& operator = (const AliObjectMetaData& entry); // assignment operator + + void SetFormat(const char* objFormat) {fFormat = objFormat;} // infos about object's format (array o floats, histos...) + void SetResponsible(const char* responsible) {fResponsible = responsible;} // who made the object? + void SetExtraInfo(const char* extraInfo) {fExtraInfo = extraInfo;} // something else you would like to know + void SetPeriod(Int_t period) {fPeriod = period;} // number of beam period + + const char* GetFormat() const; + const char* GetResponsible() const; + const char* GetExtraInfo() const; + const Int_t GetPeriod() const; + +private: + Int_t fPeriod; // beam period + TString fFormat; // object's format + TString fResponsible; // name of the person responsible for the object + TString fExtraInfo; // extra info about the object + + +ClassDef(AliObjectMetaData, 1) // Object meta data: full description of a run dependent database object +}; + +#endif diff --git a/STEER/AliRunData.cxx b/STEER/AliRunData.cxx index c374f872fe4..c05fee0b524 100644 --- a/STEER/AliRunData.cxx +++ b/STEER/AliRunData.cxx @@ -24,7 +24,7 @@ #include "AliRunData.h" - +#include "AliObjectMetaData.h" ClassImp(AliRunData) @@ -33,17 +33,17 @@ ClassImp(AliRunData) AliRunData::AliRunData() : TObject(), fObject(NULL), - fMetaData() + fObjMetaData() { // default constructor } //_____________________________________________________________________________ -AliRunData::AliRunData(TObject* object, const AliMetaData& metaData) : +AliRunData::AliRunData(TObject* object, const AliObjectMetaData& objMetaData) : TObject(), fObject(object), - fMetaData(metaData) + fObjMetaData(objMetaData) { // constructor @@ -61,7 +61,7 @@ AliRunData::~AliRunData() //_____________________________________________________________________________ AliRunData::AliRunData(const AliRunData& entry) : TObject(entry), - fMetaData(entry.fMetaData) + fObjMetaData(entry.fObjMetaData) { // copy constructor @@ -74,7 +74,7 @@ AliRunData& AliRunData::operator = (const AliRunData& entry) delete fObject; fObject = entry.fObject->Clone(); - fMetaData = entry.fMetaData; + fObjMetaData = entry.fObjMetaData; return *this; } @@ -85,16 +85,16 @@ const char* AliRunData::GetName() const { // get the name - return fMetaData.GetName(); + return fObjMetaData.GetName(); } //_____________________________________________________________________________ Int_t AliRunData::Compare(const TObject* object) const { -// check whether this is prefered to object +// check whether this is preferred to object if (!object || !object->InheritsFrom(AliRunData::Class())) return 1; - return fMetaData.Compare(&((AliRunData*)object)->GetMetaData()); + return fObjMetaData.Compare(&((AliRunData*)object)->GetObjectMetaData()); } diff --git a/STEER/AliRunData.h b/STEER/AliRunData.h index 2a6786b623c..b17e759994d 100644 --- a/STEER/AliRunData.h +++ b/STEER/AliRunData.h @@ -11,32 +11,35 @@ /// #include -#include "AliMetaData.h" +#include "AliObjectMetaData.h" class AliRunData: public TObject { public: AliRunData(); - AliRunData(TObject* object, const AliMetaData& metaData); + AliRunData(TObject* object, const AliObjectMetaData& objMetaData); virtual ~AliRunData(); AliRunData(const AliRunData& entry); AliRunData& operator = (const AliRunData& entry); void SetVersion(Int_t version = -1) - {fMetaData.SetVersion(version);} + {fObjMetaData.SetVersion(version);} + + void SetRunRange(Int_t firstRun = -1, Int_t lastRun=-1) + {fObjMetaData.SetRunRange(firstRun, lastRun);} virtual const char* GetName() const; const TObject* GetObject() const {return fObject;} - const AliMetaData& GetMetaData() const {return fMetaData;} + const AliObjectMetaData& GetObjectMetaData() const {return fObjMetaData;} virtual Int_t Compare(const TObject* object) const; private: TObject* fObject; // pointer to the data base entry obj. - AliMetaData fMetaData; // meta data + AliObjectMetaData fObjMetaData; // object's meta data - ClassDef(AliRunData, 1) // container for a data base entry object + ClassDef(AliRunData, 2) // container for a data base entry object }; #endif diff --git a/STEER/AliRunDataFile.cxx b/STEER/AliRunDataFile.cxx index 84235ea138f..cfd906b6adb 100644 --- a/STEER/AliRunDataFile.cxx +++ b/STEER/AliRunDataFile.cxx @@ -17,7 +17,7 @@ /////////////////////////////////////////////////////////////////////////////// // // -// access classes for a data base in a (local) file // +// access classes for a data base in a LOCAL file // // // /////////////////////////////////////////////////////////////////////////////// @@ -27,6 +27,8 @@ #include #include "AliLog.h" #include "AliRunData.h" +#include "AliSelectionMetaData.h" +#include "AliObjectMetaData.h" #include "AliRunDataFile.h" @@ -85,29 +87,31 @@ AliRunDataFile& AliRunDataFile::operator = (const AliRunDataFile& /*db*/) //_____________________________________________________________________________ -AliRunData* AliRunDataFile::GetEntry(AliMetaData& metaData, Int_t runNumber) +AliRunData* AliRunDataFile::GetEntry(AliSelectionMetaData& selMetaData, Int_t runNumber) { // get an object from the data base // go to the directory TDirectory* saveDir = gDirectory; - TString name(metaData.GetName()); + TDirectory *dir = fFile; + TString name(selMetaData.GetName()); Int_t last = name.Last('/'); if (last < 0) { fFile->cd(); } else { TString dirName(name(0, last)); - if (!fFile->cd(dirName)) { - AliDebug(1, Form("no directory %s found", dirName.Data())); + if (!dir->cd(dirName)) { + AliError(Form("no directory %s found", dirName.Data())); if (saveDir) saveDir->cd(); else gROOT->cd(); return NULL; } name.Remove(0, last+1); } - TKey* key = fFile->GetKey(name); + dir = gDirectory; + TKey* key = dir->GetKey(name); if (!key) { - AliDebug(1, Form("no object with name %s found", metaData.GetName())); + AliError(Form("no object with name %s found", selMetaData.GetName())); if (saveDir) saveDir->cd(); else gROOT->cd(); return NULL; } @@ -116,15 +120,16 @@ AliRunData* AliRunDataFile::GetEntry(AliMetaData& metaData, Int_t runNumber) // find the closest entry AliRunData* closestEntry = NULL; for (Int_t iCycle = nCycles; iCycle > 0; iCycle--) { - key = fFile->GetKey(name, iCycle); + key = dir->GetKey(name, iCycle); + if (!key) continue; AliRunData* entry = (AliRunData*) key->ReadObj(); if (!entry) continue; if (!entry->InheritsFrom(AliRunData::Class())) { - AliMetaData metaData; - entry = new AliRunData(entry, metaData); + AliObjectMetaData objMetaData; + entry = new AliRunData(entry, objMetaData); } - if (!entry->GetMetaData().IsValid(runNumber, &metaData) || + if (!entry->GetObjectMetaData().IsValid(runNumber, &selMetaData) || (entry->Compare(closestEntry) <= 0)) { delete entry; continue; @@ -133,14 +138,27 @@ AliRunData* AliRunDataFile::GetEntry(AliMetaData& metaData, Int_t runNumber) closestEntry = entry; } if (saveDir) saveDir->cd(); else gROOT->cd(); + if(!closestEntry) AliError(Form("No valid entry found for: name %s, version %d, run %d!!!", + selMetaData.GetName(),selMetaData.GetVersion(),runNumber)); if (!closestEntry) return NULL; + if(selMetaData.GetVersion() > -1 && (closestEntry->GetObjectMetaData()).GetVersion() != selMetaData.GetVersion()) + AliWarning(Form("Warning: selected version (%d) not found, got version %d instead", + selMetaData.GetVersion(),(closestEntry->GetObjectMetaData()).GetVersion())); return closestEntry; } //_____________________________________________________________________________ Bool_t AliRunDataFile::PutEntry(AliRunData* entry) { -// put an object into the data base +// puts an object into the database + +// AliRunData entry is composed by the object and its MetaData +// this method takes the metaData, reads the name, runRange and Version +// creates the TDirectory structure into the file +// looks for runs with same name, if exist increment version +// (therefore version should not be put in the metadata) +// Note: the key name of the entry is "DetSpecType" +// return result if (!entry || !fFile) return kFALSE; if (!fFile->IsWritable()) { @@ -148,6 +166,8 @@ Bool_t AliRunDataFile::PutEntry(AliRunData* entry) "The object %s was not inserted", entry->GetName())); return kFALSE; } + + fFile->cd(); TDirectory* saveDir = gDirectory; // go to or create the directory @@ -165,17 +185,17 @@ Bool_t AliRunDataFile::PutEntry(AliRunData* entry) // determine the version number Int_t version = 0; - TKey* key = fFile->GetKey(name); + TKey* key = dir->GetKey(name); if (key) { Int_t nCycles = key->GetCycle(); for (Int_t iCycle = nCycles; iCycle > 0; iCycle--) { - key = fFile->GetKey(entry->GetName(), iCycle); + key = dir->GetKey(name, iCycle); if (!key) continue; AliRunData* oldEntry = (AliRunData*) key->ReadObj(); if (!oldEntry) continue; if (oldEntry->InheritsFrom(AliRunData::Class())) { - if (version <= oldEntry->GetMetaData().GetVersion()) { - version = oldEntry->GetMetaData().GetVersion()+1; + if (version <= oldEntry->GetObjectMetaData().GetVersion()) { + version = oldEntry->GetObjectMetaData().GetVersion()+1; } } delete oldEntry; diff --git a/STEER/AliRunDataFile.h b/STEER/AliRunDataFile.h index 65535dc10a0..3e8ad362f0d 100644 --- a/STEER/AliRunDataFile.h +++ b/STEER/AliRunDataFile.h @@ -6,10 +6,11 @@ /* $Id$ */ /// -/// access classes for a data base in a (local) file +/// access classes for a data base in a LOCAL file /// #include "AliRunDataStorage.h" +#include "AliSelectionMetaData.h" class TFile; @@ -20,7 +21,7 @@ public: virtual ~AliRunDataFile(); protected: - virtual AliRunData* GetEntry(AliMetaData& metaData, Int_t runNumber); + virtual AliRunData* GetEntry(AliSelectionMetaData& selMetaData, Int_t runNumber); virtual Bool_t PutEntry(AliRunData* entry); @@ -28,9 +29,9 @@ private: AliRunDataFile(const AliRunDataFile& db); AliRunDataFile& operator = (const AliRunDataFile& db); - TFile* fFile; //! the DB file + TFile* fFile; //! the DB local file - ClassDef(AliRunDataFile, 0) // access classes for a data base in a (local) file + ClassDef(AliRunDataFile, 0) // access classes for a data base in a LOCAL file }; #endif diff --git a/STEER/AliRunDataOrganizedFile.cxx b/STEER/AliRunDataOrganizedFile.cxx new file mode 100644 index 00000000000..94341403c11 --- /dev/null +++ b/STEER/AliRunDataOrganizedFile.cxx @@ -0,0 +1,366 @@ +/************************************************************************** + * 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. * + **************************************************************************/ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// access class to a DB file inside an organized directory structure // +// (DBFolder/detector/dbType/detSpecType) // +// // +/////////////////////////////////////////////////////////////////////////////// + + +#include +#include +#include +#include +#include +#include +#include + +#include "AliLog.h" +#include "AliRunData.h" +#include "AliSelectionMetaData.h" +#include "AliRunDataOrganizedFile.h" + + +ClassImp(AliRunDataOrganizedFile) + +//_____________________________________________________________________________ +AliRunDataOrganizedFile::AliRunDataOrganizedFile(const char* DBFolder) : + AliRunDataStorage(), + fDBFolder(DBFolder) +{ +// constructor + TString buffer(fDBFolder); + gSystem->ExpandPathName(buffer); + if(!gSystem->OpenDirectory(buffer)){ + AliError(Form("Path %s not a directory",fDBFolder.Data())); + } +} + +//_____________________________________________________________________________ +AliRunDataOrganizedFile::~AliRunDataOrganizedFile() +{ +// destructor + + if (fDBFolder) fDBFolder=""; +} + +//_____________________________________________________________________________ +AliRunDataOrganizedFile::AliRunDataOrganizedFile(const AliRunDataOrganizedFile& /*db*/) : + AliRunDataStorage(), + fDBFolder("") +{ +// copy constructor + + AliFatal("not implemented"); +} + +//_____________________________________________________________________________ +AliRunDataOrganizedFile& AliRunDataOrganizedFile::operator = (const AliRunDataOrganizedFile& /*db*/) +{ +// assignment operator + + AliFatal("not implemented"); + return *this; +} + +//_____________________________________________________________________________ +AliRunData* AliRunDataOrganizedFile::GetEntry(AliSelectionMetaData& selMetaData, Int_t runNumber) +{ +// get an object from the data base + + TDirectory* saveDir = gDirectory; + +// Find the right file in the directory + + TObjArray *objarr = FindDataBaseFile(selMetaData, runNumber); + if(!objarr || objarr->GetEntries()==0) return NULL; + if(objarr->GetEntries()>1) + AliWarning("Warning: more than 1 file match requirements, I will open the first found!"); + +// Open the file + + TObjString *objstr= (TObjString*) objarr->At(0); // there should be only one item + TString fileName(objstr->GetName()); + TFile *dbFile = new TFile(fileName.Data(),"READ"); + if (!dbFile || !dbFile->IsOpen()) { + AliError(Form("could not open file %s", fileName.Data())); + return NULL; + } + +// get the only AliRunData object from the file +// I suppose that the object in the file is a AliRunData entry with +// name="DetSpecType" (set in SelectionMetaData) + + dbFile->cd(); + + AliRunData *entry = (AliRunData*) dbFile->Get(selMetaData.GetDetSpecType()); + + if(!entry || !entry->InheritsFrom(AliRunData::Class())) { + AliError(Form("No entry named %s found!",selMetaData.GetDetSpecType())); + dbFile->Close(); delete dbFile; + if (saveDir) saveDir->cd(); else gROOT->cd(); + return NULL; + } + +// now set the run range and version got from the filename +// to the object's metadata! + + TString fileNameShort=fileName; + fileNameShort.Remove(0,fileNameShort.Last('/')+1); + int numbers[3]={-1,-1,-1}; // numbers[0]=firstRun, numbers[1]=lastRun, numbers[2]=Version + GetNumbers(fileNameShort, numbers); + entry->SetRunRange(numbers[0],numbers[1]); + entry->SetVersion(numbers[2]); + +// close file, return retieved entry + + dbFile->Close(); delete dbFile; + if (saveDir) saveDir->cd(); else gROOT->cd(); + + if(selMetaData.GetVersion() > -1 && numbers[2] != selMetaData.GetVersion()) + AliWarning(Form("Warning: selected version (%d) not found, got version %d instead", + selMetaData.GetVersion(),numbers[2])); + return entry; + +} + + +//_____________________________________________________________________________ +Bool_t AliRunDataOrganizedFile::PutEntry(AliRunData* entry) +{ +// puts an object into the database + +// AliRunData entry is composed by the object and its MetaData +// this method takes the metaData, reads the name, runRange and Version +// creates the directory structure and the file name +// looks for runs with same or overlapping runrange, if exist increment version +// (therefore version should not be put in the metadata) +// if the runrange is different (but overlapping) from a preceding version, a warning message +// is issued. +// sets the runrange and version in the object metadata = -1 (to avoid inconsistencies) +// open the filem, write the entry in the file. +// Note: the key name of the entry is "DetSpecType" +// return result + + if(!entry) return kFALSE; + TDirectory* saveDir = gDirectory; + + Int_t firstRun=entry->GetObjectMetaData().GetFirstRun(); + Int_t lastRun=entry->GetObjectMetaData().GetLastRun(); + if(firstRun<0 || lastRun<0 || lastRunGetObjectMetaData().GetName()); + + while(name.EndsWith("/")) name.Remove(name.Last('/')); + while(name.BeginsWith("/")) name.Remove(name.First('/'),1); + + TString detSpecType(name(name.Last('/')+1, name.Length()-name.Last('/'))); + + TString buffer(fDBFolder); + gSystem->ExpandPathName(buffer); + while(buffer.EndsWith("/")) buffer.Remove(buffer.Last('/')); + + void *dir=0; + Int_t index = -1; + name+='/'; // name=detector/dbType/detSpecType/ + + while ((index = name.Index("/")) >= 0) { + TString dirName(name(0, index)); + buffer+='/'; buffer+=dirName; + dir=gSystem->OpenDirectory(buffer); + if (!dir) { + AliWarning(Form("Directory %s does not exist! It will be created...",buffer.Data())); + TString command = "mkdir "+ buffer; + gSystem->Exec(command.Data()); + } + name.Remove(0, index+1); + } + + TString strfName="Run"; + + TString levelContent=""; + Int_t maxVersion=-1, run1=-1, run2=-1; + int numbers[3]={-1,-1,-1}; // numbers[0]=firstRun, numbers[1]=lastRun, numbers[2]=Version + while(levelContent=gSystem->GetDirEntry(dir)){ + if(levelContent=="." || levelContent=="..") continue; if(levelContent=="") break; + if(levelContent.Contains(strfName)){ + GetNumbers(levelContent, numbers); + if((firstRun>=numbers[0] && firstRun<=numbers[1]) || + (lastRun>=numbers[0] && lastRun<=numbers[1]) || + (firstRun<=numbers[0] && lastRun>=numbers[1])) {// overlap! + if(numbers[2]>maxVersion) { + maxVersion=numbers[2]; + run1=numbers[0]; run2=numbers[1]; + } + } + } + } + + if((run1!=-1 && run2!=-1) && (firstRun!=run1 || lastRun!=run2)) + AliWarning(Form("Run range modified w.r.t. preceding version (%d, %d)",run1, run2)); + + + if(firstRun==lastRun) { + strfName+=firstRun; + }else{ + strfName+=firstRun; strfName+="-"; strfName+=lastRun; + } + strfName+="_v"; strfName+=maxVersion+1; strfName+=".root"; + buffer+='/'; buffer+=strfName; + + // opening file + TFile *dbFile = new TFile(buffer.Data(),"NEW"); + if(!dbFile || !dbFile->IsWritable()){ + AliError(Form("The data base file is not writable. " + "The object %s was not inserted", entry->GetName())); + return kFALSE; + } + + dbFile->cd(); + + entry->SetRunRange(-1,-1); entry->SetVersion(-1); + + // write object + Bool_t result = (entry->Write(detSpecType) != 0); + if (saveDir) saveDir->cd(); else gROOT->cd(); + dbFile->Close(); delete dbFile; + + if(result) { + AliInfo(Form("Run object %s",entry->GetName())); + AliInfo(Form("was successfully written into file %s !",buffer.Data())); + } + + return result; +} + +/*****************************************************************************/ + +TObjArray* AliRunDataOrganizedFile::FindDataBaseFile(AliSelectionMetaData& selMetaData, Int_t runNumber){ +// Find DataBase file name in a local directory. The filename must be in the form: Run#run1-#run2_v#version.root +// TRegexp allowed: selMetaData's name can be for example: "detector/*" !! + + TObjArray *fileNameColl=new TObjArray(); + + TString buffer(fDBFolder); + if(!(buffer.EndsWith("/"))) buffer+="/"; + gSystem->ExpandPathName(buffer); + + TString bufftInit=buffer; // buffInit="$ALICE_ROOT/DB/ + TString levelContent=""; + + TString detector(selMetaData.GetDetector()); + TString dbType(selMetaData.GetDBType()); + TString detSpecType(selMetaData.GetDetSpecType()); + int selVersion = selMetaData.GetVersion(); + + void *dirLevInit = gSystem->OpenDirectory(buffer); + while(levelContent=gSystem->GetDirEntry(dirLevInit)){ // lev0! In Detector directory (ZDC, TPC...)!! + + if(levelContent=="." || levelContent=="..") continue; if(levelContent=="") break; + if(!(detector=="*") && !levelContent.Contains(TRegexp(detector)) ) continue; + + buffer=bufftInit+levelContent; buffer+='/'; // buffer="$ALICE_ROOT/DB/detector/ + TString bufft0=buffer; // bufft0="$ALICE_ROOT/DB/detector/ + + void *dirLev0 = gSystem->OpenDirectory(buffer); + while(levelContent=gSystem->GetDirEntry(dirLev0)){ // lev1! dbType directory (Calib, Align)!! + + if(levelContent=="." || levelContent=="..") continue; if(levelContent=="") break; + if(!(dbType=="*") && !levelContent.Contains(TRegexp(dbType))) continue; + + buffer=bufft0+levelContent;buffer+='/'; // buffer="$ALICE_ROOT/DB/detector/dbType/ + TString bufft1=buffer; // bufft1="$ALICE_ROOT/DB/detector/dbType/ + + void *dirLev1 = gSystem->OpenDirectory(buffer); + while(levelContent=gSystem->GetDirEntry(dirLev1)){ // lev2! detSpecType directory (Pedestals, gain....)!! + + if(levelContent=="." || levelContent=="..") continue; if(levelContent=="") break; + if(!(detSpecType=="*") && !levelContent.Contains(TRegexp(detSpecType))) continue; + + buffer=bufft1+levelContent;buffer+='/'; // buffer="$ALICE_ROOT/DB/detector/dbType/detSpecType/ + TString bufft2=buffer; // bufft2="$ALICE_ROOT/DB/detector/dbType/detSpecType/ + + void *dirLev2 = gSystem->OpenDirectory(buffer); + int oldVers=-1; + TObjString *str=0; + while(levelContent=gSystem->GetDirEntry(dirLev2)){ // lev3! Run directory (Run#XXX-#YYY_v#ZZ.root)!! + + if(levelContent=="." || levelContent=="..") continue; if(levelContent=="") break; + if(!levelContent.BeginsWith("Run")) continue; + + int numbers[3]={-1,-1,-1}; // numbers[0]=firstRun, numbers[1]=lastRun, numbers[2]=Version + GetNumbers(levelContent,numbers); + if(numbers[0]<0 || numbers[1]<0 || numbers[2]<0 ) continue; // wrong run filename format! + if(numbers[0]>runNumber || numbers[1]= oldVers) { + buffer=bufft2+levelContent; + str=new TObjString(buffer.Data()); + oldVers=numbers[2]; + if(numbers[2]==selVersion) break; + } + } // end loop on runs + if(str) fileNameColl->Add(str); + } // end loop in lev1 + } // end loop in lev0 + } // end loop in levInit + + AliInfo(Form("Found %d entries matching requirements", fileNameColl->GetEntriesFast())); + ToAliInfo(fileNameColl->ls()); + return fileNameColl; +} + +//_____________________________________________________________________________ + +void AliRunDataOrganizedFile::GetNumbers(const TString strName, int *numArray) +{ +// Gets the numbers (#Run1, #Run2, #Version) from the filename: Run#Run1-#Run2_v#Version.root + + int indexMinus=strName.Last('-'); + int indexUScore=strName.Last('_'); + int indexPoint=strName.Last('.'); + + if(indexUScore<0 || indexPoint<0 ) + {AliError(Form("Check sintax %s",strName.Data())); return;} + + if(indexMinus<0){ // only 1 Run number! + TString cRun=strName(3,indexUScore-3); + if(!(cRun.IsDigit())) + {AliError(Form("%s not a digit! Check sintax %s",cRun.Data(),strName.Data())); return;} + numArray[0] = (int) strtol(cRun.Data(),0,10); + numArray[1] = numArray[0]; + }else{ + TString cFirstRun = strName(3,indexMinus-3); + TString cLastRun = strName(indexMinus+1,indexUScore-(indexMinus+1)); + if(!(cFirstRun.IsDigit()) || !(cLastRun.IsDigit())) + {AliError(Form("%s or %s are not digit! Check sintax %s", + cFirstRun.Data(), cLastRun.Data(), strName.Data())); return;} + numArray[0] = (int) strtol(cFirstRun.Data(),0,10); + numArray[1] = (int) strtol(cLastRun.Data(),0,10); + } + TString cVersion = strName(indexUScore+2,indexPoint-(indexUScore+2)); + if(!(cVersion.IsDigit())){ + AliError(Form("%s not a digit! Check sintax %s",cVersion.Data(),strName.Data())); return;} + numArray[2] = (int) strtol(cVersion.Data(),0,10); + + return; +} diff --git a/STEER/AliRunDataOrganizedFile.h b/STEER/AliRunDataOrganizedFile.h new file mode 100644 index 00000000000..a89fb98ab89 --- /dev/null +++ b/STEER/AliRunDataOrganizedFile.h @@ -0,0 +1,42 @@ +#ifndef ALIRUNDATAORGANIZEDFILE_H +#define ALIRUNDATAORGANIZEDFILE_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +/// +/// access class to a DB file inside an organized directory structure +/// (DBFolder/Detector/DBType/DetSpecType) +/// + +#include "AliRunDataStorage.h" +#include "AliSelectionMetaData.h" +#include "AliObjectMetaData.h" + +class AliRunDataOrganizedFile: public AliRunDataStorage { + +public: +// AliRunDataOrganizedFile(); + AliRunDataOrganizedFile(const char* DBFolder = "$(ALICE_ROOT)/DB"); + virtual ~AliRunDataOrganizedFile(); + + TObjArray* FindDataBaseFile(AliSelectionMetaData& selMetaData, Int_t runNumber); + +protected: + virtual AliRunData* GetEntry(AliSelectionMetaData& selMetaData, Int_t runNumber); + virtual Bool_t PutEntry(AliRunData* entry); + +private: + AliRunDataOrganizedFile(const AliRunDataOrganizedFile& db); + AliRunDataOrganizedFile& operator = (const AliRunDataOrganizedFile& db); + + void GetNumbers(const TString strName, int *numArray); + + TString fDBFolder; // the DB folder + +ClassDef(AliRunDataOrganizedFile, 0) // access class to a DB file in an organized directory structure (DBFolder/Detector/DBType/DetSpecType) +}; + +#endif diff --git a/STEER/AliRunDataStorage.cxx b/STEER/AliRunDataStorage.cxx index 0b76c3300f4..3fd1166b891 100644 --- a/STEER/AliRunDataStorage.cxx +++ b/STEER/AliRunDataStorage.cxx @@ -27,7 +27,8 @@ #include #include "AliLog.h" -#include "AliMetaData.h" +#include "AliSelectionMetaData.h" +#include "AliObjectMetaData.h" #include "AliRunData.h" #include "AliRunDataStorage.h" @@ -46,7 +47,6 @@ AliRunDataStorage::AliRunDataStorage() : fRecordFile(NULL) { // default constructor - if (fgInstance) delete fgInstance; fgInstance = this; } @@ -91,14 +91,16 @@ AliRunDataStorage& AliRunDataStorage::operator = (const AliRunDataStorage& /*db* const TObject* AliRunDataStorage::Get(const char* name, Int_t runNumber) { // get an object from the data base -// (AliRunDataStorage is the owner of the returned object) +// (AliRunDataStorage is NOT the owner of the returned object) +// name must be in the form "Detector/DBType/DetSpecType" +// es: "ZDC/Calib/Pedestals" - AliMetaData defaultMetaData; - AliMetaData* selectedMetaData = &defaultMetaData; + AliSelectionMetaData defaultMetaData; + AliSelectionMetaData* selectedMetaData = &defaultMetaData; // look for a meta data selection for (Int_t i = 0; i < fSelection.GetEntriesFast(); i++) { - AliMetaData* selection = (AliMetaData*) fSelection[i]; + AliSelectionMetaData* selection = (AliSelectionMetaData*) fSelection[i]; if (!selection) continue; if (selection->Matches(name, runNumber)) { selectedMetaData = selection; @@ -106,9 +108,9 @@ const TObject* AliRunDataStorage::Get(const char* name, Int_t runNumber) } // get the entry - AliMetaData metaData(*selectedMetaData); - metaData.SetName(name); - AliRunData* entry = GetEntry(metaData, runNumber); + AliSelectionMetaData selMetaData(*selectedMetaData); + selMetaData.SetName(name); + AliRunData* entry = GetEntry(selMetaData, runNumber); if (entry) { AliDebug(2, "got the entry:"); ToAliDebug(2, entry->Dump()); @@ -117,55 +119,56 @@ const TObject* AliRunDataStorage::Get(const char* name, Int_t runNumber) } // update array of current entries - if (!entry) return NULL; + if (!entry) return NULL; TObject* oldEntry = fEntries.FindObject(entry->GetName()); if (oldEntry) { delete fEntries.Remove(oldEntry); } fEntries.Add(entry); - // record entry to a file + // record entry to a file (in the same way as AliRunDataFile::PutEntry, + // so that the file can be opened as a AliRunDataFile!) + if (fRecordFile) { - Bool_t isAlreadyRecorded = kFALSE; - TDirectory* dir = gDirectory; fRecordFile->cd(); - TKey* key = fRecordFile->GetKey(entry->GetName()); - if (key) { - Int_t nCycles = key->GetCycle(); - for (Int_t iCycle = nCycles; iCycle > 0; iCycle--) { - key = fRecordFile->GetKey(entry->GetName(), iCycle); - if (!key) continue; - AliRunData* recEntry = (AliRunData*) key->ReadObj(); - if (!recEntry) continue; - if (recEntry->InheritsFrom(AliRunData::Class()) && - (recEntry->GetMetaData() == entry->GetMetaData())) { - isAlreadyRecorded = kTRUE; - } - delete recEntry; - if (isAlreadyRecorded) break; - } - } - if (!isAlreadyRecorded) { - if (entry->Write() == 0) { - AliError(Form("could not record entry %s", entry->GetName())); - } - } - if (dir) dir->cd(); else gROOT->cd(); + TDirectory* saveDir = gDirectory; + + // go to or create the directory + TString strname(name); + while (strname.BeginsWith("/")) strname.Remove(0); + TDirectory* dir = fRecordFile; + Int_t index = -1; + while ((index = strname.Index("/")) >= 0) { + TString dirName(strname(0, index)); + if ((index > 0) && !dir->Get(dirName)) dir->mkdir(dirName); + dir->cd(dirName); + dir = gDirectory; + strname.Remove(0, index+1); + } + + entry->Write(strname); + if (saveDir) saveDir->cd(); else gROOT->cd(); + } + + return (entry->GetObject())->Clone(); - return entry->GetObject(); } //_____________________________________________________________________________ Bool_t AliRunDataStorage::Put(const TObject* object, - const AliMetaData& metaData) + const AliObjectMetaData& objMetaData) { // put an object into the data base // (AliRunDataStorage does not adopt the object) +// location of where the object is stored is defined by +// the AliObjectMetaData's name ("Detector/DBType/DetSpecType") +// and run Range. Storage is handled by the PutEntry method +// of the current AliRunDataStorage instance. if (!object) return kFALSE; - AliRunData entry(object->Clone(), metaData); + AliRunData entry(object->Clone(), objMetaData); return PutEntry(&entry); } @@ -173,6 +176,8 @@ Bool_t AliRunDataStorage::Put(const TObject* object, Bool_t AliRunDataStorage::PutEntry(AliRunData* entry) { // put an object into the data base +// Refer to the specific method of the current AliRunDataStorage instance +// (AliRunDataFile, AliRunDataOrganizedFile, AliRunDataAlien) if (!entry) return kFALSE; AliError(Form("This is a read only data base. " @@ -182,11 +187,11 @@ Bool_t AliRunDataStorage::PutEntry(AliRunData* entry) //_____________________________________________________________________________ -void AliRunDataStorage::Select(const AliMetaData& metaData) +void AliRunDataStorage::Select(const AliSelectionMetaData& selMetaData) { // add some meta data selection criteria - fSelection.Add(new AliMetaData(metaData)); + fSelection.Add(new AliSelectionMetaData(selMetaData)); } @@ -216,7 +221,25 @@ Bool_t AliRunDataStorage::RecordToFile(const char* fileName) //_____________________________________________________________________________ AliRunDataStorage* AliRunDataStorage::Instance() { -// return the current instance of the DB +// return the current instance of the DB (AliRunDataFile, AliRunOrganizedDataFile...) +// Example of usage: after creating an istance of AliRunDataStorage: +// AliRunDataStorage::Instance()->Get(...) return fgInstance; } + + +//_____________________________________________________________________________ +const AliObjectMetaData& AliRunDataStorage::GetObjectMetaData(const char* name) +{ +// Returns the object's metadata of the already retrieved object +// (useful, for example, if you want to know the format of the object you have +// retrieved) + +AliRunData *entry = (AliRunData*) fEntries.FindObject(name); + if(!entry){ + AliError(Form("Entry %s not found! You make me crash!",name)); + } + return entry->GetObjectMetaData(); + +} diff --git a/STEER/AliRunDataStorage.h b/STEER/AliRunDataStorage.h index 62b48224a5c..4fdf28a6d05 100644 --- a/STEER/AliRunDataStorage.h +++ b/STEER/AliRunDataStorage.h @@ -13,7 +13,8 @@ #include class TFile; -class AliMetaData; +class AliSelectionMetaData; +class AliObjectMetaData; class AliRunData; @@ -21,23 +22,27 @@ class AliRunDataStorage: public TObject { public: virtual ~AliRunDataStorage(); - const TObject* Get(const char* name, Int_t runNumber); + const TObject* Get(const char* name, Int_t runNumber); // Gets an object from the database Bool_t Put(const TObject* object, - const AliMetaData& metaData); + const AliObjectMetaData& objMetaData); // Put an object into the database - void Select(const AliMetaData& metaData); + void Select(const AliSelectionMetaData& selMetaData); // Add a selection criterion - Bool_t RecordToFile(const char* fileName = "DB.root"); + Bool_t RecordToFile(const char* fileName = "DB.root"); // prepares to record the retrieved entries to a local file + + const AliObjectMetaData& GetObjectMetaData(const char* name); // Gets the ObjectMetaData of the retrieved entry (name=entry's name) + +// virtual void TagForProduction(const AliSelectionMetaData& selMetaData, Uint_t prodVers); - static AliRunDataStorage* Instance(); + static AliRunDataStorage* Instance(); // Instance of the current AliRunDataStorage object (AliRunDataFile, AliRunDataOrganizedFile etc...) protected: AliRunDataStorage(); - virtual AliRunData* GetEntry(AliMetaData& metaData, Int_t runNumber) = 0; + virtual AliRunData* GetEntry(AliSelectionMetaData& selMetaData, Int_t runNumber) = 0; // virtual, see the correspondent method of the derived classes - virtual Bool_t PutEntry(AliRunData* entry); + virtual Bool_t PutEntry(AliRunData* entry); // virtual, see the correspondent method of the derived classes AliRunData* GetCurrentEntry(const char* name) const {return (AliRunData*) fEntries.FindObject(name);} diff --git a/STEER/AliRunLoader.cxx b/STEER/AliRunLoader.cxx index d5199aa02c5..047a81e25e7 100644 --- a/STEER/AliRunLoader.cxx +++ b/STEER/AliRunLoader.cxx @@ -63,7 +63,7 @@ class TTask; #include "AliStack.h" #include "AliDetector.h" #include "AliRunDataStorage.h" -#include "AliRunDataFile.h" +#include "AliRunDataOrganizedFile.h" ClassImp(AliRunLoader) @@ -355,10 +355,10 @@ const TObject* AliRunLoader::GetRunObject(const char* name) const //Get an object from the run data storage if (!AliRunDataStorage::Instance()) { - AliWarning("No run data storage defined. Using AliRunDataFile."); - new AliRunDataFile; + AliWarning("No run data storage defined. Using AliRunDataOrganizedFile."); + new AliRunDataOrganizedFile; } - return AliRunDataStorage::Instance()->Get(name, GetEventNumber()); + return AliRunDataStorage::Instance()->Get(name, GetHeader()->GetRun()); } /**************************************************************************/ diff --git a/STEER/AliSelectionMetaData.cxx b/STEER/AliSelectionMetaData.cxx new file mode 100644 index 00000000000..3cf9802217f --- /dev/null +++ b/STEER/AliSelectionMetaData.cxx @@ -0,0 +1,77 @@ +/************************************************************************** + * 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. * + **************************************************************************/ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// subsample of the object metadata, used to retrieve // +// a stored database object: // +// name="Detector/DBType/DetSpecType", run validity, version // +// // +/////////////////////////////////////////////////////////////////////////////// + + +#include + +#include "AliSelectionMetaData.h" +#include "AliMetaData.h" +#include "AliLog.h" + + +ClassImp(AliSelectionMetaData) + + +//_____________________________________________________________________________ +AliSelectionMetaData::AliSelectionMetaData() : + AliMetaData() +{ +// default constructor +// the default values mean no selection +} + +//_____________________________________________________________________________ +AliSelectionMetaData::AliSelectionMetaData(const char* name, Int_t firstRun, Int_t lastRun, Int_t Version) : + AliMetaData(name, firstRun, lastRun, Version) +{ +// constructor +} + +//_____________________________________________________________________________ +AliSelectionMetaData::AliSelectionMetaData(const AliSelectionMetaData& entry) : + AliMetaData(entry) +{ +// copy constructor +} + +//_____________________________________________________________________________ +AliSelectionMetaData::AliSelectionMetaData(const AliMetaData& entry) : + AliMetaData(entry) +{ +// constructor of AliSelectionMetaData from AliMetaData +} + + +//_____________________________________________________________________________ +AliSelectionMetaData& AliSelectionMetaData::operator = (const AliSelectionMetaData& entry) +{ +// assignment operator + fName = entry.fName, + fFirstRun = entry.fFirstRun; + fLastRun = entry.fLastRun; + fVersion = entry.fVersion; + return *this; +} + diff --git a/STEER/AliSelectionMetaData.h b/STEER/AliSelectionMetaData.h new file mode 100644 index 00000000000..4b26c271279 --- /dev/null +++ b/STEER/AliSelectionMetaData.h @@ -0,0 +1,30 @@ +#ifndef ALISELECTIONMETADATA_H +#define ALISELECTIONMETADATA_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +/// +/// subsample of the object metadata, used to retrieve a stored database object: name="Detector/DBType/DetSpecType", run validity, version +/// + +#include + +#include "AliMetaData.h" + + +class AliSelectionMetaData: public AliMetaData { +public: + AliSelectionMetaData(); // default constructor + AliSelectionMetaData(const char* name, Int_t firstRun = -1, Int_t lastRun = -1, Int_t version = -1); // constructor + virtual ~AliSelectionMetaData() {}; // destructor + + AliSelectionMetaData(const AliSelectionMetaData& entry); // copy constructor + AliSelectionMetaData(const AliMetaData& entry); // selection metadata from base class + AliSelectionMetaData& operator = (const AliSelectionMetaData& entry); // assignment operator + +ClassDef(AliSelectionMetaData, 1) // metadata used to retrieve a DB object +}; + +#endif diff --git a/STEER/STEERLinkDef.h b/STEER/STEERLinkDef.h index c426d600650..675521dfbe3 100644 --- a/STEER/STEERLinkDef.h +++ b/STEER/STEERLinkDef.h @@ -74,9 +74,12 @@ #pragma link C++ class AliVertexGenFile+; #pragma link C++ class AliVertexer+; #pragma link C++ class AliMetaData+; +#pragma link C++ class AliObjectMetaData+; +#pragma link C++ class AliSelectionMetaData+; #pragma link C++ class AliRunData+; #pragma link C++ class AliRunDataStorage; #pragma link C++ class AliRunDataFile; +#pragma link C++ class AliRunDataOrganizedFile; #pragma link C++ class AliDetectorEventHeader+; #pragma link C++ class TTreeDataElement+; diff --git a/STEER/libSTEER.pkg b/STEER/libSTEER.pkg index a441563689f..ce6c9b91549 100644 --- a/STEER/libSTEER.pkg +++ b/STEER/libSTEER.pkg @@ -20,7 +20,8 @@ AliMemoryWatcher.cxx \ AliVertexer.cxx \ AliMC.cxx AliSimulation.cxx AliReconstruction.cxx AliVertexGenFile.cxx \ AliMetaData.cxx AliRunData.cxx AliRunDataStorage.cxx AliRunDataFile.cxx \ -AliReconstructor.cxx \ +AliRunDataOrganizedFile.cxx\ +AliReconstructor.cxx AliObjectMetaData.cxx AliSelectionMetaData.cxx \ AliDetectorEventHeader.cxx TTreeStream.cxx HDRS:= $(SRCS:.cxx=.h) -- 2.43.0