Possibility of XML IO support in ROOT S
Possibility of XML I/O support in ROOT S. Linev, GSI, Darmstadt ROOT Workshop 2004 25. 2. 2004 XML I/O in ROOT. S. Linev, GSI
Content n n n XML and existing packages Concept of XML I/O for ROOT Possible implementations Problems and questions Conclusion 25. 2. 2004 XML I/O in ROOT. S. Linev, GSI 2
e. Xtensible Markup Language (XML) n n Tree like structure (not ROOT tree) of text tags Each tag opened should be closed Tag can include other tags, contain text, has attributes In addition: DTD, XSLT, XML schema, namespaces, … <? xml version="1. 0"? > <Example> <item 1>item text</item 1> <item 2 id="001"> <subitem>subitem text</subitem> </item 2> <item 3 ref="001"/> </Example> 25. 2. 2004 Example item 1 item 2 subitem 3 XML I/O in ROOT. S. Linev, GSI values: “item text“ id="001" “subitem text“ ref="001" 3
XML packages C/C++ based XML packages: n libxml (Gnome) http: //xmlsoft. org n Xerces-C++ (Apache) http: //xml. apache. org/xerces-C/ n expat (Mozilla) http: //expat. sourceforge. net Benchmarks of XML packages: http: //xmlbench. sourceforge. net 25. 2. 2004 XML I/O in ROOT. S. Linev, GSI 4
Usage of libxml 2 library Example of code to create XML file: xml. Doc. Ptr f. Doc = xml. New. Doc(0); xml. Node. Ptr f. Node = xml. New. Doc. Node(f. Doc, 0, (const xml. Char*) "Example", 0); xml. Doc. Set. Root. Element(f. Doc, f. Node); xml. New. Text. Child(f. Node, 0, (const xml. Char*) "item 1", (const xml. Char*) "item text"); xml. Node. Ptr sub 2 = xml. Add. Child(f. Node, xml. New. Node(0, (const xml. Char*) "item 2")); xml. New. Text. Child(sub 2, 0, (const xml. Char*) "subitem", (const xml. Char*) "subitem text"); xml. New. Prop(sub 2, (const xml. Char*) "id", (const xml. Char*) "001"); xml. Node. Ptr sub 3 = xml. Add. Child(f. Node, xml. New. Node(0, (const xml. Char*) "item 3")); xml. New. Prop(sub 3, (const xml. Char*) "ref", (const xml. Char*) "001"); xml. Save. Format. File("Example. xml", f. Doc, 1); xml. Free. Doc(f. Doc); 25. 2. 2004 XML I/O in ROOT. S. Linev, GSI 5
XML and ROOT n n n XML as metadata storage place: configuration, parameters and geometry objects XML files can be viewed and edited (with some restriction) with standard XML tools Data exchange between different packages But currently: n There is no XML support in ROOT (yet) n Each new class requires its own XML streamer 25. 2. 2004 XML I/O in ROOT. S. Linev, GSI 6
Motivation n ROOT has all class information in TStreamer. Info class with methods to serialize/deserialize objects Why not implement similar mechanism for XML, not only for binary ROOT format? Aim – introduce XML I/O in ROOT, where user should not write I/O code himself 25. 2. 2004 XML I/O in ROOT. S. Linev, GSI 7
Object representation in XML object id class TXml. Example { public: Int_t f. Value; Double_t f. Array[5]; TString f. Str; TXml. Example* f. Self. Ptr; Class. Def(TXml. Example, 1); }; class name basic type array string (special case) pointer 25. 2. 2004 <TXml. Example ref="id 0"> <f. Value v="10"/> <f. Array> <Double v="1. 0"/> <Double v="10. 0"/> <Double v="5. 0"/> <Double v="7. 0"/> <Double v="2. 0"/> </f. Array> <f. Str TString="Hello"/> <f. Self. Ptr ptr="id 0"/> </TXml. Example> XML I/O in ROOT. S. Linev, GSI 8
First Implementation n New class with two functions similar to TStreamer. Info: : Write. Buffer() and TStreamer. Info: : Read. Buffer() were implemented to serialize/deserialize objects to/from XML structures Libxml 2 library was used Requires no any ROOT modifications 25. 2. 2004 XML I/O in ROOT. S. Linev, GSI 9
Problems n n n Only relatively “simple” objects can be stored Custom streamers are not supported As a result, ROOT classes like histograms (TH 1), containers (TObj. Array) and many other can not be supported 25. 2. 2004 XML I/O in ROOT. S. Linev, GSI 10
TBuffer class modification n Make six methods of TBuffer virtual: void Write. Object(const void *actual. Obj. Start, TClass *actual. Class); void* Read. Object. Any(const TClass* cast); Int_t Check. Byte. Count(UInt_t startpos, UInt_t bcnt, const TClass *clss); void Set. Byte. Count(UInt_t cntpos, Bool_t pack. In. Version = k. FALSE); Version_t Read. Version(UInt_t *start = 0, UInt_t *bcnt = 0); UInt_t Write. Version(const TClass *cl, Bool_t use. Bcnt = k. FALSE); n n Redefine these methods in new TXml. Buffer class to perform XML specific actions To support “TFile-like” key organization, new TXml. File and TXml. Key classes have been created 25. 2. 2004 XML I/O in ROOT. S. Linev, GSI 11
Example with TObj. Array <? xml version="1. 0"? > <root> <Xml. Key name="array" setup="1 xxox"> <TObj. Array version="3"> <Xml. Object> <TNamed> <f. Name TString="name 1"/> <f. Title TString="title 1"/> </TNamed> </Xml. Object> <TNamed> <f. Name TString="name 2"/> <f. Title TString="title 2"/> </TNamed> </Xml. Object> <TNamed> <f. Name TString="name 3"/> <f. Title TString="title 3"/> </TNamed> </Xml. Object> <Xml. Block size="9"> 00 00 03 00 00 </Xml. Block> </TObj. Array> <Xml. Classes> <TNamed version="1"/> </Xml. Classes> </Xml. Key> </root> 25. 2. 2004 Xml. Key with name and setup info TObj. Array tag with version TObj. Array arr; arr. Add(new TNamed("name 1", "title 1")); arr. Add(new TNamed("name 2", "title 2")); arr. Add(new TNamed("name 3", "title 3")); TXml. File file("test. xml", "1 xxox"); file. Write(&arr, "array"); Part of TObj. Array streamer (writing): … f. Name. Streamer(b); nobjects = Get. Abs. Last()+1; b << nobjects; b << f. Lower. Bound; … Now only version, later full class info XML I/O in ROOT. S. Linev, GSI <? xml version="1. 0"? > <root> <Xml. Key name="array" setup="1 xxox"> <TObj. Array version="3"> <UChar>0</UChar> <Int>3</Int> <Int>0</Int> <Xml. Object> <TNamed> <f. Name TString="name 1"/> <f. Title TString="title 1"/> </TNamed> </Xml. Object> <TNamed> <f. Name TString="name 2"/> <f. Title TString="title 2"/> </TNamed> </Xml. Object> <TNamed> <f. Name TString="name 3"/> <f. Title TString="title 3"/> </TNamed> </Xml. Object> </TObj. Array> <Xml. Classes> <TNamed version="1"/> </Xml. Classes> </Xml. Key> </root> 12
Consequence of TBuffer modification n n Most of ROOT classes can be stored Users classes with custom streamers can be supported Works, if reading and writing parts of custom streamer have similar sequence of I/O actions (normal situation) Some classes like TTree & TClones. Array are not tested and may be not required to be stored in XML format At worse case 10% lost of I/O performance Still not fully acceptable because: n this is just “hacking” of ROOT code n TXml. File and TXml. Key repeats a lot of functionality of similar TFile and TKey classes 25. 2. 2004 XML I/O in ROOT. S. Linev, GSI 13
Further investigations n n n Producing of DTD files for validation purposes Using of XML namespaces to avoid names intersection Extension of TFile and TKey logic on XML files (via abstract interfaces) C++ code generator for XML I/O to access ROOT objects outside a ROOT environment Support of different XML packages 25. 2. 2004 XML I/O in ROOT. S. Linev, GSI 14
Conclusion n n There is no general XML I/O in ROOT Very limited solution possible without ROOT changing With slight TBuffer modifications acceptable XML support in ROOT is possible Further investigations required 25. 2. 2004 XML I/O in ROOT. S. Linev, GSI 15
- Slides: 15