]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/ESD/AliTriggerConfiguration.cxx
including task to run in PWGGA train
[u/mrichter/AliRoot.git] / STEER / ESD / AliTriggerConfiguration.cxx
CommitLineData
51f6d619 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16///////////////////////////////////////////////////////////////////////////////
17//
18// This class which defines defines the Trigger Configuration
19//
20// Trigger Configuration defines the trigger setup for a particular run
21// We have default configurations for each running mode (Pb-Pb, p-p, p-A, Calibration, etc).
22// It keep:
23// All the information conained in the CTP configuration file used
24// online during the data taking
25//
26// Configurations could be created and stored in local file.
27// By default the configuration is loaded from the corresponding GRP entry
28// inside the OCDB. There one can have one and only one configuration per run.
29//
30// Example how to create a Trigger Configuration:
31//
32// AliTriggerConfiguration config( "TEST", "Test Configuration" );
33//
34// // Define a Cluster Detector
35// config.AddDetectorCluster( "VZERO ZDC MUON" );
36//
37// // Define the trigger conditions (see AliTriggerCondition.cxx)
38// config.AddCondition( "VZERO_TEST1_L0 & MUON_SPlus_LPt_L0 & ZDC_TEST2_L0", // condition
39// "VO1_M1_ZDC2", // short name
40// "Dummy", // short description
41// 0x0100 ); // class mask (set one bit)
42//
43// config.AddCondition( "VZERO_TEST2_L0 & MUON_SMinus_HPt_L0 & ZDC_TEST1_L0",
44// "VO2_M3_ZDC1",
45// "Dummy",
46// 0x0200 );
47//
48// config.AddCondition( "VZERO_TEST3_L0 | MUON_Unlike_LPt_L0 | ZDC_TEST3_L0",
49// "VO3_M1_ZDC3",
50// "Dummy",
51// 0x0400 );
52// config.CheckInputsConditions("Config.C");
53// config.Print();
54//
55// // save the configuration to file
56// // (default file name $ALICE_ROOT/data/triggerConfigurations.root)
57// config.WriteConfiguration(); or config.WriteConfiguration( filename );
58//
59///////////////////////////////////////////////////////////////////////////////
60#include <Riostream.h>
51f6d619 61
3e2e3ece 62#include <TCint.h>
63#include <TFile.h>
64#include <TKey.h>
65#include <TObjArray.h>
66#include <TObjString.h>
51f6d619 67#include <TObject.h>
3e2e3ece 68#include <TROOT.h>
51f6d619 69#include <TString.h>
51f6d619 70#include <TSystem.h>
2efec14e 71#include <TMath.h>
51f6d619 72
73#include "AliLog.h"
51f6d619 74#include "AliTriggerBCMask.h"
51f6d619 75#include "AliTriggerClass.h"
3e2e3ece 76#include "AliTriggerCluster.h"
51f6d619 77#include "AliTriggerConfiguration.h"
3e2e3ece 78#include "AliTriggerDescriptor.h"
79#include "AliTriggerInput.h"
80#include "AliTriggerInteraction.h"
81#include "AliTriggerPFProtection.h"
51f6d619 82
83ClassImp(AliTriggerConfiguration)
84
85const TString AliTriggerConfiguration::fgkConfigurationFileName("/data/triggerConfigurations.root");
86
87//_____________________________________________________________________________
88AliTriggerConfiguration::AliTriggerConfiguration():
89 TNamed(),
90 fInputs(),
91 fInteractions(),
92 fFunctions(),
93 fPFProtections(),
94 fMasks(),
95 fDescriptors(),
96 fClusters(),
509b7052 97 fClasses(),
98 fVersion(0)
51f6d619 99{
100 // Default constructor
101}
102
103//_____________________________________________________________________________
104AliTriggerConfiguration::AliTriggerConfiguration( TString & name, TString & description ):
105 TNamed( name, description ),
106 fInputs(),
107 fInteractions(),
108 fFunctions(),
109 fPFProtections(),
110 fMasks(),
111 fDescriptors(),
112 fClusters(),
509b7052 113 fClasses(),
114 fVersion(0)
51f6d619 115{
116 // Constructor
117}
118
119//_____________________________________________________________________________
120AliTriggerConfiguration::~AliTriggerConfiguration()
121{
f3eb4d78 122 // Destructor
51f6d619 123 fInputs.SetOwner();
124 fInputs.Delete();
125 fInteractions.SetOwner();
126 fInteractions.Delete();
127 fFunctions.SetOwner();
128 fFunctions.Delete();
129 fPFProtections.SetOwner();
130 fPFProtections.Delete();
131 fMasks.SetOwner();
132 fMasks.Delete();
133 fDescriptors.SetOwner();
134 fDescriptors.Delete();
135 fClusters.SetOwner();
136 fClusters.Delete();
137 fClasses.SetOwner();
138 fClasses.Delete();
139}
140
141//_____________________________________________________________________________
142Bool_t AliTriggerConfiguration::AddInput( AliTriggerInput* input )
143{
f3eb4d78 144 // Add a trigger input to
145 // the list of the trigger inputs
51f6d619 146 if (fInputs.GetEntries() < kNMaxInputs) {
147 fInputs.AddLast( input );
148 return kTRUE;
149 }
150 else {
a5a9f26b 151 AliError("CTP can handle up to 60 inputs ! Impossible to add the required input !");
51f6d619 152 return kFALSE;
153 }
154}
155
156//_____________________________________________________________________________
157AliTriggerInput* AliTriggerConfiguration::AddInput( TString &name, TString &det,
158 UChar_t level, UInt_t signature,
159 UChar_t number )
160{
f3eb4d78 161 // Add a trigger input to
162 // the list of the trigger inputs
51f6d619 163 AliTriggerInput *input = new AliTriggerInput(name,det,level,signature,number);
164 if (!AddInput(input)) {
165 delete input;
166 return NULL;
167 }
168 else
169 return input;
170}
171
172//_____________________________________________________________________________
173AliTriggerInteraction* AliTriggerConfiguration::AddInteraction(TString &name, TString &logic)
174{
f3eb4d78 175 // Add a trigger interaction object to
176 // the list of the trigger interactions
51f6d619 177 AliTriggerInteraction *interact = new AliTriggerInteraction(name,logic);
178 if (!AddInteraction(interact)) {
179 delete interact;
180 return NULL;
181 }
182 else
183 return interact;
184}
185
186//_____________________________________________________________________________
187Bool_t AliTriggerConfiguration::AddInteraction(AliTriggerInteraction *interact)
188{
f3eb4d78 189 // Add a trigger interaction object to
190 // the list of the trigger interactions
51f6d619 191 if (fInteractions.GetEntries() < kNMaxInteractions) {
192 if (interact->CheckInputs(fInputs)) {
193 fInteractions.AddLast( interact );
194 return kTRUE;
195 }
196 else
197 AliError("Invalid interaction ! Impossible to add it !");
198 }
199 else
200 AliError("CTP can handle up to 2 interactions ! Impossible to add the required interaction !");
201
202 return kFALSE;
203}
204
205//_____________________________________________________________________________
206AliTriggerInteraction* AliTriggerConfiguration::AddFunction(TString &name, TString &logic)
207{
f3eb4d78 208 // Add a trigger function object to
209 // the list of the trigger functions
51f6d619 210 AliTriggerInteraction *func = new AliTriggerInteraction(name,logic);
211 if (!AddFunction(func)) {
212 delete func;
213 return NULL;
214 }
215 else
216 return func;
217}
218
219//_____________________________________________________________________________
220Bool_t AliTriggerConfiguration::AddFunction(AliTriggerInteraction *func)
221{
f3eb4d78 222 // Add a trigger function object to
223 // the list of the trigger functions
51f6d619 224 if (fFunctions.GetEntries() < kNMaxFunctions) {
225 if (func->CheckInputs(fInputs)) {
226 fFunctions.AddLast( func );
227 return kTRUE;
228 }
229 else
230 AliError("Invalid logical function ! Impossible to add it !");
231 }
232 else
233 AliError("CTP can handle up to 2 logical functions ! Impossible to add the required interaction !");
234
235 return kFALSE;
236}
237
238//_____________________________________________________________________________
239Bool_t AliTriggerConfiguration::AddPFProtection( AliTriggerPFProtection* pfp )
240{
f3eb4d78 241 // Add a trigger past-future protection object to
242 // the list of the trigger past-future protections
51f6d619 243 if (fPFProtections.GetEntries() < kNMaxPFProtections) {
e0602036 244 //if (pfp->CheckInteractions(fInteractions)) {
245 if (1) {
51f6d619 246 fPFProtections.AddLast( pfp );
247 return kTRUE;
248 }
249 else
250 AliError("Invalid past-future protection ! Impossible to add it !");
251 }
252 else
253 AliError("CTP can handle up to 4 past-future protections ! Impossible to add the required protection !");
254
255 return kFALSE;
256}
257
258//_____________________________________________________________________________
259AliTriggerBCMask* AliTriggerConfiguration::AddMask( TString &name, TString &mask )
260{
f3eb4d78 261 // Add a trigger bunch-crossing mask object to
262 // the list of the trigger bunch-crossing masks
51f6d619 263 AliTriggerBCMask *bcmask = new AliTriggerBCMask(name,mask);
264 if (!AddMask(bcmask)) {
265 delete bcmask;
266 return NULL;
267 }
268 else
269 return bcmask;
270}
271
272//_____________________________________________________________________________
273Bool_t AliTriggerConfiguration::AddMask( AliTriggerBCMask* mask )
274{
f3eb4d78 275 // Add a trigger bunch-crossing mask object to
276 // the list of the trigger bunch-crossing masks
583e63b8 277 if (fMasks.GetEntries() < (kNMaxMasks+1)) { //+1 to account for NONE
51f6d619 278 fMasks.AddLast( mask );
279 return kTRUE;
280 }
281 else
282 AliError("CTP can handle up to 4 bunch-crossing masks ! Impossible to add the required mask !");
283
284 return kFALSE;
285}
286
287//_____________________________________________________________________________
288AliTriggerCluster* AliTriggerConfiguration::AddCluster( TString &name, UChar_t index, TString &detectors)
289{
f3eb4d78 290 // Add a trigger detector readout cluster to
291 // the list of the trigger clusters
51f6d619 292 AliTriggerCluster *clust = new AliTriggerCluster(name,index,detectors);
293 if (!AddCluster(clust)) {
294 delete clust;
295 return NULL;
296 }
297 else
298 return clust;
299
300}
301
302//_____________________________________________________________________________
303Bool_t AliTriggerConfiguration::AddCluster( AliTriggerCluster* cluster )
304{
f3eb4d78 305 // Add a trigger detector readout cluster to
306 // the list of the trigger clusters
51f6d619 307 if (fClusters.GetEntries() < kNMaxClusters) {
308 TString dets(cluster->GetDetectorsInCluster());
309 if (!(dets.IsNull())) {
310 fClusters.AddLast( cluster );
311 return kTRUE;
312 }
313 else
314 AliError("Empty trigger cluster ! Impossible to add it !");
315 }
316 else
317 AliError("CTP can handle up to 6 different detector clusters ! Impossible to add the required cluster !");
318
319 return kFALSE;
320}
321
322//_____________________________________________________________________________
323TString AliTriggerConfiguration::GetActiveDetectors() const
324{
f3eb4d78 325 // Return an string with all active detector
326 // from each cluster
51f6d619 327
328 TString activeDet = "";
329
330 Int_t nclus = fClusters.GetEntriesFast();
331 if( !nclus ) return activeDet;
332
605cb8bb 333 for( Int_t j=0; j<nclus; ++j ) {
51f6d619 334 TString detStr = ((AliTriggerCluster*)fClusters.At(j))->GetDetectorsInCluster();
335 TObjArray* det = detStr.Tokenize(" ");
336 Int_t ndet = det->GetEntriesFast();
605cb8bb 337 for( Int_t k=0; k<ndet; ++k ) {
338 if( activeDet.Contains( ((TObjString*)det->At(k))->String() ) )continue;
51f6d619 339 activeDet.Append( " " );
605cb8bb 340 activeDet.Append( ((TObjString*)det->At(k))->String() );
51f6d619 341 }
342 }
343 return activeDet;
344}
345
346//_____________________________________________________________________________
347TString AliTriggerConfiguration::GetTriggeringDetectors() const
348{
f3eb4d78 349 // Return an string with all detectors
350 // used for triggering
51f6d619 351
352 TString trDet = "";
353
354 Int_t ninputs = fInputs.GetEntriesFast();
355 if( !ninputs ) return trDet;
356
357 for( Int_t j=0; j<ninputs; j++ ) {
358 TString detStr = ((AliTriggerInput*)fInputs.At(j))->GetDetector();
359 if( trDet.Contains( detStr ) ) continue;
360 trDet.Append( " " );
361 trDet.Append( detStr );
362 }
363 return trDet;
364}
365
366//_____________________________________________________________________________
367TString AliTriggerConfiguration::GetTriggeringModules() const
368{
369 // Return an string with all detectors (modules in the AliRoot
370 // simulation sense) used for triggering
371
372 TString trDet = "";
373
374 Int_t ninputs = fInputs.GetEntriesFast();
375 if( !ninputs ) return trDet;
376
377 for( Int_t j=0; j<ninputs; j++ ) {
378 TString detStr = ((AliTriggerInput*)fInputs.At(j))->GetModule();
379 if( trDet.Contains( detStr ) ) continue;
380 trDet.Append( " " );
381 trDet.Append( detStr );
382 }
383 return trDet;
384}
385
386//_____________________________________________________________________________
387AliTriggerDescriptor* AliTriggerConfiguration::AddDescriptor( TString &name, TString &cond )
388{
f3eb4d78 389 // Add a trigger descriptor to
390 // the list of the trigger descriptors
51f6d619 391 AliTriggerDescriptor *desc = new AliTriggerDescriptor(name,cond);
392 if (!AddDescriptor(desc)) {
393 delete desc;
394 return NULL;
395 }
396 else
397 return desc;
398}
399
400//_____________________________________________________________________________
401Bool_t AliTriggerConfiguration::AddDescriptor( AliTriggerDescriptor *desc )
402{
f3eb4d78 403 // Add a trigger descriptor to
404 // the list of the trigger descriptors
51f6d619 405 if (fDescriptors.GetEntries() < kNMaxClasses) {
406 if (desc->CheckInputsAndFunctions(fInputs,fFunctions)) {
407 fDescriptors.AddLast( desc );
408 return kTRUE;
409 }
410 else
411 AliError("Invalid trigger desciptor ! Impossible to add it !");
412 }
413 else
414 AliError("CTP can handle up to 50 different descriptors ! Impossible to add the required descriptor !");
415
416 return kFALSE;
417}
418
419//_____________________________________________________________________________
420Bool_t AliTriggerConfiguration::AddClass( AliTriggerClass *trclass )
421{
f3eb4d78 422 // Add a trigger class to
423 // the list of the trigger classes
51f6d619 424 if (fClasses.GetEntries() < kNMaxClasses) {
425 if (trclass->CheckClass(this)) {
426 fClasses.AddLast( trclass );
427 return kTRUE;
428 }
429 else
430 AliError("Invalid trigger class ! Impossible to add it !");
431 }
432 else
433 AliError("CTP can handle up to 50 different classes ! Impossible to add the required class !");
434
435 return kFALSE;
436}
437
438//_____________________________________________________________________________
439AliTriggerClass *AliTriggerConfiguration::AddClass( TString &name, UChar_t index,
440 AliTriggerDescriptor *desc, AliTriggerCluster *clus,
441 AliTriggerPFProtection *pfp, AliTriggerBCMask *mask,
442 UInt_t prescaler, Bool_t allrare)
443{
f3eb4d78 444 // Add a trigger class to
445 // the list of the trigger classes
51f6d619 446 if (!fDescriptors.FindObject(desc)) {
447 AliError("Invalid descriptor ! Impossible to add the class !");
448 return NULL;
449 }
450 if (!fClusters.FindObject(clus)) {
451 AliError("Invalid cluster ! Impossible to add the class !");
452 return NULL;
453 }
454 if (!fPFProtections.FindObject(pfp)) {
455 AliError("Invalid past-future protection ! Impossible to add the class !");
456 return NULL;
457 }
458 if (!fMasks.FindObject(mask)) {
459 AliError("Invalid bunch-crossing mask ! Impossible to add the class !");
460 return NULL;
461 }
462 AliTriggerClass* trclass = new AliTriggerClass( name,index,desc,clus,pfp,mask,prescaler,allrare );
463 if (!AddClass(trclass)) {
464 delete trclass;
465 return NULL;
466 }
467 else
468 return trclass;
469}
470
471//_____________________________________________________________________________
472AliTriggerClass *AliTriggerConfiguration::AddClass( TString &name, UChar_t index,
473 TString &desc, TString &clus,
474 TString &pfp, TString &mask,
475 UInt_t prescaler, Bool_t allrare)
476{
477 // Add a new trigger class
478 if (!fDescriptors.FindObject(desc)) {
479 AliError("Invalid descriptor ! Impossible to add the class !");
480 return NULL;
481 }
482 if (!fClusters.FindObject(clus)) {
483 AliError("Invalid cluster ! Impossible to add the class !");
484 return NULL;
485 }
486 if (!fPFProtections.FindObject(pfp)) {
487 AliError("Invalid past-future protection ! Impossible to add the class !");
488 return NULL;
489 }
490 if (!fMasks.FindObject(mask)) {
491 AliError("Invalid bunch-crossing mask ! Impossible to add the class !");
492 return NULL;
493 }
494 AliTriggerClass* trclass = new AliTriggerClass( this, name,index,desc,clus,pfp,mask,prescaler,allrare );
495 if (!AddClass(trclass)) {
496 delete trclass;
497 return NULL;
498 }
499 else
500 return trclass;
501}
502
503//_____________________________________________________________________________
43afc9d8 504Bool_t AliTriggerConfiguration::ProcessConfigurationLine(const char* line, Int_t& level)
51f6d619 505{
43afc9d8 506 // processes one line of configuration
51f6d619 507
43afc9d8 508 TString strLine(line);
51f6d619 509
43afc9d8 510 if (strLine.BeginsWith("#")) return kTRUE;
509b7052 511 if (strLine.BeginsWith("PARTITION:")) {
512 strLine.ReplaceAll("PARTITION:","");
513 SetName(strLine.Data());
514 return kTRUE;
515 }
516 if (strLine.BeginsWith("VERSION:")) {
517 strLine.ReplaceAll("VERSION:","");
518 fVersion = strLine.Atoi();
519 return kTRUE;
520 }
51f6d619 521 if (strLine.BeginsWith("INPUTS:")) {
522 level = 1;
43afc9d8 523 return kTRUE;
51f6d619 524 }
525 if (strLine.BeginsWith("INTERACTIONS:")) {
526 level = 2;
43afc9d8 527 return kTRUE;
51f6d619 528 }
529 if (strLine.BeginsWith("DESCRIPTORS:")) {
530 level = 3;
43afc9d8 531 return kTRUE;
51f6d619 532 }
533 if (strLine.BeginsWith("CLUSTERS:")) {
534 level = 4;
43afc9d8 535 return kTRUE;
51f6d619 536 }
537 if (strLine.BeginsWith("PFS:")) {
538 level = 5;
43afc9d8 539 return kTRUE;
51f6d619 540 }
541 if (strLine.BeginsWith("BCMASKS:")) {
542 level = 6;
43afc9d8 543 return kTRUE;
51f6d619 544 }
545 if (strLine.BeginsWith("CLASSES:")) {
546 level = 7;
43afc9d8 547 return kTRUE;
51f6d619 548 }
43afc9d8 549
51f6d619 550 strLine.ReplaceAll("*",'!');
31e839aa 551 strLine.ReplaceAll("~",'!');
51f6d619 552 TObjArray *tokens = strLine.Tokenize(" \t");
553 Int_t ntokens = tokens->GetEntriesFast();
43afc9d8 554 if (ntokens == 0)
555 {
556 delete tokens;
557 return kTRUE;
558 }
51f6d619 559 switch (level) {
560 case 1:
561 // Read inputs
562 if (ntokens != 5) {
43afc9d8 563 AliError(Form("Invalid trigger input syntax (%s)!",strLine.Data()));
564 return kFALSE;
51f6d619 565 }
43afc9d8 566 AddInput(((TObjString*)tokens->At(0))->String(),
51f6d619 567 ((TObjString*)tokens->At(1))->String(),
568 ((TObjString*)tokens->At(2))->String().Atoi(),
569 ((TObjString*)tokens->At(3))->String().Atoi(),
570 ((TObjString*)tokens->At(4))->String().Atoi());
571 break;
572 case 2:
43afc9d8 573 // Read interaction
574 if (ntokens != 2) {
575 AliError(Form("Invalid trigger interaction syntax (%s)!",strLine.Data()));
576 return kFALSE;
577 }
578 AddInteraction(((TObjString*)tokens->At(0))->String(),
51f6d619 579 ((TObjString*)tokens->At(1))->String());
580 break;
581 case 3:
582 // Read logical functions and descriptors
43afc9d8 583 if (ntokens < 2) {
e89c03c6 584 if ((((TObjString*)tokens->At(0))->String().CompareTo("EMPTY") == 0) ||
583e63b8 585 (((TObjString*)tokens->At(0))->String().CompareTo("DTRUE") == 0) ||
e89c03c6 586 (((TObjString*)tokens->At(0))->String().CompareTo("DEMPTY") == 0)) {
587 AddDescriptor(((TObjString*)tokens->At(0))->String(),
588 strLine.ReplaceAll(((TObjString*)tokens->At(0))->String(),""));
589 break;
590 }
591 else {
592 AliError(Form("Invalid trigger descriptor syntax (%s)!",strLine.Data()));
593 return kFALSE;
594 }
43afc9d8 595 }
51f6d619 596 if (((TObjString*)tokens->At(0))->String().BeginsWith("l0f")) {
597 // function
43afc9d8 598 AddFunction(((TObjString*)tokens->At(0))->String(),
51f6d619 599 strLine.ReplaceAll(((TObjString*)tokens->At(0))->String(),""));
600 }
601 else {
43afc9d8 602 AddDescriptor(((TObjString*)tokens->At(0))->String(),
51f6d619 603 strLine.ReplaceAll(((TObjString*)tokens->At(0))->String(),""));
604 }
605 break;
606 case 4:
607 {
43afc9d8 608 if (ntokens < 2) {
609 AliError(Form("Invalid trigger cluster syntax (%s)!",strLine.Data()));
610 return kFALSE;
611 }
af51ca16 612 if (((TObjString*)tokens->At(1))->String().Atoi() <= 0) {
613 AliError(Form("Invalid trigger cluster syntax (%s)!",strLine.Data()));
614 return kFALSE;
615 }
51f6d619 616 TString strTemp;
617 for(Int_t i = 2; i < ntokens; i++) {
618 strTemp += ((TObjString*)tokens->At(i))->String();
619 strTemp += " ";
620 }
43afc9d8 621 AddCluster(((TObjString*)tokens->At(0))->String(),
51f6d619 622 ((TObjString*)tokens->At(1))->String().Atoi(),
623 strTemp);
624 }
625 break;
626 case 5:
627 {
628 AliTriggerPFProtection *pfp = NULL;
909d646e 629 if ((((TObjString*)tokens->At(0))->String().CompareTo("NONE") == 0) ||
630 (((TObjString*)tokens->At(0))->String().CompareTo("NOPF") == 0)) {
51f6d619 631 pfp = new AliTriggerPFProtection(((TObjString*)tokens->At(0))->String());
632 }
633 else {
b87d7e83 634 if (ntokens == 10){
635 pfp = new AliTriggerPFProtection(((TObjString*)tokens->At(0))->String(),
51f6d619 636 ((TObjString*)tokens->At(1))->String(),
637 ((TObjString*)tokens->At(2))->String(),
638 ((TObjString*)tokens->At(3))->String());
b87d7e83 639 pfp->SetNa1(((TObjString*)tokens->At(4))->String().Atoi());
640 pfp->SetNa2(((TObjString*)tokens->At(5))->String().Atoi());
641 pfp->SetNb1(((TObjString*)tokens->At(6))->String().Atoi());
642 pfp->SetNb2(((TObjString*)tokens->At(7))->String().Atoi());
643 pfp->SetTa(((TObjString*)tokens->At(8))->String().Atoi());
644 pfp->SetTb(((TObjString*)tokens->At(9))->String().Atoi());
645 }else if(ntokens == 13){
646 UInt_t pfdef[12];
647 for(Int_t i=0;i<12;i++){
648 TString ss(((TObjString*)tokens->At(i+1))->String());
649 ss.Remove(0,2);
650 UInt_t num=0;
651 for(Int_t j=ss.Length()-1;j>=0;j--){
652 UInt_t nn=ss[j];
417aea4a 653 if(nn >= (UInt_t)'0' && nn <= (UInt_t)'9')nn=nn-(UInt_t)'0'; else
654 if(nn >= (UInt_t)'A' && nn <= (UInt_t)'F')nn=10+nn-(UInt_t)'A'; else
655 if(nn >= (UInt_t)'a' && nn <= (UInt_t)'f')nn=10+nn-(UInt_t)'a'; else{
656 AliError(Form("Invalid trigger pfs syntax (%s)!",strLine.Data()));
657 //return kFALSE;
658 }
b87d7e83 659 num=num+(1<<(ss.Length()-1-j)*4)*nn;
417aea4a 660 //cout << ss[j] << " 2 " << nn << " " << num << endl;
b87d7e83 661 }
662 pfdef[i]=num;
663 }
664 pfp = new AliTriggerPFProtection(((TObjString*)tokens->At(0))->String(),pfdef);
665 }else{
666 AliError(Form("Invalid trigger pfs syntax (%s)!",strLine.Data()));
417aea4a 667 //return kFALSE;
b87d7e83 668 }
51f6d619 669 }
43afc9d8 670 AddPFProtection(pfp);
51f6d619 671 }
672 break;
673 case 6:
43afc9d8 674 if (ntokens > 2) {
675 AliError(Form("Invalid trigger bcmasks syntax (%s)!",strLine.Data()));
676 return kFALSE;
677 }
51f6d619 678 if (((TObjString*)tokens->At(0))->String().CompareTo("NONE") == 0)
583e63b8 679 {
680 AddMask(new AliTriggerBCMask(((TObjString*)tokens->At(0))->String()));
681 }
51f6d619 682 else {
43afc9d8 683 AddMask(((TObjString*)tokens->At(0))->String(),
51f6d619 684 ((TObjString*)tokens->At(1))->String());
685 }
686 break;
687 case 7:
688 {
342b8153 689 if ((ntokens !=8) && (ntokens != 10)) {
43afc9d8 690 AliError(Form("Invalid trigger class syntax (%s)!",strLine.Data()));
691 return kFALSE;
692 }
342b8153 693 AliTriggerClass *trclass=0;
694 if(ntokens == 8)trclass = new AliTriggerClass(this,
695 ((TObjString*)tokens->At(0))->String(),((TObjString*)tokens->At(1))->String().Atoi(),
696 ((TObjString*)tokens->At(2))->String(),((TObjString*)tokens->At(3))->String(),
697 ((TObjString*)tokens->At(4))->String(),((TObjString*)tokens->At(5))->String(),
698 ((TObjString*)tokens->At(6))->String().Atoi(),(Bool_t)(((TObjString*)tokens->At(7))->String().Atoi()));
699 else trclass = new AliTriggerClass(this,
700 ((TObjString*)tokens->At(0))->String(),((TObjString*)tokens->At(1))->String().Atoi(),
701 ((TObjString*)tokens->At(2))->String(),((TObjString*)tokens->At(3))->String(),
702 ((TObjString*)tokens->At(4))->String(),((TObjString*)tokens->At(5))->String(),
703 ((TObjString*)tokens->At(6))->String().Atoi(),(Bool_t)(((TObjString*)tokens->At(7))->String().Atoi()),
704 (((TObjString*)tokens->At(8))->String().Atoi()),(((TObjString*)tokens->At(9))->String().Atoi()));
43afc9d8 705 AddClass(trclass);
51f6d619 706 }
707 default:
708 break;
709 }
710 delete tokens;
43afc9d8 711
712 return kTRUE;
713}
714
715//_____________________________________________________________________________
716AliTriggerConfiguration* AliTriggerConfiguration::LoadConfiguration(TString & configuration)
717{
718 // Load one pre-created Configurations from database/file that match
719 // with the input string 'configuration'
720 // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL"
721 // By default the files are stored in GRP/CTP folder.
722 // The filename is constructed as: GRP/CTP/<configuration>.cfg
723
724 // Load the selected configuration
725 TString filename;
726 if (configuration.EndsWith(".cfg") ||
727 configuration.EndsWith(".shuttle")) {
728 filename = configuration;
729 }
730 else {
731 filename = gSystem->Getenv("ALICE_ROOT");
732 filename += "/GRP/CTP/";
733 filename += configuration;
734 filename += ".cfg";
735 }
736
737 if( gSystem->AccessPathName( filename.Data() ) ) {
738 AliErrorClass( Form( "file (%s) not found", filename.Data() ) );
739 return NULL;
740 }
741
742
743 ifstream *file = new ifstream ( filename.Data() );
744 if (!*file) {
745 AliErrorClass(Form("Error opening file (%s) !",filename.Data()));
746 file->close();
747 delete file;
748 return NULL;
749 }
750
751 AliTriggerConfiguration *cfg = new AliTriggerConfiguration();
752
753 Int_t level = 0;
754
755 TString strLine;
756 while (strLine.ReadLine(*file)) {
757 if (cfg->ProcessConfigurationLine(strLine, level) == kFALSE)
758 {
759 delete cfg;
760 cfg = 0;
761 break;
762 }
51f6d619 763 }
764
765 file->close();
766 delete file;
767
768 return cfg;
43afc9d8 769}
51f6d619 770
43afc9d8 771//_____________________________________________________________________________
772AliTriggerConfiguration* AliTriggerConfiguration::LoadConfigurationFromString(const char* configuration)
773{
774 // Loads configuration given as parameter <configuration>
775
776 if (!configuration)
777 return 0;
778
779 AliTriggerConfiguration *cfg = new AliTriggerConfiguration();
780
781 Int_t level = 0;
782
783 TObjArray* tokens = TString(configuration).Tokenize("\n");
784 for (Int_t i=0; i<tokens->GetEntries(); i++)
785 {
786 TObjString* str = dynamic_cast<TObjString*>(tokens->At(i));
787 if (!str)
788 continue;
789
790 if (cfg->ProcessConfigurationLine(str->String(), level) == kFALSE)
791 {
792 delete cfg;
793 cfg = 0;
794 break;
795 }
796 }
797
798 delete tokens;
799
800 return cfg;
51f6d619 801}
802
803//_____________________________________________________________________________
804TObjArray* AliTriggerConfiguration::GetAvailableConfigurations( const char* filename )
805{
806 // Return an array of configuration in the file
807
808 TString path;
809 if( !filename[0] ) {
810 path += gSystem->Getenv( "ALICE_ROOT" );
811 path += fgkConfigurationFileName;
812 }
813 else
814 path += filename;
815
816 if( gSystem->AccessPathName( path.Data() ) ) {
817 AliErrorGeneral( "AliTriggerConfiguration", Form( "file (%s) not found", path.Data() ) );
818 return NULL;
819 }
820
821 TObjArray* desArray = new TObjArray();
822
823 TFile file( path.Data(), "READ" );
824 if( file.IsZombie() ) {
825 AliErrorGeneral( "AliTriggerConfiguration", Form( "Error opening file (%s)", path.Data() ) );
826 return NULL;
827 }
828
829 file.ReadAll();
830
831 TKey* key;
832 TIter next( file.GetListOfKeys() );
833 while( (key = (TKey*)next()) ) {
834 TObject* obj = key->ReadObj();
835 if( obj->InheritsFrom( "AliTriggerConfiguration" ) ) {
836 desArray->AddLast( obj );
837 }
838 }
839 file.Close();
840
841 return desArray;
842}
843
844//_____________________________________________________________________________
845void AliTriggerConfiguration::WriteConfiguration( const char* filename )
846{
847 // Write the configuration
848 TString path;
849 if( !filename[0] ) {
850 path += gSystem->Getenv("ALICE_ROOT");
851 path += fgkConfigurationFileName;
852 }
853 else
854 path += filename;
855
856 TFile file( path.Data(), "UPDATE" );
857 if( file.IsZombie() ) {
858 AliErrorGeneral( "AliTriggerConfiguration",
859 Form( "Can't open file (%s)", path.Data() ) );
860 return;
861 }
862
863 Bool_t result = (Write( GetName(), TObject::kOverwrite ) != 0);
864 if( !result )
865 AliErrorGeneral( "AliTriggerConfiguration",
866 Form( "Can't write entry to file <%s>!", path.Data() ) );
867 file.Close();
868}
869
c3e7fba3 870//_____________________________________________________________________________
871Int_t AliTriggerConfiguration::GetClassIndexFromName(const char* className) const
872{
873 //const TObjArray& classes = cfg->GetClasses();
874 Int_t nclasses = (Int_t)fClasses.GetEntriesFast();
875 for (Int_t i=0;i<nclasses;i++) {
876 AliTriggerClass* trgclass = (AliTriggerClass*)fClasses.At(i);
877 if (TString(trgclass->GetName()).CompareTo(className) == 0) {
878 ULong64_t classmask = (ULong64_t)trgclass->GetMask();
879 return TMath::Nint(TMath::Log2(classmask))+1;
880 }
881 }
882 return -1;
883}
884//_____________________________________________________________________________
885const char* AliTriggerConfiguration::GetClassNameFromIndex(Int_t classIndex) const
886{
887 Int_t nclasses = (Int_t)fClasses.GetEntriesFast();
888 for (Int_t i=0;i<nclasses;i++) {
889 AliTriggerClass* trgclass = (AliTriggerClass*)fClasses.At(i);
890 ULong64_t classmask = (ULong64_t)trgclass->GetMask();
891 if (TMath::Nint(TMath::Log2(classmask))+1 == classIndex) return trgclass->GetName();
892 }
893 return 0;
894}
895//_____________________________________________________________________________
896AliTriggerClass* AliTriggerConfiguration::GetTriggerClass(Int_t classIndex) const
897{
898 Int_t nclasses = (Int_t)fClasses.GetEntriesFast();
899 for (Int_t i=0;i<nclasses;i++) {
900 AliTriggerClass* trgclass = (AliTriggerClass*)fClasses.At(i);
901 ULong64_t classmask = (ULong64_t)trgclass->GetMask();
902 if (TMath::Nint(TMath::Log2(classmask))+1 == classIndex) return trgclass;
903 }
904 return 0;
905}
895affe8 906//_____________________________________________________________________________
907void AliTriggerConfiguration::Reset()
908{
909 for( Int_t j=0; j<fInputs.GetEntriesFast(); j++ )
910 ((AliTriggerInput*)fInputs.At(j))->Reset();
911
912 for( Int_t j=0; j<fClasses.GetEntriesFast(); j++ )
913 ((AliTriggerClass*)fClasses.At(j))->Reset();
914}
51f6d619 915
916//_____________________________________________________________________________
917void AliTriggerConfiguration::Print( const Option_t* ) const
918{
919 // Print
920 cout << "#################################################" << endl;
921 cout << "Trigger Configuration:" << endl;
922 cout << " Name: " << GetName() << endl;
923 cout << " Description: " << GetTitle() << endl;
509b7052 924 cout << " Version: " << GetVersion() << endl;
51f6d619 925 cout << " Active Detectors: " << GetActiveDetectors() << endl;
926 cout << " Trigger Detectors: " << GetTriggeringDetectors() << endl;
927
928 cout << "#################################################" << endl;
929 fInputs.Print();
930 cout << "#################################################" << endl;
931 fInteractions.Print();
932 cout << "#################################################" << endl;
933 fFunctions.Print();
934 cout << "#################################################" << endl;
935 fDescriptors.Print();
936 cout << "#################################################" << endl;
937 fClusters.Print();
938 cout << "#################################################" << endl;
939 fPFProtections.Print();
940 cout << "#################################################" << endl;
941 fMasks.Print();
942 cout << "#################################################" << endl;
943 fClasses.Print();
944 cout << "#################################################" << endl;
945
946 cout << endl;
947}
948
949
950//////////////////////////////////////////////////////////////////////////////
951// Helper method
952
953//_____________________________________________________________________________
954Bool_t AliTriggerConfiguration::IsSelected( TString detName, TString& detectors ) const
955{
956 // check whether detName is contained in detectors
957 // if yes, it is removed from detectors
958
959 // check if all detectors are selected
960 if( (detectors.CompareTo("ALL") == 0 ) ||
961 detectors.BeginsWith("ALL ") ||
962 detectors.EndsWith(" ALL") ||
963 detectors.Contains(" ALL ") ) {
964 detectors = "ALL";
965 return kTRUE;
966 }
967
968 // search for the given detector
969 Bool_t result = kFALSE;
970 if( (detectors.CompareTo( detName ) == 0) ||
971 detectors.BeginsWith( detName+" " ) ||
972 detectors.EndsWith( " "+detName ) ||
973 detectors.Contains( " "+detName+" " ) ) {
974 detectors.ReplaceAll( detName, "" );
975 result = kTRUE;
976 }
977
978 // clean up the detectors string
979 while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " );
980 while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 );
981 while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 );
982
983 return result;
984}