go-hep.org/x/hep@v0.38.1/groot/riofs/gendata/pyroot-gen-small-root.py (about)

     1  #!/usr/bin/env python2
     2  import ROOT
     3  from array import array as carray
     4  
     5  ARRAYSZ = 10
     6  EVTMAX = 100
     7  
     8  def main():
     9      fname = "test-small.root"
    10  
    11      compress = True
    12      netopt = 0
    13      splitlevel = 32
    14      bufsiz = 32000
    15      
    16      f = ROOT.TFile.Open(fname, "recreate", "small event file", compress, netopt)
    17      if not f:
    18          raise SystemError()
    19  
    20      t = ROOT.TTree("tree", "my tree title", splitlevel)
    21  
    22      i32 = carray("i", [0])
    23      i64 = carray("l", [0])
    24      u32 = carray("I", [0])
    25      u64 = carray("L", [0])
    26      f32 = carray("f", [0.])
    27      f64 = carray("d", [0.])
    28      s06 = carray("b", [0]*7)
    29  
    30      arr_i32 = carray("i", [0]*ARRAYSZ)
    31      arr_i64 = carray("l", [0]*ARRAYSZ)
    32      arr_u32 = carray("I", [0]*ARRAYSZ)
    33      arr_u64 = carray("L", [0]*ARRAYSZ)
    34      arr_f32 = carray("f", [0]*ARRAYSZ)
    35      arr_f64 = carray("d", [0]*ARRAYSZ)
    36  
    37      n = carray("i", [0])
    38      sli_i32 = carray("i", [0]*ARRAYSZ)
    39      sli_i64 = carray("l", [0]*ARRAYSZ)
    40      sli_u32 = carray("I", [0]*ARRAYSZ)
    41      sli_u64 = carray("L", [0]*ARRAYSZ)
    42      sli_f32 = carray("f", [0]*ARRAYSZ)
    43      sli_f64 = carray("d", [0]*ARRAYSZ)
    44  
    45      t.Branch("Int32", i32, "Int32/I")
    46      t.Branch("Int64", i64, "Int64/L")
    47      t.Branch("UInt32", u32, "UInt32/i")
    48      t.Branch("UInt64", u64, "UInt64/l")
    49      t.Branch("Float32", f32, "Float32/F")
    50      t.Branch("Float64", f64, "Float64/D")
    51      t.Branch("Str", s06, "Str/C")
    52  
    53      t.Branch("ArrayInt32", arr_i32, "ArrayInt32[10]/I")
    54      t.Branch("ArrayInt64", arr_i64, "ArrayInt64[10]/L")
    55      t.Branch("ArrayUInt32", arr_u32, "ArrayInt32[10]/i")
    56      t.Branch("ArrayUInt64", arr_u64, "ArrayInt64[10]/l")
    57      t.Branch("ArrayFloat32", arr_f32, "ArrayFloat32[10]/F")
    58      t.Branch("ArrayFloat64", arr_f64, "ArrayFloat64[10]/D")
    59  
    60      t.Branch("N", n, "N/I")
    61      t.Branch("SliceInt32", sli_i32, "SliceInt32[N]/I")
    62      t.Branch("SliceInt64", sli_i64, "SliceInt64[N]/L")
    63      t.Branch("SliceUInt32", sli_u32, "SliceInt32[N]/i")
    64      t.Branch("SliceUInt64", sli_u64, "SliceInt64[N]/l")
    65      t.Branch("SliceFloat32", sli_f32, "SliceFloat32[N]/F")
    66      t.Branch("SliceFloat64", sli_f64, "SliceFloat64[N]/D")
    67  
    68  
    69      for i in range(EVTMAX):
    70          #print ">>>",i
    71          i32[0] = i
    72          i64[0] = i
    73          u32[0] = i
    74          u64[0] = i
    75  
    76          f32[0] = i
    77          f64[0] = i
    78          for ii,vv in enumerate(bytes("evt-%03d" % i,"ascii")):
    79              s06[ii]=vv
    80              pass
    81          
    82          for jj in range(ARRAYSZ):
    83              arr_i32[jj] = i
    84              arr_i64[jj] = i
    85              arr_u32[jj] = i
    86              arr_u64[jj] = i
    87              arr_f32[jj] = i
    88              arr_f64[jj] = i
    89  
    90          n[0] = i % 10
    91          for jj in range(ARRAYSZ):
    92              sli_i32[jj] = i
    93              sli_i64[jj] = i
    94              sli_u32[jj] = i
    95              sli_u64[jj] = i
    96              sli_f32[jj] = i
    97              sli_f64[jj] = i
    98  
    99  
   100          t.Fill()
   101          pass
   102  
   103      f.Write()
   104      f.Close()
   105  
   106  if __name__ == "__main__":
   107      main()
   108      
   109