ATLAS Offline Software
Loading...
Searching...
No Matches
GenericMonitoringTool.GenericMonitoringArray Class Reference
Collaboration diagram for GenericMonitoringTool.GenericMonitoringArray:

Public Member Functions

 __init__ (self, flags, name, dimensions, **kwargs)
 __getitem__ (self, index)
 toolList (self)
 broadcast (self, member, value)
 defineHistogram (self, varname, title=None, path=None, pattern=None, **kwargs)

Public Attributes

dict Tools = {}
 Postfixes
 Accessors = GenericMonitoringArray._postfixes(dimensions)

Static Protected Member Functions

 _postfixes (dimensions, previous='')

Detailed Description

Array of configurables of GenericMonitoringTool objects

Definition at line 61 of file GenericMonitoringTool.py.

Constructor & Destructor Documentation

◆ __init__()

GenericMonitoringTool.GenericMonitoringArray.__init__ ( self,
flags,
name,
dimensions,
** kwargs )

Definition at line 63 of file GenericMonitoringTool.py.

63 def __init__(self, flags, name, dimensions, **kwargs):
64 self.Tools = {}
65 self.Postfixes, self.Accessors = GenericMonitoringArray._postfixes(dimensions)
66 for postfix in self.Postfixes:
67 self.Tools[postfix] = GenericMonitoringTool(flags, name+postfix,**kwargs)
68

Member Function Documentation

◆ __getitem__()

GenericMonitoringTool.GenericMonitoringArray.__getitem__ ( self,
index )
Forward operator[] on class to the list of tools

Definition at line 69 of file GenericMonitoringTool.py.

69 def __getitem__(self,index):
70 '''Forward operator[] on class to the list of tools'''
71 return self.toolList()[index]
72

◆ _postfixes()

GenericMonitoringTool.GenericMonitoringArray._postfixes ( dimensions,
previous = '' )
staticprotected
Generates a list of subscripts to add to the name of each tool

Arguments:
dimensions -- List containing the lengths of each side of the array off tools
previous -- Strings appended from the other dimensions of the array

Definition at line 138 of file GenericMonitoringTool.py.

138 def _postfixes(dimensions, previous=''):
139 '''Generates a list of subscripts to add to the name of each tool
140
141 Arguments:
142 dimensions -- List containing the lengths of each side of the array off tools
143 previous -- Strings appended from the other dimensions of the array
144 '''
145 import collections
146 assert isinstance(dimensions,list) and len(dimensions)>0, \
147 'GenericMonitoringArray must have list of dimensions.'
148 try:
149 if dimensions==[1]:
150 return [''], {'': ['']}
151 except AttributeError:
152 #Evidently not [1]
153 pass
154 postList = []
155 accessorDict = collections.OrderedDict()
156 first = dimensions[0]
157 if isinstance(first,list):
158 iterable = first
159 elif isinstance(first,int):
160 iterable = range(first)
161 else:
162 #Assume GaudiConfig2.semantics._ListHelper
163 iterable = list(first)
164 for i in iterable:
165 if len(dimensions)==1:
166 postList.append(previous+'_'+str(i))
167 accessorDict[previous+'_'+str(i)]=[str(i)]
168 else:
169 postfixes, accessors = GenericMonitoringArray._postfixes(dimensions[1:],previous+'_'+str(i))
170 postList.extend(postfixes)
171 for acckey, accval in accessors.items():
172 accessorDict[acckey] = [str(i)] + accval
173 return postList, accessorDict
174
175

◆ broadcast()

GenericMonitoringTool.GenericMonitoringArray.broadcast ( self,
member,
value )
Allows one to set attributes of every tool simultaneously

Arguments:
member -- string which contains the name of the attribute to be set
value -- value of the attribute to be set

Definition at line 76 of file GenericMonitoringTool.py.

76 def broadcast(self, member, value):
77 '''Allows one to set attributes of every tool simultaneously
78
79 Arguments:
80 member -- string which contains the name of the attribute to be set
81 value -- value of the attribute to be set
82 '''
83 for tool in self.toolList():
84 setattr(tool,member,value)
85

◆ defineHistogram()

GenericMonitoringTool.GenericMonitoringArray.defineHistogram ( self,
varname,
title = None,
path = None,
pattern = None,
** kwargs )
Propogate defineHistogram to each tool, adding a unique tag.

Arguments:
pattern -- if specified, list of n-tuples of indices for plots to create

Definition at line 86 of file GenericMonitoringTool.py.

86 def defineHistogram(self, varname, title=None, path=None, pattern=None, **kwargs):
87 '''Propogate defineHistogram to each tool, adding a unique tag.
88
89 Arguments:
90 pattern -- if specified, list of n-tuples of indices for plots to create
91 '''
92 unAliased = varname.split(';')[0]
93 _, aliasBase = _alias(varname)
94 if aliasBase is None or aliasBase.strip() == '':
95 raise ValueError(f'Unable to define histogram using definition "{varname}" since we cannot determine its name')
96 if pattern is not None:
97 try:
98 iter(pattern)
99 except TypeError:
100 raise ValueError('Argument to GenericMonitoringArray.defineHistogram must be iterable')
101 if not isinstance(pattern, list):
102 pattern = list(pattern)
103 if len(pattern) == 0: # nothing to do
104 return
105 if isinstance(pattern[0], (str, int)):
106 # assume we have list of strings or ints; convert to list of 1-element tuples
107 pattern = [(_2,) for _2 in pattern]
108 for postfix, tool in self.Tools.items():
109 try:
110 accessors = tuple(self.Accessors[postfix])
111 if pattern is not None:
112 if accessors not in pattern:
113 continue
114 # two options for alias formatting,
115 # a) default convention: (var_0, var_1, etc.)
116 # b) custom formatting: 'alias{0}custom'.format(*(0, 1))
117 aliasBaseFormatted = aliasBase.format(*accessors)
118 if aliasBaseFormatted==aliasBase:
119 # if format call did not do anything, use default
120 aliased = unAliased+';'+aliasBase+postfix
121 else:
122 # if format call changed the alias, use custom
123 aliased = unAliased+';'+aliasBaseFormatted
124 if title is not None:
125 kwargs['title'] = title.format(*accessors)
126 if path is not None:
127 kwargs['path'] = path.format(*accessors)
128 except IndexError as e:
129 log.error('In title or path template of histogram {0}, too many positional '\
130 'arguments were requested. Title and path templates were "{1}" and "{2}", '\
131 'while only {3} fillers were given: {4}.'.format(aliasBase, title,\
132 path, len(accessors), accessors))
133 raise e
134
135 tool.defineHistogram(aliased, **kwargs)
136

◆ toolList()

GenericMonitoringTool.GenericMonitoringArray.toolList ( self)

Definition at line 73 of file GenericMonitoringTool.py.

73 def toolList(self):
74 return list(self.Tools.values())
75

Member Data Documentation

◆ Accessors

GenericMonitoringTool.GenericMonitoringArray.Accessors = GenericMonitoringArray._postfixes(dimensions)

Definition at line 65 of file GenericMonitoringTool.py.

◆ Postfixes

GenericMonitoringTool.GenericMonitoringArray.Postfixes

Definition at line 65 of file GenericMonitoringTool.py.

◆ Tools

dict GenericMonitoringTool.GenericMonitoringArray.Tools = {}

Definition at line 64 of file GenericMonitoringTool.py.


The documentation for this class was generated from the following file: