forked from EKPCN/MAPSA_Software
-
Notifications
You must be signed in to change notification settings - Fork 0
/
daq.py
1147 lines (865 loc) · 30.5 KB
/
daq.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from classes import *
from xml.dom import minidom
#import elementtree.ElementTree
#from elementtree.ElementTree import Element, SubElement, Comment
import xml.etree.ElementTree
from xml.etree.ElementTree import Element, SubElement, Comment
import ROOT
from ROOT import TH2F, TCanvas, TTree, TBranch, TFile
#from ROOT import TGraph
import sys, select, os, array,subprocess
from array import array
#import ROOT
#from ROOT import TGraph
import datetime
saveout = sys.stdout
from optparse import OptionParser
parser = OptionParser()
parser.add_option('-s', '--setting', metavar='F', type='string', action='store',
default = 'default',
dest = 'setting',
help = 'settings ie default, testbeam etc')
parser.add_option('-C', '--calib', metavar='F', type='string', action='store',
default = 'False',
dest = 'calib',
help = 'calibration')
parser.add_option('-r', '--readout', metavar='F', type='string', action='store',
default = 'both',
dest = 'readout',
help = 'readout which data ie counters, memory, both')
parser.add_option('-f', '--format', metavar='F', type='string', action='store',
default = 'noprocessing',
dest = 'format',
help = 'memout format noprocessing, stubfinding, centroid, stripemulator ')
parser.add_option('-m', '--mpa', metavar='F', type='int', action='store',
default = 1,
dest = 'mpa',
help = 'mpa to configure (0 for all)')
parser.add_option('-c', '--charge', metavar='F', type='int', action='store',
default = 80,
dest = 'charge',
help = 'Charge for caldac')
parser.add_option('-t', '--thresh', metavar='F', type='int', action='store',
default = 90,
dest = 'thresh',
help = 'threshold')
parser.add_option('-T', '--testclock', metavar='F', type='string', action='store',
default = 'glib',
dest = 'testclock',
help = 'test beam clock')
parser.add_option('-n', '--number', metavar='F', type='int', action='store',
default = 0xF,
dest = 'number',
help = 'number of calcstrobe pulses to send')
parser.add_option('-x', '--record', metavar='F', type='string', action='store',
default = 'True',
dest = 'record',
help = 'record this daq cycle')
parser.add_option('-y', '--daqstring', metavar='F', type='string', action='store',
default = 'none',
dest = 'daqstring',
help = 'string to append on daq folder name')
parser.add_option('-z', '--monitor', metavar='F', type='string', action='store',
default = 'False',
dest = 'monitor',
help = 'start event monitor in background')
parser.add_option('-w', '--shutterdur', metavar='F', type='int', action='store',
default = 0xFFFFF,
dest = 'shutterdur',
help = 'shutter duration')
parser.add_option('-v', '--skip', metavar='F', type='string', action='store',
default = 'True',
dest = 'skip',
help = 'skip zero counts')
parser.add_option('-u', '--autospill', metavar='F', type='string', action='store',
default = 'True',
dest = 'autospill',
help = 'write every spill')
parser.add_option('-N', '--norm', metavar='F', type='string', action='store',
default = 'False',
dest = 'norm',
help = 'use normalization mpa scheme')
parser.add_option('-D', '--direction', metavar='F', type='string', action='store',
default = 'glib',
dest = 'direction',
help = 'strip direction (glib or mpa)')
parser.add_option('-L', '--loops', metavar='F', type='int', action='store',
default = -1,
dest = 'loops',
help = 'number of daq loops')
(options, args) = parser.parse_args()
sys.stdout = saveout
daqver=1
a = uasic(connection="file://connections_test.xml",device="board0")
mapsa = MAPSA(a)
firmver = a._hw.getNode("Control").getNode('firm_ver').read()
a._hw.dispatch()
print "Running firmware version " + str(firmver)
sdur = options.shutterdur
snum = options.number
sdel = 0xFFF
slen = 0xFFF
sdist = 0xFF
formarr = ['stubfinding','stripemulator' ,'centroid','noprocessing']
memmode = formarr.index(options.format)
#a._hw.getNode("Control").getNode("logic_reset").write(0x1)
#a._hw.dispatch()
a._hw.getNode("Control").getNode("MPA_clock_enable").write(0x1)
a._hw.dispatch()
mpa_number = options.mpa
mpa_index = mpa_number-1
nmpas=1
mpa = []
for i in range(1,7):
mpa.append(mapsa.getMPA(i))
rbuffer=1
timestr = datetime.datetime.now().time().isoformat().replace(":","").replace(".","")
if options.daqstring!='':
dstr= '_'+options.daqstring
foldername = 'daqout_'+options.setting+'_'+options.format+'_'+timestr+dstr
CE=0
if options.calib == 'True':
CE=1
if options.readout=='both':
AR=1
SR=1
readmode = 0x1
if options.readout=='counters':
AR=1
SR=0
readmode = 0x0
if options.readout=='memory':
AR=0
SR=1
readmode = 0x1
shutters=0
cntsperspill = 0.
Startspill=True
if options.norm == 'False':
thdac = [options.thresh,options.thresh,options.thresh,options.thresh,options.thresh,options.thresh]
else:
thdac = [options.thresh,90,options.thresh,90,options.thresh,90]
Endloop = False
spillnumber = 0
confdict = {'OM':[memmode]*6,'RT':[0]*6,'SCW':[0]*6,'SH2':[0]*6,'SH1':[0]*6,'THDAC':thdac,'CALDAC':[options.charge]*6,'PML':[1]*6,'ARL':[AR]*6,'CEL':[CE]*6,'CW':[0]*6,'PMR':[1]*6,'ARR':[AR]*6,'CER':[CE]*6,'SP':[0]*6,'SR':[SR]*6,'TRIMDACL':[None]*6,'TRIMDACR':[None]*6}
if options.record=='True':
timestr = datetime.datetime.now().time().isoformat().replace(":","").replace(".","")
foldername = 'daqout_'+options.setting+'_'+options.format+'_'+timestr+dstr
commands = []
commands.append('mkdir daqlogs')
commands.append('mkdir daqlogs/'+foldername)
commands.append('cp -r data daqlogs/'+foldername)
logfname = 'daqlogs/'+foldername+'/log_'+timestr+'.log'
if options.monitor=='True':
commands.append('python show.py '+logfname+' &')
for s in commands :
print 'executing ' + s
subprocess.call( [s], shell=True )
tree_vars = {}
tree_vars["SPILL"] = array('L',[0])
#tree_vars["TIMESTAMP"] = array('L',[0])
if options.setting == 'testbeam':
tree_vars["TRIG_COUNTS_SHUTTER"] = array('L',[0])
tree_vars["TRIG_COUNTS_TOTAL_SHUTTER"] = array('L',[0])
tree_vars["TRIG_COUNTS_TOTAL"] = array('L',[0])
tree_vars["TRIG_OFFSET_BEAM"] = array('L',[0]*2048)
tree_vars["TRIG_OFFSET_MPA"] = array('L',[0]*2048)
for i in range(0,6):
tree_vars["AR_MPA_"+str(i)] = array('L',[0]*48)
if options.readout=='both':
tree_vars["SR_BX_MPA_"+str(i)] = array('L',[0]*96)
tree_vars["SR_MPA_"+str(i)] = array('L',[0]*96)
F = TFile('daqlogs/'+foldername+'/output.root','recreate')
tree=TTree("Tree","Tree")
for key in tree_vars.keys():
if "SR" in key:
tree.Branch(key,tree_vars[key],key+"[96]/l")
if "AR" in key:
tree.Branch(key,tree_vars[key],key+"[48]/l")
if "TRIG_OFFSET" in key:
tree.Branch(key,tree_vars[key],key+"[2048]/l")
if "TRIG_COUNTS" in key:
tree.Branch(key,tree_vars[key],key+"[1]/l")
Outf1 = open(logfname, 'w')
sys.stdout = Outf1
print "Firmware Version " + str(firmver)
print "DAQ Version " + str(daqver)
print
print "Options summary"
print "=================="
for opt,value in options.__dict__.items():
print str(opt) +': '+ str(value)
print "=================="
print
print "---------------------------------------------------------------------------"
print "----------------------------Starting Datataking----------------------------"
print "---------------------------------------------------------------------------"
print
else:
Outf1 = saveout
Kill=False
mapsa.daq().Strobe_settings(snum,sdel,slen,sdist,CE)
if options.setting == 'manual':
bufferdata=[]
if options.autospill == 'True':
sys.stdout = saveout
print "Starting DAQ loop. Press Enter to quit"
#raw_input("...")
sys.stdout = Outf1
while Endloop == False:
Endspill = False
Startspill=True
while Endspill == False:
zeroshutters=0
cntsperspill = 0
Startspill=True
spillnumber+=1
sys.stdout = saveout
print "Starting spill " + str(spillnumber)
sys.stdout = Outf1
print
print
print "---------------------------------------------------------------------------"
print "-----------------------------Starting spill " + str(spillnumber)+"------------------------------"
print "---------------------------------------------------------------------------"
print
sys.stdout = saveout
config = mapsa.config(Config=1,string='calibrated')
config.upload()
config.modifyfull(confdict)
while True:
if sys.stdin in select.select([sys.stdin], [], [], 0)[0] :
line = raw_input()
print "Ending loop"
Endspill = True
Endloop = True
break
if zeroshutters>=20:
print "Spill "+str(spillnumber)
Endspill = True
if options.autospill == 'False':
Endloop = True
break
shutters+=1
print
print "---------------------------------------------------------------------------"
print "Total shutters "+str(shutters)
sys.stdout = saveout
print "Total shutters "+str(shutters)
sys.stdout = Outf1
print "Timestamp: " + str(datetime.datetime.now().time().isoformat().replace(":","").replace(".",""))
mapsa.daq().Sequencer_init(0x0,sdur,mem=1)
#print mem
sys.stdout = saveout
pix,mem = mapsa.daq().read_data(1)
sys.stdout = Outf1
parray = []
marray = []
cntspershutter = 0
for i in range(0,6):
pix[i].pop(0)
pix[i].pop(0)
parray.append(pix[i])
sys.stdout = saveout
marray.append(mpa[i].daq().read_memory(mem[i],memmode))
sys.stdout = Outf1
cntsperspill += sum(pix[i])
cntspershutter += sum(pix[i])
sys.stdout = saveout
print "Total counts: " + str(cntsperspill)
print "Counts this shutter: " + str(cntspershutter)
sys.stdout = Outf1
if cntsperspill>100.:
Startspill=False
if cntspershutter == 0 and options.skip=='True':
sys.stdout = saveout
sys.stdout = Outf1
if Startspill==False:
zeroshutters+=1
continue
if AR:
print "Counter output"
i=0
temp_vars = {}
for p in parray:
sys.stdout = Outf1
print p
print ""
sys.stdout = saveout
temp_vars["AR_MPA_"+str(i)]=p
i+=1
ipix=0
sys.stdout = Outf1
if SR:
print "Memory output"
i=0
for memo in marray:
memfilt0 = []
memfilt1 = []
for imemo in range(0,len(memo[0])):
if memo[0][imemo]==bufferdata[imemo]:
break
memfilt0.append(memo[0][imemo])
memfilt1.append(memo[1][imemo])
print "BX:"+str(memfilt0)
print "Data:"+str(memfilt1)
print ""
sys.stdout = saveout
BXmemo = np.array(memfilt0)
DATAmemo = np.array(memfilt1)
DATAmemoint = []
for DATAmem in DATAmemo:
DATAmemoint.append(long(DATAmem,2))
temp_vars["SR_BX_MPA_"+str(i)]=BXmemo
temp_vars["SR_MPA_"+str(i)]=DATAmemoint
sys.stdout = Outf1
i+=1
bufferdata=memo[0]
temp_vars["SPILL"] = [spillnumber]
for tv in tree_vars.keys():
sys.stdout = saveout
for i in range(0,len(temp_vars[tv])):
tree_vars[tv][i] = temp_vars[tv][i]
sys.stdout = Outf1
tree.Fill()
print "---------------------------------------------------------------------------"
F.Write()
F.Close()
if options.setting == 'strip':
sys.stdout = saveout
print "Starting DAQ loop. Press Enter to quit"
#raw_input("...")
confdict = {'OM':[memmode]*6,'RT':[0]*6,'SCW':[0]*6,'SH2':[0]*6,'SH1':[0]*6,'THDAC':thdac,'CALDAC':[options.charge]*6,'PML':[0,0,0,0,0,0],'ARL':[AR]*6,'CEL':[CE]*6,'CW':[0]*6,'PMR':[0,0,0,0,0,0],'ARR':[AR]*6,'CER':[CE]*6,'SP':[0]*6,'SR':[SR]*6,'TRIMDACL':[None]*6,'TRIMDACR':[None]*6}
config = mapsa.config(Config=1,string='calibrated')
config.upload()
config.modifyfull(confdict)
config.upload()
a._hw.dispatch()
confdict = {'OM':[memmode]*6,'RT':[0]*6,'SCW':[0]*6,'SH2':[0]*6,'SH1':[0]*6,'THDAC':thdac,'CALDAC':[options.charge]*6,'PML':[1,0,0,0,0,0],'ARL':[AR]*6,'CEL':[CE]*6,'CW':[0]*6,'PMR':[0,0,0,0,0,0],'ARR':[AR]*6,'CER':[CE]*6,'SP':[0]*6,'SR':[SR]*6,'TRIMDACL':[None]*6,'TRIMDACR':[None]*6}
config.modifyfull(confdict,pixels=[5,6])
config.upload()
a._hw.dispatch()
#config.modifypixel( 5,['PML'],[1]*6)
#config._confs[0].upload()
#config.upload()
a._hw.dispatch()
mapsa.daq().header_init()
iread=0
cntsperspill = 0
mpasettings = a._hw.getNode("Utility").getNode("MPA_settings").read()
mpasettingsread = a._hw.getNode("Utility").getNode("MPA_settings_read").read()
#a._hw.getNode("Control").getNode("strip_phase").write(0)
#a._hw.getNode("Utility").getNode("MPA_settings").getNode('strip_direction').write(0)
a._hw.dispatch()
#if options.direction=='glib':
# print "writing glib"
# a._hw.getNode("Strip").getNode("enable_TEMP").write(0x00)
# a._hw.dispatch()
#if options.direction=='mpa':
# print "writing mpa"
a._hw.getNode("Strip").getNode("enable").write(0x3F)
a._hw.dispatch()
read1 = a._hw.getNode("Strip").getNode("enable").read()
a._hw.dispatch()
numloops=0
while True:
if options.loops!=-1:
if numloops>=options.loops:
Kill=True
if sys.stdin in select.select([sys.stdin], [], [], 0)[0] or Kill:
line = raw_input()
print "Ending loop"
Endspill = True
Endloop = True
break
confdict = {'OM':[memmode]*6,'RT':[0]*6,'SCW':[0]*6,'SH2':[0]*6,'SH1':[0]*6,'THDAC':thdac,'CALDAC':[options.charge]*6,'PML':[0,0,0,0,0,0],'ARL':[AR]*6,'CEL':[CE]*6,'CW':[0]*6,'PMR':[0,0,0,0,0,0],'ARR':[AR]*6,'CER':[CE]*6,'SP':[0]*6,'SR':[SR]*6,'TRIMDACL':[None]*6,'TRIMDACR':[None]*6}
config.modifyfull(confdict)
config.upload()
a._hw.dispatch()
confdict = {'OM':[memmode]*6,'RT':[0]*6,'SCW':[0]*6,'SH2':[0]*6,'SH1':[0]*6,'THDAC':thdac,'CALDAC':[options.charge]*6,'PML':[1,0,0,0,0,0],'ARL':[AR]*6,'CEL':[CE]*6,'CW':[0]*6,'PMR':[0,0,0,0,0,0],'ARR':[AR]*6,'CER':[CE]*6,'SP':[0]*6,'SR':[SR]*6,'TRIMDACL':[None]*6,'TRIMDACR':[None]*6}
config.modifyfull(confdict,pixels=[numloops,numloops+1])
config.upload()
a._hw.dispatch()
stripread = a._hw.getNode("Strip").getNode("enable").read()
print "new event"
a._hw.getNode("Control").getNode("full_flag").write(0x1)
a._hw.dispatch()
mpasettings = a._hw.getNode("Utility").getNode("MPA_settings").read()
mpasettingsread = a._hw.getNode("Utility").getNode("MPA_settings_read").read()
a._hw.dispatch()
#print "MPA settings"
#print binary(mpasettings)
#print "MPA settings read"
#print binary(mpasettingsread)
#print "strip enable register"
#print binary(stripread)
#print "Current Configuration:"
#print confdict
#print
mapsa.daq().Sequencer_init(0x0,sdur,mem=1)
pix,mem = mapsa.daq().read_data(1)
print 'reading counts'
parray = []
marray = []
"""for i in range(0,6):
pix[i].pop(0)
pix[i].pop(0)
parray.append(pix[i])
#marray.append(mpa[i].daq().read_memory(mem[i],memmode))
print pix[i]"""
for i in range(0,1):
pix[i].pop(0)
pix[i].pop(0)
#marray.append(mpa[i].daq().read_memory(mem[i],memmode))
rows = [0]*16,[0]*16,[0]*16
for ipixel in range(0,len(pix[i])):
if 0<ipixel<16:
rows[0][ipixel]= pix[i][ipixel]
if 16<ipixel<31:
rows[1][31-ipixel]= pix[i][ipixel]
if 31<ipixel<46:
rows[2][-31+ipixel]= pix[i][ipixel]
for r in rows:
print str(r).replace('[','').replace(']','').replace(',','')
#print mem[1]
write1 = a._hw.getNode("Strip").getNode("write_address").getNode("MPA1").read()
write2 = a._hw.getNode("Strip").getNode("write_address").getNode("MPA2").read()
write3 = a._hw.getNode("Strip").getNode("write_address").getNode("MPA3").read()
write4 = a._hw.getNode("Strip").getNode("write_address").getNode("MPA4").read()
write5 = a._hw.getNode("Strip").getNode("write_address").getNode("MPA5").read()
write6 = a._hw.getNode("Strip").getNode("write_address").getNode("MPA6").read()
strip1 = a._hw.getNode("Strip").getNode("buffer_in").getNode("MPA1").readBlock(0x400)
strip2 = a._hw.getNode("Strip").getNode("buffer_in").getNode("MPA2").readBlock(0x400)
strip3 = a._hw.getNode("Strip").getNode("buffer_in").getNode("MPA3").readBlock(0x400)
strip4 = a._hw.getNode("Strip").getNode("buffer_in").getNode("MPA4").readBlock(0x400)
strip5 = a._hw.getNode("Strip").getNode("buffer_in").getNode("MPA5").readBlock(0x400)
strip6 = a._hw.getNode("Strip").getNode("buffer_in").getNode("MPA6").readBlock(0x400)
out1 = a._hw.getNode("Strip").getNode("buffer_out").getNode("MPA1").read()
out2 = a._hw.getNode("Strip").getNode("buffer_out").getNode("MPA2").read()
out3 = a._hw.getNode("Strip").getNode("buffer_out").getNode("MPA3").read()
out4 = a._hw.getNode("Strip").getNode("buffer_out").getNode("MPA4").read()
out5 = a._hw.getNode("Strip").getNode("buffer_out").getNode("MPA5").read()
out6 = a._hw.getNode("Strip").getNode("buffer_out").getNode("MPA6").read()
a._hw.dispatch()
stripf = []
print "counts"
for strip in [strip1,strip2,strip3,strip4,strip5,strip6]:
temparr = []
for iel in range(0,len(strip)):
temparr.append(binary(strip[iel])[-16:])
stripf.append(temparr)
print
#print "MPA1"
#print "strip write address"
#print hex(write1)
#print "number of strip words"
#print write1>>2
print "strips"
#print stripf[0][1]
#print
for strip in stripf[0]:
if strip!='0000000000000000':
print strip
break
#print stripf[0][0]
#print stripf[0][1]
# print "out buffer"
# print out1
print
"""print "MPA2"
print "strip write address"
print hex(write2)
#print "strip words"
#print write2>>2
print "strip words"
for strip in stripf[1]:
if strip!='0000000000000000':
print strip
print "out buffer"
print out2
print
print "MPA3"
print "strip write address"
print hex(write3)
print "strip words"
for strip in stripf[2]:
if strip!='0000000000000000':
print strip
print "out buffer"
print out3
print
print "MPA4"
print "strip write address"
print hex(write4)
print "strip words"
for strip in stripf[3]:
if strip!='0000000000000000':
print strip
print "out buffer"
print out4
print
print "MPA5"
print "strip write address"
print hex(write5)
print "strip words"
for strip in stripf[4]:
if strip!='0000000000000000':
print strip
print "out buffer"
print out5
print
print "MPA6"
print "strip write address"
print hex(write6)
print "strip words"
for strip in stripf[5]:
if strip!='0000000000000000':
print strip
print "out buffer"
print out6
print
print "-------------------------------"
print """
numloops+=1
if options.setting == 'stripinput':
sys.stdout = saveout
print "Starting DAQ loop. Press Enter to quit"
#raw_input("...")
confdict = {'OM':[memmode]*6,'RT':[0]*6,'SCW':[0]*6,'SH2':[0]*6,'SH1':[0]*6,'THDAC':thdac,'CALDAC':[options.charge]*6,'PML':[1,1,1,1,1,1],'ARL':[AR]*6,'CEL':[CE]*6,'CW':[0]*6,'PMR':[1,1,1,1,1,1],'ARR':[AR]*6,'CER':[CE]*6,'SP':[0]*6,'SR':[SR]*6,'TRIMDACL':[None]*6,'TRIMDACR':[None]*6}
breakout=False
config = mapsa.config(Config=1,string='calibrated')
config.upload()
config.modifyfull(confdict)
config.upload()
a._hw.dispatch()
#config.modifypixel( 5,['PML'],[1]*6)
#config._confs[0].upload()
#config.upload()
#a._hw.dispatch()
mapsa.daq().header_init()
iread=0
cntsperspill = 0
#mpasettingsread = a._hw.getNode("Utility").getNode("MPA_settings_read").read()
#a._hw.getNode("Control").getNode("strip_phase").write(0)
a._hw.getNode("Utility").getNode("MPA_settings").getNode('strip_direction').write(0x3F)
a._hw.dispatch()
a._hw.getNode("Strip").getNode("enable").write(0x0)
a._hw.dispatch()
sphase = 0
numloops=0
while True:
#print sphase
sphase+=1
if sphase>375:
sphase=0
a._hw.getNode("Control").getNode("strip_phase").write(sphase)
a._hw.dispatch()
print sphase
if options.loops!=-1:
if numloops>=options.loops:
Kill=True
if sys.stdin in select.select([sys.stdin], [], [], 0)[0] or Kill:
line = raw_input()
print "Ending loop"
Endspill = True
Endloop = True
break
#confdict = {'OM':[memmode]*6,'RT':[1]*6,'SCW':[1]*6,'SH2':[2]*6,'SH1':[2]*6,'THDAC':thdac,'CALDAC':[options.charge]*6,'PML':[0,0,0,0,0,0],'ARL':[AR]*6,'CEL':[CE]*6,'CW':[2]*6,'PMR':[0,0,0,0,0,0],'ARR':[AR]*6,'CER':[CE]*6,'SP':[0]*6,'SR':[SR]*6,'TRIMDACL':[None]*6,'TRIMDACR':[None]*6}
#config.modifyfull(confdict)
#config.upload()
#a._hw.dispatch()
#confdict = {'OM':[memmode]*6,'RT':[1]*6,'SCW':[1]*6,'SH2':[2]*6,'SH1':[2]*6,'THDAC':thdac,'CALDAC':[options.charge]*6,'PML':[1,1,1,1,1,1],'ARL':[AR]*6,'CEL':[CE]*6,'CW':[2]*6,'PMR':[1,1,1,1,1,1],'ARR':[AR]*6,'CER':[CE]*6,'SP':[0]*6,'SR':[SR]*6,'TRIMDACL':[None]*6,'TRIMDACR':[None]*6}
#config.modifyfull(confdict,pixels=[numloops,numloops+1])
#config.upload()
#a._hw.dispatch()
print "new event"
#a._hw.getNode("Control").getNode("full_flag").write(0x1)
#a._hw.dispatch()
#mpasettings = a._hw.getNode("Utility").getNode("MPA_settings").read()
#mpasettingsread = a._hw.getNode("Utility").getNode("MPA_settings_read").read()
#a._hw.dispatch()
#print "MPA settings"
#print binary(mpasettings)
#print "MPA settings read"
#print binary(mpasettingsread)
#print "strip enable register"
#print binary(stripread)
#print "Current Configuration:"
#print confdict
#print
a._hw.getNode("Utility").getNode("MPA_settings").getNode('strip_direction').write(0x3F)
a._hw.dispatch()
a._hw.getNode("Strip").getNode("buffer_out").getNode("MPA1").write(0x810)
a._hw.getNode("Strip").getNode("buffer_out").getNode("MPA2").write(0x810)
a._hw.getNode("Strip").getNode("buffer_out").getNode("MPA3").write(0x810)
a._hw.getNode("Strip").getNode("buffer_out").getNode("MPA4").write(0x810)
a._hw.getNode("Strip").getNode("buffer_out").getNode("MPA5").write(0x810)
a._hw.getNode("Strip").getNode("buffer_out").getNode("MPA6").write(0x810)
a._hw.dispatch()
a._hw.getNode("Strip").getNode("write").write(0x3F)
a._hw.dispatch()
mapsa.daq().Sequencer_init(0x0,sdur,mem=1)
pix,mem = mapsa.daq().read_data(1)
print 'reading counts'
parray = []
marray = []
#print mem
for i in range(0,6):
pix[i].pop(0)
pix[i].pop(0)
parray.append(pix[i])
marray.append(mpa[i].daq().read_memory(mem[i],memmode))
print marray
for i in range(0,6):
#pix[i].pop(0)
#pix[i].pop(0)
#marray.append(mpa[i].daq().read_memory(mem[i],memmode))
rows = [0]*16,[0]*16,[0]*16
for ipixel in range(0,len(pix[i])):
if 0<=ipixel<16:
rows[0][ipixel]= pix[i][ipixel]
if 16<=ipixel<32:
rows[1][31-ipixel]= pix[i][ipixel]
if 32<=ipixel<48:
rows[2][-32+ipixel]= pix[i][ipixel]
for r in rows:
print str(r).replace('[','').replace(']','').replace(',','')
for me in mem:
print me[0]
for m in me:
if m!='000000000000000000000000000000000000000000000000000000000000000000000000' and m!='00000000000000000000000000000000000000000000000000000000000000000000000':
print m
breakout=True
if breakout:
break
#a._hw.getNode("Strip").getNode("buffer_out").getNode("MPA1").write(0xFFFF)
#a._hw.getNode("Strip").getNode("buffer_out").getNode("MPA2").write(0xFFFF)
#a._hw.getNode("Strip").getNode("buffer_out").getNode("MPA3").write(0xFFFF)
#a._hw.getNode("Strip").getNode("buffer_out").getNode("MPA4").write(0xFFFF)
#a._hw.getNode("Strip").getNode("buffer_out").getNode("MPA5").write(0xFFFF)
#a._hw.getNode("Strip").getNode("buffer_out").getNode("MPA6").write(0xFFFF)
stripf = []
print
numloops+=1
if options.setting == 'testbeam' or options.setting == 'default':
sys.stdout = saveout
print "Starting DAQ loop. Press Enter to quit"
#raw_input("...")
sys.stdout = Outf1
config = mapsa.config(Config=1,string='calibrated')
config.upload()
config.modifyfull(confdict)
if options.setting == 'testbeam':
polltime = 5000
a._hw.getNode("Shutter").getNode("time").write(options.shutterdur)
a._hw.dispatch()
mapsa.daq().Testbeam_init(clock=options.testclock ,calib=0x0)
mapsa.daq().header_init()
if options.setting == 'default':
polltime = 200
mapsa.daq().Sequencer_init(0x1,sdur,mem=1)
mapsa.daq().header_init()
time.sleep(0.1)
for cbuff in range(1,5):
cpix,cmem = mapsa.daq().read_data(cbuff,wait=False)
if options.setting == 'testbeam':
ctotal_triggers,ctrigger_counter,ctrigger_total_counter,cOffset_BEAM,cOffset_MPA = mapsa.daq().read_trig(cbuff)
time.sleep(0.1)
ibuffer=1
iread=0
Endrun = False
zeroshutters = 0
poll = 0
while Endrun == False:
Endspill = False
Startspill=True
cntsperspill = 0
spillnumber+=1
sys.stdout = saveout
print "Starting spill " + str(spillnumber)
start = time.time()
sys.stdout = Outf1
print
print
print "---------------------------------------------------------------------------"
print "-----------------------------Starting spill " + str(spillnumber)+"------------------------------"
print "---------------------------------------------------------------------------"
print
sys.stdout = saveout
while Endspill == False:
buffers_num = a._hw.getNode("Control").getNode('Sequencer').getNode('buffers_num').read()
spill = a._hw.getNode("Control").getNode('Sequencer').getNode('spill').read()
buffers_index = a._hw.getNode("Control").getNode('Sequencer').getNode("buffers_index").read()
a._hw.dispatch()
sys.stdout = saveout
#print buffers_num
if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
for ibuffer in range(1,5):
pix,mem = mapsa.daq().read_data(ibuffer,wait=False)
a._hw.getNode("Control").getNode('testbeam_mode').write(0x0)
line = raw_input()
print "Ending loop"
Endrun = True
Endspill = True
break
poll += 1
if poll % polltime == 0:
sys.stdout = saveout
cur = time.time()
if Startspill==True:
print "Waiting for spill for " +str(cur-start)+ " seconds"
if Startspill==False:
if cur-start>3.:
print "Spill ended"
Endspill == True
if options.setting == 'testbeam':
Endrun = True
break
else:
print "Idle for " +str(cur-start)+ " seconds"
if buffers_num<4:
shutters+=1
iread+=1
sys.stdout = saveout
#print "Buffer index pre trig " + str(buffers_index)
#time.sleep(0.001)
if options.setting == 'testbeam':
total_triggers,trigger_counter,trigger_total_counter,Offset_BEAM,Offset_MPA = mapsa.daq().read_trig(ibuffer)
pix,mem = mapsa.daq().read_data(ibuffer,wait=False)
#print buffers_num
sys.stdout = Outf1
parray = []
marray = []
cntspershutter = 0
for i in range(0,6):
pix[i].pop(0)
pix[i].pop(0)
parray.append(pix[i])
cntspershutter+=sum(pix[i])
sys.stdout = saveout
marray.append(mpa[i].daq().read_memory(mem[i],memmode))
sys.stdout = Outf1
if cntspershutter != 0 or options.setting == 'testbeam':
print "Reading buffer: " + str(ibuffer)
sys.stdout = saveout
print "Reading buffer: " + str(ibuffer)
sys.stdout = Outf1
ibuffer+=1
if ibuffer >4:
ibuffer=1
if cntsperspill>60.:
Startspill=False
if cntspershutter == 0 and options.skip=='True' and options.setting != 'testbeam':
continue
if options.setting == 'testbeam':
offdat = []
#To fix
offsetbeam = [0]*2048
offsetmpa = [0]*2048
sys.stdout = saveout
for i in range(0,trigger_counter):
offsetbeam[i] = Offset_BEAM[i]
offdat.append(1000*(Offset_BEAM[i]-Offset_BEAM[0])/26.5)
offsetmpa[i] = Offset_MPA[i]