forked from alisw/AliRoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAliTrigScheduler.cxx
370 lines (335 loc) · 13.3 KB
/
AliTrigScheduler.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
/**************************************************************************
* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
* *
* Author: The ALICE Off-line Project. *
* Contributors are mentioned in the code where appropriate. *
* *
* Permission to use, copy, modify and distribute this software and its *
* documentation strictly for non-commercial purposes is hereby granted *
* without fee, provided that the above copyright notice appears in all *
* copies and that both the copyright notice and this permission notice *
* appear in the supporting documentation. The authors make no claims *
* about the suitability of this software for any purpose. It is *
* provided "as is" without express or implied warranty. *
**************************************************************************/
/* $Id$ */
// Author: Andrei Gheata, 05/01/2010
#include "AliTrigScheduler.h"
#include <TMath.h>
#include <TList.h>
#include <TObjArray.h>
#include "AliTrigScheduledEntry.h"
ClassImp(AliTrigScheduledGroup)
//==============================================================================
//
// AliTrigScheduledGroup - A group of scheduled entries that will simply be
// fired-up sequentially. The group delay in global time
// units is the latest start time of the contained
// entries. A group has a priority assigned by the
// owner scheduler object. Groups are fired-up according
// a programable sequence.
//
//==============================================================================
//______________________________________________________________________________
AliTrigScheduledGroup::AliTrigScheduledGroup()
:TNamed(),
fPriority(0),
fDelay(0),
fEntries(NULL)
{
// I/O constructor.
}
//______________________________________________________________________________
AliTrigScheduledGroup::AliTrigScheduledGroup(const char *name, Int_t priority)
:TNamed(name,""),
fPriority(priority),
fDelay(0),
fEntries(new TObjArray())
{
// Constructor.
}
//______________________________________________________________________________
AliTrigScheduledGroup::~AliTrigScheduledGroup()
{
// Destructor.
if (fEntries) delete fEntries;
}
//______________________________________________________________________________
void AliTrigScheduledGroup::AddEntry(AliTrigScheduledEntry *entry)
{
// Add a scheduled entry to the group. There is no check if an entry was added twice !
if (!fEntries) fEntries = new TObjArray();
fEntries->Add(entry);
}
//______________________________________________________________________________
void AliTrigScheduledGroup::FireUp(Int_t time)
{
// Fire-up all entries in the group.
Int_t nentries = GetNentries();
AliTrigScheduledEntry *entry;
for (Int_t i=0; i<nentries; i++) {
entry = (AliTrigScheduledEntry*)fEntries->At(i);
entry->FireUp(time);
}
}
//______________________________________________________________________________
Int_t AliTrigScheduledGroup::GetNentries() const
{
// Get number of scheduled entries in the group.
return (fEntries)?fEntries->GetEntriesFast():0;
}
//______________________________________________________________________________
void AliTrigScheduledGroup::Print(Option_t *option) const
{
// Print the group content.
Int_t nentries = GetNentries();
printf("Group: %s containing %d entries.\n", GetName(), nentries);
TString opt(option);
opt.ToUpper();
// Check if details are requested.
if (!opt.Contains("D")) return;
for (Int_t i=0; i<nentries; i++) {
printf(" %d: ", i);
fEntries->At(i)->Print(option);
}
}
//______________________________________________________________________________
void AliTrigScheduledGroup::RemoveEntry(AliTrigScheduledEntry *entry)
{
// Remove an entry.
if (!fEntries) return;
fEntries->RecursiveRemove(entry);
fEntries->Compress();
}
ClassImp(AliTrigScheduledSequence)
//==============================================================================
//
// AliTrigScheduledSequence - A programable group sequence. Scheduled groups
// are owned and controlled by a trigger scheduler. They
// are fired-up in such a sequence. A sequence supports some
// default modes but can also be programed manually.
//
//==============================================================================
//______________________________________________________________________________
AliTrigScheduledSequence::AliTrigScheduledSequence()
:TNamed(),
fScheduler(NULL),
fNgroups(0),
fType(AliTrigScheduledSequence::kDefault),
fArray(NULL)
{
// I/O constructor
}
//______________________________________________________________________________
AliTrigScheduledSequence::AliTrigScheduledSequence(const char *name, AliTrigScheduler *scheduler)
:TNamed(name,""),
fScheduler(scheduler),
fNgroups(scheduler->GetNgroups()),
fType(AliTrigScheduledSequence::kDefault),
fArray(NULL)
{
// Constructor
if (fNgroups) {
fArray = new Int_t[fNgroups];
for (Int_t i=0; i<fNgroups; i++) fArray[i] = i;
}
}
//______________________________________________________________________________
AliTrigScheduledSequence::~AliTrigScheduledSequence()
{
// Destructor.
if (fArray) delete [] fArray;
}
//______________________________________________________________________________
void AliTrigScheduledSequence::Print(Option_t *) const
{
// Print the sequence.
printf("Sequence: %s scheduled by: %s\n", GetName(), fScheduler->GetName());
printf(" type: %d sequence: ", (Int_t)fType);
for (Int_t i=0; i<fNgroups; i++) printf("%d ", fArray[i]);
printf("\n");
}
//______________________________________________________________________________
void AliTrigScheduledSequence::SortArray(Int_t *array, Bool_t increasing)
{
// Sort the internal sequence array.
Int_t *ind = new Int_t[fNgroups];
TMath::Sort(fNgroups, array, ind, !increasing);
memcpy(fArray, ind, fNgroups*sizeof(Int_t));
delete [] ind;
}
//______________________________________________________________________________
void AliTrigScheduledSequence::Sort(ESortingType type, Int_t *sequence)
{
// Sort the group sequence according a predefined type. The sequence
// custom input array is considered only for kCustom type.
Int_t i;
Int_t *array = 0;
switch (type) {
case AliTrigScheduledSequence::kDefault:
// Just ID permutation
for (i=0; i<fNgroups; i++) fArray[i] = i;
break;
case AliTrigScheduledSequence::kTimeInc:
// Sort by increasing start time
array = new Int_t[fNgroups];
for (i=0; i<fNgroups; i++) {
array[i] = fScheduler->GetScheduledGroup(i)->GetDelay();
}
SortArray(array, kTRUE);
break;
case AliTrigScheduledSequence::kTimeDec:
// Sort by decreasing start time
array = new Int_t[fNgroups];
for (i=0; i<fNgroups; i++) {
array[i] = fScheduler->GetScheduledGroup(i)->GetDelay();
}
SortArray(array, kFALSE);
break;
case AliTrigScheduledSequence::kPriorityInc:
// Sort by increasing priority
array = new Int_t[fNgroups];
for (i=0; i<fNgroups; i++) {
array[i] = fScheduler->GetScheduledGroup(i)->GetPriority();
}
SortArray(array, kTRUE);
break;
case AliTrigScheduledSequence::kPriorityDec:
// Sort by decreasing priority
array = new Int_t[fNgroups];
for (i=0; i<fNgroups; i++) {
array[i] = fScheduler->GetScheduledGroup(i)->GetPriority();
}
SortArray(array, kFALSE);
break;
case AliTrigScheduledSequence::kCustom:
if (!sequence) {
Error("Sort", "Sequence array must be provided for custom type");
return;
}
memcpy(fArray, sequence, fNgroups*sizeof(Int_t));
}
if (array) delete [] array;
}
ClassImp(AliTrigScheduler)
//==============================================================================
// AliTrigScheduler - Device response function scheduler. Every device has a
// scheduler, but the same scheduler can replay responses of
// several devices. A scheduler holds groups of scheduled
// entries. The groups can be replayed in programable
// sequences. A default group and sequence are always created.
//==============================================================================
//______________________________________________________________________________
AliTrigScheduler::AliTrigScheduler()
:TNamed(),
fNgroups(0),
fGroups(NULL),
fSequences(NULL),
fCurrentSequence(NULL)
{
// I/O constructor.
}
//______________________________________________________________________________
AliTrigScheduler::AliTrigScheduler(const char *name)
:TNamed(name,""),
fNgroups(0),
fGroups(new TObjArray()),
fSequences(new TObjArray()),
fCurrentSequence(NULL)
{
// Constructor.
AddGroup("default");
AddSequence("default");
}
//______________________________________________________________________________
AliTrigScheduler::~AliTrigScheduler()
{
// Destructor.
if (fGroups) {fGroups->Delete(); delete fGroups;}
if (fSequences) {fSequences->Delete(); delete fSequences;}
}
//______________________________________________________________________________
void AliTrigScheduler::AddScheduledEntry(AliTrigScheduledEntry *entry, const char *togroup)
{
// Add a scheduled entry to a given group.
AliTrigScheduledGroup *group = GetScheduledGroup(togroup);
if (!group) {
Error("AddScheduledEntry", "Group %s does not exist in scheduler %s", togroup, GetName());
return;
}
group->AddEntry(entry);
}
//______________________________________________________________________________
AliTrigScheduledGroup *AliTrigScheduler::AddGroup(const char *groupname)
{
// Add a group to the list of groups.
if (!fGroups) fGroups = new TObjArray();
if (fGroups->FindObject(groupname)) {
Error("AddGroup", "Scheduler %s contains already a group named: %s", GetName(), groupname);
return NULL;
}
AliTrigScheduledGroup *group = new AliTrigScheduledGroup(groupname);
fGroups->Add(group);
return group;
}
//______________________________________________________________________________
AliTrigScheduledGroup *AliTrigScheduler::AddGroup(AliTrigScheduledGroup *group)
{
// Add a group to the list of groups.
if (!fGroups) fGroups = new TObjArray();
if (fGroups->FindObject(group->GetName())) {
Error("AddGroup", "Scheduler %s contains already a group named: %s", GetName(), group->GetName());
return NULL;
}
fGroups->Add(group);
return group;
}
//______________________________________________________________________________
AliTrigScheduledSequence *AliTrigScheduler::AddSequence(const char *seqname, AliTrigScheduledSequence::ESortingType type, Int_t *sequence)
{
// Add a sequence to the scheduler. Becomes the current sequence.
if (!fSequences) fSequences = new TObjArray();
if (fSequences->FindObject(seqname)) {
Error("AddSequence", "Scheduler %s contains already a sequence named: %s", GetName(), seqname);
return NULL;
}
AliTrigScheduledSequence *seq = new AliTrigScheduledSequence(seqname, (AliTrigScheduler*)this);
seq->Sort(type, sequence);
fCurrentSequence = seq;
return seq;
}
//______________________________________________________________________________
void AliTrigScheduler::FireUp(Int_t time)
{
// Fire-up groups in the order given by the current sequence.
if (!fCurrentSequence) Fatal("FireUp", "No scheduled sequence booked for scheduler: %s", GetName());
Int_t *sequence = fCurrentSequence->GetArray();
AliTrigScheduledGroup *group;
for (Int_t i=0; i<fNgroups; i++) {
group = GetScheduledGroup(sequence[i]);
group->FireUp(time);
}
}
//______________________________________________________________________________
AliTrigScheduledGroup *AliTrigScheduler::GetScheduledGroup(Int_t i) const
{
// Get i-th registered group (scheduling order does not matter, only group addition order).
return (AliTrigScheduledGroup*)fGroups->At(i);
}
//______________________________________________________________________________
AliTrigScheduledGroup *AliTrigScheduler::GetScheduledGroup(const char *name) const
{
// Get a scheduled group by name.
return (AliTrigScheduledGroup*)fGroups->FindObject(name);
}
//______________________________________________________________________________
void AliTrigScheduler::SetGroupPriority(const char *groupname, Int_t priority)
{
// Set the priority of a group.
AliTrigScheduledGroup *group = GetScheduledGroup(groupname);
if (!group) {
Error("SetGroupPriority", "Scheduler %s has no group named: %s", GetName(), groupname);
return;
}
group->SetPriority(priority);
}