AliOADBContainer first commit.
[u/mrichter/AliRoot.git] / OADB / AliOADBContainer.cxx
CommitLineData
cc336771 1/**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18//-------------------------------------------------------------------------
19// Offline Analysis Database Container and Service Class
20// Author: Andreas Morsch, CERN
21//-------------------------------------------------------------------------
22
23
24
25
26#include "AliOADBContainer.h"
27#include "AliLog.h"
28#include <TObjArray.h>
29#include <TArrayI.h>
30#include <TFile.h>
31
32ClassImp(AliOADBContainer);
33
34//______________________________________________________________________________
35AliOADBContainer::AliOADBContainer() :
36 TNamed(),
37 fArray(new TObjArray(100)),
38 fLowerLimits(),
39 fUpperLimits(),
40 fEntries(0)
41{
42}
43
44AliOADBContainer::AliOADBContainer(char* name) :
45 TNamed(name, "OADBContainer"),
46 fArray(new TObjArray(100)),
47 fLowerLimits(),
48 fUpperLimits(),
49 fEntries(0)
50{
51}
52
53
54//______________________________________________________________________________
55AliOADBContainer::~AliOADBContainer()
56{
57 // destructor
58}
59
60//______________________________________________________________________________
61AliOADBContainer::AliOADBContainer(const AliOADBContainer& cont) :
62 TNamed(cont),
63 fArray(cont.fArray),
64 fLowerLimits(cont.fLowerLimits),
65 fUpperLimits(cont.fUpperLimits),
66 fEntries(cont.fEntries)
67{
68 // Copy constructor.
69}
70
71//______________________________________________________________________________
72AliOADBContainer& AliOADBContainer::operator=(const AliOADBContainer& cont)
73{
74 // Assignment operator
75 if(this!=&cont) {
76 TNamed::operator=(cont);
77 }
78 return *this;
79}
80
81void AliOADBContainer::AppendObject(TObject* obj, Int_t lower, Int_t upper)
82{
83 // Append a new object to the list
84 fEntries++;
85 fLowerLimits.Set(fEntries);
86 fUpperLimits.Set(fEntries);
87
88 fLowerLimits[fEntries - 1] = lower;
89 fUpperLimits[fEntries - 1] = upper;
90
91 fArray->Add(obj);
92}
93
94void AliOADBContainer::RemoveObject(Int_t idx)
95{
96 // Remove object from the list
97 if (idx < 0 || idx >= fEntries)
98 {
99 AliError(Form("Index out of Range %5d >= %5d", idx, fEntries));
100 return;
101 }
102
103 TObject* obj = fArray->RemoveAt(idx);
104 delete obj;
105
106 for (Int_t i = idx; i < (fEntries-1); i++) {
107 fLowerLimits[i] = fLowerLimits[i + 1];
108 fUpperLimits[i] = fUpperLimits[i + 1];
109 fArray->AddAt(fArray->At(i+1), i);
110 }
111 fArray->RemoveAt(fEntries - 1);
112 fEntries--;
113}
114
115void AliOADBContainer::UpdateObject(Int_t idx, TObject* obj, Int_t lower, Int_t upper)
116{
117 // Append a new object to the list
118 if (idx < 0 || idx >= fEntries)
119 {
120 AliError(Form("Index out of Range %5d >= %5d", idx, fEntries));
121 return;
122 }
123
124 fLowerLimits[idx] = lower;
125 fUpperLimits[idx] = upper;
126 fArray->AddAt(obj, idx);
127}
128
129Int_t AliOADBContainer::GetIndexForRun(Int_t run)
130{
131 // Find the index for a given run
132 Int_t found = 0;
133 Int_t index = -1;
134 for (Int_t i = 0; i < fEntries; i++)
135 {
136 if (run >= fLowerLimits[i] && run <= fUpperLimits[i])
137 {
138 found++;
139 index = i;
140 }
141 }
142 return index;
143}
144
145void AliOADBContainer::WriteToFile(char* fname)
146{
147 // Write object to file
148 TFile* f = new TFile(fname, "recreate");
149 Write();
150 f->Close();
151}
152
153void AliOADBContainer::List()
154{
155 // List Objects
156 for (Int_t i = 0; i < fEntries; i++) {
157 printf("Lower %5d Upper %5d \n", fLowerLimits[i], fUpperLimits[i]);
158 (fArray->At(i))->Dump();
159 }
160}