Logo ROOT   6.12/07
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 #include "TXMLEngine.h"
16 #include "TFile.h"
17 #include "TXMLSetup.h"
18 
19 class TKeyXML;
20 class TList;
21 class TStreamerElement;
22 class TStreamerInfo;
23 
24 class TXMLFile : public TFile, public TXMLSetup {
25 
26 protected:
27  void InitXmlFile(Bool_t create);
28  // Interface to basic system I/O routines
29  virtual Int_t SysOpen(const char *, Int_t, UInt_t) { return 0; }
30  virtual Int_t SysClose(Int_t) { return 0; }
31  virtual Int_t SysRead(Int_t, void *, Int_t) { return 0; }
32  virtual Int_t SysWrite(Int_t, const void *, Int_t) { return 0; }
33  virtual Long64_t SysSeek(Int_t, Long64_t, Int_t) { return 0; }
34  virtual Int_t SysStat(Int_t, Long_t *, Long64_t *, Long_t *, Long_t *) { return 0; }
35  virtual Int_t SysSync(Int_t) { return 0; }
36 
37  // Overwrite methods for directory I/O
39  virtual Int_t DirReadKeys(TDirectory *);
40  virtual void DirWriteKeys(TDirectory *);
41  virtual void DirWriteHeader(TDirectory *);
42 
43 private:
44  // let the compiler do the job. gcc complains when the following line is activated
45  // TXMLFile(const TXMLFile &) {} //Files cannot be copied
46  void operator=(const TXMLFile &);
47 
48 public:
49  TXMLFile();
50  TXMLFile(const char *filename, Option_t *option = "read", const char *title = "title", Int_t compression = 1);
51  virtual ~TXMLFile();
52 
53  virtual void Close(Option_t *option = ""); // *MENU*
54  virtual TKey *CreateKey(TDirectory *mother, const TObject *obj, const char *name, Int_t bufsize);
55  virtual TKey *CreateKey(TDirectory *mother, const void *obj, const TClass *cl, const char *name, Int_t bufsize);
56  virtual void DrawMap(const char * = "*", Option_t * = "") {}
57  virtual void FillBuffer(char *&) {}
58  virtual void Flush() {}
59 
60  virtual Long64_t GetEND() const { return 0; }
61  virtual Int_t GetErrno() const { return 0; }
62  virtual void ResetErrno() const {}
63 
64  virtual Int_t GetNfree() const { return 0; }
65  virtual Int_t GetNbytesInfo() const { return 0; }
66  virtual Int_t GetNbytesFree() const { return 0; }
67  virtual Long64_t GetSeekFree() const { return 0; }
68  virtual Long64_t GetSeekInfo() const { return 0; }
69  virtual Long64_t GetSize() const { return 0; }
70  virtual TList *GetStreamerInfoList();
71  Int_t GetIOVersion() const { return fIOVersion; }
72 
73  virtual Bool_t IsOpen() const;
74 
75  virtual void MakeFree(Long64_t, Long64_t) {}
76  virtual void MakeProject(const char *, const char * = "*", Option_t * = "new") {} // *MENU*
77  virtual void Map(Option_t *) {} //
78  virtual void Map() {} //
79  virtual void Paint(Option_t * = "") {}
80  virtual void Print(Option_t * = "") const {}
81  virtual Bool_t ReadBuffer(char *, Int_t) { return kFALSE; }
82  virtual Bool_t ReadBuffer(char *, Long64_t, Int_t) { return kFALSE; }
83  virtual void ReadFree() {}
84  virtual Int_t Recover() { return 0; }
85  virtual Int_t ReOpen(Option_t *mode);
86  virtual void Seek(Long64_t, ERelativeTo = kBeg) {}
87 
88  virtual void SetEND(Long64_t) {}
89  virtual Int_t Sizeof() const { return 0; }
90 
91  virtual Bool_t WriteBuffer(const char *, Int_t) { return kFALSE; }
92  virtual Int_t Write(const char * = 0, Int_t = 0, Int_t = 0) { return 0; }
93  virtual Int_t Write(const char * = 0, Int_t = 0, Int_t = 0) const { return 0; }
94  virtual void WriteFree() {}
95  virtual void WriteHeader() {}
96  virtual void WriteStreamerInfo();
97 
98  // XML specific functions
99 
100  virtual void SetXmlLayout(EXMLLayout layout);
101  virtual void SetStoreStreamerInfos(Bool_t iConvert = kTRUE);
102  virtual void SetUsedDtd(Bool_t use = kTRUE);
103  virtual void SetUseNamespaces(Bool_t iUseNamespaces = kTRUE);
104 
105  Bool_t AddXmlComment(const char *comment);
106  Bool_t AddXmlStyleSheet(const char *href, const char *type = "text/css", const char *title = 0, int alternate = -1,
107  const char *media = 0, const char *charset = 0);
108  Bool_t AddXmlLine(const char *line);
109 
110  TXMLEngine *XML() { return fXML; }
111 
112 protected:
113  // functions to store streamer infos
114 
117 
121  TDirectory *FindKeyDir(TDirectory *mother, Long64_t keyid);
122  void CombineNodesTree(TDirectory *dir, XMLNodePointer_t topnode, Bool_t dolink);
123 
124  void SaveToFile();
125 
126  static void ProduceFileNames(const char *filename, TString &fname, TString &dtdname);
127 
129 
130  XMLNodePointer_t fStreamerInfoNode; //! pointer of node with streamer info data
131 
132  TXMLEngine *fXML; //! object for interface with xml library
133 
134  Int_t fIOVersion; //! indicates format of ROOT xml file
135 
136  Long64_t fKeyCounter; //! counter of created keys, used for keys id
137 
138  ClassDef(TXMLFile, 3) // ROOT file in XML format
139 };
140 
141 #endif
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:43
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:395
virtual Int_t SysRead(Int_t, void *, Int_t)
Interface to system read. All arguments like in POSIX read().
Definition: TXMLFile.h:31
virtual ~TXMLFile()
destructor of TXMLFile object
Definition: TXMLFile.cxx:366
long long Long64_t
Definition: RtypesCore.h:69
TXMLEngine * XML()
Definition: TXMLFile.h:110
TLine * line
const char Option_t
Definition: RtypesCore.h:62
TKeyXML * FindDirKey(TDirectory *dir)
Search for key which correspond to directory dir.
Definition: TXMLFile.cxx:1037
XMLDocPointer_t fDoc
Definition: TXMLFile.h:128
virtual Long64_t GetSeekFree() const
Definition: TXMLFile.h:67
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:86
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:46
virtual void SetXmlLayout(EXMLLayout layout)
Change layout of objects in xml file Can be changed only for newly created file.
Definition: TXMLFile.cxx:922
virtual Bool_t IsOpen() const
return kTRUE if file is opened and can be accessed
Definition: TXMLFile.cxx:386
virtual void DirWriteKeys(TDirectory *)
Update key attributes.
Definition: TXMLFile.cxx:1094
Basic string class.
Definition: TString.h:125
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
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:76
virtual void Close(Option_t *option="")
Close a XML file For more comments see TFile::Close() function.
Definition: TXMLFile.cxx:310
ERelativeTo
Definition: TFile.h:171
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:431
Int_t fIOVersion
object for interface with xml library
Definition: TXMLFile.h:134
Int_t GetIOVersion() const
Definition: TXMLFile.h:71
TXMLEngine * fXML
pointer of node with streamer info data
Definition: TXMLFile.h:132
virtual void ReadFree()
Read the FREE linked list.
Definition: TXMLFile.h:83
virtual void ResetErrno() const
Method resetting the errno. Is overridden in TRFIOFile.
Definition: TXMLFile.h:62
virtual void Flush()
Synchronize a file's in-memory and on-disk states.
Definition: TXMLFile.h:58
virtual void SetEND(Long64_t)
Definition: TXMLFile.h:88
void StoreStreamerElement(XMLNodePointer_t node, TStreamerElement *elem)
store data of single TStreamerElement in streamer node
Definition: TXMLFile.cxx:780
virtual Bool_t WriteBuffer(const char *, Int_t)
Write a buffer to the file.
Definition: TXMLFile.h:91
virtual void SetUseNamespaces(Bool_t iUseNamespaces=kTRUE)
Specify usage of namespaces in xml file In current implementation every instrumented class in file ge...
Definition: TXMLFile.cxx:965
XMLNodePointer_t fStreamerInfoNode
Definition: TXMLFile.h:130
#define ClassDef(name, id)
Definition: Rtypes.h:320
void * XMLDocPointer_t
Definition: TXMLEngine.h:20
virtual void FillBuffer(char *&)
Encode file output buffer.
Definition: TXMLFile.h:57
virtual Int_t SysOpen(const char *, Int_t, UInt_t)
Interface to system open. All arguments like in POSIX open().
Definition: TXMLFile.h:29
virtual Int_t SysClose(Int_t)
Interface to system close. All arguments like in POSIX close().
Definition: TXMLFile.h:30
void operator=(const TXMLFile &)
make private to exclude copy operator
Definition: TXMLFile.cxx:379
virtual Bool_t ReadBuffer(char *, Int_t)
Read a buffer from the file.
Definition: TXMLFile.h:81
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:24
virtual Int_t GetNbytesFree() const
Definition: TXMLFile.h:66
Long64_t fKeyCounter
indicates format of ROOT xml file
Definition: TXMLFile.h:136
void InitXmlFile(Bool_t create)
initialize xml file and correspondent structures identical to TFile::Init() function ...
Definition: TXMLFile.cxx:273
void SaveToFile()
Saves xml structures to the file xml elements are kept in list of TKeyXML objects When saving...
Definition: TXMLFile.cxx:477
virtual Long64_t GetSeekInfo() const
Definition: TXMLFile.h:68
virtual Int_t SysSync(Int_t)
Interface to system fsync. All arguments like in POSIX fsync().
Definition: TXMLFile.h:35
A doubly linked list.
Definition: TList.h:44
virtual void Map(Option_t *)
List the contents of a file sequentially.
Definition: TXMLFile.h:77
virtual void WriteHeader()
Write File Header.
Definition: TXMLFile.h:95
void CombineNodesTree(TDirectory *dir, XMLNodePointer_t topnode, Bool_t dolink)
Connect/disconnect all file nodes to single tree before/after saving.
Definition: TXMLFile.cxx:549
virtual Int_t Write(const char *=0, Int_t=0, Int_t=0)
Write memory objects to this file.
Definition: TXMLFile.h:92
virtual Int_t GetErrno() const
Method returning errno. Is overriden in TRFIOFile.
Definition: TXMLFile.h:61
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:934
Int_t ReadKeysList(TDirectory *dir, XMLNodePointer_t topnode)
Read list of keys for directory.
Definition: TXMLFile.cxx:644
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:1010
virtual Int_t Sizeof() const
Return the size in bytes of the file header.
Definition: TXMLFile.h:89
unsigned int UInt_t
Definition: RtypesCore.h:42
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
virtual void SetUsedDtd(Bool_t use=kTRUE)
Specify usage of DTD for this file.
Definition: TXMLFile.cxx:945
void * XMLNodePointer_t
Definition: TXMLEngine.h:17
const Bool_t kFALSE
Definition: RtypesCore.h:88
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:82
static void ProduceFileNames(const char *filename, TString &fname, TString &dtdname)
function produces pair of xml and dtd file names
Definition: TXMLFile.cxx:447
long Long_t
Definition: RtypesCore.h:50
virtual Int_t GetNbytesInfo() const
Definition: TXMLFile.h:65
virtual void DrawMap(const char *="*", Option_t *="")
Draw map of objects in this file.
Definition: TXMLFile.h:56
Describe directory structure in memory.
Definition: TDirectory.h:34
int type
Definition: TGX11.cxx:120
virtual void Paint(Option_t *="")
Paint all objects in the file.
Definition: TXMLFile.h:79
virtual Int_t Recover()
Attempt to recover file if not correctly closed.
Definition: TXMLFile.h:84
virtual TList * GetStreamerInfoList()
Read streamerinfo structures from xml format and provide them in the list It is user responsibility t...
Definition: TXMLFile.cxx:730
virtual Int_t SysStat(Int_t, Long_t *, Long64_t *, Long_t *, Long_t *)
Return file stat information.
Definition: TXMLFile.h:34
virtual void Map()
Definition: TXMLFile.h:78
Mother of all ROOT objects.
Definition: TObject.h:37
virtual void WriteFree()
Write FREE linked list on the file.
Definition: TXMLFile.h:94
virtual void Print(Option_t *="") const
Print all objects in the file.
Definition: TXMLFile.h:80
Bool_t ReadFromFile()
read document from file Now full content of document reads into the memory Then document decomposed t...
Definition: TXMLFile.cxx:573
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 <?xml-stylesheet alternate="yes" title...
Definition: TXMLFile.cxx:994
virtual void MakeFree(Long64_t, Long64_t)
Mark unused bytes on the file.
Definition: TXMLFile.h:75
virtual Long64_t DirCreateEntry(TDirectory *)
Create key for directory entry in the key.
Definition: TXMLFile.cxx:1021
TXMLFile()
default TXMLFile constructor
Definition: TXMLFile.cxx:97
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:93
virtual Long64_t SysSeek(Int_t, Long64_t, Int_t)
Interface to system lseek.
Definition: TXMLFile.h:33
virtual Int_t DirReadKeys(TDirectory *)
Read keys for directory Make sense only once, while next time no new subnodes will be created...
Definition: TXMLFile.cxx:1082
virtual Long64_t GetSize() const
Returns the current file size.
Definition: TXMLFile.h:69
TDirectory * FindKeyDir(TDirectory *mother, Long64_t keyid)
Find a directory in motherdir with a seek equal to keyid.
Definition: TXMLFile.cxx:1060
virtual void DirWriteHeader(TDirectory *)
Write the directory header.
Definition: TXMLFile.cxx:1109
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual Int_t GetNfree() const
Definition: TXMLFile.h:64
virtual Long64_t GetEND() const
Definition: TXMLFile.h:60
char name[80]
Definition: TGX11.cxx:109
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:976
virtual Int_t SysWrite(Int_t, const void *, Int_t)
Interface to system write. All arguments like in POSIX write().
Definition: TXMLFile.h:32
virtual void WriteStreamerInfo()
convert all TStreamerInfo, used in file, to xml format
Definition: TXMLFile.cxx:678