import jsonArray
import time
import json
#from redis.sentinel import Sentinel
import connect
import sys
import numpy
if __name__ == '__main__':
    # ======Try to connect NEON server
  
    #sentinel=Sentinel([('10.1.53.240', 9001),('10.1.53.240', 9011),('10.1.53.240', 9021)], socket_timeout=0.1)
    #sentinel=Sentinel([('10.1.33.141', 9001),('10.1.33.141', 9011),('10.1.33.141', 9021)], socket_timeout=0.1)
    #r=sentinel.master_for('neonmaster', socket_timeout=20, password='sanlie;123')

    ip_port =  [('10.1.34.116', 9001), ('10.1.34.116',9001)]
    #ip_port = [('10.1.53.240', 9001), ('10.1.53.240',9011), ('10.1.53.240',9021)]
    passwd = 'sanlie;123'

    r= connect.connectNeon(ip_port, passwd, 10)
    r_read = r.getRedisRead()

    #path1='/SANS/workspace/detector/'+sys.argv[1]+'/tof' 
    path1='/SANS/workspace/detector/'+sys.argv[1]+'/value' 
    #path1='/SANS/workspace/monitor1/value' 
    #path1='/SANS/drone/proton_charge' 
    v=r_read.get(path1)
    #print type(json.loads(v))
    #print v
    value=jsonArray.jsonDecoder(v)
    #print value
    #'''
    #print "dim of data: ",numpy.array(value).shape
    a=0
    num=1
    for ix in value:
        a+=sum(ix)
        #print "pid:",num," counts:",sum(ix)
        num+=1
    print "total neutron counts: ",a
    #'''
