ROOT  6.06/09
Reference Guide
TXMLFile.h
Go to the documentation of this file.
1 // @(#)root/xml:$Id$
2 // Author: Sergey Linev 10.05.2004
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TXMLFile
13 #define ROOT_TXMLFile
14 
15 #ifndef ROOT_TXMLEngine
16 #include "TXMLEngine.h"
17 #endif
18 #ifndef ROOT_TFile
19 #include "TFile.h"
20 #endif
21 #ifndef ROOT_TXMLSetup
22 #include "TXMLSetup.h"
23 #endif
24 
25 
26 class TKeyXML;
27 class TList;
28 class TStreamerElement;
29 class TStreamerInfo;
30 
31 
32 class TXMLFile : public TFile, public TXMLSetup {
33 
34 protected:
35 
36  void InitXmlFile(Bool_t create);
37  // Interface to basic system I/O routines
38  virtual Int_t SysOpen(const char*, Int_t, UInt_t) { return 0; }
39  virtual Int_t SysClose(Int_t) { return 0; }
40  virtual Int_t SysRead(Int_t, void*, Int_t) { return 0; }
41  virtual Int_t SysWrite(Int_t, const void*, Int_t) { return 0; }
42  virtual Long64_t SysSeek(Int_t, Long64_t, Int_t) { return 0; }
43  virtual Int_t SysStat(Int_t, Long_t*, Long64_t*, Long_t*, Long_t*) { return 0; }
44  virtual Int_t SysSync(Int_t) { return 0; }
45 
46  // Overwrite methods for directory I/O
48  virtual Int_t DirReadKeys(TDirectory*);
49  virtual void DirWriteKeys(TDirectory*);
50  virtual void DirWriteHeader(TDirectory*);
51 
52 private:
53  //let the compiler do the job. gcc complains when the following line is activated
54  //TXMLFile(const TXMLFile &) {} //Files cannot be copied
55  void operator=(const TXMLFile &);
56 
57 public:
58  TXMLFile();
59  TXMLFile(const char* filename, Option_t* option = "read", const char* title = "title", Int_t compression = 1);
60  virtual ~TXMLFile();
61 
62  virtual void Close(Option_t *option=""); // *MENU*
63  virtual TKey* CreateKey(TDirectory* mother, const TObject* obj, const char* name, Int_t bufsize);
64  virtual TKey* CreateKey(TDirectory* mother, const void* obj, const TClass* cl, const char* name, Int_t bufsize);
65  virtual void DrawMap(const char* ="*",Option_t* ="") {}
66  virtual void FillBuffer(char* &) {}
67  virtual void Flush() {}
68 
69  virtual Long64_t GetEND() const { return 0; }
70  virtual Int_t GetErrno() const { return 0; }
71  virtual void ResetErrno() const {}
72 
73  virtual Int_t GetNfree() const { return 0; }
74  virtual Int_t GetNbytesInfo() const {return 0; }
75  virtual Int_t GetNbytesFree() const {return 0; }
76  virtual Long64_t GetSeekFree() const {return 0; }
77  virtual Long64_t GetSeekInfo() const {return 0; }
78  virtual Long64_t GetSize() const { return 0; }
79  virtual TList* GetStreamerInfoList();
80  Int_t GetIOVersion() const { return fIOVersion; }
81 
82  virtual Bool_t IsOpen() const;
83 
84  virtual void MakeFree(Long64_t, Long64_t) {}
85  virtual void MakeProject(const char *, const char* ="*", Option_t* ="new") {} // *MENU*
86  virtual void Map() {} //
87  virtual void Paint(Option_t* ="") {}
88  virtual void Print(Option_t* ="") const {}
89  virtual Bool_t ReadBuffer(char*, Int_t) { return kFALSE; }
90  virtual Bool_t ReadBuffer(char*, Long64_t, Int_t) { return kFALSE; }
91  virtual void ReadFree() {}
92  virtual Int_t Recover() { return 0; }
93  virtual Int_t ReOpen(Option_t *mode);
94  virtual void Seek(Long64_t, ERelativeTo=kBeg) {}
95 
96  virtual void SetEND(Long64_t) {}
97  virtual Int_t Sizeof() const { return 0; }
98 
99  virtual Bool_t WriteBuffer(const char*, Int_t) { return kFALSE; }
100  virtual Int_t Write(const char* =0, Int_t=0, Int_t=0) { return 0; }
101  virtual Int_t Write(const char* =0, Int_t=0, Int_t=0) const { return 0; }
102  virtual void WriteFree() {}
103  virtual void WriteHeader() {}
104  virtual void WriteStreamerInfo();
105 
106  // XML specific functions
107 
108  virtual void SetXmlLayout(EXMLLayout layout);
109  virtual void SetStoreStreamerInfos(Bool_t iConvert = kTRUE);
110  virtual void SetUsedDtd(Bool_t use = kTRUE);
111  virtual void SetUseNamespaces(Bool_t iUseNamespaces = kTRUE);
112 
113  Bool_t AddXmlComment(const char* comment);
114  Bool_t AddXmlStyleSheet(const char* href,
115  const char* type = "text/css",
116  const char* title = 0,
117  int alternate = -1,
118  const char* media = 0,
119  const char* charset = 0);
120  Bool_t AddXmlLine(const char* line);
121 
122  TXMLEngine* XML() { return fXML; }
123 
124 protected:
125  // functions to store streamer infos
126 
129 
133  TDirectory* FindKeyDir(TDirectory* mother, Long64_t keyid);
134  void CombineNodesTree(TDirectory* dir, XMLNodePointer_t topnode, Bool_t dolink);
135 
136  void SaveToFile();
137 
138  static void ProduceFileNames(const char* filename, TString& fname, TString& dtdname);
139 
141 
142  XMLNodePointer_t fStreamerInfoNode; //! pointer of node with streamer info data
143 
144  TXMLEngine* fXML; //! object for interface with xml library
145 
146  Int_t fIOVersion; //! indicates format of ROOT xml file
147 
148  Long64_t fKeyCounter; //! counter of created keys, used for keys id
149 
150 ClassDef(TXMLFile, 3) //ROOT file in XML format
151 };
152 
153 
154 
155 #endif
156 
void ReadStreamerElement(XMLNodePointer_t node, TStreamerInfo *info)
read and reconstruct single TStreamerElement from xml node
Definition: TXMLFile.cxx:836
Describe Streamer information for one class version.
Definition: TStreamerInfo.h:47
virtual Int_t ReOpen(Option_t *mode)
Reopen a file with a different access mode, like from READ to See TFile::Open() for details...
Definition: TXMLFile.cxx:400
virtual Int_t SysRead(Int_t, void *, Int_t)
Interface to system read. All arguments like in POSIX read().
Definition: TXMLFile.h:40
virtual ~TXMLFile()
destructor of TXMLFile object
Definition: TXMLFile.cxx:371
long long Long64_t
Definition: RtypesCore.h:69
TXMLEngine * XML()
Definition: TXMLFile.h:122
TLine * line
const char Option_t
Definition: RtypesCore.h:62
static const std::string comment("comment")
TKeyXML * FindDirKey(TDirectory *dir)
Serach for key which correspond to direcory dir.
Definition: TXMLFile.cxx:1041
XMLDocPointer_t fDoc
Definition: TXMLFile.h:140
virtual void Seek(Long64_t, ERelativeTo=kBeg)
Seek to a specific position in the file. Pos it either kBeg, kCur or kEnd.
Definition: TXMLFile.h:94
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
virtual void SetXmlLayout(EXMLLayout layout)
Change layout of objects in xml file Can be changed only for newly created file.
Definition: TXMLFile.cxx:925
static const char * filename()
Int_t GetIOVersion() const
Definition: TXMLFile.h:80
virtual void DirWriteKeys(TDirectory *)
Update key attributes.
Definition: TXMLFile.cxx:1095
Basic string class.
Definition: TString.h:137
virtual void ResetErrno() const
Method resetting the errno. Is overridden in TRFIOFile.
Definition: TXMLFile.h:71
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void MakeProject(const char *, const char *="*", Option_t *="new")
Generate source code necessary to access the objects stored in the file.
Definition: TXMLFile.h:85
virtual void Close(Option_t *option="")
Close a XML file For more comments see TFile::Close() function.
Definition: TXMLFile.cxx:318
ERelativeTo
Definition: TFile.h:160
virtual TKey * CreateKey(TDirectory *mother, const TObject *obj, const char *name, Int_t bufsize)
create XML key, which will store object in xml structures
Definition: TXMLFile.cxx:436
Int_t fIOVersion
object for interface with xml library
Definition: TXMLFile.h:146
TXMLEngine * fXML
pointer of node with streamer info data
Definition: TXMLFile.h:144
virtual void ReadFree()
Read the FREE linked list.
Definition: TXMLFile.h:91
virtual void Flush()
Synchronize a file's in-memory and on-disk states.
Definition: TXMLFile.h:67
virtual void SetEND(Long64_t)
Definition: TXMLFile.h:96
void StoreStreamerElement(XMLNodePointer_t node, TStreamerElement *elem)
store data of single TStreamerElement in streamer node
Definition: TXMLFile.cxx:777
virtual Bool_t WriteBuffer(const char *, Int_t)
Write a buffer to the file.
Definition: TXMLFile.h:99
virtual void SetUseNamespaces(Bool_t iUseNamespaces=kTRUE)
Specifiy usage of namespaces in xml file In current implementation every instrumented class in file g...
Definition: TXMLFile.cxx:968
XMLNodePointer_t fStreamerInfoNode
Definition: TXMLFile.h:142
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual Int_t GetNfree() const
Definition: TXMLFile.h:73
void * XMLDocPointer_t
Definition: TXMLEngine.h:22
virtual void FillBuffer(char *&)
Encode file output buffer.
Definition: TXMLFile.h:66
virtual Int_t SysOpen(const char *, Int_t, UInt_t)
Interface to system open. All arguments like in POSIX open().
Definition: TXMLFile.h:38
virtual Int_t SysClose(Int_t)
Interface to system close. All arguments like in POSIX close().
Definition: TXMLFile.h:39
void operator=(const TXMLFile &)
make private to exclude copy operator
Definition: TXMLFile.cxx:384
virtual Bool_t ReadBuffer(char *, Int_t)
Read a buffer from the file.
Definition: TXMLFile.h:89
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:30
virtual void Print(Option_t *="") const
Print all objects in the file.
Definition: TXMLFile.h:88
Long64_t fKeyCounter
indicates format of ROOT xml file
Definition: TXMLFile.h:148
void InitXmlFile(Bool_t create)
initialize xml file and correspondent structures identical to TFile::Init() function ...
Definition: TXMLFile.cxx:283
void SaveToFile()
Saves xml structures to file xml elements are kept in list of TKeyXML objects When saving...
Definition: TXMLFile.cxx:482
virtual Int_t SysSync(Int_t)
Interface to system fsync. All arguments like in POSIX fsync().
Definition: TXMLFile.h:44
A doubly linked list.
Definition: TList.h:47
virtual void WriteHeader()
Write File Header.
Definition: TXMLFile.h:103
virtual Int_t Write(const char *=0, Int_t=0, Int_t=0) const
One can not save a const TDirectory object.
Definition: TXMLFile.h:101
void CombineNodesTree(TDirectory *dir, XMLNodePointer_t topnode, Bool_t dolink)
Connect/disconnect all file nodes to single tree before/after saving.
Definition: TXMLFile.cxx:553
virtual Int_t Write(const char *=0, Int_t=0, Int_t=0)
Write memory objects to this file.
Definition: TXMLFile.h:100
virtual void SetStoreStreamerInfos(Bool_t iConvert=kTRUE)
If true, all correspondent to file TStreamerInfo objects will be stored in file this allows to apply ...
Definition: TXMLFile.cxx:937
Int_t ReadKeysList(TDirectory *dir, XMLNodePointer_t topnode)
Read list of keys for directory.
Definition: TXMLFile.cxx:646
Bool_t AddXmlLine(const char *line)
Add just one line on the top of xml document For instance, line can contain special xml processing in...
Definition: TXMLFile.cxx:1016
unsigned int UInt_t
Definition: RtypesCore.h:42
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
virtual void SetUsedDtd(Bool_t use=kTRUE)
Specify usage of DTD for this file.
Definition: TXMLFile.cxx:948
virtual Int_t Sizeof() const
Return the size in bytes of the file header.
Definition: TXMLFile.h:97
virtual Int_t GetNbytesInfo() const
Definition: TXMLFile.h:74
void * XMLNodePointer_t
Definition: TXMLEngine.h:19
virtual Bool_t ReadBuffer(char *, Long64_t, Int_t)
Read a buffer from the file at the offset 'pos' in the file.
Definition: TXMLFile.h:90
static void ProduceFileNames(const char *filename, TString &fname, TString &dtdname)
function produces pair of xml and dtd file names
Definition: TXMLFile.cxx:452
long Long_t
Definition: RtypesCore.h:50
virtual Bool_t IsOpen() const
return kTRUE if file is opened and can be accessed
Definition: TXMLFile.cxx:391
virtual void DrawMap(const char *="*", Option_t *="")
Draw map of objects in this file.
Definition: TXMLFile.h:65
Describe directory structure in memory.
Definition: TDirectory.h:41
int type
Definition: TGX11.cxx:120
virtual void Paint(Option_t *="")
Paint all objects in the file.
Definition: TXMLFile.h:87
virtual Int_t Recover()
Attempt to recover file if not correctly closed.
Definition: TXMLFile.h:92
virtual TList * GetStreamerInfoList()
Read streamerinfo structures from xml format and provide them in the list It is user responsibility t...
Definition: TXMLFile.cxx:728
virtual Int_t SysStat(Int_t, Long_t *, Long64_t *, Long_t *, Long_t *)
Return file stat information.
Definition: TXMLFile.h:43
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual void Map()
List the contents of a file sequentially.
Definition: TXMLFile.h:86
Mother of all ROOT objects.
Definition: TObject.h:58
virtual void WriteFree()
Write FREE linked list on the file.
Definition: TXMLFile.h:102
virtual Long64_t GetSeekInfo() const
Definition: TXMLFile.h:77
virtual Long64_t GetSize() const
Returns the current file size.
Definition: TXMLFile.h:78
Bool_t ReadFromFile()
read document from file Now full content of docuument reads into the memory Then document decomposed ...
Definition: TXMLFile.cxx:577
Bool_t AddXmlStyleSheet(const char *href, const char *type="text/css", const char *title=0, int alternate=-1, const char *media=0, const char *charset=0)
Adds style sheet definition on the top of xml document Creates
Definition: TXMLFile.cxx:997
virtual void MakeFree(Long64_t, Long64_t)
Mark unused bytes on the file.
Definition: TXMLFile.h:84
virtual Long64_t DirCreateEntry(TDirectory *)
Create key for directory entry in the key.
Definition: TXMLFile.cxx:1026
TXMLFile()
default TXMLFile constructor
Definition: TXMLFile.cxx:96
virtual Long64_t SysSeek(Int_t, Long64_t, Int_t)
Interface to system lseek.
Definition: TXMLFile.h:42
virtual Int_t DirReadKeys(TDirectory *)
Read keys for directory Make sence only once, while next time no new subnodes will be created...
Definition: TXMLFile.cxx:1084
virtual Int_t GetErrno() const
Method returning errno. Is overriden in TRFIOFile.
Definition: TXMLFile.h:70
virtual Long64_t GetSeekFree() const
Definition: TXMLFile.h:76
TDirectory * FindKeyDir(TDirectory *mother, Long64_t keyid)
Find a directory in motherdir with a seek equal to keyid.
Definition: TXMLFile.cxx:1063
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual Int_t GetNbytesFree() const
Definition: TXMLFile.h:75
virtual Long64_t GetEND() const
Definition: TXMLFile.h:69
TObject * obj
virtual void DirWriteHeader(TDirectory *)
Write the directory header.
Definition: TXMLFile.cxx:1109
Bool_t AddXmlComment(const char *comment)
Add comment line on the top of the xml document This line can only be seen in xml editor and cannot b...
Definition: TXMLFile.cxx:979
virtual Int_t SysWrite(Int_t, const void *, Int_t)
Interface to system write. All arguments like in POSIX write().
Definition: TXMLFile.h:41
virtual void WriteStreamerInfo()
convert all TStreamerInfo, used in file, to xml format
Definition: TXMLFile.cxx:679