3 from collections
import OrderedDict
4 from AthenaCommon.Logging
import logging
7 log = logging.getLogger( __name__ )
15 grouping_order = [
'AllTag',
'JetMET',
'MinBias',
'Beamspot',
'MuonnoL1',
'AllProbe']
17 from TriggerMenuMT.HLT.Menu.SignatureDicts
import getSignatureGroupingDict
25 signature_for_alignment = signature + extra
27 log.debug(
"[get_alignment_group_from_pattern] Searching for alignment group for %s",signature_for_alignment)
29 if signature_for_alignment
in the_signature_grouping.keys():
30 return the_signature_grouping[signature_for_alignment]
31 elif signature
in the_signature_grouping.keys():
32 log.debug(
"[get_alignment_group_from_pattern] Falling back to signature alignment grouping for %s (%s)",signature, extra)
33 return the_signature_grouping[signature]
35 log.debug(
"[get_alignment_group_from_pattern] No dedicated alignment grouping for signature %s (%s)",signature, extra)
42 list_of_groups = [x[1]
for x
in config_tuples]
44 if len(list_of_groups) == len(
set(list_of_groups)):
48 unique_list = OrderedDict()
49 for ag_length, ag
in config_tuples:
51 if ag_length > unique_list[ag]:
52 unique_list[ag] = ag_length
54 unique_list[ag] = ag_length
56 unique_config_tuples = []
57 for ag, ag_length
in unique_list.items():
58 unique_config_tuples += [(ag_length, ag)]
59 return unique_config_tuples
62 """ Class to hold/calculate chain alignment """
63 def __init__(self, combinations_in_menu, groups_to_align, length_of_configs):
77 for value
in the_signature_grouping.values():
113 for comb_pair
in list(itertools.combinations(comb,2)):
117 _,eigenvecs = np.linalg.eig(the_matrix)
121 eigenvecs = np.transpose(eigenvecs)
124 pre_unique_sets =
list(
set([tuple(np.nonzero(eigenvec)[0])
for eigenvec
in eigenvecs]))
129 for aset
in pre_unique_sets:
130 if len(unique_sets) == 0 :
134 for ibset,bset
in enumerate(unique_sets):
138 elif set(aset).issubset(
set(bset)):
141 elif set(bset).issubset(
set(aset)):
142 unique_sets.pop(ibset)
143 unique_sets += [aset]
152 unique_by_sig = [[ self.
inverse_sig_dict[sig_int]
for sig_int
in setlist ]
for setlist
in unique_sets]
156 for aset
in unique_by_sig:
158 sig_to_set[sig] = aset
188 return all_groups_to_align[:index_of_chain_group]
193 if len(
set(chainDict[
'alignmentGroups'])) != 1:
194 log.error(
"Cannot call single_align on chain %s with alignment groups %s",
195 chainDict[
'chainName'],
",".
join(chainDict[
'alignmentGroups']))
196 raise Exception(
"Will not proceed, the chain is not suitable for single alignment.")
198 alignment_grp = chainDict[
'alignmentGroups'][0]
201 log.debug(
"Finished with retrieving chain configuration for chain %s", chainDict[
'chainName'])
202 chainConfig.numberAllSteps()
206 log.debug(
"Finished with retrieving chain configuration for chain %s", chainDict[
'chainName'])
207 chainConfig.numberAllSteps()
212 aligngroups_set.reverse()
214 for align_grp_to_align
in aligngroups_set:
215 chainConfig.insertEmptySteps(
'Empty'+align_grp_to_align+
'Align',self.
length_of_configs[align_grp_to_align],0)
216 log.debug(
"Finished with retrieving chain configuration for chain %s", chainDict[
'chainName'])
217 chainConfig.numberAllSteps()
221 def multi_align(self, chainDict, chainConfig, lengthOfChainConfigs):
225 alignment_grps = chainDict[
'alignmentGroups']
229 log.error(
" one of the alignmentGroups in %s is not available in the sets to align dictionary!", alignment_grps)
230 raise Exception(
"MenuAlignment.analyse_combinations() needs checking, this should never happen.")
232 log.error(
" the alignmentGroups %s point to different sets in the sets to align dictionary", alignment_grps)
233 for x
in alignment_grps:
235 raise Exception(
"MenuAlignment.analyse_combinations() needs checking, this should never happen.")
250 for config_length,config_grp
in lengthOfChainConfigs:
252 length_firstgrp = config_length
254 if length_firstgrp < max_length_firstgrp:
256 needed_steps = max_length_firstgrp - length_firstgrp
257 chainConfig.insertEmptySteps(
'Empty'+self.
sets_to_align[alignment_grps[0]][0]+
'Align',needed_steps,length_firstgrp)
259 elif length_firstgrp > max_length_firstgrp:
260 log.error(
"%s first signature length %d is greater than the max calculated, %d",chainDict.name,length_firstgrp, max_length_firstgrp)
261 raise Exception(
"Probably something went wrong in GenerateMenuMT.generateChains()!")
267 log.error(
" one of the alignmentGroups in %s is not available in the sets to align dictionary!", alignment_grps)
268 raise Exception(
"MenuAlignment.analyse_combinations() needs checking, this should never happen.")
270 log.error(
" the alignmentGroups %s point to different sets in the sets to align dictionary", alignment_grps)
271 for x
in alignment_grps:
273 raise Exception(
"MenuAlignment.analyse_combinations() needs checking, this should never happen.")
283 alignment_grps_ordered = [x
for x
in alignment_grp_ordering
if x
in alignment_grps]
291 aligngroups_set.reverse()
292 grp_masks = [x
in alignment_grps_ordered
for x
in aligngroups_set]
294 for align_grp,grp_in_chain
in zip(aligngroups_set,grp_masks):
296 for config_length,config_grp
in lengthOfChainConfigs:
297 if config_grp == align_grp:
298 grp_lengths += [config_length]
302 for istep,(align_grp,grp_in_chain,length_in_chain)
in enumerate(zip(aligngroups_set,grp_masks,grp_lengths)):
305 n_steps_before_grp = 0
306 if istep < len(grp_lengths)-1:
307 n_steps_before_grp =
sum(grp_lengths[istep+1:])
310 if length_in_chain < max_length_grp:
312 needed_steps = max_length_grp - length_in_chain
313 start_step = n_steps_before_grp + length_in_chain
314 chainConfig.insertEmptySteps(
'Empty'+align_grp+
'Align',needed_steps,start_step)
318 chainConfig.insertEmptySteps(
'Empty'+align_grp+
'Align',self.
length_of_configs[align_grp],n_steps_before_grp)
320 log.error(
"Should never reach this point. Ordered alignmentGroups: %s, sets_to_align: %s",alignment_grps_ordered,self.
sets_to_align)
321 raise Exception(
"MenuAlignment.multi_align() needs checking, this should never happen.")
323 log.debug(
"Finished with retrieving chain configuration for chain %s", chainDict[
'chainName'])
324 chainConfig.numberAllSteps()