Commits

Anonymous committed c9d3bf2

beginning of support for TLeafI

  • Participants
  • Parent commits 0adb907

Comments (0)

Files changed (5)

File pkg/groot/base_leaf.go

 package groot
 
-import (
-	"reflect"
-)
-
-type BaseLeaf struct {
+type baseLeaf struct {
 	name   string
 	title  string
 	ndata  uint32 // number of elements in fAddress
 	length uint32 // number of fixed length elements
 
-	leaf_count *BaseLeaf // pointer to Leaf-count if variable length
+	leaf_count *baseLeaf // pointer to Leaf-count if variable length
 }
 
-func init() {
-	f := func() reflect.Value {
-		o := &BaseLeaf{}
-		return reflect.ValueOf(o)
-	}
-	Factory.db["TBaseLeaf"] = f
-	Factory.db["*groot.BaseLeaf"] = f
+func (base *baseLeaf) Class() Class {
+	panic("not implemented")
 }
 
+func (base *baseLeaf) Name() string {
+	return base.name
+}
+
+func (base *baseLeaf) Title() string {
+	return base.title
+}
+
+func (base *baseLeaf) ROOTDecode(b *Buffer) (err error) {
+
+	vers, pos, bcnt := b.read_version()
+	dprintf("baseleaf-vers=%v pos=%v bcnt=%v\n", vers, pos, bcnt)
+	base.name, base.title = b.read_tnamed()
+	dprintf("baseleaf-name='%v' title='%v'\n", base.name, base.title)
+	base.length = b.ntou4()
+	dprintf("baseleaf-length=%v\n", base.length)
+	b.ntoi4() // fLengthType
+	b.ntoi4() // fOffset
+	b.ntobyte() // fIsRange
+	b.ntobyte() // fIsUnsigned
+
+	obj := b.read_object()
+	dprintf("baseleaf-nobjs: %v\n", obj)
+	if obj != nil {
+		base.leaf_count = obj.(*baseLeaf)
+	}
+	if base.length != 0 {
+		//FIXME: ??? really ??? (check with Guy)
+		base.length = 1
+	}
+	return
+}
+
+// func init() {
+// 	f := func() reflect.Value {
+// 		o := &BaseLeaf{}
+// 		return reflect.ValueOf(o)
+// 	}
+// 	Factory.db["TBaseLeaf"] = f
+// 	Factory.db["*groot.BaseLeaf"] = f
+// }
+
 // EOF

File pkg/groot/basket.go

 package groot
 
 import (
+	"fmt"
 	"reflect"
 )
 
 type Basket struct {
-	Key
+	key Key
 
 	nev_bufsz    uint32 // Length in Int_t of entry_offset
 	nev          uint32 // Number of entries in basket
 
 }
 
-/*
+func (basket *Basket) Class() Class {
+	//FIXME
+	panic("not implemented")
+}
+
+func (basket *Basket) Name() string {
+	return basket.key.Name()
+}
+
+func (basket *Basket) Title() string {
+	return basket.key.Title()
+}
+
 func (basket *Basket) ROOTDecode(b *Buffer) (err error) {
-	err = basket.Key.ROOTDecode(b)
+	startpos := b.Len()
+	k,err := NewKey(nil, 0, 0)
+	if err != nil {
+		return err
+	}
+	basket.key = *k
+	err = basket.key.init_from_buffer(b)
+	if err != nil {
+		return err
+	}
+
+	vers, pos, bcnt := b.read_version()
+	dprintf("vers=%v pos=%v bcnt=%v\n", vers, pos, bcnt)
+	bufsz := b.ntou4()
+	basket.nev_bufsz = b.ntou4()
+	basket.nev = b.ntou4()
+	basket.last = b.ntou4()
+	flag := b.ntobyte()
+	if basket.last > bufsz {
+		bufsz = basket.last
+	}
+	
+	basket_key_len := b.Len() - startpos
+	if basket_key_len != int(basket.key.keysz) {
+		basket.key.keysz = uint16(basket_key_len)
+	}
+	if basket.key.objsz != 0 {
+		basket.key.objsz = uint32(basket.key.nbytes) - uint32(basket.key.keysz)
+	}
+	if flag != 0 {
+		// fHeaderOnly
+		return
+	}
+	// from Guy: adding this useful (?) test
+	if (flag!=1 && flag!=2 &&
+		flag!=11 && flag!=12 &&
+		flag!=41 && flag!=42 &&
+		flag!=51 && flag!=52) {
+		err = fmt.Errorf("groot.basket.ROOTDecode: bad flag (=%v)",
+			int(flag))
+	}
+	return
+}
+
+func (basket *Basket) ROOTEncode(b *Buffer) (err error) {
+	//bb := b.Clone()
+	//err = basket.key.ROOTEncode(b)
 	if err != nil {
 		return err
 	}
 	return
 }
 
-func (basket *Basket) ROOTEncode(b *Buffer) (err error) {
-	err = basket.Key.ROOTEncode(b)
-	if err != nil {
-		return err
-	}
-	panic("fixme")
-	return
-}
-*/
-
 func init() {
 	f := func() reflect.Value {
 		o := &Basket{}

File pkg/groot/branch.go

 	title string
 
 	file *File
+
+	autodelete bool
+	branches []Branch
+	leaves   []baseLeaf
+	baskets  []Basket
+	entryOffsetLen uint32 // initial length of fEntryOffset table in the basket buffers
+	writeBasket uint32 // last basket number written
+	entryNumber uint32 // current entry number (last one filled in this branch)
+	readBasket uint32  // current basket number when reading
+	
+	//fBasketBytes
+	//fBasketEntry
+	//fBasketSeek
+
 }
 
 func (branch *Branch) Class() Class {
 	branch.name, branch.title = b.read_tnamed()
 	dprintf("name='%v' title='%v'\n", branch.name, branch.title)
 
+	if vers <= 5 {
+		b.ntoi4() // fCompress
+		b.ntoi4() // fBasketSize
+		branch.entryOffsetLen = b.ntou4()
+		b.ntou4() // fMaxBaskets
+		branch.writeBasket = b.ntou4()
+		branch.entryNumber = b.ntou4()
+		b.ntod() // entries
+		b.ntod() // tot_bytes
+		b.ntod() // zip_bytes
+		b.ntoi4() // fOffset
+	} else if vers <= 6 {
+		b.ntoi4() // fCompress
+		b.ntoi4() // fBasketSize
+		branch.entryOffsetLen = b.ntou4()
+		branch.writeBasket = b.ntou4()
+		branch.entryNumber = b.ntou4()
+		b.ntoi4() // fOffset
+		b.ntou4() // fMaxBaskets
+		b.ntod() // entries
+		b.ntod() // tot_bytes
+		b.ntod() // zip_bytes
+	} else if vers <= 7 {
+		b.ntoi4() // fCompress
+		b.ntoi4() // fBasketSize
+		branch.entryOffsetLen = b.ntou4()
+		branch.writeBasket = b.ntou4()
+		branch.entryNumber = b.ntou4()
+		b.ntoi4() // fOffset
+		b.ntou4() // fMaxBaskets
+		b.ntoi4() // fSplitLevel
+		b.ntod() // entries
+		b.ntod() // tot_bytes
+		b.ntod() // zip_bytes
+	} else if vers <= 9 {
+		b.read_attfill()
+		b.ntoi4() // fCompress
+		b.ntoi4() // fBasketSize
+		branch.entryOffsetLen = b.ntou4()
+		branch.writeBasket = b.ntou4()
+		branch.entryNumber = b.ntou4()
+		b.ntoi4() // fOffset
+		b.ntou4() // fMaxBaskets
+		b.ntoi4() // fSplitLevel
+		b.ntod() // entries
+		b.ntod() // tot_bytes
+		b.ntod() // zip_bytes
+	} else if vers <= 10 {
+		b.read_attfill()
+		b.ntoi4() // fCompress
+		b.ntoi4() // fBasketSize
+		branch.entryOffsetLen = b.ntou4()
+		branch.writeBasket = b.ntou4()
+		branch.entryNumber = uint32(b.ntou8()) //fixme ?
+		b.ntoi4() // fOffset
+		b.ntou4() // fMaxBaskets
+		b.ntoi4() // fSplitLevel
+		b.ntou8() // entries
+		b.ntou8() // tot_bytes
+		b.ntou8() // zip_bytes
+	} else { //vers>=11
+		b.read_attfill()
+		b.ntoi4() // fCompress
+		b.ntoi4() // fBasketSize
+		branch.entryOffsetLen = b.ntou4()
+		branch.writeBasket = b.ntou4()
+		branch.entryNumber = uint32(b.ntou8()) //fixme ?
+		b.ntoi4() // fOffset
+		b.ntou4() // fMaxBaskets
+		b.ntoi4() // fSplitLevel
+		b.ntou8() // entries
+		b.ntou8() // fFirstEntry
+		b.ntou8() // tot_bytes
+		b.ntou8() // zip_bytes
+	}
+	branches := b.read_obj_array()
+	dprintf("sub-branches: %v\n", len(branches))
+
+	leaves := b.read_obj_array()
+	dprintf("sub-leaves: %v\n", len(leaves))
+
+	baskets := b.read_obj_array()
+	dprintf("baskets: %v\n", len(baskets))
+
 	return
 }
 

File pkg/groot/buffer.go

 	return NewBuffer(buf, k.file.order, uint32(k.keysz))
 }
 
+func (b *Buffer) Len() int {
+	return len(b.Bytes())
+}
+
 func (b *Buffer) Bytes() []byte {
 	return b.buf.Bytes()
 }
 }
 
 func (b *Buffer) read_object() (o Object) {
+	// before reading object, save start position
+	startbuf := b.clone()
+
 	clsname, bcnt, isref := b.read_class()
-	printf(">>[%s] [%v] [%v]\n", clsname, bcnt, isref)
+	dprintf(">>[%s] [%v] [%v]\n", clsname, bcnt, isref)
 	if isref {
 		obj_offset := bcnt - kMapOffset - b.klen
 		bb := b.clone()
 			if scls == "" {
 				panic("groot.Buffer.read_object: read_class_tag did not find a class name")
 			}
+			factory := Factory.Get(scls)
+			if factory == nil {
+				dprintf("**err** no factory for class [%s]\n", clsname)
+				return
+			}
+
+			vv := factory()
+			o = vv.Interface().(Object)
+			panic("chasing refs isnt implemented")
 		} else {
 			/* boo */
 		}
 		 // but enforce it anyway : 
 		 m_pos = m_buffer+startpos+sizeof(unsigned int); 
 		*/
+		b = startbuf //FIXME ??
+		b.read_nbytes(4)
 	} else {
 		if clsname == "" {
 			o = nil
+			// m_pos = m_buffer+startpos+bcnt+sizeof(unsigned int);
+			b = startbuf
+			b.read_nbytes(int(bcnt+4))
 		} else {
 
 			factory := Factory.Get(clsname)
 			vv := factory()
 			o = vv.Interface().(Object)
 			if vv, ok := vv.Interface().(ROOTStreamer); ok {
-				err := vv.ROOTDecode(b.clone())
+				err := vv.ROOTDecode(b)
 				if err != nil {
 					panic(err)
+				} else {
+					dprintf("--decoded[%s]--\n", o.Name())
 				}
 			} else {
 				dprintf("**err** class [%s] does not satisfy the ROOTStreamer interface\n", clsname)
 
 	//var bufvers = 0
 	i := b.ntou4()
-
+	dprintf("..first_int: %x\n", i)
 	if i == kNullTag {
 		/*empty*/
 	} else if (i & kByteCountMask) != 0 {
 		//bufvers = 1
 		clstag := b.read_class_tag()
 		if clstag == "" {
-			panic("groot.breader.readClass: empty class tag")
+			panic("groot.Buffer.read_class: empty class tag")
 		}
 		name = clstag
 		bcnt = uint32(int64(i) & ^kByteCountMask)
 		bcnt = uint32(i)
 		isref = true
 	}
-	printf("--[%s] [%v] [%v]\n", name, bcnt, isref)
+	dprintf("--[%s] [%v] [%v]\n", name, bcnt, isref)
 	return
 }
 
 func (b *Buffer) read_class_tag() (clstag string) {
 	tag := b.ntou4()
-
+	dprintf("--tag:%v %x\n", tag, tag)
 	if tag == kNewClassTag {
 		clstag = b.read_string(80)
 		printf("--class+tag: [%v]\n", clstag)
 		// skip version
 		b.read_nbytes(2)
 		// skip object bits and unique id
-		id := b.ntou4()
-		bits := b.ntou4()
-		//b.read_nbytes(8)
-		dprintf("id=%v bits=%v\n", id, bits)
+		b.read_nbytes(8)
 	}
 	name :=  b.read_tstring()
 
 
 	elmts = make([]Object, nobjs)
 	for i := 0; i < nobjs; i++ {
+		dprintf("--[%d]...\n", i)
 		obj := b.read_object()
+		dprintf("--[%d]... [done]\n", i)
 		elmts[i] = obj
 	}
 	//FIXME: buffer.check_byte_count(s,c,"TObjArray")

File pkg/groot/leaf.go

+package groot
+
+import (
+	"reflect"
+)
+
+type LeafI struct {
+	base baseLeaf
+	min int32
+	max int32
+	data []int
+}
+
+func (leaf *LeafI) Class() Class {
+	panic("not implemented")
+}
+
+func (leaf *LeafI) Name() string {
+	return leaf.base.name
+}
+
+func (leaf *LeafI) Title() string {
+	return leaf.base.title
+}
+
+func (leaf *LeafI) ROOTDecode(b *Buffer) (err error) {
+
+	vers, pos, bcnt := b.read_version()
+	dprintf("leafI-vers=%v pos=%v bcnt=%v\n", vers, pos, bcnt)
+	err = leaf.base.ROOTDecode(b)
+	if err != nil {
+		return err
+	}
+	leaf.min = b.ntoi4()
+	leaf.max = b.ntoi4()
+	leaf.data = make([]int, int(leaf.base.length))
+	dprintf("leafI min=%v max=%v len=%d\n", leaf.min, leaf.max, len(leaf.data))
+	return
+}
+
+func (leaf *LeafI) ROOTEncode(b *Buffer) (err error) {
+	//FIXME
+	panic("not implemented")
+}
+
+func init() {
+	f := func() reflect.Value {
+		o := &LeafI{}
+		return reflect.ValueOf(o)
+	}
+	Factory.db["TLeafI"] = f
+	Factory.db["*groot.LeafI"] = f
+}
+
+// EOF