ATLAS Offline Software
Loading...
Searching...
No Matches
trigbs_truncateEvents.py
Go to the documentation of this file.
1#!/usr/bin/env python
2
3# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
4
5#tool to corrupt fragment in data file
6
7import sys
8import array
9
10def readEvent(file):
11 event = array.array('I')
12 event.read(file, 4)
13 if event[0]!=0x1234cccc:
14 inFile.seek(-16,1)
15 return None
16# for val in event:
17# print '%08x' % val
18
19 event.read(file, event[3]/4)
20 return event
21
22def corruptEvent(event,badList):
23 newEvent=array.array('I')
24 headerSize=event[4+2]
25 robIdx=4+headerSize
26 #copy header - we will adjust size at the end
27 newEvent.fromlist(event.tolist()[0:robIdx])
28 reducedWords=0
29 while robIdx<len(event):
30 rob=event[robIdx:robIdx+event[robIdx+1]]
31 #corrupt rob
32 id=rob[4]
33 if (id >= badList[0]) and (id<=badList[1]):
34 print('Found rob to be truncated: %08x - org length %d' % (id,len(rob)))
35 if (len(rob)>50): #don't truncate basically empty fragments
36 newrob=array.array('I',rob[0:len(rob)-20])
37 reducedWords+=20
38 newrob[1]-=20
39 newrob[6]|=(1<<27)|8 #mark as truncated
40 #make sure trailer is messed up
41 newrob[-1]=0xfe77efdd
42 newrob[-2]=0xfe77efdd
43 newrob[-3]=0xfe77efdd
44 rob=newrob
45 else:
46 print('good rob %08x' % id)
47# newEvent.fromlist(rob.tolist())
48 newEvent.extend(rob)
49 robIdx+=event[robIdx+1]
50 newEvent[3]-=4*reducedWords
51 newEvent[5]-=reducedWords
52 return newEvent
53
54input_file=sys.argv[1]
55output_file=sys.argv[2]
56
57inFile = open(input_file, mode='rb')
58outFile= open(output_file, mode='wb')
59
60#first copy headers - should not have any size in it
61cnt=0
62while True:
63 binvalues = array.array('I')
64 binvalues.fromfile(inFile, 1)
65 if binvalues[-1]==0x1234cccc:
66 inFile.seek(-4,1)
67 break
68 binvalues.tofile(outFile)
69
70while True:
71 event=readEvent(inFile)
72 if not event:
73 break
74 #corrupt event
75# corrupt=corruptEvent(event,range(0x00670001,0x0067000c))
76#all of ID
77 corrupt=corruptEvent(event,[0x00100000,0x00350000])
78 corrupt.tofile(outFile)
79
80#copy tail record
81binvalues = array.array('I')
82binvalues.fromfile(inFile, 10)
83binvalues.tofile(outFile)
84
85
void print(char *figname, TCanvas *c1)