KaliVeda
Toolkit for HIC analysis
KVBase.h
1 /***************************************************************************
2  kvbase.h - description
3  -------------------
4  begin : Thu May 16 2002
5  copyright : (C) 2002 by J.D. Frankland
6  email : frankland@ganil.fr
7 
8 $Id: KVBase.h,v 1.42 2009/03/12 13:59:40 franklan Exp $
9 ***************************************************************************/
10 
11 #ifndef KVBASE_H
12 #define KVBASE_H
13 
14 #include "KVConfig.h"
15 #include "KVMacros.h"
16 #include "TRandom3.h"
17 #include "TNamed.h"
18 #include "RVersion.h"
19 #include "TString.h"
20 #include "KVLockfile.h"
21 #include "Riostream.h"
22 #include "TPluginManager.h"
23 #include "TFile.h"
24 #include "TF1.h"
25 class KVString;
26 #ifdef WITH_RSQLITE
27 namespace KVSQLite {
28  class database;
29 }
30 #endif
31 
142 class KVBase: public TNamed {
143 
144 private:
145  static UInt_t fNbObj;
147 protected:
149 
150 private:
153 
154  void init();
155  static void ReadGUIMimeTypes();
156  static void ReadConfigFiles();
157 
158 public:
159 
160  static void Deprecated(const char* method, const char* advice);
161 
163  kIsKaliVedaObject = BIT(23) //all KVBase-derived objects have this bit set in TObject::fBits
164  };
165 
166  static void InitEnvironment();
167  KVBase();
168  KVBase(const Char_t* name, const Char_t* title = "");
169  KVBase(const KVBase&);
170  KVBase& operator=(const KVBase&);
171  virtual ~ KVBase();
172 
173  virtual void SetType(const Char_t* str)
174  {
175  SetTitle(str);
176  }
177  virtual const Char_t* GetType() const
178  {
179  return GetTitle();
180  }
181  static const Char_t* WorkingDirectory()
182  {
183  return fWorkingDirectory.Data();
184  }
185  virtual Bool_t IsType(const Char_t* typ) const
186  {
188  return !strcmp(GetType(), typ);
189  }
190  virtual Bool_t IsCalled(const Char_t* name) const
191  {
193  return !strcmp(GetName(), name);
194  }
195  void SetLabel(const Char_t* lab)
196  {
197  fLabel = lab;
198  }
199  const Char_t* GetLabel() const
200  {
201  return fLabel;
202  }
203  Bool_t HasLabel() const
204  {
205  return fLabel.Length();
206  }
207  Bool_t IsLabelled(const Char_t* l) const
208  {
210  return fLabel == l;
211  }
212  virtual void Print(Option_t* option = "") const;
213  virtual void List()
214  {
215  }
216  virtual void SetNumber(UInt_t num)
217  {
218  fNumber = num;
219  }
221  {
222  return fNumber;
223  }
225  {
226  return fNbObj;
227  }
228  virtual void Clear(Option_t* opt = "");
229 #if ROOT_VERSION_CODE >= ROOT_VERSION(3,4,0)
230  virtual void Copy(TObject&) const;
231 #else
232  virtual void Copy(TObject&);
233 #endif
234 
235  static Bool_t SearchKVFile(const Char_t* name, TString& fullpath,
236  const Char_t* kvsubdir = "");
237 #ifdef WITH_RSQLITE
238  static Bool_t SearchAndOpenKVFile(const Char_t* name, KVSQLite::database& dbfile,
239  const Char_t* kvsubdir = "");
240 #endif
241  static Bool_t SearchAndOpenKVFile(const Char_t* name, std::ifstream& file,
242  const Char_t* kvsubdir = "", KVLockfile* locks = 0);
243  static Bool_t SearchAndOpenKVFile(const Char_t* name, std::ofstream& file,
244  const Char_t* kvsubdir = "", KVLockfile* locks = 0);
245  static void BackupFileWithDate(const Char_t* path);
246  static TPluginHandler* LoadPlugin(const Char_t* base,
247  const Char_t* uri = "0");
248  static const Char_t* GetPluginURI(const Char_t* base, const Char_t* plugin);
249  static const Char_t* GetListOfPlugins(const Char_t* base);
250  static const Char_t* GetListOfPluginURIs(const Char_t* base);
251  static Bool_t IsThisAPlugin(const TString& uri, TString& base);
252  static void OpenTempFile(TString& base, std::ofstream& fp); /* open temp file with basename 'base' */
253  static void GetTempFileName(TString& base);
254 
255  static const Char_t* GetKVVersion();
256  static const Char_t* GetKVBuildDate();
257  static const Char_t* GetKVBuildTime();
258  static const Char_t* GetKVBuildType();
259  static const Char_t* GetKVBuildUser();
260  static const Char_t* GetKVSourceDir();
261  static const Char_t* GetKVBuildDir();
262 
263 #ifdef WITH_GIT_INFOS
264  static const Char_t* gitBranch();
265  static const Char_t* gitCommit();
266 #endif
267 
268  static const Char_t* GetETCDIRFilePath(const Char_t* namefile = "");
269  static const Char_t* GetDATADIRFilePath(const Char_t* namefile = "");
270  static const Char_t* GetDATABASEFilePath();
271  static const Char_t* GetLIBDIRFilePath(const Char_t* namefile = "");
272  static const Char_t* GetINCDIRFilePath(const Char_t* namefile = "");
273  static const Char_t* GetBINDIRFilePath(const Char_t* namefile = "");
274  static const Char_t* GetWORKDIRFilePath(const Char_t* namefile = "");
275  static const Char_t* GetTEMPLATEDIRFilePath(const Char_t* namefile = "");
276  static const Char_t* GetExampleFilePath(const Char_t* library, const Char_t* namefile);
277  static bool is_gnuinstall()
278  {
282 #ifdef WITH_GNU_INSTALL
283  return true;
284 #else
285  return false;
286 #endif
287  }
288 
289  static Bool_t FindExecutable(TString& exec, const Char_t* path =
290  "$(PATH)");
291 
292  static const Char_t* FindFile(const Char_t* search, TString& wfil);
293  static Bool_t FindClassSourceFiles(const Char_t* class_name, KVString& imp_file,
294  KVString& dec_file, const Char_t* dir_name = ".");
295 
296  static Bool_t AreEqual(Double_t x, Double_t y, Long64_t maxdif = 1);
297 
298  static Bool_t OpenContextMenu(const char* method, TObject* obj, const char* alt_method_name = "");
299 
300  static void CombineFiles(const Char_t* file1, const Char_t* file2, const Char_t* newfilename, Bool_t keep = kTRUE);
301 
302  virtual TObject* GetObject() const;
303 
304  static void PrintSplashScreen();
305  static const Char_t* GetDataSetEnv(const Char_t* dataset, const Char_t* type, const Char_t* defval);
306  static Double_t GetDataSetEnv(const Char_t* dataset, const Char_t* type, Double_t defval);
307  static Bool_t GetDataSetEnv(const Char_t* dataset, const Char_t* type, Bool_t defval);
308 
309  Double_t ProtectedGetX(const TF1* func, Double_t val, int& status, Double_t xmin = 0.0, Double_t xmax = 0.0) const;
310 
311  ClassDef(KVBase, 4) //Base class for all KaliVeda objects
312 };
313 
316 extern void AssignAndDelete(TString& target, char* tobedeleted);
318 Bool_t SearchFile(const Char_t* name, TString& fullpath, int ndirs, ...);
319 #endif
unsigned int UInt_t
bool Bool_t
char Char_t
double Double_t
const char Option_t
#define ClassDef(name, id)
#define BIT(n)
char name[80]
void AssignAndDelete(TString &target, char *tobedeleted)
Base class for KaliVeda framework.
Definition: KVBase.h:142
static TString fWorkingDirectory
user working directory for e.g. database files
Definition: KVBase.h:152
static const Char_t * WorkingDirectory()
Definition: KVBase.h:181
static UInt_t fNbObj
Total number of KaliVeda objects (actually counts number of calls to default ctor)
Definition: KVBase.h:145
void SetLabel(const Char_t *lab)
Definition: KVBase.h:195
UInt_t fNumber
for numbering objects
Definition: KVBase.h:146
virtual const Char_t * GetType() const
Definition: KVBase.h:177
static Bool_t FindClassSourceFiles(const Char_t *class_name, KVString &imp_file, KVString &dec_file, const Char_t *dir_name=".")
Definition: KVBase.cpp:1102
static const Char_t * GetBINDIRFilePath(const Char_t *namefile="")
Definition: KVBase.cpp:118
static void OpenTempFile(TString &base, std::ofstream &fp)
Definition: KVBase.cpp:827
static const Char_t * GetDATADIRFilePath(const Char_t *namefile="")
Definition: KVBase.cpp:74
static const Char_t * GetDATABASEFilePath()
Definition: KVBase.cpp:92
static const Char_t * GetKVBuildDate()
Returns KaliVeda build date.
Definition: KVBase.cpp:900
static const Char_t * FindFile(const Char_t *search, TString &wfil)
Definition: KVBase.cpp:1060
static const Char_t * GetINCDIRFilePath(const Char_t *namefile="")
Definition: KVBase.cpp:109
static const Char_t * gitCommit()
Returns last git commit of sources.
Definition: KVBase.cpp:976
static const Char_t * GetWORKDIRFilePath(const Char_t *namefile="")
Definition: KVBase.cpp:127
void init()
Default initialisation.
Definition: KVBase.cpp:138
UInt_t GetNumberOfObjects() const
Definition: KVBase.h:224
static Bool_t FindExecutable(TString &exec, const Char_t *path="$(PATH)")
Definition: KVBase.cpp:1001
static const Char_t * GetKVBuildUser()
Returns username of person who performed build.
Definition: KVBase.cpp:887
static void BackupFileWithDate(const Char_t *path)
Definition: KVBase.cpp:753
static void ReadConfigFiles()
Definition: KVBase.cpp:272
static const Char_t * gitBranch()
Returns git branch of sources.
Definition: KVBase.cpp:964
static const Char_t * GetListOfPluginURIs(const Char_t *base)
Definition: KVBase.cpp:1327
TString fLabel
label for the object
Definition: KVBase.h:148
virtual void Clear(Option_t *opt="")
Clear object properties : name, type/title, number, label.
Definition: KVBase.cpp:380
KVBase()
Default constructor.
Definition: KVBase.cpp:317
static const Char_t * GetListOfPlugins(const Char_t *base)
Definition: KVBase.cpp:1260
static Bool_t fEnvIsInit
set when environment is initialised
Definition: KVBase.h:151
Bool_t HasLabel() const
Definition: KVBase.h:203
static Bool_t AreEqual(Double_t x, Double_t y, Long64_t maxdif=1)
Comparison between two 64-bit floating-point values.
Definition: KVBase.cpp:1442
virtual Bool_t IsType(const Char_t *typ) const
Definition: KVBase.h:185
KVBase & operator=(const KVBase &)
copy assignment operator
Definition: KVBase.cpp:355
static void CombineFiles(const Char_t *file1, const Char_t *file2, const Char_t *newfilename, Bool_t keep=kTRUE)
Definition: KVBase.cpp:1527
const Char_t * GetLabel() const
Definition: KVBase.h:199
virtual void SetNumber(UInt_t num)
Definition: KVBase.h:216
static Bool_t SearchAndOpenKVFile(const Char_t *name, std::ifstream &file, const Char_t *kvsubdir="", KVLockfile *locks=0)
static bool is_gnuinstall()
Definition: KVBase.h:277
static const Char_t * GetTEMPLATEDIRFilePath(const Char_t *namefile="")
Definition: KVBase.cpp:83
static const Char_t * GetKVSourceDir()
Returns top-level directory of source tree used for build.
Definition: KVBase.cpp:938
Bool_t IsLabelled(const Char_t *l) const
Definition: KVBase.h:207
static void InitEnvironment()
Definition: KVBase.cpp:181
virtual void Print(Option_t *option="") const
Definition: KVBase.cpp:410
virtual void SetType(const Char_t *str)
Definition: KVBase.h:173
static const Char_t * GetDataSetEnv(const Char_t *dataset, const Char_t *type, const Char_t *defval)
Definition: KVBase.cpp:1619
static const Char_t * GetKVBuildTime()
Returns KaliVeda build time.
Definition: KVBase.cpp:912
static void PrintSplashScreen()
Prints welcome message and infos on version etc.
Definition: KVBase.cpp:1593
virtual void List()
Definition: KVBase.h:213
static const Char_t * GetLIBDIRFilePath(const Char_t *namefile="")
Definition: KVBase.cpp:100
static const Char_t * GetExampleFilePath(const Char_t *library, const Char_t *namefile)
Return full path to example file for given library (="KVMultiDet", "BackTrack", etc....
Definition: KVBase.cpp:1577
virtual Bool_t IsCalled(const Char_t *name) const
Definition: KVBase.h:190
Double_t ProtectedGetX(const TF1 *func, Double_t val, int &status, Double_t xmin=0.0, Double_t xmax=0.0) const
Definition: KVBase.cpp:1691
static const Char_t * GetKVBuildDir()
Returns top-level directory used for build.
Definition: KVBase.cpp:951
static void ReadGUIMimeTypes()
Definition: KVBase.cpp:1397
static Bool_t IsThisAPlugin(const TString &uri, TString &base)
Definition: KVBase.cpp:1357
EKaliVedaBits
Definition: KVBase.h:162
@ kIsKaliVedaObject
Definition: KVBase.h:163
virtual TObject * GetObject() const
Definition: KVBase.cpp:1560
static void GetTempFileName(TString &base)
Definition: KVBase.cpp:848
static Bool_t SearchKVFile(const Char_t *name, TString &fullpath, const Char_t *kvsubdir="")
Definition: KVBase.cpp:538
static const Char_t * GetKVBuildType()
Returns KaliVeda build type (cmake build: Release, Debug, RelWithDebInfo, ...)
Definition: KVBase.cpp:925
static const Char_t * GetPluginURI(const Char_t *base, const Char_t *plugin)
Definition: KVBase.cpp:1177
static const Char_t * GetETCDIRFilePath(const Char_t *namefile="")
Definition: KVBase.cpp:65
virtual ~ KVBase()
static Bool_t OpenContextMenu(const char *method, TObject *obj, const char *alt_method_name="")
Definition: KVBase.cpp:1495
static Bool_t SearchAndOpenKVFile(const Char_t *name, KVSQLite::database &dbfile, const Char_t *kvsubdir="")
Definition: KVBase.cpp:649
virtual void Copy(TObject &) const
Make a copy of this object.
Definition: KVBase.cpp:394
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Definition: KVBase.cpp:793
static const Char_t * GetKVVersion()
Returns KaliVeda version string.
Definition: KVBase.cpp:874
static void Deprecated(const char *method, const char *advice)
Definition: KVBase.cpp:1734
UInt_t GetNumber() const
Definition: KVBase.h:220
static Bool_t SearchAndOpenKVFile(const Char_t *name, std::ofstream &file, const Char_t *kvsubdir="", KVLockfile *locks=0)
Interface to (Linux) system lockfile command.
Definition: KVLockfile.h:70
Interface to ROOT SQLite database backend.
Definition: SQLiteDB.h:401
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
virtual void SetTitle(const char *title="")
const char * GetName() const override
const char * GetTitle() const override
Ssiz_t Length() const
const char * Data() const
long long Long64_t
TLine l