Skip to content

Commit

Permalink
Merge branch 'python' of https://github.com/CMS-HGCAL/rpi-daq into py…
Browse files Browse the repository at this point in the history
…thon
  • Loading branch information
DAQ committed Sep 24, 2018
2 parents 8fdde65 + bde186a commit 2bbccf4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
40 changes: 20 additions & 20 deletions daq-zmq-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,26 @@ def get_comma_separated_args(option, opt, value, parser):
daq_options=conf.yaml_opt['daq_options']
glb_options=conf.yaml_opt['glb_options']

print "Global options = "+yaml.dump(glb_options)
print("Global options = ",yaml.dump(glb_options))

if glb_options['startServerManually']==False:
os.system("ssh -T pi@"+glb_options['serverIpAdress']+" \"nohup python "+glb_options['serverCodePath']+"/daq-zmq-server.py > log.log 2>&1& \"")

context = zmq.Context()
socket = context.socket(zmq.REQ)
print("Send request to server")
print("Send_String request to server")
socket.connect("tcp://"+glb_options['serverIpAdress']+":5555")

cmd="DAQ_CONFIG"
print cmd
socket.send(cmd)
status=socket.recv()
print(cmd)
socket.send_string(cmd)
status=socket.recv_string()
if status=="READY_FOR_CONFIG":
socket.send(conf.dump())
the_config=socket.recv()
socket.send_string(conf.dump())
the_config=socket.recv_string()
print("Returned DAQ_CONFIG:\n%s"%the_config)
else:
print "WRONG STATUS -> exit()"
print("WRONG STATUS -> exit()")
exit()

dataSize=30786 # 30784 + 2 for injection value
Expand Down Expand Up @@ -105,9 +105,9 @@ def get_comma_separated_args(option, opt, value, parser):
break

cmd="CONFIGURE"
print cmd
socket.send(cmd)
return_bitstring = socket.recv()
print(cmd)
socket.send_string(cmd)
return_bitstring = socket.recv_string()
print("Returned bit string = %s" % return_bitstring)
bitstring=[int(i,16) for i in return_bitstring.split()]
print("\t write bits string in output file")
Expand All @@ -117,10 +117,10 @@ def get_comma_separated_args(option, opt, value, parser):

#data_unpacker=unpacker.unpacker(daq_options['compressRawData'])

# for i in xrange(0,daq_options['nEvent']):
# for i in range(0,daq_options['nEvent']):
# cmd="PROCESS_EVENT"
# socket.send(cmd)
# str_data=socket.recv()
# socket.send_string(cmd)
# str_data=socket.recv_string()
# rawdata=dataStringUnpacker.unpack(str_data)
# print("Receive event %d",i)
# #data_unpacker.unpack(rawdata)
Expand All @@ -130,8 +130,8 @@ def get_comma_separated_args(option, opt, value, parser):
# outputFile.write(byteArray)

cmd="PROCESS_AND_PUSH_N_EVENTS"
socket.send(cmd)
mes=socket.recv()
socket.send_string(cmd)
mes=socket.recv_string()
print(mes)
puller=context.socket(zmq.PULL)
puller.connect("tcp://"+glb_options['serverIpAdress']+":5556")
Expand All @@ -140,17 +140,17 @@ def get_comma_separated_args(option, opt, value, parser):
bar = progressbar.ProgressBar(maxval=daq_options['nEvent'], widgets=[progressbar.Bar('=', '[', ']'), ' ', progressbar.Percentage()])
bar.start()
print("Progression :")
for i in xrange(0,daq_options['nEvent']):
str_data=puller.recv()
for i in range(0,daq_options['nEvent']):
str_data=puller.recv()
rawdata=dataStringUnpacker.unpack(str_data)
bar.update(i+1)
byteArray = bytearray(rawdata)
if options.dataNotSaved==False:
outputFile.write(byteArray)
bar.finish()
puller.close()
socket.send("END_OF_RUN")
if socket.recv()=="CLOSING_SERVER":
socket.send_string("END_OF_RUN")
if socket.recv_string()=="CLOSING_SERVER":
socket.close()
context.term()
break
Expand Down
4 changes: 2 additions & 2 deletions unpacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def unpack(self,rawdata):

def showData(self,eventID):
for sk in range(4):
print "Event = "+str(eventID)+"\t Chip = "+str(sk)+"\t RollMask = "+hex(self.rollMask)
print("Event = "+str(eventID)+"\t Chip = "+str(sk)+"\t RollMask = "+hex(self.rollMask))
for ch in range(128):
stream="channelID = "+str(63-ch%64)+""
for sca in range(15):
stream=stream+" "+str(self.sk2cms_data[sk][ch][sca])
print stream
print(stream)

0 comments on commit 2bbccf4

Please sign in to comment.