From cc336771b2d04aa7afd13b3ba9d8657cdc120b0f Mon Sep 17 00:00:00 2001 From: morsch Date: Fri, 14 Jan 2011 15:14:09 +0000 Subject: [PATCH] AliOADBContainer first commit. --- OADB/AliOADBContainer.cxx | 160 ++++++++++++++++++++++++++++++++++++++ OADB/AliOADBContainer.h | 42 ++++++++++ OADB/OADBLinkDef.h | 13 ++++ OADB/libOADB.pkg | 13 ++++ OADB/test.C | 25 ++++++ 5 files changed, 253 insertions(+) create mode 100644 OADB/AliOADBContainer.cxx create mode 100644 OADB/AliOADBContainer.h create mode 100644 OADB/OADBLinkDef.h create mode 100644 OADB/libOADB.pkg create mode 100644 OADB/test.C diff --git a/OADB/AliOADBContainer.cxx b/OADB/AliOADBContainer.cxx new file mode 100644 index 00000000000..167b7ab27fe --- /dev/null +++ b/OADB/AliOADBContainer.cxx @@ -0,0 +1,160 @@ +/************************************************************************** + * Copyright(c) 1998-2007, 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$ */ + +//------------------------------------------------------------------------- +// Offline Analysis Database Container and Service Class +// Author: Andreas Morsch, CERN +//------------------------------------------------------------------------- + + + + +#include "AliOADBContainer.h" +#include "AliLog.h" +#include +#include +#include + +ClassImp(AliOADBContainer); + +//______________________________________________________________________________ +AliOADBContainer::AliOADBContainer() : + TNamed(), + fArray(new TObjArray(100)), + fLowerLimits(), + fUpperLimits(), + fEntries(0) +{ +} + +AliOADBContainer::AliOADBContainer(char* name) : + TNamed(name, "OADBContainer"), + fArray(new TObjArray(100)), + fLowerLimits(), + fUpperLimits(), + fEntries(0) +{ +} + + +//______________________________________________________________________________ +AliOADBContainer::~AliOADBContainer() +{ + // destructor +} + +//______________________________________________________________________________ +AliOADBContainer::AliOADBContainer(const AliOADBContainer& cont) : + TNamed(cont), + fArray(cont.fArray), + fLowerLimits(cont.fLowerLimits), + fUpperLimits(cont.fUpperLimits), + fEntries(cont.fEntries) +{ + // Copy constructor. +} + +//______________________________________________________________________________ +AliOADBContainer& AliOADBContainer::operator=(const AliOADBContainer& cont) +{ + // Assignment operator + if(this!=&cont) { + TNamed::operator=(cont); + } + return *this; +} + +void AliOADBContainer::AppendObject(TObject* obj, Int_t lower, Int_t upper) +{ + // Append a new object to the list + fEntries++; + fLowerLimits.Set(fEntries); + fUpperLimits.Set(fEntries); + + fLowerLimits[fEntries - 1] = lower; + fUpperLimits[fEntries - 1] = upper; + + fArray->Add(obj); +} + +void AliOADBContainer::RemoveObject(Int_t idx) +{ + // Remove object from the list + if (idx < 0 || idx >= fEntries) + { + AliError(Form("Index out of Range %5d >= %5d", idx, fEntries)); + return; + } + + TObject* obj = fArray->RemoveAt(idx); + delete obj; + + for (Int_t i = idx; i < (fEntries-1); i++) { + fLowerLimits[i] = fLowerLimits[i + 1]; + fUpperLimits[i] = fUpperLimits[i + 1]; + fArray->AddAt(fArray->At(i+1), i); + } + fArray->RemoveAt(fEntries - 1); + fEntries--; +} + +void AliOADBContainer::UpdateObject(Int_t idx, TObject* obj, Int_t lower, Int_t upper) +{ + // Append a new object to the list + if (idx < 0 || idx >= fEntries) + { + AliError(Form("Index out of Range %5d >= %5d", idx, fEntries)); + return; + } + + fLowerLimits[idx] = lower; + fUpperLimits[idx] = upper; + fArray->AddAt(obj, idx); +} + +Int_t AliOADBContainer::GetIndexForRun(Int_t run) +{ + // Find the index for a given run + Int_t found = 0; + Int_t index = -1; + for (Int_t i = 0; i < fEntries; i++) + { + if (run >= fLowerLimits[i] && run <= fUpperLimits[i]) + { + found++; + index = i; + } + } + return index; +} + +void AliOADBContainer::WriteToFile(char* fname) +{ + // Write object to file + TFile* f = new TFile(fname, "recreate"); + Write(); + f->Close(); +} + +void AliOADBContainer::List() +{ + // List Objects + for (Int_t i = 0; i < fEntries; i++) { + printf("Lower %5d Upper %5d \n", fLowerLimits[i], fUpperLimits[i]); + (fArray->At(i))->Dump(); + } +} diff --git a/OADB/AliOADBContainer.h b/OADB/AliOADBContainer.h new file mode 100644 index 00000000000..00a5f1a84fc --- /dev/null +++ b/OADB/AliOADBContainer.h @@ -0,0 +1,42 @@ +#ifndef AliOADBContainer_H +#define AliOADBContainer_H +/* Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +//------------------------------------------------------------------------- +// Offline Analysis Database Container and Service Class +// Author: Andreas Morsch, CERN +//------------------------------------------------------------------------- + +#include +#include + + +class TObjArray; +class TArrayI; + +class AliOADBContainer : public TNamed { + + public : + AliOADBContainer(); + AliOADBContainer(char* name); + virtual ~AliOADBContainer(); + AliOADBContainer(const AliOADBContainer& cont); + AliOADBContainer& operator=(const AliOADBContainer& cont); + void AppendObject(TObject* obj, Int_t lower, Int_t upper); + void UpdateObject(Int_t index, TObject* obj, Int_t lower, Int_t upper); + void RemoveObject(Int_t index); + Int_t GetIndexForRun(Int_t run); + void WriteToFile(char* fname); + void List(); + private : + TObjArray* fArray; // Array with objects + TArrayI fLowerLimits; // lower limit of run range + TArrayI fUpperLimits; // upper limit of run range + Int_t fEntries; // Number of entries + ClassDef(AliOADBContainer, 1); +}; + +#endif diff --git a/OADB/OADBLinkDef.h b/OADB/OADBLinkDef.h new file mode 100644 index 00000000000..c37d91a5f50 --- /dev/null +++ b/OADB/OADBLinkDef.h @@ -0,0 +1,13 @@ +#ifdef __CINT__ +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; + + +#pragma link C++ class AliOADBContainer+; +#endif diff --git a/OADB/libOADB.pkg b/OADB/libOADB.pkg new file mode 100644 index 00000000000..ede65d0c129 --- /dev/null +++ b/OADB/libOADB.pkg @@ -0,0 +1,13 @@ +#-*- Mode: Makefile -*- + +SRCS = AliOADBContainer.cxx + +HDRS:= $(SRCS:.cxx=.h) + +DHDR= OADBLinkDef.h + +EXPORT:=$(SRCS:.cxx=.h) + +ifeq (win32gcc,$(ALICE_TARGET)) +PACKSOFLAGS:= $(SOFLAGS) -L$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET) -L$(ROOTLIBDIR) +endif diff --git a/OADB/test.C b/OADB/test.C new file mode 100644 index 00000000000..16751d36b53 --- /dev/null +++ b/OADB/test.C @@ -0,0 +1,25 @@ +void test() +{ + gSystem->Load("libOADB"); + con = new AliOADBContainer("OADB"); + // + obj1 = new TNamed("obj1", ""); + obj2 = new TNamed("obj2", ""); + obj3 = new TNamed("obj3", ""); + obj4 = new TNamed("obj4", ""); + // + con->AppendObject(obj1, 1, 10); + con->AppendObject(obj2, 11, 20); + con->AppendObject(obj3, 21, 30); + con->UpdateObject(1, obj4, 100, 101); + con->RemoveObject(0); + // + con->WriteToFile("test.root"); + // + TFile* file = TFile::Open("test.root"); + // + AliOADBContainer* cont0; + file->GetObject("OADB", cont0); + cont0->Dump(); + cont0->List(); +} -- 2.31.1