Example #1
0
def convertToROOT(path, ascii_file):
    try:
        ascifilename = path + '/' + ascii_file + '.txt'
        spamReader = csv.reader(open(ascifilename, 'rb'),
                                delimiter=' ',
                                skipinitialspace=True)
        print "ASCI file name =", ascifilename
    except IOError:
        print 'File %s does not exist' % (ascifilename)
        return 666

    stuff = MyStruct()

    ArrSize = 3700

    nB1 = array('i', [0])
    nB2 = array('i', [0])
    b1_bunches = array('i', ArrSize * [0])
    b2_bunches = array('i', ArrSize * [0])
    b1_time_zc = array('f', ArrSize * [0])
    b2_time_zc = array('f', ArrSize * [0])
    #b1_time_le   = array('f', ArrSize*[0])
    #b2_time_le   = array('f', ArrSize*[0])
    b1_amp = array('f', ArrSize * [0])
    b2_amp = array('f', ArrSize * [0])
    b1_int = array('f', ArrSize * [0])
    b2_int = array('f', ArrSize * [0])
    b1_len = array('f', ArrSize * [0])
    b2_len = array('f', ArrSize * [0])
    nCol = array('i', [0])
    deltaT = array('f', [0])
    bMode = array('i', [0])

    rootFile = TFile(path + '/root/' + ascii_file + '.root', "recreate")
    bunchTree = TTree("bunchTree", "")

    bunchTree.Branch(
        "vars", stuff,
        "version/F:status/i:scale/F:b1_offset:b1_gain:b2_offset:b2_gain:orb_len_trig:orb_len_1:orb_1_2:cog_ddly_c3_c4:cog_ddly_c1_c3:cog_ddly_c2_c4:cog_ddly_c1_c2"
    )
    bunchTree.Branch("time", AddressOf(stuff, 'daTime'), "daTime/l")

    bunchTree.Branch('nB1', nB1, 'nB1/I')
    bunchTree.Branch('nB2', nB2, 'nB2/I')
    bunchTree.Branch('b1_bunches', b1_bunches, 'b1_bunches[nB1]/I')
    bunchTree.Branch('b2_bunches', b2_bunches, 'b2_bunches[nB2]/I')
    bunchTree.Branch('b1_time_zc', b1_time_zc, 'b1_time_zc[nB1]/F')
    bunchTree.Branch('b2_time_zc', b2_time_zc, 'b2_time_zc[nB2]/F')
    #bunchTree.Branch('b1_time_le', b1_time_le, 'b1_time_le[nB1]/F')
    #bunchTree.Branch('b2_time_le', b2_time_le, 'b2_time_le[nB2]/F')
    bunchTree.Branch('b1_amp', b1_amp, 'b1_amp[nB1]/F')
    bunchTree.Branch('b2_amp', b2_amp, 'b2_amp[nB2]/F')
    bunchTree.Branch('b1_int', b1_int, 'b1_int[nB1]/F')
    bunchTree.Branch('b2_int', b2_int, 'b2_int[nB2]/F')
    bunchTree.Branch('b1_len', b1_len, 'b1_len[nB1]/F')
    bunchTree.Branch('b2_len', b2_len, 'b2_len[nB2]/F')
    bunchTree.Branch('nCol', nCol, 'nCol/I')
    bunchTree.Branch('deltaT', deltaT, 'deltaT/F')
    bunchTree.Branch('bMode', bMode, 'bMode/I')

    i = 0
    for row in spamReader:
        #if i>500: break
        if (row[0] == "#" or row[2] != "1"): continue

        stuff.version = float(row[0])

        #Parse date and time, save as TDatime
        date = re.split("-|T|:|U|", row[1])
        #print date
        dt = TDatime(int(date[0]), int(date[1]), int(date[2]), int(date[3]),
                     int(date[4]), int(date[5]))
        stuff.daTime = dt.Convert()

        stuff.status = bool(row[2])
        try:
            stuff.scale = float(row[3])
        except ValueError:
            stuff.scale = 1.0
        stuff.b1_offset = float(row[4])
        stuff.b1_gain = float(row[5])
        stuff.b2_offset = float(row[6])
        stuff.b2_gain = float(row[7])
        '''# Zero-crossing '''
        nB1[0] = int(row[8])
        nB2[0] = int(row[10])
        """
      if row[8]!=row[12]:
          print "Miss-match in number of bunches for beam 1 !!!\n",
          continue
      if row[10]!=row[14]:
          continue
          print "Miss-match in number of bunches for beam 2 !!!\n"

      if row[16]!= row[8] or row[18]!= row[10]:
          print "\n \t ---Leading edge and zc Number of bunches don't match --- \n"
          continue
      if row[20]!= row[8] or row[22]!= row[10]:
          print "\n \t --- Number of bunches don't match Amplitudes--- \n"
          continue
      if (nB1[0]!=0 and nB2[0]!=0) and (row[24]!= row[8] or row[27]!= row[10]):
          print "\n \t --- Number of bunches don't match Integrals--- \n"
          print i, [row[a] for a in [24,8,27, 10]]
          continue
      """

        #12,13 = foldovwer stuff

        # This is the arrays for B1
        bunchNum = n.array(re.split(",", row[9]), dtype=n.int)
        time_zc = n.array(re.split(",", row[14]), dtype=n.float)
        amp = n.array(re.split(",", row[16]), dtype=n.float)
        integ = n.array(re.split(",", row[18]), dtype=n.float)
        length = n.array(re.split(",", row[20]), dtype=n.float)

        # Debugging the Intensity problems
        # n.set_printoptions(precision=3)
        # if i>2950 and i<2965:
        #print 'line number ', i, row[1]
        # print 'Int=', integ[0:10]*0.960E9
        #print 'Len=', length[0:3]*1E9
        # for a in range (0,29):
        #print a, row[a][:60]

        for j in range(nB1[0]):
            try:
                b1_bunches[j] = bunchNum[j]
            except IndexError:
                print 'Warning: out of range... but will continue'
                print 'bunchNum', bunchNum

                for a in range(0, 29):
                    print a, row[a][:40]
                return 666

            b1_time_zc[j] = time_zc[j]
            if bunchNum[j] > 3300:
                b1_time_zc[j] += ORBIT_LEN * 1e-9

            b1_amp[j] = amp[j]
            if nB1[0] != 0 and nB2[0] != 0:
                b1_int[j] = integ[j]
                b1_len[j] = length[j]

        # now the same for B2
        bunchNum = n.array(re.split(",", row[11]), dtype=n.int)
        time_zc = n.array(re.split(",", row[15]), dtype=n.float)
        amp = n.array(re.split(",", row[17]), dtype=n.float)
        integ = n.array(re.split(",", row[19]), dtype=n.float)
        length = n.array(re.split(",", row[21]), dtype=n.float)

        for j in range(nB2[0]):
            try:
                b2_bunches[j] = bunchNum[j]
            except IndexError:
                print 'Warning: out of range... but will continue'
                print 'bunchNum', bunchNum
                return 666
            b2_time_zc[j] = time_zc[j]
            if bunchNum[j] > 3300:
                b2_time_zc[j] += ORBIT_LEN * 1e-9

            b2_amp[j] = amp[j]
            if nB1[0] != 0 and nB2[0] != 0:
                b2_int[j] = integ[j]
                b2_len[j] = length[j]
        '''Checks'''

        #if (nB1[0]==358):
        #    print b1_bunches
        '''
      if (nB1[0]==352 and nB2[0]==352):

          print "b1 po", b1_bunches[0], b1_bunches[1], b1_bunches[2]
          print "b2 po", b2_bunches[0], b2_bunches[1], b2_bunches[2]
          print "b1 zc", b1_time_zc[0], b1_time_zc[1], b1_time_zc[2]
          print "b2 zc", b2_time_zc[0], b2_time_zc[1], b2_time_zc[2]
          print "b1 le", b1_time_le[0], b1_time_le[1], b1_time_le[2]
          print "b2 le", b2_time_le[0], b2_time_le[1], b2_time_le[2]
      '''

        stuff.orb_len_trig = 0.0
        stuff.orb_len_1 = 0.0
        stuff.orb_1_2 = 0.0
        stuff.cog_ddly_c3_c4 = 0.0
        stuff.cog_ddly_c1_c3 = 0.0
        stuff.cog_ddly_c2_c4 = 0.0
        stuff.cog_ddly_c1_c2 = 0.0
        if nB1[0] != 0 and nB2[0] != 0:
            stuff.orb_len_trig = float(row[22])
            stuff.orb_len_1 = float(row[23])
            stuff.orb_1_2 = float(row[24])
            stuff.cog_ddly_c3_c4 = float(row[25])
            stuff.cog_ddly_c1_c3 = float(row[26])
            stuff.cog_ddly_c2_c4 = float(row[27])
            stuff.cog_ddly_c1_c2 = float(row[28])

        if stuff.version >= 4.6:
            nCol[0] = int(row[29])
            deltaT[0] = float(row[30])

        if stuff.version >= 4.8:
            #print row[30:]
            bMode = int(row[31])
        else:
            bMode = 0

        bunchTree.Fill()
        i += 1

    bunchTree.Write()
    print 'Number of entries in this tree =', bunchTree.GetEntries()

    rootFile.Close()

    return 42
def convertToROOT(path, ascii_file):
  try:
    ascifilename = path+'/'+ascii_file+'.txt'
    spamReader = csv.reader(open(ascifilename, 'rb'), delimiter=' ', skipinitialspace=True)
    print "ASCI file name =", ascifilename
  except IOError:
    print 'File %s does not exist' % (ascifilename)
    return 666

  stuff = MyStruct()

  ArrSize = 3700

  nB1          = array('i', [ 0 ] )
  nB2          = array('i', [ 0 ] )
  b1_bunches   = array('i', ArrSize*[0])
  b2_bunches   = array('i', ArrSize*[0])
  b1_time_zc   = array('f', ArrSize*[0])
  b2_time_zc   = array('f', ArrSize*[0])
  #b1_time_le   = array('f', ArrSize*[0])
  #b2_time_le   = array('f', ArrSize*[0])
  b1_amp       = array('f', ArrSize*[0])
  b2_amp       = array('f', ArrSize*[0])
  b1_int  = array('f', ArrSize*[0])
  b2_int  = array('f', ArrSize*[0])
  b1_len       = array('f', ArrSize*[0])
  b2_len       = array('f', ArrSize*[0])
  nCol         = array('i', [ 0 ] )
  deltaT       = array('f', [ 0 ] )
  bMode        = array('i', [ 0 ] )


  rootFile    = TFile(path+'/root/'+ascii_file+'.root',"recreate")
  bunchTree = TTree("bunchTree","")

  bunchTree.Branch("vars", stuff, "version/F:status/i:scale/F:b1_offset:b1_gain:b2_offset:b2_gain:orb_len_trig:orb_len_1:orb_1_2:cog_ddly_c3_c4:cog_ddly_c1_c3:cog_ddly_c2_c4:cog_ddly_c1_c2")
  bunchTree.Branch("time",  AddressOf( stuff, 'daTime' ), "daTime/l")

  bunchTree.Branch('nB1', nB1, 'nB1/I')
  bunchTree.Branch('nB2', nB2, 'nB2/I')
  bunchTree.Branch('b1_bunches', b1_bunches, 'b1_bunches[nB1]/I')
  bunchTree.Branch('b2_bunches', b2_bunches, 'b2_bunches[nB2]/I')
  bunchTree.Branch('b1_time_zc', b1_time_zc, 'b1_time_zc[nB1]/F')
  bunchTree.Branch('b2_time_zc', b2_time_zc, 'b2_time_zc[nB2]/F')
  #bunchTree.Branch('b1_time_le', b1_time_le, 'b1_time_le[nB1]/F')
  #bunchTree.Branch('b2_time_le', b2_time_le, 'b2_time_le[nB2]/F')
  bunchTree.Branch('b1_amp', b1_amp, 'b1_amp[nB1]/F')
  bunchTree.Branch('b2_amp', b2_amp, 'b2_amp[nB2]/F')
  bunchTree.Branch('b1_int', b1_int, 'b1_int[nB1]/F')
  bunchTree.Branch('b2_int', b2_int, 'b2_int[nB2]/F')
  bunchTree.Branch('b1_len', b1_len, 'b1_len[nB1]/F')
  bunchTree.Branch('b2_len', b2_len, 'b2_len[nB2]/F')
  bunchTree.Branch('nCol', nCol, 'nCol/I')
  bunchTree.Branch('deltaT', deltaT, 'deltaT/F')
  bunchTree.Branch('bMode', bMode, 'bMode/I')


  i=0
  for row in spamReader:
      #if i>500: break
      if (row[0] == "#" or row[2]!="1"): continue

      stuff.version = float(row[0])

      #Parse date and time, save as TDatime
      date = re.split("-|T|:|U|", row[1])
      #print date
      dt = TDatime(int(date[0]), int(date[1]), int(date[2]), int(date[3]), int(date[4]), int(date[5]))
      stuff.daTime = dt.Convert()

      stuff.status    = bool(row[2])
      try:
          stuff.scale     = float(row[3])
      except ValueError:
          stuff.scale = 1.0
      stuff.b1_offset = float(row[4])
      stuff.b1_gain   = float(row[5])
      stuff.b2_offset = float(row[6])
      stuff.b2_gain   = float(row[7])


      '''# Zero-crossing '''
      nB1[0]    = int(row[8])
      nB2[0]    = int(row[10])


      """
      if row[8]!=row[12]:
          print "Miss-match in number of bunches for beam 1 !!!\n",
          continue
      if row[10]!=row[14]:
          continue
          print "Miss-match in number of bunches for beam 2 !!!\n"

      if row[16]!= row[8] or row[18]!= row[10]:
          print "\n \t ---Leading edge and zc Number of bunches don't match --- \n"
          continue
      if row[20]!= row[8] or row[22]!= row[10]:
          print "\n \t --- Number of bunches don't match Amplitudes--- \n"
          continue
      if (nB1[0]!=0 and nB2[0]!=0) and (row[24]!= row[8] or row[27]!= row[10]):
          print "\n \t --- Number of bunches don't match Integrals--- \n"
          print i, [row[a] for a in [24,8,27, 10]]
          continue
      """

      #12,13 = foldovwer stuff

      # This is the arrays for B1
      bunchNum = n.array(re.split(",",row[9]),  dtype = n.int)
      time_zc  = n.array(re.split(",",row[14]), dtype = n.float)
      amp      = n.array(re.split(",",row[16]), dtype = n.float)
      integ    = n.array(re.split(",",row[18]), dtype = n.float)
      length   = n.array(re.split(",",row[20]), dtype = n.float)

      # Debugging the Intensity problems
      # n.set_printoptions(precision=3)
      # if i>2950 and i<2965:
          #print 'line number ', i, row[1]
          # print 'Int=', integ[0:10]*0.960E9
          #print 'Len=', length[0:3]*1E9
              # for a in range (0,29):
              #print a, row[a][:60]


      for j in range(nB1[0]):
          try:
              b1_bunches[j]  = bunchNum[j]
          except IndexError:
              print 'Warning: out of range... but will continue'
              print 'bunchNum', bunchNum

              for a in range (0,29):
                  print a, row[a][:40]
              return 666


          b1_time_zc[j] = time_zc[j]
          if bunchNum[j] > 3300:
            b1_time_zc[j] += ORBIT_LEN*1e-9

          b1_amp[j]      = amp[j]
          if nB1[0]!=0 and nB2[0]!=0:
              b1_int[j] = integ[j]
              b1_len[j] = length[j]

      # now the same for B2
      bunchNum = n.array(re.split(",",row[11]), dtype = n.int)
      time_zc  = n.array(re.split(",",row[15]), dtype = n.float)
      amp      = n.array(re.split(",",row[17]), dtype = n.float)
      integ    = n.array(re.split(",",row[19]), dtype = n.float)
      length   = n.array(re.split(",",row[21]), dtype = n.float)

      for j in range(nB2[0]):
          try:
              b2_bunches[j]  = bunchNum[j]
          except IndexError:
              print 'Warning: out of range... but will continue'
              print 'bunchNum', bunchNum
              return 666
          b2_time_zc[j]  = time_zc[j]
          if bunchNum[j] > 3300:
            b2_time_zc[j] += ORBIT_LEN*1e-9

          b2_amp[j]      = amp[j]
          if nB1[0]!=0 and nB2[0]!=0:
              b2_int[j] = integ[j]
              b2_len[j] = length[j]



      '''Checks'''

      #if (nB1[0]==358):
      #    print b1_bunches

      '''
      if (nB1[0]==352 and nB2[0]==352):

          print "b1 po", b1_bunches[0], b1_bunches[1], b1_bunches[2]
          print "b2 po", b2_bunches[0], b2_bunches[1], b2_bunches[2]
          print "b1 zc", b1_time_zc[0], b1_time_zc[1], b1_time_zc[2]
          print "b2 zc", b2_time_zc[0], b2_time_zc[1], b2_time_zc[2]
          print "b1 le", b1_time_le[0], b1_time_le[1], b1_time_le[2]
          print "b2 le", b2_time_le[0], b2_time_le[1], b2_time_le[2]
      '''


      stuff.orb_len_trig = 0.0
      stuff.orb_len_1    = 0.0
      stuff.orb_1_2      = 0.0
      stuff.cog_ddly_c3_c4 = 0.0
      stuff.cog_ddly_c1_c3 = 0.0
      stuff.cog_ddly_c2_c4 = 0.0
      stuff.cog_ddly_c1_c2 = 0.0
      if nB1[0]!=0 and nB2[0]!=0:
          stuff.orb_len_trig = float(row[22])
          stuff.orb_len_1    = float(row[23])
          stuff.orb_1_2      = float(row[24])
          stuff.cog_ddly_c3_c4 = float(row[25])
          stuff.cog_ddly_c1_c3 = float(row[26])
          stuff.cog_ddly_c2_c4 = float(row[27])
          stuff.cog_ddly_c1_c2 = float(row[28])

      if stuff.version>=4.6:
          nCol[0]    = int(row[29])
          deltaT[0]  = float(row[30])


      if stuff.version>=4.8:
        #print row[30:]
        bMode = int(row[31])
      else:
        bMode = 0


      bunchTree.Fill()
      i+=1

  bunchTree.Write()
  print 'Number of entries in this tree =', bunchTree.GetEntries()

  rootFile.Close()

  return 42
Example #3
0
def convertToROOT(path, ascii_file):
    try:
      ascifilename = path+'/'+ascii_file+'.txt'
      spamReader = csv.reader(open(ascifilename, 'rb'), delimiter=' ', skipinitialspace=True)
      print "ASCI file name =", ascifilename
    except IOError:
      print 'File %s does not exist' % (ascifilename)
      return

    stuff = MyStruct()

    root_fileName = path+'/root/'+ascii_file+'.root'
    print "Creating the file: ", root_fileName
    root_file    = TFile(root_fileName,"recreate")
    timeTree = TTree("timeTree","")

    timeTree.Branch("vars1", stuff, "version/F:status/I:scale/D:b1_offset:b1_gain:b2_offset:b2_gain:nB1/I:nB2/I:\
b1_phase_min/D:b1_phase_max:b1_phase_mean:b1_phase_sigma:\
b2_phase_min/D:b2_phase_max:b2_phase_mean:b2_phase_sigma:\
bb_phase_min/D:bb_phase_max:bb_phase_mean:bb_phase_sigma:\
bcmain_jitter/F:b1_flag/I:b2_flag/I:nCol/I:bMode/I")

    timeTree.Branch("vars5",  AddressOf( stuff, 'daTime' ), "daTime/l")

    i=0
    for row in spamReader:
        # if i>500: break
        #print row
        if (row[0] == "#" or row[4]=="?"): continue
        #if i>600:   print i, [row[a] for a in [16,17,18,8,9]]

        stuff.version = float(row[0])

        # Parse date and time, save as TDatime
        date = re.split("-|T|:|U|", row[1])
        # print date
        dt = TDatime(int(date[0]), int(date[1]), int(date[2]), int(date[3]), int(date[4]), int(date[5]))
        stuff.daTime = dt.Convert()
        # stuff.daTime = dt.Convert(kTRUE)
        # dt.Print()

        stuff.status    = bool(int(row[2]))
        try:
            stuff.scale     = float(row[3])
        except ValueError:
            stuff.scale = 1.0
        stuff.b1_offset = float(row[4])
        stuff.b1_gain   = float(row[5])
        stuff.b2_offset = float(row[6])
        stuff.b2_gain   = float(row[7])
        stuff.nB1   = int(row[8])
        stuff.nB2   = int(row[9])

        # print "N bunches = ", stuff.nB1, stuff.nB2

        if stuff.nB1!=0:
            if row[10]!="-": stuff.b1_phase_min   = float(row[10])
            if row[11]!="-": stuff.b1_phase_max   = float(row[11])
            if row[12]!="-": stuff.b1_phase_mean  = float(row[12])
            if row[13]!="-": stuff.b1_phase_sigma = float(row[13])
        if stuff.nB2!=0:
            if row[14]!="-": stuff.b2_phase_min   = float(row[14])
            if row[15]!="-": stuff.b2_phase_max   = float(row[15])
            if row[16]!="-": stuff.b2_phase_mean  = float(row[16])
            if row[17]!="-": stuff.b2_phase_sigma = float(row[17])
        if (stuff.nB1!=0 and stuff.nB2!=0):
            if row[18]!="-": stuff.bb_phase_min   = float(row[18])
            if row[19]!="-": stuff.bb_phase_max   = float(row[19])
            if row[20]!="-": stuff.bb_phase_mean  = float(row[20])
            if row[21]!="-": stuff.bb_phase_sigma = float(row[21])

            # print 'Delta T = ', stuff.bb_phase_mean

        # if (len(row)!=22): print "len(row) = ", len(row)
        if len(row)>21:
            stuff.bcmain_jitter = float(row[22])
            stuff.b1_flag = int(row[23])
            stuff.b2_flag = int(row[24])

        if stuff.version>=4.6:
            stuff.nCol  = int(row[25])
        if stuff.version>=4.8:
            #print row[25:]
            stuff.bMode = int(row[26])
        else:
            stuff.bMode = 0

        timeTree.Fill()
        i+=1

    timeTree.Write()
    print timeTree.GetEntries()

    root_file.Close()

    return 42
Example #4
0
def convertToROOT(path, ascii_file):
    try:
        ascifilename = path + '/' + ascii_file + '.txt'
        spamReader = csv.reader(open(ascifilename, 'rb'),
                                delimiter=' ',
                                skipinitialspace=True)
        print "ASCI file name =", ascifilename
    except IOError:
        print 'File %s does not exist' % (ascifilename)
        return

    stuff = MyStruct()

    root_fileName = path + '/root/' + ascii_file + '.root'
    print "Creating the file: ", root_fileName
    root_file = TFile(root_fileName, "recreate")
    timeTree = TTree("timeTree", "")

    timeTree.Branch(
        "vars1", stuff,
        "version/F:status/I:scale/D:b1_offset:b1_gain:b2_offset:b2_gain:nB1/I:nB2/I:\
b1_phase_min/D:b1_phase_max:b1_phase_mean:b1_phase_sigma:\
b2_phase_min/D:b2_phase_max:b2_phase_mean:b2_phase_sigma:\
bb_phase_min/D:bb_phase_max:bb_phase_mean:bb_phase_sigma:\
bcmain_jitter/F:b1_flag/I:b2_flag/I:nCol/I:bMode/I")

    timeTree.Branch("vars5", AddressOf(stuff, 'daTime'), "daTime/l")

    i = 0
    for row in spamReader:
        # if i>500: break
        #print row
        if (row[0] == "#" or row[4] == "?"): continue
        #if i>600:   print i, [row[a] for a in [16,17,18,8,9]]

        stuff.version = float(row[0])

        # Parse date and time, save as TDatime
        date = re.split("-|T|:|U|", row[1])
        # print date
        dt = TDatime(int(date[0]), int(date[1]), int(date[2]), int(date[3]),
                     int(date[4]), int(date[5]))
        stuff.daTime = dt.Convert()
        # stuff.daTime = dt.Convert(kTRUE)
        # dt.Print()

        stuff.status = bool(int(row[2]))
        try:
            stuff.scale = float(row[3])
        except ValueError:
            stuff.scale = 1.0
        stuff.b1_offset = float(row[4])
        stuff.b1_gain = float(row[5])
        stuff.b2_offset = float(row[6])
        stuff.b2_gain = float(row[7])
        stuff.nB1 = int(row[8])
        stuff.nB2 = int(row[9])

        # print "N bunches = ", stuff.nB1, stuff.nB2

        if stuff.nB1 != 0:
            if row[10] != "-": stuff.b1_phase_min = float(row[10])
            if row[11] != "-": stuff.b1_phase_max = float(row[11])
            if row[12] != "-": stuff.b1_phase_mean = float(row[12])
            if row[13] != "-": stuff.b1_phase_sigma = float(row[13])
        if stuff.nB2 != 0:
            if row[14] != "-": stuff.b2_phase_min = float(row[14])
            if row[15] != "-": stuff.b2_phase_max = float(row[15])
            if row[16] != "-": stuff.b2_phase_mean = float(row[16])
            if row[17] != "-": stuff.b2_phase_sigma = float(row[17])
        if (stuff.nB1 != 0 and stuff.nB2 != 0):
            if row[18] != "-": stuff.bb_phase_min = float(row[18])
            if row[19] != "-": stuff.bb_phase_max = float(row[19])
            if row[20] != "-": stuff.bb_phase_mean = float(row[20])
            if row[21] != "-": stuff.bb_phase_sigma = float(row[21])

            # print 'Delta T = ', stuff.bb_phase_mean

        # if (len(row)!=22): print "len(row) = ", len(row)
        if len(row) > 21:
            stuff.bcmain_jitter = float(row[22])
            stuff.b1_flag = int(row[23])
            stuff.b2_flag = int(row[24])

        if stuff.version >= 4.6:
            stuff.nCol = int(row[25])
        if stuff.version >= 4.8:
            #print row[25:]
            stuff.bMode = int(row[26])
        else:
            stuff.bMode = 0

        timeTree.Fill()
        i += 1

    timeTree.Write()
    print timeTree.GetEntries()

    root_file.Close()

    return 42