KaliVeda  1.12/06
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 
63 
65 {
66  //Read .kvrootrc and set up all data repositories it defines.
67  //The default data repository (gDataRepository) is defined by the environment variable
68  //DataRepository.Default (default value = "default").
69  //For this repository, KVDataRepository::cd() will be called and
70  //gDataRepository and gDataSetManager will point, respectively, to the repository and
71  //to its data set manager.
72  //If the repository corresponding to DataRepository.Default is not found,
73  //the last repository defined in the .kvrootrc file will be made default.
74 
75  //make sure KaliVeda environment is initialised
77 
78  //delete any previously defined repositories
79  if (fRepositories.GetSize())
80  fRepositories.Delete();
81 
82  //get whitespace-separated list of data repository names
83  TString rep_list = gEnv->GetValue("DataRepository", "");
84  if (rep_list == "") {
85  cout <<
86  "<KVDataRepositoryManager::Init> : no repositories defined in .kvrootrc"
87  << endl;
88  // Initialise a repository-less dataset manager which will give access to
89  // all datasets regardless of data availability (which is unknowable)
92  return;
93  }
94  //split list
95  TObjArray* toks = rep_list.Tokenize(' ');
96  KVDataRepository* new_rep = 0;
97  KVDataRepository* last_defined = 0;
98  for (int i_rep = 0; i_rep < toks->GetEntries(); i_rep++) {
99 
100  //loop over each defined repository
101 
102  TString rep_name = ((TObjString*)(*toks)[i_rep])->String(); //name of repository
103  //look for repository type
104  TString rep_type =
105  gEnv->GetValue(Form("%s.DataRepository.Type", rep_name.Data()),
106  "local");
107  rep_type.ToLower();
108 
109  //create new repository
110  new_rep = KVDataRepository::NewRepository(rep_type.Data());
111  new_rep->SetName(rep_name.Data());
112  //new_rep->SetType(rep_type.Data()); 'type' is set in default ctor of each repository class
113  if (new_rep->Init()) {
114  fRepositories.Add(new_rep);
115  last_defined = new_rep; //keep pointer to last defined repository
116  }
117  else {
118  //problem with initialisation of data repository.
119  //it is ignored.
120  delete new_rep;
121  new_rep = 0;
122  }
123 
124  }
125  delete toks;
126  //look for 'default' repository
127  new_rep = (KVDataRepository*) fRepositories.FindObject(
128  gEnv->GetValue("DataRepository.Default", "default"));
129  if (new_rep) new_rep->cd();
130  else if (last_defined) last_defined->cd();
131 }
132 
133 
134 
135 
142 
144  name) const
145 {
146  //Return pointer to data repository with given name.
147  //Data repository names are defined in .kvrootrc file by lines such as
148  //
149  //DataRepository: default
150  //+DataRepository: ccali
151 
152  return (KVDataRepository*) fRepositories.FindObject(name);
153 }
154 
155 
156 
157 
161 
163 {
164  //Print list of repositories
165  //opt = "all" : print full configuration information for each repository
166  KVDataRepository* rep;
167  TString _opt(opt);
168  _opt.ToUpper();
169  Bool_t _all = (_opt == "ALL");
170  TIter nxt(&fRepositories);
171  cout << "Available data repositories: " << endl << endl;
172  while ((rep = (KVDataRepository*) nxt())) {
173  if (_all) {
174  rep->Print();
175  }
176  else {
177  cout << "\t" << rep->GetName() << " [";
178  if (rep->IsRemote())
179  cout << "REMOTE";
180  else
181  cout << "LOCAL";
182  cout << "] : ";
183  cout << rep->GetRootDirectory() << endl;
184  }
185  }
186 }
187 
188 
189 
190 
193 
194 KVDataSet* KVDataRepositoryManager::GetDataSet(const Char_t* repository, const Char_t* dataset) const
195 {
196  // Return pointer to named dataset in the given repository
197  if (KVDataRepository* R = GetRepository(repository)) {
198 
199  return R->GetDataSetManager()->GetDataSet(dataset);
200 
201  }
202  return 0;
203 }
204 
205 
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