KaliVeda
Toolkit for HIC analysis
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 "KVDataSetRepository.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 
21 KVDataRepositoryManager* gDataRepositoryManager = nullptr;
22 
23 using namespace std;
24 
26 
27 
28 
32 {
33  //Default constructor
34  gDataRepositoryManager = this;
35 }
36 
37 
38 
41 
42 KVDataRepositoryManager::~KVDataRepositoryManager()
43 {
44  //Destructor
45  gDataRepositoryManager = nullptr;
46 }
47 
48 
49 
50 
64 
66 {
67  //Read .kvrootrc and set up all data repositories it defines.
68  //
69  //The default data repository (gDataRepository) is defined by the environment variable
70  //DataRepository.Default (default value = "default").
71  //
72  //For this repository, KVDataRepository::cd() will be called and
73  //gDataRepository and gDataSetManager will point, respectively, to the repository and
74  //to its data set manager.
75  //
76  //If the repository corresponding to DataRepository.Default is not found,
77  //the last repository defined in the .kvrootrc file will be made default.
78 
79  // make sure KaliVeda environment is initialised
81 
82  // forget any previously defined repositories
83  fRepositories.Clear();
84 
85  //get whitespace-separated list of data repository names
86  KVString rep_list = gEnv->GetValue("DataRepository", "");
87  if (rep_list == "") {
88  cout <<
89  "<KVDataRepositoryManager::Init> : no repositories defined in .kvrootrc"
90  << endl;
91  // Initialise a repository-less dataset manager which will give access to
92  // all datasets regardless of data availability (which is unknowable)
93  gDataSetManager = new KVDataSetManager;
94  gDataSetManager->Init();
95  return;
96  }
97  //split list
98  rep_list.Begin(" ");
99  KVDataSetRepository* new_rep = nullptr;
100  KVDataSetRepository* last_defined = nullptr;
101  while (!rep_list.End()) {
102  //loop over each defined repository
103 
104  auto rep_name = rep_list.Next(); //name of repository
105  //look for repository type = "local" or "irods"
106  TString rep_type =
107  gEnv->GetValue(Form("%s.DataRepository.Type", rep_name.Data()),
108  "local");
109  rep_type.ToLower();
110 
111  //create new repository - KVDataSetRepository by default
112  new_rep = KVDataSetRepository::NewRepository(rep_type);
113  new_rep->SetName(rep_name.Data());
114 
115  if (new_rep->Init()) {
116  fRepositories.Add(new_rep);
117  last_defined = new_rep; //keep pointer to last defined repository
118  }
119  else {
120  //problem with initialisation of data repository.
121  //it is ignored.
122  delete new_rep;
123  }
124 
125  }
126  //look for 'default' repository
127  new_rep = (KVDataSetRepository*) 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 {
145  //Return pointer to data repository with given name.
146  //Data repository names are defined in .kvrootrc file by lines such as
147  //
148  //DataRepository: default
149  //+DataRepository: ccali
150 
151  return (KVDataSetRepository*)fRepositories.FindObject(name);
152 }
153 
154 
155 
156 
160 
162 {
163  //Print list of repositories
164  //opt = "all" : print full configuration information for each repository
165  KVDataRepository* rep;
166  TString _opt(opt);
167  _opt.ToUpper();
168  Bool_t _all = (_opt == "ALL");
169  TIter nxt(&fRepositories);
170  cout << "Available data repositories: " << endl << endl;
171  while ((rep = (KVDataRepository*) nxt())) {
172  if (_all) {
173  rep->Print();
174  }
175  else {
176  cout << "\t" << rep->GetName() << " [" << rep->GetType() << "] : ";
177  cout << rep->GetRootDirectory() << endl;
178  }
179  }
180 }
181 
182 
183 
184 
187 
188 KVDataSet* KVDataRepositoryManager::GetDataSet(const Char_t* repository, const Char_t* dataset) const
189 {
190  // Return pointer to named dataset in the given repository
191  if (auto R = dynamic_cast<KVDataSetRepository*>(GetRepository(repository))) {
192  return R->GetDataSetManager()->GetDataSet(dataset);
193  }
194  return nullptr;
195 }
196 
197 
bool Bool_t
char Char_t
const char Option_t
R__EXTERN TEnv * gEnv
char name[80]
char * Form(const char *fmt,...)
static void InitEnvironment()
Definition: KVBase.cpp:197
Manages access to one or more data repositories.
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
KVDataSetRepository * GetRepository(const TString &name) const
Base class for managing repositories of data.
const Char_t * GetType() const override
void Print(Option_t *opt="") const override
Print info on repository.
TString GetRootDirectory() const
returns root directory of data repository (fLocalrootdir)
Manage all datasets contained in a given data repository.
Bool_t Init(KVDataSetRepository *=0)
A repository for experimental datasets.
static KVDataSetRepository * NewRepository(const TString &local_or_irods)
Manage an experimental dataset corresponding to a given experiment or campaign.
Definition: KVDataSet.h:146
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
void Begin(TString delim) const
Definition: KVString.cpp:565
Bool_t End() const
Definition: KVString.cpp:634
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:695
virtual const char * GetValue(const char *name, const char *dflt) const
const char * GetName() const override
virtual void SetName(const char *name)
virtual TObject * FindObject(const char *name) const
void ToLower()
void ToUpper()
constexpr Double_t R()
ClassImp(TPyArg)