]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliTriggerConfiguration.cxx
Changes in QA to be able to process separately different triggers (Ruben)
[u/mrichter/AliRoot.git] / STEER / 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) {
244 if (pfp->CheckInteractions(fInteractions)) {
245 fPFProtections.AddLast( pfp );
246 return kTRUE;
247 }
248 else
249 AliError("Invalid past-future protection ! Impossible to add it !");
250 }
251 else
252 AliError("CTP can handle up to 4 past-future protections ! Impossible to add the required protection !");
253
254 return kFALSE;
255}
256
257//_____________________________________________________________________________
258AliTriggerBCMask* AliTriggerConfiguration::AddMask( TString &name, TString &mask )
259{
f3eb4d78 260 // Add a trigger bunch-crossing mask object to
261 // the list of the trigger bunch-crossing masks
51f6d619 262 AliTriggerBCMask *bcmask = new AliTriggerBCMask(name,mask);
263 if (!AddMask(bcmask)) {
264 delete bcmask;
265 return NULL;
266 }
267 else
268 return bcmask;
269}
270
271//_____________________________________________________________________________
272Bool_t AliTriggerConfiguration::AddMask( AliTriggerBCMask* mask )
273{
f3eb4d78 274 // Add a trigger bunch-crossing mask object to
275 // the list of the trigger bunch-crossing masks
583e63b8 276 if (fMasks.GetEntries() < (kNMaxMasks+1)) { //+1 to account for NONE
51f6d619 277 fMasks.AddLast( mask );
278 return kTRUE;
279 }
280 else
281 AliError("CTP can handle up to 4 bunch-crossing masks ! Impossible to add the required mask !");
282
283 return kFALSE;
284}
285
286//_____________________________________________________________________________
287AliTriggerCluster* AliTriggerConfiguration::AddCluster( TString &name, UChar_t index, TString &detectors)
288{
f3eb4d78 289 // Add a trigger detector readout cluster to
290 // the list of the trigger clusters
51f6d619 291 AliTriggerCluster *clust = new AliTriggerCluster(name,index,detectors);
292 if (!AddCluster(clust)) {
293 delete clust;
294 return NULL;
295 }
296 else
297 return clust;
298
299}
300
301//_____________________________________________________________________________
302Bool_t AliTriggerConfiguration::AddCluster( AliTriggerCluster* cluster )
303{
f3eb4d78 304 // Add a trigger detector readout cluster to
305 // the list of the trigger clusters
51f6d619 306 if (fClusters.GetEntries() < kNMaxClusters) {
307 TString dets(cluster->GetDetectorsInCluster());
308 if (!(dets.IsNull())) {
309 fClusters.AddLast( cluster );
310 return kTRUE;
311 }
312 else
313 AliError("Empty trigger cluster ! Impossible to add it !");
314 }
315 else
316 AliError("CTP can handle up to 6 different detector clusters ! Impossible to add the required cluster !");
317
318 return kFALSE;
319}
320
321//_____________________________________________________________________________
322TString AliTriggerConfiguration::GetActiveDetectors() const
323{
f3eb4d78 324 // Return an string with all active detector
325 // from each cluster
51f6d619 326
327 TString activeDet = "";
328
329 Int_t nclus = fClusters.GetEntriesFast();
330 if( !nclus ) return activeDet;
331
605cb8bb 332 for( Int_t j=0; j<nclus; ++j ) {
51f6d619 333 TString detStr = ((AliTriggerCluster*)fClusters.At(j))->GetDetectorsInCluster();
334 TObjArray* det = detStr.Tokenize(" ");
335 Int_t ndet = det->GetEntriesFast();
605cb8bb 336 for( Int_t k=0; k<ndet; ++k ) {
337 if( activeDet.Contains( ((TObjString*)det->At(k))->String() ) )continue;
51f6d619 338 activeDet.Append( " " );
605cb8bb 339 activeDet.Append( ((TObjString*)det->At(k))->String() );
51f6d619 340 }
341 }
342 return activeDet;
343}
344
345//_____________________________________________________________________________
346TString AliTriggerConfiguration::GetTriggeringDetectors() const
347{
f3eb4d78 348 // Return an string with all detectors
349 // used for triggering
51f6d619 350
351 TString trDet = "";
352
353 Int_t ninputs = fInputs.GetEntriesFast();
354 if( !ninputs ) return trDet;
355
356 for( Int_t j=0; j<ninputs; j++ ) {
357 TString detStr = ((AliTriggerInput*)fInputs.At(j))->GetDetector();
358 if( trDet.Contains( detStr ) ) continue;
359 trDet.Append( " " );
360 trDet.Append( detStr );
361 }
362 return trDet;
363}
364
365//_____________________________________________________________________________
366TString AliTriggerConfiguration::GetTriggeringModules() const
367{
368 // Return an string with all detectors (modules in the AliRoot
369 // simulation sense) used for triggering
370
371 TString trDet = "";
372
373 Int_t ninputs = fInputs.GetEntriesFast();
374 if( !ninputs ) return trDet;
375
376 for( Int_t j=0; j<ninputs; j++ ) {
377 TString detStr = ((AliTriggerInput*)fInputs.At(j))->GetModule();
378 if( trDet.Contains( detStr ) ) continue;
379 trDet.Append( " " );
380 trDet.Append( detStr );
381 }
382 return trDet;
383}
384
385//_____________________________________________________________________________
386AliTriggerDescriptor* AliTriggerConfiguration::AddDescriptor( TString &name, TString &cond )
387{
f3eb4d78 388 // Add a trigger descriptor to
389 // the list of the trigger descriptors
51f6d619 390 AliTriggerDescriptor *desc = new AliTriggerDescriptor(name,cond);
391 if (!AddDescriptor(desc)) {
392 delete desc;
393 return NULL;
394 }
395 else
396 return desc;
397}
398
399//_____________________________________________________________________________
400Bool_t AliTriggerConfiguration::AddDescriptor( AliTriggerDescriptor *desc )
401{
f3eb4d78 402 // Add a trigger descriptor to
403 // the list of the trigger descriptors
51f6d619 404 if (fDescriptors.GetEntries() < kNMaxClasses) {
405 if (desc->CheckInputsAndFunctions(fInputs,fFunctions)) {
406 fDescriptors.AddLast( desc );
407 return kTRUE;
408 }
409 else
410 AliError("Invalid trigger desciptor ! Impossible to add it !");
411 }
412 else
413 AliError("CTP can handle up to 50 different descriptors ! Impossible to add the required descriptor !");
414
415 return kFALSE;
416}
417
418//_____________________________________________________________________________
419Bool_t AliTriggerConfiguration::AddClass( AliTriggerClass *trclass )
420{
f3eb4d78 421 // Add a trigger class to
422 // the list of the trigger classes
51f6d619 423 if (fClasses.GetEntries() < kNMaxClasses) {
424 if (trclass->CheckClass(this)) {
425 fClasses.AddLast( trclass );
426 return kTRUE;
427 }
428 else
429 AliError("Invalid trigger class ! Impossible to add it !");
430 }
431 else
432 AliError("CTP can handle up to 50 different classes ! Impossible to add the required class !");
433
434 return kFALSE;
435}
436
437//_____________________________________________________________________________
438AliTriggerClass *AliTriggerConfiguration::AddClass( TString &name, UChar_t index,
439 AliTriggerDescriptor *desc, AliTriggerCluster *clus,
440 AliTriggerPFProtection *pfp, AliTriggerBCMask *mask,
441 UInt_t prescaler, Bool_t allrare)
442{
f3eb4d78 443 // Add a trigger class to
444 // the list of the trigger classes
51f6d619 445 if (!fDescriptors.FindObject(desc)) {
446 AliError("Invalid descriptor ! Impossible to add the class !");
447 return NULL;
448 }
449 if (!fClusters.FindObject(clus)) {
450 AliError("Invalid cluster ! Impossible to add the class !");
451 return NULL;
452 }
453 if (!fPFProtections.FindObject(pfp)) {
454 AliError("Invalid past-future protection ! Impossible to add the class !");
455 return NULL;
456 }
457 if (!fMasks.FindObject(mask)) {
458 AliError("Invalid bunch-crossing mask ! Impossible to add the class !");
459 return NULL;
460 }
461 AliTriggerClass* trclass = new AliTriggerClass( name,index,desc,clus,pfp,mask,prescaler,allrare );
462 if (!AddClass(trclass)) {
463 delete trclass;
464 return NULL;
465 }
466 else
467 return trclass;
468}
469
470//_____________________________________________________________________________
471AliTriggerClass *AliTriggerConfiguration::AddClass( TString &name, UChar_t index,
472 TString &desc, TString &clus,
473 TString &pfp, TString &mask,
474 UInt_t prescaler, Bool_t allrare)
475{
476 // Add a new trigger class
477 if (!fDescriptors.FindObject(desc)) {
478 AliError("Invalid descriptor ! Impossible to add the class !");
479 return NULL;
480 }
481 if (!fClusters.FindObject(clus)) {
482 AliError("Invalid cluster ! Impossible to add the class !");
483 return NULL;
484 }
485 if (!fPFProtections.FindObject(pfp)) {
486 AliError("Invalid past-future protection ! Impossible to add the class !");
487 return NULL;
488 }
489 if (!fMasks.FindObject(mask)) {
490 AliError("Invalid bunch-crossing mask ! Impossible to add the class !");
491 return NULL;
492 }
493 AliTriggerClass* trclass = new AliTriggerClass( this, name,index,desc,clus,pfp,mask,prescaler,allrare );
494 if (!AddClass(trclass)) {
495 delete trclass;
496 return NULL;
497 }
498 else
499 return trclass;
500}
501
502//_____________________________________________________________________________
43afc9d8 503Bool_t AliTriggerConfiguration::ProcessConfigurationLine(const char* line, Int_t& level)
51f6d619 504{
43afc9d8 505 // processes one line of configuration
51f6d619 506
43afc9d8 507 TString strLine(line);
51f6d619 508
43afc9d8 509 if (strLine.BeginsWith("#")) return kTRUE;
509b7052 510 if (strLine.BeginsWith("PARTITION:")) {
511 strLine.ReplaceAll("PARTITION:","");
512 SetName(strLine.Data());
513 return kTRUE;
514 }
515 if (strLine.BeginsWith("VERSION:")) {
516 strLine.ReplaceAll("VERSION:","");
517 fVersion = strLine.Atoi();
518 return kTRUE;
519 }
51f6d619 520 if (strLine.BeginsWith("INPUTS:")) {
521 level = 1;
43afc9d8 522 return kTRUE;
51f6d619 523 }
524 if (strLine.BeginsWith("INTERACTIONS:")) {
525 level = 2;
43afc9d8 526 return kTRUE;
51f6d619 527 }
528 if (strLine.BeginsWith("DESCRIPTORS:")) {
529 level = 3;
43afc9d8 530 return kTRUE;
51f6d619 531 }
532 if (strLine.BeginsWith("CLUSTERS:")) {
533 level = 4;
43afc9d8 534 return kTRUE;
51f6d619 535 }
536 if (strLine.BeginsWith("PFS:")) {
537 level = 5;
43afc9d8 538 return kTRUE;
51f6d619 539 }
540 if (strLine.BeginsWith("BCMASKS:")) {
541 level = 6;
43afc9d8 542 return kTRUE;
51f6d619 543 }
544 if (strLine.BeginsWith("CLASSES:")) {
545 level = 7;
43afc9d8 546 return kTRUE;
51f6d619 547 }
43afc9d8 548
51f6d619 549 strLine.ReplaceAll("*",'!');
31e839aa 550 strLine.ReplaceAll("~",'!');
51f6d619 551 TObjArray *tokens = strLine.Tokenize(" \t");
552 Int_t ntokens = tokens->GetEntriesFast();
43afc9d8 553 if (ntokens == 0)
554 {
555 delete tokens;
556 return kTRUE;
557 }
51f6d619 558 switch (level) {
559 case 1:
560 // Read inputs
561 if (ntokens != 5) {
43afc9d8 562 AliError(Form("Invalid trigger input syntax (%s)!",strLine.Data()));
563 return kFALSE;
51f6d619 564 }
43afc9d8 565 AddInput(((TObjString*)tokens->At(0))->String(),
51f6d619 566 ((TObjString*)tokens->At(1))->String(),
567 ((TObjString*)tokens->At(2))->String().Atoi(),
568 ((TObjString*)tokens->At(3))->String().Atoi(),
569 ((TObjString*)tokens->At(4))->String().Atoi());
570 break;
571 case 2:
43afc9d8 572 // Read interaction
573 if (ntokens != 2) {
574 AliError(Form("Invalid trigger interaction syntax (%s)!",strLine.Data()));
575 return kFALSE;
576 }
577 AddInteraction(((TObjString*)tokens->At(0))->String(),
51f6d619 578 ((TObjString*)tokens->At(1))->String());
579 break;
580 case 3:
581 // Read logical functions and descriptors
43afc9d8 582 if (ntokens < 2) {
e89c03c6 583 if ((((TObjString*)tokens->At(0))->String().CompareTo("EMPTY") == 0) ||
583e63b8 584 (((TObjString*)tokens->At(0))->String().CompareTo("DTRUE") == 0) ||
e89c03c6 585 (((TObjString*)tokens->At(0))->String().CompareTo("DEMPTY") == 0)) {
586 AddDescriptor(((TObjString*)tokens->At(0))->String(),
587 strLine.ReplaceAll(((TObjString*)tokens->At(0))->String(),""));
588 break;
589 }
590 else {
591 AliError(Form("Invalid trigger descriptor syntax (%s)!",strLine.Data()));
592 return kFALSE;
593 }
43afc9d8 594 }
51f6d619 595 if (((TObjString*)tokens->At(0))->String().BeginsWith("l0f")) {
596 // function
43afc9d8 597 AddFunction(((TObjString*)tokens->At(0))->String(),
51f6d619 598 strLine.ReplaceAll(((TObjString*)tokens->At(0))->String(),""));
599 }
600 else {
43afc9d8 601 AddDescriptor(((TObjString*)tokens->At(0))->String(),
51f6d619 602 strLine.ReplaceAll(((TObjString*)tokens->At(0))->String(),""));
603 }
604 break;
605 case 4:
606 {
43afc9d8 607 if (ntokens < 2) {
608 AliError(Form("Invalid trigger cluster syntax (%s)!",strLine.Data()));
609 return kFALSE;
610 }
af51ca16 611 if (((TObjString*)tokens->At(1))->String().Atoi() <= 0) {
612 AliError(Form("Invalid trigger cluster syntax (%s)!",strLine.Data()));
613 return kFALSE;
614 }
51f6d619 615 TString strTemp;
616 for(Int_t i = 2; i < ntokens; i++) {
617 strTemp += ((TObjString*)tokens->At(i))->String();
618 strTemp += " ";
619 }
43afc9d8 620 AddCluster(((TObjString*)tokens->At(0))->String(),
51f6d619 621 ((TObjString*)tokens->At(1))->String().Atoi(),
622 strTemp);
623 }
624 break;
625 case 5:
626 {
627 AliTriggerPFProtection *pfp = NULL;
909d646e 628 if ((((TObjString*)tokens->At(0))->String().CompareTo("NONE") == 0) ||
629 (((TObjString*)tokens->At(0))->String().CompareTo("NOPF") == 0)) {
51f6d619 630 pfp = new AliTriggerPFProtection(((TObjString*)tokens->At(0))->String());
631 }
632 else {
43afc9d8 633 if (ntokens != 10) {
634 AliError(Form("Invalid trigger pfs syntax (%s)!",strLine.Data()));
635 return kFALSE;
636 }
51f6d619 637 pfp = new AliTriggerPFProtection(((TObjString*)tokens->At(0))->String(),
638 ((TObjString*)tokens->At(1))->String(),
639 ((TObjString*)tokens->At(2))->String(),
640 ((TObjString*)tokens->At(3))->String());
641 pfp->SetNa1(((TObjString*)tokens->At(4))->String().Atoi());
642 pfp->SetNa2(((TObjString*)tokens->At(5))->String().Atoi());
643 pfp->SetNb1(((TObjString*)tokens->At(6))->String().Atoi());
644 pfp->SetNb2(((TObjString*)tokens->At(7))->String().Atoi());
645 pfp->SetTa(((TObjString*)tokens->At(8))->String().Atoi());
646 pfp->SetTb(((TObjString*)tokens->At(9))->String().Atoi());
647 }
43afc9d8 648 AddPFProtection(pfp);
51f6d619 649 }
650 break;
651 case 6:
43afc9d8 652 if (ntokens > 2) {
653 AliError(Form("Invalid trigger bcmasks syntax (%s)!",strLine.Data()));
654 return kFALSE;
655 }
51f6d619 656 if (((TObjString*)tokens->At(0))->String().CompareTo("NONE") == 0)
583e63b8 657 {
658 AddMask(new AliTriggerBCMask(((TObjString*)tokens->At(0))->String()));
659 }
51f6d619 660 else {
43afc9d8 661 AddMask(((TObjString*)tokens->At(0))->String(),
51f6d619 662 ((TObjString*)tokens->At(1))->String());
663 }
664 break;
665 case 7:
666 {
b98dcc47 667 if ((ntokens < 8) || (ntokens >10)) {
43afc9d8 668 AliError(Form("Invalid trigger class syntax (%s)!",strLine.Data()));
669 return kFALSE;
670 }
671 AliTriggerClass *trclass = new AliTriggerClass(this,
51f6d619 672 ((TObjString*)tokens->At(0))->String(),((TObjString*)tokens->At(1))->String().Atoi(),
673 ((TObjString*)tokens->At(2))->String(),((TObjString*)tokens->At(3))->String(),
674 ((TObjString*)tokens->At(4))->String(),((TObjString*)tokens->At(5))->String(),
43afc9d8 675 ((TObjString*)tokens->At(6))->String().Atoi(),(Bool_t)(((TObjString*)tokens->At(7))->String().Atoi()));
676 AddClass(trclass);
51f6d619 677 }
678 default:
679 break;
680 }
681 delete tokens;
43afc9d8 682
683 return kTRUE;
684}
685
686//_____________________________________________________________________________
687AliTriggerConfiguration* AliTriggerConfiguration::LoadConfiguration(TString & configuration)
688{
689 // Load one pre-created Configurations from database/file that match
690 // with the input string 'configuration'
691 // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL"
692 // By default the files are stored in GRP/CTP folder.
693 // The filename is constructed as: GRP/CTP/<configuration>.cfg
694
695 // Load the selected configuration
696 TString filename;
697 if (configuration.EndsWith(".cfg") ||
698 configuration.EndsWith(".shuttle")) {
699 filename = configuration;
700 }
701 else {
702 filename = gSystem->Getenv("ALICE_ROOT");
703 filename += "/GRP/CTP/";
704 filename += configuration;
705 filename += ".cfg";
706 }
707
708 if( gSystem->AccessPathName( filename.Data() ) ) {
709 AliErrorClass( Form( "file (%s) not found", filename.Data() ) );
710 return NULL;
711 }
712
713
714 ifstream *file = new ifstream ( filename.Data() );
715 if (!*file) {
716 AliErrorClass(Form("Error opening file (%s) !",filename.Data()));
717 file->close();
718 delete file;
719 return NULL;
720 }
721
722 AliTriggerConfiguration *cfg = new AliTriggerConfiguration();
723
724 Int_t level = 0;
725
726 TString strLine;
727 while (strLine.ReadLine(*file)) {
728 if (cfg->ProcessConfigurationLine(strLine, level) == kFALSE)
729 {
730 delete cfg;
731 cfg = 0;
732 break;
733 }
51f6d619 734 }
735
736 file->close();
737 delete file;
738
739 return cfg;
43afc9d8 740}
51f6d619 741
43afc9d8 742//_____________________________________________________________________________
743AliTriggerConfiguration* AliTriggerConfiguration::LoadConfigurationFromString(const char* configuration)
744{
745 // Loads configuration given as parameter <configuration>
746
747 if (!configuration)
748 return 0;
749
750 AliTriggerConfiguration *cfg = new AliTriggerConfiguration();
751
752 Int_t level = 0;
753
754 TObjArray* tokens = TString(configuration).Tokenize("\n");
755 for (Int_t i=0; i<tokens->GetEntries(); i++)
756 {
757 TObjString* str = dynamic_cast<TObjString*>(tokens->At(i));
758 if (!str)
759 continue;
760
761 if (cfg->ProcessConfigurationLine(str->String(), level) == kFALSE)
762 {
763 delete cfg;
764 cfg = 0;
765 break;
766 }
767 }
768
769 delete tokens;
770
771 return cfg;
51f6d619 772}
773
774//_____________________________________________________________________________
775TObjArray* AliTriggerConfiguration::GetAvailableConfigurations( const char* filename )
776{
777 // Return an array of configuration in the file
778
779 TString path;
780 if( !filename[0] ) {
781 path += gSystem->Getenv( "ALICE_ROOT" );
782 path += fgkConfigurationFileName;
783 }
784 else
785 path += filename;
786
787 if( gSystem->AccessPathName( path.Data() ) ) {
788 AliErrorGeneral( "AliTriggerConfiguration", Form( "file (%s) not found", path.Data() ) );
789 return NULL;
790 }
791
792 TObjArray* desArray = new TObjArray();
793
794 TFile file( path.Data(), "READ" );
795 if( file.IsZombie() ) {
796 AliErrorGeneral( "AliTriggerConfiguration", Form( "Error opening file (%s)", path.Data() ) );
797 return NULL;
798 }
799
800 file.ReadAll();
801
802 TKey* key;
803 TIter next( file.GetListOfKeys() );
804 while( (key = (TKey*)next()) ) {
805 TObject* obj = key->ReadObj();
806 if( obj->InheritsFrom( "AliTriggerConfiguration" ) ) {
807 desArray->AddLast( obj );
808 }
809 }
810 file.Close();
811
812 return desArray;
813}
814
815//_____________________________________________________________________________
816void AliTriggerConfiguration::WriteConfiguration( const char* filename )
817{
818 // Write the configuration
819 TString path;
820 if( !filename[0] ) {
821 path += gSystem->Getenv("ALICE_ROOT");
822 path += fgkConfigurationFileName;
823 }
824 else
825 path += filename;
826
827 TFile file( path.Data(), "UPDATE" );
828 if( file.IsZombie() ) {
829 AliErrorGeneral( "AliTriggerConfiguration",
830 Form( "Can't open file (%s)", path.Data() ) );
831 return;
832 }
833
834 Bool_t result = (Write( GetName(), TObject::kOverwrite ) != 0);
835 if( !result )
836 AliErrorGeneral( "AliTriggerConfiguration",
837 Form( "Can't write entry to file <%s>!", path.Data() ) );
838 file.Close();
839}
840
c3e7fba3 841//_____________________________________________________________________________
842Int_t AliTriggerConfiguration::GetClassIndexFromName(const char* className) const
843{
844 //const TObjArray& classes = cfg->GetClasses();
845 Int_t nclasses = (Int_t)fClasses.GetEntriesFast();
846 for (Int_t i=0;i<nclasses;i++) {
847 AliTriggerClass* trgclass = (AliTriggerClass*)fClasses.At(i);
848 if (TString(trgclass->GetName()).CompareTo(className) == 0) {
849 ULong64_t classmask = (ULong64_t)trgclass->GetMask();
850 return TMath::Nint(TMath::Log2(classmask))+1;
851 }
852 }
853 return -1;
854}
855//_____________________________________________________________________________
856const char* AliTriggerConfiguration::GetClassNameFromIndex(Int_t classIndex) const
857{
858 Int_t nclasses = (Int_t)fClasses.GetEntriesFast();
859 for (Int_t i=0;i<nclasses;i++) {
860 AliTriggerClass* trgclass = (AliTriggerClass*)fClasses.At(i);
861 ULong64_t classmask = (ULong64_t)trgclass->GetMask();
862 if (TMath::Nint(TMath::Log2(classmask))+1 == classIndex) return trgclass->GetName();
863 }
864 return 0;
865}
866//_____________________________________________________________________________
867AliTriggerClass* AliTriggerConfiguration::GetTriggerClass(Int_t classIndex) const
868{
869 Int_t nclasses = (Int_t)fClasses.GetEntriesFast();
870 for (Int_t i=0;i<nclasses;i++) {
871 AliTriggerClass* trgclass = (AliTriggerClass*)fClasses.At(i);
872 ULong64_t classmask = (ULong64_t)trgclass->GetMask();
873 if (TMath::Nint(TMath::Log2(classmask))+1 == classIndex) return trgclass;
874 }
875 return 0;
876}
895affe8 877//_____________________________________________________________________________
878void AliTriggerConfiguration::Reset()
879{
880 for( Int_t j=0; j<fInputs.GetEntriesFast(); j++ )
881 ((AliTriggerInput*)fInputs.At(j))->Reset();
882
883 for( Int_t j=0; j<fClasses.GetEntriesFast(); j++ )
884 ((AliTriggerClass*)fClasses.At(j))->Reset();
885}
51f6d619 886
887//_____________________________________________________________________________
888void AliTriggerConfiguration::Print( const Option_t* ) const
889{
890 // Print
891 cout << "#################################################" << endl;
892 cout << "Trigger Configuration:" << endl;
893 cout << " Name: " << GetName() << endl;
894 cout << " Description: " << GetTitle() << endl;
509b7052 895 cout << " Version: " << GetVersion() << endl;
51f6d619 896 cout << " Active Detectors: " << GetActiveDetectors() << endl;
897 cout << " Trigger Detectors: " << GetTriggeringDetectors() << endl;
898
899 cout << "#################################################" << endl;
900 fInputs.Print();
901 cout << "#################################################" << endl;
902 fInteractions.Print();
903 cout << "#################################################" << endl;
904 fFunctions.Print();
905 cout << "#################################################" << endl;
906 fDescriptors.Print();
907 cout << "#################################################" << endl;
908 fClusters.Print();
909 cout << "#################################################" << endl;
910 fPFProtections.Print();
911 cout << "#################################################" << endl;
912 fMasks.Print();
913 cout << "#################################################" << endl;
914 fClasses.Print();
915 cout << "#################################################" << endl;
916
917 cout << endl;
918}
919
920
921//////////////////////////////////////////////////////////////////////////////
922// Helper method
923
924//_____________________________________________________________________________
925Bool_t AliTriggerConfiguration::IsSelected( TString detName, TString& detectors ) const
926{
927 // check whether detName is contained in detectors
928 // if yes, it is removed from detectors
929
930 // check if all detectors are selected
931 if( (detectors.CompareTo("ALL") == 0 ) ||
932 detectors.BeginsWith("ALL ") ||
933 detectors.EndsWith(" ALL") ||
934 detectors.Contains(" ALL ") ) {
935 detectors = "ALL";
936 return kTRUE;
937 }
938
939 // search for the given detector
940 Bool_t result = kFALSE;
941 if( (detectors.CompareTo( detName ) == 0) ||
942 detectors.BeginsWith( detName+" " ) ||
943 detectors.EndsWith( " "+detName ) ||
944 detectors.Contains( " "+detName+" " ) ) {
945 detectors.ReplaceAll( detName, "" );
946 result = kTRUE;
947 }
948
949 // clean up the detectors string
950 while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " );
951 while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 );
952 while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 );
953
954 return result;
955}