KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVDataRepositoryManager.cpp
Go to the documentation of this file.
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 
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 
22 
23 using namespace std;
24 
26 
27 
28 
32 {
33  //Default constructor
34  fRepositories.SetOwner(kTRUE);
36 }
37 
38 
39 
42 
43 KVDataRepositoryManager::~KVDataRepositoryManager()
44 {
45  //Destructor
46  fRepositories.Delete(); //destroy all data repositories
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
85  if (fRepositories.GetSize())
86  fRepositories.Delete();
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)
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
133  new_rep = (KVDataRepository*) fRepositories.FindObject(
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 
158  return (KVDataRepository*) fRepositories.FindObject(name);
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 
200 KVDataSet* 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 
KVDataRepositoryManager * gDataRepositoryManager
KVDataSetManager * gDataSetManager
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
char Char_t
bool Bool_t
const Bool_t kTRUE
const char Option_t
R__EXTERN TEnv * gEnv
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
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 Bool_t Init()
virtual const Char_t * GetRootDirectory() const
returns root directory of data repository (fLocalrootdir)
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:207
virtual const char * GetValue(const char *name, const char *dflt) const
virtual const char * GetName() const
virtual void SetName(const char *name)
Int_t GetEntries() const
virtual TObject * FindObject(const char *name) const
void ToLower()
void ToUpper()
TObjArray * Tokenize(const TString &delim) const
const char * Data() const
constexpr Double_t R()
const char * String