FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairParRootFileIo.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 #ifndef FAIRPARROOTFILEIO_H
9 #define FAIRPARROOTFILEIO_H
10 
11 #include "FairParIo.h" // for FairParIo
12 
13 #include <Rtypes.h> // for Bool_t, Text_t, Int_t, etc
14 #include <TFile.h> // for TFile
15 #include <TNamed.h> // for TNamed
16 #include <fstream>
17 using std::fstream;
18 
19 class FairRtdbRun;
20 class TKey;
21 class TList;
22 
23 class FairParRootFile : public TNamed
24 {
25  public:
27  FairParRootFile(const Text_t* fname, Option_t* option = "READ", const Text_t* ftitle = "", Int_t compress = 1);
28  FairParRootFile(TFile* f);
30  FairRtdbRun* getRun() { return run; }
32 
33  Bool_t IsOpen() { return RootFile->IsOpen(); }
34  void cd() { RootFile->cd(); }
35  Bool_t IsWritable() { return RootFile->IsWritable(); }
36 
37  TKey* GetKey(Text_t* t) { return RootFile->GetKey(t); }
38  TList* GetListOfKeys() { return RootFile->GetListOfKeys(); }
39  void Close() { RootFile->Close(); }
40 
41  protected:
42  TFile* RootFile;
43 
44  private:
46  FairParRootFile& operator=(const FairParRootFile&);
47 
48  ClassDef(FairParRootFile, 0); // ROOT file for Parameter I/O
49 };
50 
52 {
53  protected:
54  FairParRootFile* file; // pointer to ROOT file
55  Bool_t fMerging;
56 
57  public:
59  FairParRootFileIo(Bool_t merged);
61  Bool_t open(const Text_t* fname, Option_t* option = "READ", const Text_t* ftitle = "", Int_t compress = 1);
62  Bool_t open(const TList* fnamelist, Option_t* option = "READ", const Text_t* ftitle = "", Int_t compress = 1);
63  void close();
64  void print();
67  TList* getKeys();
68  Bool_t check()
69  {
70  // returns kTRUE if file is open
71  if (file) {
72  return file->IsOpen();
73  } else {
74  return kFALSE;
75  }
76  }
77  void cd()
78  {
79  // sets the global ROOT file pointer gFile
80  if (file) {
81  file->cd();
82  }
83  }
87  Bool_t open(TFile* f);
88  void setMerging(Bool_t io) { fMerging = io; }
89 
90  private:
92  FairParRootFileIo& operator=(const FairParRootFileIo&);
93 
94  ClassDef(FairParRootFileIo, 0); // Parameter I/O from ROOT files
95 };
96 
97 #endif /* !FAIRPARROOTFILEIO_H */
FairParRootFile * getParRootFile()
TList * GetListOfKeys()
TKey * GetKey(Text_t *t)
FairParRootFile * file
void readVersions(FairRtdbRun *)
Bool_t open(const Text_t *fname, Option_t *option="READ", const Text_t *ftitle="", Int_t compress=1)
FairParRootFile(const Text_t *fname, Option_t *option="READ", const Text_t *ftitle="", Int_t compress=1)
pointer to current run in ROOT file
FairRtdbRun * getRun()
FairRtdbRun * run
void setMerging(Bool_t io)
void readVersions(FairRtdbRun *)