All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LVDSpatterns.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Applies shifts on a specified pairing pattern and produces an output
4 # good for being pasted in a configuration file in JSON/FHiCL format.
5 #
6 # The applied pattern is coded in MainPattern.
7 #
8 
9 from __future__ import print_function
10 
11 #
12 # y
13 # /\
14 # ||
15 # || | | |
16 # || | 4 7 14 | 17 24 27 |
17 # || | 1 9 11 | 19 21 29 |
18 # || | 3 6 13 | 16 23 26 |
19 # || | 0 8 10 | 18 20 28 |
20 # || | 2 5 12 | 15 22 25 |
21 # || | | |
22 # ||
23 # ##====================================================================> z
24 #
25 # pattern in three levels:
26 # * inner: pairs (or single channels)
27 # * middle: line-group
28 # * outer: pattern-group
29 #
30 # line-groups are printed each on its own line; there is no other meaning
31 # in that middle layer beyond output eye candy.
32 #
33 
34 MainPattern = [
35  [
36  [ 0, 2, ],
37  [ 1, 4, ],
38  [ 3, 6, ],
39  [ 5, 8, ],
40  [ 7, 9, ],
41  [ 10, 12, ],
42  [ 11, 14, ],
43  [ 13 ],
44  ],
45  [
46  [ 15, 18, ],
47  [ 16 ],
48  [ 17, 19, ],
49  [ 20, 22, ],
50  [ 21, 24, ],
51  [ 23, 26, ],
52  [ 25, 28, ],
53  [ 27, 29, ],
54  ],
55 ] # MainPattern
56 
57 NChannels = 360
58 
59 
60 # ------------------------------------------------------------------------------
61 class Pattern:
62 
63  def __init__(self, patter, offset):
64  self.pairs = self.shiftPattern(patter, offset)
65 
66  @staticmethod
67  def shiftPattern(pattern, offset):
68  l = list()
69  for orig in pattern:
70  l.append(
71  Pattern.shiftPattern(orig, offset) if isinstance(orig, list)
72  else orig + offset
73  )
74  # for
75  return l
76  # shiftPattern()
77 
78  def __str__(self):
79  return "\n".join(
80  " ".join(
81  "{:12}".format(
82  "[ {} ],".format(
83  ",".join(
84  "{:3d}".format(c) for c in p # elements in pair
85  )
86  )
87  )
88  for p in g # pairs in group
89  )
90  for g in self.pairs # groups
91  )
92  # __str__()
93 
94 # class Pattern
95 
96 
97 def countElements(pattern):
98  c = 0
99  for orig in pattern:
100  c += countElements(orig) if isinstance(orig, list) else 1
101  return c
102 # countElements()
103 
104 
105 # ------------------------------------------------------------------------------
106 if __name__ == "__main__":
107 
108  ChannelsPerPattern = countElements(MainPattern)
109  print("Pattern is made of {} elements.".format(ChannelsPerPattern))
110 
111  for offset in range(0, NChannels, ChannelsPerPattern):
112  pattern = Pattern(MainPattern, offset)
113  print("# offset {}\n{}".format(offset, pattern))
114  # for
115 
116 # main
117 
static std::string format(PyObject *obj, unsigned int pos, unsigned int indent, unsigned int maxlen, unsigned int depth)
Definition: fclmodule.cxx:374
do one_file $F done echo for F in find $TOP name CMakeLists txt print
S join(S const &sep, Coll const &s)
Returns a concatenation of strings in s separated by sep.
list
Definition: file_to_url.sh:28