12 from operator
import itemgetter
15 """Calculate the specific configuration of the current job in the digi
16 task. Try to make each fragment utilize the same amount of CPU and
17 Cache resources. Exploits the fact that the task when sorted by
18 mu value will have long finishing pieces near the beginning and
19 short pieces near the end. A more even solution is obtained by
20 pairing chunks of maxEvents/2 from the beginning and end of the
23 hiMaxEvents,loMaxEvents=0,0
25 hiMaxEvents=loMaxEvents=
int(maxEvents/2)
27 hiMaxEvents=
int((maxEvents-1)/2)
28 loMaxEvents=
int((maxEvents+1)/2)
32 hi_mu_frag=
getFragment(jobnumber,
sorted(task,key=
lambda job: job[
'mu'],reverse=
True),hiMaxEvents)
34 lo_mu_frag=
getFragment(jobnumber,
sorted(task,key=
lambda job: job[
'mu']),loMaxEvents)
36 fragment=
sorted(
sum([hi_mu_frag,lo_mu_frag],[]),key=
lambda job: job[
'run'])
37 if sequentialEventNumbers:
43 """Calculate the specific configuration of the current job in the digi
44 task. Sample the mu values randomly.
47 random.seed(jobnumber)
51 max_index = len(lookup_table) - 1
55 evt_nbr = jobnumber * totalEvents + skipEvents
56 for i
in range(maxEvents):
59 index = lookup_table[random.randint(0, max_index)]
65 'starttstamp': t[
'starttstamp'],
71 item[
'force_new'] = t[
'force_new']
73 if sequentialEventNumbers:
74 item[
'evt_nbr'] = evt_nbr
78 return sorted(new_frag, key=itemgetter(
'run',
'starttstamp'))
81 """ Calculate the specific configuration of the current job in the digi task.
85 raise IndexError(
'There are only %i jobs in this task (not %i).' % (len([1
for i
in taskIterator(task,maxEvents)]) + 1,jobnumber + 1))
92 """ Get the 'i'th job in the task, where each job tries to do maxEvents events.
93 The 'force_new' flag in the LB list ends the task before that LB, ignoring maxEvents.
94 Returns a taskIterator. Can raise StopIteration, so you should nest in try.
96 jobnumber =
max(
int(jobnumber),0)
99 if (i == jobnumber):
return jobs
105 """iterator over a list of dicts (the 'task'). Each dict must contain 'evts', optionally 'force_new'.
108 """create the iterator from task (a list of dicts) and step (the max number of evts. per job)
116 if min(e[
'evts']
for e
in task) < 0:
117 raise ValueError(
"Cannot use empty task lists or negative N(events).")
119 raise ValueError(
"Cannot use tasks that don't always define 'evts':", task)
120 if (step < 1):
raise ValueError(
"Cannot use step size smaller than 1 in a taskIterator.")
124 return (self.
current == another.current)
and (self.
step == another.step)
139 if ( can_do > to_do ) :
151 if self.
current.
get(
'force_new',
False): to_do = 0
156 """ Generate task lookup table
159 for i, item
in enumerate(task):
160 for k
in range(item[
'evts']):
165 """ Calculate sequential event numbers for the defined getFragment.
168 evt_nbr = jobnumber * totalEvents + skipEvents
170 for i
in range(t[
'evts']):
175 'starttstamp': t[
'starttstamp'],