KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVDataRepositoryManager.cpp
1/*
2$Id: KVDataRepositoryManager.cpp,v 1.9 2007/11/20 16:46:21 franklan Exp $
3$Revision: 1.9 $
4$Date: 2007/11/20 16:46:21 $
5*/
6
7//Created by KVClassFactory on Sun Jul 30 12:04:19 2006
8//Author: John Frankland
9
10#include "KVDataRepositoryManager.h"
11#include "KVDataRepository.h"
12#include "KVDataSetManager.h"
13#include "TEnv.h"
14#include "KVBase.h"
15#include "Riostream.h"
16#include "TString.h"
17#include "TObjString.h"
18#include "TObjArray.h"
19#include "KVDataSet.h"
20
21KVDataRepositoryManager* gDataRepositoryManager;
22
23using namespace std;
24
26
27
28
30
32{
33 //Default constructor
34 fRepositories.SetOwner(kTRUE);
35 gDataRepositoryManager = this;
36}
37
38
39
42
44{
45 //Destructor
46 fRepositories.Delete(); //destroy all data repositories
47 gDataRepositoryManager = 0;
48}
49
50
51
52
66
68{
69 //Read .kvrootrc and set up all data repositories it defines.
70 //
71 //The default data repository (gDataRepository) is defined by the environment variable
72 //DataRepository.Default (default value = "default").
73 //
74 //For this repository, KVDataRepository::cd() will be called and
75 //gDataRepository and gDataSetManager will point, respectively, to the repository and
76 //to its data set manager.
77 //
78 //If the repository corresponding to DataRepository.Default is not found,
79 //the last repository defined in the .kvrootrc file will be made default.
80
81 //make sure KaliVeda environment is initialised
83
84 //delete any previously defined repositories
87
88 //get whitespace-separated list of data repository names
89 TString rep_list = gEnv->GetValue("DataRepository", "");
90 if (rep_list == "") {
91 cout <<
92 "<KVDataRepositoryManager::Init> : no repositories defined in .kvrootrc"
93 << endl;
94 // Initialise a repository-less dataset manager which will give access to
95 // all datasets regardless of data availability (which is unknowable)
96 gDataSetManager = new KVDataSetManager;
97 gDataSetManager->Init();
98 return;
99 }
100 //split list
101 TObjArray* toks = rep_list.Tokenize(' ');
102 KVDataRepository* new_rep = 0;
103 KVDataRepository* last_defined = 0;
104 for (int i_rep = 0; i_rep < toks->GetEntries(); i_rep++) {
105
106 //loop over each defined repository
107
108 TString rep_name = ((TObjString*)(*toks)[i_rep])->String(); //name of repository
109 //look for repository type
110 TString rep_type =
111 gEnv->GetValue(Form("%s.DataRepository.Type", rep_name.Data()),
112 "local");
113 rep_type.ToLower();
114
115 //create new repository
116 new_rep = KVDataRepository::NewRepository(rep_type.Data());
117 new_rep->SetName(rep_name.Data());
118 //new_rep->SetType(rep_type.Data()); 'type' is set in default ctor of each repository class
119 if (new_rep->Init()) {
120 fRepositories.Add(new_rep);
121 last_defined = new_rep; //keep pointer to last defined repository
122 }
123 else {
124 //problem with initialisation of data repository.
125 //it is ignored.
126 delete new_rep;
127 new_rep = 0;
128 }
129
130 }
131 delete toks;
132 //look for 'default' repository
134 gEnv->GetValue("DataRepository.Default", "default"));
135 if (new_rep) new_rep->cd();
136 else if (last_defined) last_defined->cd();
137}
138
139
140
141
148
150 name) const
151{
152 //Return pointer to data repository with given name.
153 //Data repository names are defined in .kvrootrc file by lines such as
154 //
155 //DataRepository: default
156 //+DataRepository: ccali
157
159}
160
161
162
163
167
169{
170 //Print list of repositories
171 //opt = "all" : print full configuration information for each repository
172 KVDataRepository* rep;
173 TString _opt(opt);
174 _opt.ToUpper();
175 Bool_t _all = (_opt == "ALL");
176 TIter nxt(&fRepositories);
177 cout << "Available data repositories: " << endl << endl;
178 while ((rep = (KVDataRepository*) nxt())) {
179 if (_all) {
180 rep->Print();
181 }
182 else {
183 cout << "\t" << rep->GetName() << " [";
184 if (rep->IsRemote())
185 cout << "REMOTE";
186 else
187 cout << "LOCAL";
188 cout << "] : ";
189 cout << rep->GetRootDirectory() << endl;
190 }
191 }
192}
193
194
195
196
199
200KVDataSet* KVDataRepositoryManager::GetDataSet(const Char_t* repository, const Char_t* dataset) const
201{
202 // Return pointer to named dataset in the given repository
203 if (KVDataRepository* R = GetRepository(repository)) {
204
205 return R->GetDataSetManager()->GetDataSet(dataset);
206
207 }
208 return 0;
209}
210
211
bool Bool_t
char Char_t
constexpr Bool_t kTRUE
const char Option_t
R__EXTERN TEnv * gEnv
char name[80]
char * Form(const char *fmt,...)
static void InitEnvironment()
Definition KVBase.cpp:181
Manages access to one or more data repositories.
KVDataRepository * GetRepository(const Char_t *name) const
KVDataSet * GetDataSet(const Char_t *repository, const Char_t *dataset) const
Return pointer to named dataset in the given repository.
void Print(Option_t *opt="") const
virtual ~KVDataRepositoryManager()
Destructor.
TList fRepositories
list of available repositories
Base class for managing repositories of experimental data.
virtual Bool_t IsRemote() const
Returns kTRUE for remote repositories, kFALSE for local repositories.
static KVDataRepository * NewRepository(const Char_t *type)
virtual void Print(Option_t *opt="") const
Print info on repository.
virtual const Char_t * GetRootDirectory() const
returns root directory of data repository (fLocalrootdir)
virtual Bool_t Init()
Manage all datasets contained in a given data repository.
virtual Bool_t Init(KVDataRepository *=0)
Manage an experimental dataset corresponding to a given experiment or campaign.
Definition KVDataSet.h:35
virtual Int_t GetSize() const
virtual const char * GetValue(const char *name, const char *dflt) const
TObject * FindObject(const char *name) const override
void Add(TObject *obj) override
void Delete(Option_t *option="") override
const char * GetName() const override
virtual void SetName(const char *name)
Int_t GetEntries() const override
void ToLower()
const char * Data() const
void ToUpper()
TObjArray * Tokenize(const TString &delim) const
constexpr Double_t R()
const char * String
ClassImp(TPyArg)