Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
src
FWCore
Services
bin
TreeToEdges.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
3
# go to the tree file and pick out all the paths that have hits greater
4
# than the cutoff and convert the entries to edge definitions.
5
6
import
sys
7
8
class
Int
:
9
def
__init__
(self,num):
10
self.
value
= num
11
12
def
inc
(self,num):
13
self.
value
+=num
14
15
def
__repr__
(self):
16
return
str(self.
value
)
17
18
def
runme
(infile,outfile,cutoff):
19
fin = open(infile,
'
r')
20
fout = open(outfile,
'w'
)
21
tree = {}
22
count = 0
23
24
for
line
in
fin.xreadlines():
25
26
a = line.split()
27
id = int(a.pop(0))
28
tot = int(a.pop(0))
29
if
tot < cutoff:
break
30
head = int(a.pop(0))
31
32
for
node
in
a:
33
val = int(node)
34
key = (head,val)
35
36
n = tree.get(key)
37
if
n ==
None
:
38
tree[key] =
Int
(tot)
39
else
:
40
n.inc(tot)
41
head = val
42
43
count += 1
44
45
for
node
in
tree.items():
46
# print node
47
print
>>fout, node[1],
' '
, node[0][0],
' '
, node[0][1]
48
49
if
__name__ ==
"__main__"
:
50
if
len(sys.argv) < 4:
51
print
"usage: "
, sys.argv[0],
" in_tree_file out_edge_file cutoff"
52
sys.exit(1)
53
54
infile = sys.argv[1]
55
outfile = sys.argv[2]
56
cutoff = int(sys.argv[3])
57
print
"cutoff="
,cutoff
58
# if cutoff == 0: cutoff = 1000000000
59
runme
(infile, outfile, cutoff)
TreeToEdges.Int.__repr__
def __repr__
Definition:
TreeToEdges.py:15
TreeToEdges.runme
def runme
Definition:
TreeToEdges.py:18
TreeToEdges.Int
Definition:
TreeToEdges.py:8
TreeToEdges.Int.value
value
Definition:
TreeToEdges.py:10
TreeToEdges.Int.__init__
def __init__
Definition:
TreeToEdges.py:9
TreeToEdges.Int.inc
def inc
Definition:
TreeToEdges.py:12
Generated for CMSSW Reference Manual by
1.8.5