Anonymous avatar Anonymous committed f3af75b

reduce malloc pressure + fixed indices of jmohep/jdahep to be C-consistent

Comments (0)

Files changed (1)

 	Encode(v interface{}) os.Error
 }
 
-func max(i,j int) int {
-	switch i > j {
-	case true:
-		return i
-	default:
-		return j
+// the global event, mapped onto the HEPEVT common block
+var g_evt Event
+
+func GetEvent() *Event {
+	evt := &g_evt
+	evt.Nevhep = EventNumber()
+	evt.Nhep = NumberEntries()
+	if len(evt.Isthep) > evt.Nhep {
+		evt.Isthep = evt.Isthep[:evt.Nhep]
+		evt.Idhep  = evt.Idhep[:evt.Nhep]
+		evt.Jmohep = evt.Jmohep[:evt.Nhep]
+		evt.Jdahep = evt.Jdahep[:evt.Nhep]
+		evt.Phep   = evt.Phep[:evt.Nhep]
+		evt.Vhep   = evt.Vhep[:evt.Nhep]
+	} else {
+		sz := evt.Nhep - len(evt.Isthep)
+		evt.Isthep = append(evt.Isthep, make([]int, sz)...)
+		evt.Idhep  = append(evt.Idhep,  make([]int, sz)...)
+		evt.Jmohep = append(evt.Jmohep, make([][2]int, sz)...)
+		evt.Jdahep = append(evt.Jdahep, make([][2]int, sz)...)
+		evt.Phep   = append(evt.Phep, make([][5]float64, sz)...)
+		evt.Vhep   = append(evt.Vhep, make([][4]float64, sz)...)
 	}
-	return j
-}
-func GetEvent() *Event {
-	evt := &Event{Nevhep: EventNumber(),	Nhep: NumberEntries()}
-	evt.Isthep = make([]int, evt.Nhep)
-	evt.Idhep  = make([]int, evt.Nhep)
-	evt.Jmohep = make([][2]int, evt.Nhep)
-	evt.Jdahep = make([][2]int, evt.Nhep)
-	evt.Phep =   make([][5]float64, evt.Nhep)
-	evt.Vhep =   make([][4]float64, evt.Nhep)
 
 	for i:=0; i != evt.Nhep; i++ {
 		evt.Isthep[i] = StatusCode(i)
 		evt.Idhep[i]  = PdgId(i)
 		// -1 to correct for fortran index value
-		// if return value <0 => no parent
-		fp := FirstParent(i)-1
-		evt.Jmohep[i][0] = fp //max(0, fp)
+		evt.Jmohep[i][0] = FirstParent(i)-1
 		//println("::firstparent#",i,evt.Jmohep[i][0])
 		// -1 to correct for fortran index value
-		lp := LastParent(i)-1
-		evt.Jmohep[i][1] = lp //max(0, lp)
+		evt.Jmohep[i][1] = LastParent(i)-1
 		// -1 to correct for fortran index value
-		// if return value <0 => no child
-		fc := FirstChild(i)-1
-		evt.Jdahep[i][0] = fc //max(0, fc)
+		evt.Jdahep[i][0] = FirstChild(i)-1
 		// -1 to correct for fortran index value
-		lc := LastChild(i)-1
-		evt.Jdahep[i][1] = lc //max(0, lc)
+		evt.Jdahep[i][1] = LastChild(i)-1
 		evt.Phep[i][0] = Px(i)
 		evt.Phep[i][1] = Py(i)
 		evt.Phep[i][2] = Pz(i)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.