Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "TFile.h"
16#include "TXMLSetup.h"
17#include "TXMLEngine.h"
18#include "Compression.h"
19#include <memory>
20
21class TKeyXML;
23class TStreamerInfo;
24
25class TXMLFile final : public TFile, public TXMLSetup {
26
27protected:
28 void InitXmlFile(Bool_t create);
29 // Interface to basic system I/O routines
30 Int_t SysOpen(const char *, Int_t, UInt_t) final { return 0; }
31 Int_t SysClose(Int_t) final { return 0; }
32 Int_t SysRead(Int_t, void *, Int_t) final { return 0; }
33 Int_t SysWrite(Int_t, const void *, Int_t) final { return 0; }
34 Long64_t SysSeek(Int_t, Long64_t, Int_t) final { return 0; }
35 Int_t SysStat(Int_t, Long_t *, Long64_t *, Long_t *, Long_t *) final { return 0; }
36 Int_t SysSync(Int_t) final { return 0; }
37
38 // Overwrite methods for directory I/O
41 void DirWriteKeys(TDirectory *) final;
42 void DirWriteHeader(TDirectory *) final;
43
44 InfoListRet GetStreamerInfoListImpl(bool lookupSICache) final;
45
46private:
47 TXMLFile(const TXMLFile &) = delete; // TXMLFile cannot be copied, not implemented
48 void operator=(const TXMLFile &) = delete; // TXMLFile cannot be copied, not implemented
49
50public:
51 TXMLFile() {} // NOLINT: not allowed to use = default because of TObject::kIsOnHeap detection, see ROOT-10300
52 TXMLFile(const char *filename, Option_t *option = "read", const char *title = "title", Int_t compression = ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault);
53 virtual ~TXMLFile();
54
55 void Close(Option_t *option = "") final; // *MENU*
56 TKey *CreateKey(TDirectory *mother, const TObject *obj, const char *name, Int_t bufsize) final;
57 TKey *CreateKey(TDirectory *mother, const void *obj, const TClass *cl, const char *name, Int_t bufsize) final;
58 void DrawMap(const char * = "*", Option_t * = "") final {}
59 void FillBuffer(char *&) final {}
60 void Flush() final {}
61
62 Long64_t GetEND() const final { return 0; }
63 Int_t GetErrno() const final { return 0; }
64 void ResetErrno() const final {}
65
66 Int_t GetNfree() const final { return 0; }
67 Int_t GetNbytesInfo() const final { return 0; }
68 Int_t GetNbytesFree() const final { return 0; }
69 Long64_t GetSeekFree() const final { return 0; }
70 Long64_t GetSeekInfo() const final { return 0; }
71 Long64_t GetSize() const final { return 0; }
72
73 Int_t GetIOVersion() const { return fIOVersion; }
74
75 Bool_t IsOpen() const final;
76
77 void MakeFree(Long64_t, Long64_t) final {}
78 void MakeProject(const char *, const char * = "*", Option_t * = "new") final {} // *MENU*
79 void Map(Option_t *) final {} //
80 void Map() final {} //
81 void Paint(Option_t * = "") final {}
82 void Print(Option_t * = "") const final {}
83 Bool_t ReadBuffer(char *, Int_t) final { return kFALSE; }
84 Bool_t ReadBuffer(char *, Long64_t, Int_t) final { return kFALSE; }
85 void ReadFree() final {}
86 Int_t Recover() final { return 0; }
87 Int_t ReOpen(Option_t *mode) final;
88 void Seek(Long64_t, ERelativeTo = kBeg) final {}
89
90 void SetEND(Long64_t) final {}
91 Int_t Sizeof() const final { return 0; }
92
93 Bool_t WriteBuffer(const char *, Int_t) final { return kFALSE; }
94 Int_t Write(const char * = nullptr, Int_t = 0, Int_t = 0) final { return 0; }
95 Int_t Write(const char * = nullptr, Int_t = 0, Int_t = 0) const final { return 0; }
96 void WriteFree() final {}
97 void WriteHeader() final {}
98 void WriteStreamerInfo() final;
99
100 // XML specific functions
101
102 void SetXmlLayout(EXMLLayout layout) final;
103 void SetStoreStreamerInfos(Bool_t iConvert = kTRUE) final;
104 void SetUsedDtd(Bool_t use = kTRUE) final;
105 void SetUseNamespaces(Bool_t iUseNamespaces = kTRUE) final;
106
107 Bool_t AddXmlComment(const char *comment);
108 Bool_t AddXmlStyleSheet(const char *href, const char *type = "text/css", const char *title = nullptr, int alternate = -1,
109 const char *media = nullptr, const char *charset = nullptr);
110 Bool_t AddXmlLine(const char *line);
111
112 TXMLEngine *XML() { return fXML.get(); }
113
114protected:
115 // functions to store streamer infos
116
119
123 TDirectory *FindKeyDir(TDirectory *mother, Long64_t keyid);
124 void CombineNodesTree(TDirectory *dir, XMLNodePointer_t topnode, Bool_t dolink);
125
126 void SaveToFile();
127
128 static void ProduceFileNames(const char *filename, TString &fname, TString &dtdname);
129
130 XMLDocPointer_t fDoc{nullptr}; //!
131
132 XMLNodePointer_t fStreamerInfoNode{nullptr}; //! pointer of node with streamer info data
133
134 std::unique_ptr<TXMLEngine> fXML; //! object for interface with xml library
135
136 Int_t fIOVersion{0}; //! indicates format of ROOT xml file
137
138 Long64_t fKeyCounter{0}; //! counter of created keys, used for keys id
139
140 ClassDefOverride(TXMLFile, 3) // ROOT file in XML format
141};
142
143#endif
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
long Long_t
Definition RtypesCore.h:54
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
long long Long64_t
Definition RtypesCore.h:80
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Option_t Option_t TPoint TPoint const char text
void * XMLNodePointer_t
Definition TXMLEngine.h:17
void * XMLDocPointer_t
Definition TXMLEngine.h:20
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
Describe directory structure in memory.
Definition TDirectory.h:45
const char * name
Definition TDirectory.h:308
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition TFile.h:51
ERelativeTo
Definition TFile.h:190
@ kBeg
Definition TFile.h:190
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition TKey.h:28
Mother of all ROOT objects.
Definition TObject.h:41
Describes a persistent version of a class.
Basic string class.
Definition TString.h:139
Int_t SysOpen(const char *, Int_t, UInt_t) final
Interface to system open. All arguments like in POSIX open().
Definition TXMLFile.h:30
Int_t SysSync(Int_t) final
Interface to system fsync. All arguments like in POSIX fsync().
Definition TXMLFile.h:36
void Paint(Option_t *="") final
Paint all objects in the file.
Definition TXMLFile.h:81
Bool_t IsOpen() const final
return kTRUE if file is opened and can be accessed
Definition TXMLFile.cxx:363
Int_t Sizeof() const final
Return the size in bytes of the file header.
Definition TXMLFile.h:91
void DrawMap(const char *="*", Option_t *="") final
Draw map of objects in this file.
Definition TXMLFile.h:58
Int_t fIOVersion
object for interface with xml library
Definition TXMLFile.h:136
TXMLFile()
Definition TXMLFile.h:51
TDirectory * FindKeyDir(TDirectory *mother, Long64_t keyid)
Find a directory in motherdir with a seek equal to keyid.
TKey * CreateKey(TDirectory *mother, const TObject *obj, const char *name, Int_t bufsize) final
create XML key, which will store object in xml structures
Definition TXMLFile.cxx:408
void ReadFree() final
Read the FREE linked list.
Definition TXMLFile.h:85
void InitXmlFile(Bool_t create)
initialize xml file and correspondent structures identical to TFile::Init() function
Definition TXMLFile.cxx:262
void Map() final
Definition TXMLFile.h:80
Int_t SysRead(Int_t, void *, Int_t) final
Interface to system read. All arguments like in POSIX read().
Definition TXMLFile.h:32
Bool_t AddXmlStyleSheet(const char *href, const char *type="text/css", const char *title=nullptr, int alternate=-1, const char *media=nullptr, const char *charset=nullptr)
Adds style sheet definition on the top of xml document Creates <?xml-stylesheet alternate="yes" title...
Definition TXMLFile.cxx:983
InfoListRet GetStreamerInfoListImpl(bool lookupSICache) final
Read streamerinfo structures from xml format and provide them in the list It is user responsibility t...
Definition TXMLFile.cxx:715
Int_t GetNfree() const final
Definition TXMLFile.h:66
Long64_t GetEND() const final
Definition TXMLFile.h:62
Int_t SysClose(Int_t) final
Interface to system close. All arguments like in POSIX close().
Definition TXMLFile.h:31
void SaveToFile()
Saves xml structures to the file xml elements are kept in list of TKeyXML objects When saving,...
Definition TXMLFile.cxx:454
Int_t Write(const char *=nullptr, Int_t=0, Int_t=0) final
Write memory objects to this file.
Definition TXMLFile.h:94
XMLNodePointer_t fStreamerInfoNode
Definition TXMLFile.h:132
Long64_t fKeyCounter
indicates format of ROOT xml file
Definition TXMLFile.h:138
void CombineNodesTree(TDirectory *dir, XMLNodePointer_t topnode, Bool_t dolink)
Connect/disconnect all file nodes to single tree before/after saving.
Definition TXMLFile.cxx:535
void Map(Option_t *) final
List the contents of a file sequentially.
Definition TXMLFile.h:79
Bool_t ReadBuffer(char *, Int_t) final
Read a buffer from the file.
Definition TXMLFile.h:83
void DirWriteHeader(TDirectory *) final
Write the directory header.
void FillBuffer(char *&) final
Encode file output buffer.
Definition TXMLFile.h:59
Int_t DirReadKeys(TDirectory *) final
Read keys for directory Make sense only once, while next time no new subnodes will be created.
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:999
Long64_t GetSize() const final
Returns the current file size.
Definition TXMLFile.h:71
void WriteHeader() final
Write File Header.
Definition TXMLFile.h:97
void DirWriteKeys(TDirectory *) final
Update key attributes.
TXMLFile(const TXMLFile &)=delete
Int_t Recover() final
Attempt to recover file if not correctly closed.
Definition TXMLFile.h:86
void WriteStreamerInfo() final
convert all TStreamerInfo, used in file, to xml format
Definition TXMLFile.cxx:664
Int_t ReadKeysList(TDirectory *dir, XMLNodePointer_t topnode)
Read list of keys for directory.
Definition TXMLFile.cxx:630
void WriteFree() final
Write FREE linked list on the file.
Definition TXMLFile.h:96
void SetEND(Long64_t) final
Definition TXMLFile.h:90
void SetXmlLayout(EXMLLayout layout) final
Change layout of objects in xml file Can be changed only for newly created file.
Definition TXMLFile.cxx:911
Bool_t WriteBuffer(const char *, Int_t) final
Write a buffer to the file.
Definition TXMLFile.h:93
void ResetErrno() const final
Method resetting the errno.
Definition TXMLFile.h:64
Int_t SysStat(Int_t, Long_t *, Long64_t *, Long_t *, Long_t *) final
Return file stat information.
Definition TXMLFile.h:35
Int_t Write(const char *=nullptr, Int_t=0, Int_t=0) const final
One can not save a const TDirectory object.
Definition TXMLFile.h:95
void operator=(const TXMLFile &)=delete
Long64_t GetSeekInfo() const final
Definition TXMLFile.h:70
void SetStoreStreamerInfos(Bool_t iConvert=kTRUE) final
If true, all correspondent to file TStreamerInfo objects will be stored in file this allows to apply ...
Definition TXMLFile.cxx:923
void SetUseNamespaces(Bool_t iUseNamespaces=kTRUE) final
Specify usage of namespaces in xml file In current implementation every instrumented class in file ge...
Definition TXMLFile.cxx:954
Long64_t SysSeek(Int_t, Long64_t, Int_t) final
Interface to system lseek.
Definition TXMLFile.h:34
Int_t GetIOVersion() const
Definition TXMLFile.h:73
void SetUsedDtd(Bool_t use=kTRUE) final
Specify usage of DTD for this file.
Definition TXMLFile.cxx:934
virtual ~TXMLFile()
destructor of TXMLFile object
Definition TXMLFile.cxx:355
XMLDocPointer_t fDoc
Definition TXMLFile.h:130
void StoreStreamerElement(XMLNodePointer_t node, TStreamerElement *elem)
store data of single TStreamerElement in streamer node
Definition TXMLFile.cxx:767
Int_t GetErrno() const final
Method returning errno.
Definition TXMLFile.h:63
void Print(Option_t *="") const final
Print all objects in the file.
Definition TXMLFile.h:82
void MakeFree(Long64_t, Long64_t) final
Mark unused bytes on the file.
Definition TXMLFile.h:77
Int_t GetNbytesFree() const final
Definition TXMLFile.h:68
Long64_t GetSeekFree() const final
Definition TXMLFile.h:69
void ReadStreamerElement(XMLNodePointer_t node, TStreamerInfo *info)
read and reconstruct single TStreamerElement from xml node
Definition TXMLFile.cxx:825
Bool_t ReadBuffer(char *, Long64_t, Int_t) final
Read a buffer from the file at the offset 'pos' in the file.
Definition TXMLFile.h:84
void MakeProject(const char *, const char *="*", Option_t *="new") final
Generate source code necessary to access the objects stored in the file.
Definition TXMLFile.h:78
Int_t SysWrite(Int_t, const void *, Int_t) final
Interface to system write. All arguments like in POSIX write().
Definition TXMLFile.h:33
Int_t ReOpen(Option_t *mode) final
Reopen a file with a different access mode, like from READ to See TFile::Open() for details.
Definition TXMLFile.cxx:372
std::unique_ptr< TXMLEngine > fXML
pointer of node with streamer info data
Definition TXMLFile.h:134
void Close(Option_t *option="") final
Close a XML file For more comments see TFile::Close() function.
Definition TXMLFile.cxx:299
Bool_t ReadFromFile()
read document from file Now full content of document reads into the memory Then document decomposed t...
Definition TXMLFile.cxx:559
void Flush() final
Synchronize a file's in-memory and on-disk states.
Definition TXMLFile.h:60
void Seek(Long64_t, ERelativeTo=kBeg) final
Seek to a specific position in the file. Pos it either kBeg, kCur or kEnd.
Definition TXMLFile.h:88
TXMLEngine * XML()
Definition TXMLFile.h:112
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:965
Long64_t DirCreateEntry(TDirectory *) final
Create key for directory entry in the key.
TKeyXML * FindDirKey(TDirectory *dir)
Search for key which correspond to directory dir.
static void ProduceFileNames(const char *filename, TString &fname, TString &dtdname)
function produces pair of xml and dtd file names
Definition TXMLFile.cxx:424
Int_t GetNbytesInfo() const final
Definition TXMLFile.h:67
TLine * line
@ kUseCompiledDefault
Use the compile-time default setting.
Definition Compression.h:50