AliRoot Core  edcc906 (edcc906)
AliTriggerConfiguration.cxx
Go to the documentation of this file.
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 
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 //
60 #include <Riostream.h>
61 
62 #include <TFile.h>
63 #include <TKey.h>
64 #include <TObjArray.h>
65 #include <TObjString.h>
66 #include <TObject.h>
67 #include <TROOT.h>
68 #include <TString.h>
69 #include <TSystem.h>
70 #include <TMath.h>
71 
72 #include "AliLog.h"
73 #include "AliTriggerBCMask.h"
74 #include "AliTriggerClass.h"
75 #include "AliTriggerCluster.h"
77 #include "AliTriggerDescriptor.h"
78 #include "AliTriggerInput.h"
79 #include "AliTriggerInteraction.h"
80 #include "AliTriggerPFProtection.h"
81 
82 using std::endl;
83 using std::cout;
84 using std::ifstream;
86 
87 const TString AliTriggerConfiguration::fgkConfigurationFileName("/data/triggerConfigurations.root");
88 
89 //_____________________________________________________________________________
91  TNamed(),
92  fInputs(),
93  fInteractions(),
94  fFunctions(),
95  fPFProtections(),
96  fMasks(),
97  fDescriptors(),
98  fClusters(),
99  fClasses(),
100  fVersion(0)
101 {
102  // Default constructor
103 }
104 
105 //_____________________________________________________________________________
106 AliTriggerConfiguration::AliTriggerConfiguration( TString & name, TString & description ):
107  TNamed( name, description ),
108  fInputs(),
109  fInteractions(),
110  fFunctions(),
111  fPFProtections(),
112  fMasks(),
113  fDescriptors(),
114  fClusters(),
115  fClasses(),
116  fVersion(0)
117 {
118  // Constructor
119 }
120 
121 //_____________________________________________________________________________
123 {
124  // Destructor
125  fInputs.SetOwner();
126  fInputs.Delete();
127  fInteractions.SetOwner();
128  fInteractions.Delete();
129  fFunctions.SetOwner();
130  fFunctions.Delete();
131  fPFProtections.SetOwner();
132  fPFProtections.Delete();
133  fMasks.SetOwner();
134  fMasks.Delete();
135  fDescriptors.SetOwner();
136  fDescriptors.Delete();
137  fClusters.SetOwner();
138  fClusters.Delete();
139  fClasses.SetOwner();
140  fClasses.Delete();
141 }
142 
143 //_____________________________________________________________________________
145 {
146  // Add a trigger input to
147  // the list of the trigger inputs
148  if (fInputs.GetEntries() < kNMaxInputs) {
149  fInputs.AddLast( input );
150  return kTRUE;
151  }
152  else {
153  AliError("CTP can handle up to 64 inputs ! Impossible to add the required input !");
154  return kFALSE;
155  }
156 }
157 
158 //_____________________________________________________________________________
160  UChar_t level, UInt_t signature,
161  UChar_t number )
162 {
163  // Add a trigger input to
164  // the list of the trigger inputs
165  AliTriggerInput *input = new AliTriggerInput(name,det,level,signature,number);
166  if (!AddInput(input)) {
167  delete input;
168  return NULL;
169  }
170  else
171  return input;
172 }
173 //_____________________________________________________________________________
175  UChar_t level, UInt_t signature,
176  UInt_t indexCTP, UInt_t indexSwitch )
177 {
178  // Add a trigger input to
179  // the list of the trigger inputs
180  AliTriggerInput *input = new AliTriggerInput(name,det,level,signature,indexCTP,indexSwitch);
181  if (!AddInput(input)) {
182  delete input;
183  return NULL;
184  }
185  else
186  return input;
187 }
188 
189 //_____________________________________________________________________________
191 {
192  // Add a trigger interaction object to
193  // the list of the trigger interactions
194  AliTriggerInteraction *interact = new AliTriggerInteraction(name,logic);
195  if (!AddInteraction(interact)) {
196  delete interact;
197  return NULL;
198  }
199  else
200  return interact;
201 }
202 
203 //_____________________________________________________________________________
205 {
206  // Add a trigger interaction object to
207  // the list of the trigger interactions
208  if (fInteractions.GetEntries() < kNMaxInteractions) {
209  if (interact->CheckInputs(fInputs)) {
210  fInteractions.AddLast( interact );
211  return kTRUE;
212  }
213  else
214  AliError("Invalid interaction ! Impossible to add it !");
215  }
216  else
217  AliError("CTP can handle up to 2 interactions ! Impossible to add the required interaction !");
218 
219  return kFALSE;
220 }
221 
222 //_____________________________________________________________________________
224 {
225  // Add a trigger function object to
226  // the list of the trigger functions
227  AliTriggerInteraction *func = new AliTriggerInteraction(name,logic);
228  if (!AddFunction(func)) {
229  delete func;
230  return NULL;
231  }
232  else
233  return func;
234 }
235 
236 //_____________________________________________________________________________
238 {
239  // Add a trigger function object to
240  // the list of the trigger functions
241  if (fFunctions.GetEntries() < kNMaxFunctions) {
242  if (func->CheckInputs(fInputs)) {
243  fFunctions.AddLast( func );
244  return kTRUE;
245  }
246  else
247  AliError("Invalid logical function ! Impossible to add it !");
248  }
249  else
250  AliError("CTP can handle up to 4 logical functions ! Impossible to add the required interaction !");
251 
252  return kFALSE;
253 }
254 
255 //_____________________________________________________________________________
257 {
258  // Add a trigger past-future protection object to
259  // the list of the trigger past-future protections
260  if (fPFProtections.GetEntries() < kNMaxPFProtections) {
261  //if (pfp->CheckInteractions(fInteractions)) {
262  if (1) {
263  fPFProtections.AddLast( pfp );
264  return kTRUE;
265  }
266  else
267  AliError("Invalid past-future protection ! Impossible to add it !");
268  }
269  else
270  AliError("CTP can handle up to 4 past-future protections ! Impossible to add the required protection !");
271 
272  return kFALSE;
273 }
274 
275 //_____________________________________________________________________________
276 AliTriggerBCMask* AliTriggerConfiguration::AddMask( TString &name, TString &mask )
277 {
278  // Add a trigger bunch-crossing mask object to
279  // the list of the trigger bunch-crossing masks
280  AliTriggerBCMask *bcmask = new AliTriggerBCMask(name,mask);
281  if (!AddMask(bcmask)) {
282  delete bcmask;
283  return NULL;
284  }
285  else
286  return bcmask;
287 }
288 
289 //_____________________________________________________________________________
291 {
292  // Add a trigger bunch-crossing mask object to
293  // the list of the trigger bunch-crossing masks
294  if (fMasks.GetEntries() < (kNMaxMasks)) {
295  fMasks.AddLast( mask );
296  return kTRUE;
297  }
298  else
299  AliError("CTP can handle up to 12 bunch-crossing masks ! Impossible to add the required mask !");
300 
301  return kFALSE;
302 }
303 
304 //_____________________________________________________________________________
305 AliTriggerCluster* AliTriggerConfiguration::AddCluster( TString &name, UChar_t index, TString &detectors)
306 {
307  // Add a trigger detector readout cluster to
308  // the list of the trigger clusters
309  AliTriggerCluster *clust = new AliTriggerCluster(name,index,detectors);
310  if (!AddCluster(clust)) {
311  delete clust;
312  return NULL;
313  }
314  else
315  return clust;
316 
317 }
318 
319 //_____________________________________________________________________________
321 {
322  // Add a trigger detector readout cluster to
323  // the list of the trigger clusters
324  if (fClusters.GetEntries() < kNMaxClusters) {
325  TString dets(cluster->GetDetectorsInCluster());
326  if (!(dets.IsNull())) {
327  fClusters.AddLast( cluster );
328  return kTRUE;
329  }
330  else
331  AliError("Empty trigger cluster ! Impossible to add it !");
332  }
333  else
334  AliError("CTP can handle up to 6 different detector clusters ! Impossible to add the required cluster !");
335 
336  return kFALSE;
337 }
338 
339 //_____________________________________________________________________________
341 {
342  // Return an string with all active detector
343  // from each cluster
344 
345  TString activeDet = "";
346 
347  Int_t nclus = fClusters.GetEntriesFast();
348  if( !nclus ) return activeDet;
349 
350  for( Int_t j=0; j<nclus; ++j ) {
351  TString detStr = ((AliTriggerCluster*)fClusters.At(j))->GetDetectorsInCluster();
352  TObjArray* det = detStr.Tokenize(" ");
353  Int_t ndet = det->GetEntriesFast();
354  for( Int_t k=0; k<ndet; ++k ) {
355  if( activeDet.Contains( ((TObjString*)det->At(k))->String() ) )continue;
356  activeDet.Append( " " );
357  activeDet.Append( ((TObjString*)det->At(k))->String() );
358  }
359  delete det;
360  }
361  return activeDet;
362 }
363 
364 //_____________________________________________________________________________
366 {
367  // Return an string with all detectors
368  // used for triggering
369 
370  TString trDet = "";
371 
372  Int_t ninputs = fInputs.GetEntriesFast();
373  if( !ninputs ) return trDet;
374 
375  for( Int_t j=0; j<ninputs; j++ ) {
376  TString detStr = ((AliTriggerInput*)fInputs.At(j))->GetDetector();
377  if( trDet.Contains( detStr ) ) continue;
378  trDet.Append( " " );
379  trDet.Append( detStr );
380  }
381  return trDet;
382 }
383 
384 //_____________________________________________________________________________
386 {
387  // Return an string with all detectors (modules in the AliRoot
388  // simulation sense) used for triggering
389 
390  TString trDet = "";
391 
392  Int_t ninputs = fInputs.GetEntriesFast();
393  if( !ninputs ) return trDet;
394 
395  for( Int_t j=0; j<ninputs; j++ ) {
396  TString detStr = ((AliTriggerInput*)fInputs.At(j))->GetModule();
397  if( trDet.Contains( detStr ) ) continue;
398  trDet.Append( " " );
399  trDet.Append( detStr );
400  }
401  return trDet;
402 }
403 
404 //_____________________________________________________________________________
406 {
407  // Add a trigger descriptor to
408  // the list of the trigger descriptors
409  AliTriggerDescriptor *desc = new AliTriggerDescriptor(name,cond);
410  if (!AddDescriptor(desc)) {
411  delete desc;
412  return NULL;
413  }
414  else
415  return desc;
416 }
417 
418 //_____________________________________________________________________________
420 {
421  // Add a trigger descriptor to
422  // the list of the trigger descriptors
423  if (fDescriptors.GetEntries() < kNMaxClasses) {
425  fDescriptors.AddLast( desc );
426  return kTRUE;
427  }
428  else
429  AliError("Invalid trigger desciptor ! Impossible to add it !");
430  }
431  else
432  AliError("CTP can handle up to 50 different descriptors ! Impossible to add the required descriptor !");
433 
434  return kFALSE;
435 }
436 
437 //_____________________________________________________________________________
439 {
440  // Add a trigger class to
441  // the list of the trigger classes
442  if (fClasses.GetEntries() < kNMaxClasses) {
443  if (trclass->CheckClass(this)) {
444  fClasses.AddLast( trclass );
445  return kTRUE;
446  }
447  else
448  AliError("Invalid trigger class ! Impossible to add it !");
449  }
450  else
451  AliError("CTP can handle up to 50 different classes ! Impossible to add the required class !");
452 
453  return kFALSE;
454 }
455 
456 //_____________________________________________________________________________
457 AliTriggerClass *AliTriggerConfiguration::AddClass( TString &name, UChar_t index,
460  UInt_t prescaler, Bool_t allrare)
461 {
462  // Add a trigger class to
463  // the list of the trigger classes
464  if (!fDescriptors.FindObject(desc)) {
465  AliError("Invalid descriptor ! Impossible to add the class !");
466  return NULL;
467  }
468  if (!fClusters.FindObject(clus)) {
469  AliError("Invalid cluster ! Impossible to add the class !");
470  return NULL;
471  }
472  if (!fPFProtections.FindObject(pfp)) {
473  AliError("Invalid past-future protection ! Impossible to add the class !");
474  return NULL;
475  }
476  if (!fMasks.FindObject(mask)) {
477  AliError("Invalid bunch-crossing mask ! Impossible to add the class !");
478  return NULL;
479  }
480  AliTriggerClass* trclass = new AliTriggerClass( name,index,desc,clus,pfp,mask,prescaler,allrare );
481  if (!AddClass(trclass)) {
482  delete trclass;
483  return NULL;
484  }
485  else
486  return trclass;
487 }
488 
489 //_____________________________________________________________________________
490 AliTriggerClass *AliTriggerConfiguration::AddClass( TString &name, UChar_t index,
491  TString &desc, TString &clus,
492  TString &pfp, TString &mask,
493  UInt_t prescaler, Bool_t allrare)
494 {
495  // Add a new trigger class
496  if (!fDescriptors.FindObject(desc)) {
497  AliError("Invalid descriptor ! Impossible to add the class !");
498  return NULL;
499  }
500  if (!fClusters.FindObject(clus)) {
501  AliError("Invalid cluster ! Impossible to add the class !");
502  return NULL;
503  }
504  if (!fPFProtections.FindObject(pfp)) {
505  AliError("Invalid past-future protection ! Impossible to add the class !");
506  return NULL;
507  }
508  if (!fMasks.FindObject(mask)) {
509  AliError("Invalid bunch-crossing mask ! Impossible to add the class !");
510  return NULL;
511  }
512  AliTriggerClass* trclass = new AliTriggerClass( this, name,index,desc,clus,pfp,mask,prescaler,allrare );
513  if (!AddClass(trclass)) {
514  delete trclass;
515  return NULL;
516  }
517  else
518  return trclass;
519 }
520 
521 //_____________________________________________________________________________
522 Bool_t AliTriggerConfiguration::ProcessConfigurationLine(const char* line, Int_t& level)
523 {
524  // processes one line of configuration
525 
526  TString strLine(line);
527 
528  if (strLine.BeginsWith("#")) return kTRUE;
529  if (strLine.BeginsWith("PARTITION:")) {
530  strLine.ReplaceAll("PARTITION:","");
531  SetName(strLine.Data());
532  return kTRUE;
533  }
534  if (strLine.BeginsWith("VERSION:")) {
535  strLine.ReplaceAll("VERSION:","");
536  fVersion = strLine.Atoi();
537  return kTRUE;
538  }
539  if (strLine.BeginsWith("INPUTS:")) {
540  level = 1;
541  return kTRUE;
542  }
543  if (strLine.BeginsWith("INTERACTIONS:")) {
544  level = 2;
545  return kTRUE;
546  }
547  if (strLine.BeginsWith("DESCRIPTORS:")) {
548  level = 3;
549  return kTRUE;
550  }
551  if (strLine.BeginsWith("CLUSTERS:")) {
552  level = 4;
553  return kTRUE;
554  }
555  if (strLine.BeginsWith("PFS:")) {
556  level = 5;
557  return kTRUE;
558  }
559  if (strLine.BeginsWith("BCMASKS:")) {
560  level = 6;
561  return kTRUE;
562  }
563  if (strLine.BeginsWith("CLASSES:")) {
564  level = 7;
565  return kTRUE;
566  }
567 
568  strLine.ReplaceAll("*",'!');
569  strLine.ReplaceAll("~",'!');
570  TObjArray *tokens = strLine.Tokenize(" \t");
571  Int_t ntokens = tokens->GetEntriesFast();
572  if (ntokens == 0)
573  {
574  delete tokens;
575  return kTRUE;
576  }
577  switch (level) {
578  case 1:
579  // Read inputs
580  if ((ntokens != 5) && (ntokens !=6)) {
581  AliError(Form("Invalid trigger input syntax (%s)!",strLine.Data()));
582  delete tokens;
583  return kFALSE;
584  }
585  if(ntokens==5){
586  AddInput(((TObjString*)tokens->At(0))->String(),
587  ((TObjString*)tokens->At(1))->String(),
588  ((TObjString*)tokens->At(2))->String().Atoi(),
589  ((TObjString*)tokens->At(3))->String().Atoi(),
590  ((TObjString*)tokens->At(4))->String().Atoi());
591  }else{
592  AddInput(((TObjString*)tokens->At(0))->String(),
593  ((TObjString*)tokens->At(1))->String(),
594  ((TObjString*)tokens->At(2))->String().Atoi(),
595  ((TObjString*)tokens->At(3))->String().Atoi(),
596  ((TObjString*)tokens->At(4))->String().Atoi(),
597  ((TObjString*)tokens->At(5))->String().Atoi());
598  }
599  break;
600  case 2:
601  // Read interaction
602  {
603  TString inter;
604  if (ntokens < 2) {
605  AliError(Form("Invalid trigger interaction syntax (%s)!",strLine.Data()));
606  delete tokens;
607  return kFALSE;
608  } else if (ntokens == 2) {
609  inter=((TObjString*)tokens->At(1))->String();
610  } else {
611  AliWarning(Form("Trigger interaction syntax (%s)!",strLine.Data()));
612  for(Int_t i=1;i<ntokens;i++){
613  inter=inter+((TObjString*)tokens->At(i))->String();
614  }
615  }
616  AddInteraction(((TObjString*)tokens->At(0))->String(),inter);
617  break;
618  }
619  case 3:
620  // Read logical functions and descriptors
621  if (ntokens < 2) {
622  if ((((TObjString*)tokens->At(0))->String().CompareTo("EMPTY") == 0) ||
623  (((TObjString*)tokens->At(0))->String().CompareTo("DTRUE") == 0) ||
624  (((TObjString*)tokens->At(0))->String().CompareTo("DEMPTY") == 0)) {
625  AddDescriptor(((TObjString*)tokens->At(0))->String(),
626  strLine.ReplaceAll(((TObjString*)tokens->At(0))->String(),""));
627  break;
628  }
629  else {
630  AliError(Form("Invalid trigger descriptor syntax (%s)!",strLine.Data()));
631  delete tokens;
632  return kFALSE;
633  }
634  }
635  if (((TObjString*)tokens->At(0))->String().BeginsWith("l0f")) {
636  // function
637  if(!AddFunction(((TObjString*)tokens->At(0))->String(),
638  strLine.ReplaceAll(((TObjString*)tokens->At(0))->String(),""))) {
639  delete tokens;
640  return kFALSE;
641  }
642  }
643  else {
644  if(!AddDescriptor(((TObjString*)tokens->At(0))->String(),
645  strLine.ReplaceAll(((TObjString*)tokens->At(0))->String(),""))) {
646  delete tokens;
647  return kFALSE;
648  }
649  }
650  break;
651  case 4:
652  {
653  if (ntokens < 2) {
654  AliError(Form("Invalid trigger cluster syntax (%s)!",strLine.Data()));
655  delete tokens;
656  return kFALSE;
657  }
658  if (((TObjString*)tokens->At(1))->String().Atoi() <= 0) {
659  AliError(Form("Invalid trigger cluster syntax (%s)!",strLine.Data()));
660  return kFALSE;
661  }
662  TString strTemp;
663  for(Int_t i = 2; i < ntokens; i++) {
664  strTemp += ((TObjString*)tokens->At(i))->String();
665  strTemp += " ";
666  }
667  AddCluster(((TObjString*)tokens->At(0))->String(),
668  ((TObjString*)tokens->At(1))->String().Atoi(),
669  strTemp);
670  }
671  break;
672  case 5:
673  {
674  AliTriggerPFProtection *pfp = NULL;
675  if ((((TObjString*)tokens->At(0))->String().CompareTo("NONE") == 0) ||
676  (((TObjString*)tokens->At(0))->String().CompareTo("NOPF") == 0)) {
677  pfp = new AliTriggerPFProtection(((TObjString*)tokens->At(0))->String());
678  }
679  else {
680  if ((ntokens == 10) && (fVersion<=7)){
681  pfp = new AliTriggerPFProtection(((TObjString*)tokens->At(0))->String(),
682  ((TObjString*)tokens->At(1))->String(),
683  ((TObjString*)tokens->At(2))->String(),
684  ((TObjString*)tokens->At(3))->String());
685  pfp->SetNa1(((TObjString*)tokens->At(4))->String().Atoi());
686  pfp->SetNa2(((TObjString*)tokens->At(5))->String().Atoi());
687  pfp->SetNb1(((TObjString*)tokens->At(6))->String().Atoi());
688  pfp->SetNb2(((TObjString*)tokens->At(7))->String().Atoi());
689  pfp->SetTa(((TObjString*)tokens->At(8))->String().Atoi());
690  pfp->SetTb(((TObjString*)tokens->At(9))->String().Atoi());
691  }else if((ntokens == 13) && (fVersion<=7)){
692  UInt_t pfdef[12];
693  for(Int_t i=0;i<12;i++){
694  TString ss(((TObjString*)tokens->At(i+1))->String());
695  ss.Remove(0,2);
696  UInt_t num=0;
697  for(Int_t j=ss.Length()-1;j>=0;j--){
698  UInt_t nn=ss[j];
699  if(nn >= (UInt_t)'0' && nn <= (UInt_t)'9')nn=nn-(UInt_t)'0'; else
700  if(nn >= (UInt_t)'A' && nn <= (UInt_t)'F')nn=10+nn-(UInt_t)'A'; else
701  if(nn >= (UInt_t)'a' && nn <= (UInt_t)'f')nn=10+nn-(UInt_t)'a'; else{
702  AliError(Form("Invalid trigger pfs syntax (%s)!",strLine.Data()));
703  //return kFALSE;
704  }
705  num=num+(1<<(ss.Length()-1-j)*4)*nn;
706  //cout << ss[j] << " 2 " << nn << " " << num << endl;
707  }
708  pfdef[i]=num;
709  }
710  pfp = new AliTriggerPFProtection(((TObjString*)tokens->At(0))->String(),pfdef);
711  }else if((ntokens==9) && (fVersion>7)){
712  // new LML0 PF
713  pfp = new AliTriggerPFProtection(
714  ((TObjString*)tokens->At(0))->String(),
715  ((TObjString*)tokens->At(1))->String(),
716  ((TObjString*)tokens->At(2))->String(),
717  ((TObjString*)tokens->At(3))->String().Atoi(),
718  ((TObjString*)tokens->At(4))->String().Atoi(),
719  ((TObjString*)tokens->At(5))->String().Atoi(),
720  ((TObjString*)tokens->At(6))->String().Atoi(),
721  ((TObjString*)tokens->At(7))->String().Atoi(),
722  ((TObjString*)tokens->At(8))->String().Atoi()
723  );
724  }else{
725  AliError(Form("Invalid trigger pfs syntax (%s)!",strLine.Data()));
726  //return kFALSE;
727  }
728  }
729  AddPFProtection(pfp);
730  }
731  break;
732  case 6:
733  if (ntokens > 2) {
734  AliError(Form("Invalid trigger bcmasks syntax (%s)!",strLine.Data()));
735  delete tokens;
736  return kFALSE;
737  }
738  if (((TObjString*)tokens->At(0))->String().CompareTo("NONE") == 0)
739  {
740  if(!AddMask(new AliTriggerBCMask(((TObjString*)tokens->At(0))->String()))) {
741  delete tokens;
742  return kFALSE;
743  }
744  }
745  else {
746  if(!AddMask(((TObjString*)tokens->At(0))->String(),((TObjString*)tokens->At(1))->String())) {
747  delete tokens;
748  return kFALSE;
749  }
750  }
751  break;
752  case 7:
753  {
754  if ((ntokens !=8) && (ntokens != 10) && (ntokens != 11)) {
755  AliError(Form("Invalid trigger class syntax (%s)!",strLine.Data()));
756  delete tokens;
757  return kFALSE;
758  }
759  AliTriggerClass *trclass=0;
760  if(ntokens == 8)trclass = new AliTriggerClass(this,
761  ((TObjString*)tokens->At(0))->String(),((TObjString*)tokens->At(1))->String().Atoi(),
762  ((TObjString*)tokens->At(2))->String(),((TObjString*)tokens->At(3))->String(),
763  ((TObjString*)tokens->At(4))->String(),((TObjString*)tokens->At(5))->String(),
764  ((TObjString*)tokens->At(6))->String().Atoi(),(Bool_t)(((TObjString*)tokens->At(7))->String().Atoi()));
765  else{ trclass = new AliTriggerClass(this,
766  ((TObjString*)tokens->At(0))->String(),((TObjString*)tokens->At(1))->String().Atoi(),
767  ((TObjString*)tokens->At(2))->String(),((TObjString*)tokens->At(3))->String(),
768  ((TObjString*)tokens->At(4))->String(),
769  ((TObjString*)tokens->At(6))->String().Atoi(),(Bool_t)(((TObjString*)tokens->At(7))->String().Atoi()),
770  (((TObjString*)tokens->At(8))->String().Atoi()),(((TObjString*)tokens->At(9))->String().Atoi()));
771  if(!trclass->SetMasks(this,((TObjString*)tokens->At(5))->String())) {
772  delete tokens;
773  return kFALSE;
774  }
775  }
776  AddClass(trclass);
777  }
778  default:
779  break;
780  }
781  delete tokens;
782 
783  return kTRUE;
784 }
785 
786 //_____________________________________________________________________________
788 {
789  // Load one pre-created Configurations from database/file that match
790  // with the input string 'configuration'
791  // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL"
792  // By default the files are stored in GRP/CTP folder.
793  // The filename is constructed as: GRP/CTP/<configuration>.cfg
794 
795  // Load the selected configuration
796  TString filename;
797  if (configuration.EndsWith(".cfg") ||
798  configuration.EndsWith(".shuttle")) {
799  filename = configuration;
800  }
801  else {
802  filename = gSystem->Getenv("ALICE_ROOT");
803  filename += "/GRP/CTP/";
804  filename += configuration;
805  filename += ".cfg";
806  }
807 
808  if( gSystem->AccessPathName( filename.Data() ) ) {
809  AliErrorClass( Form( "file (%s) not found", filename.Data() ) );
810  return NULL;
811  }
812 
813 
814  ifstream *file = new ifstream ( filename.Data() );
815  if (!*file) {
816  AliErrorClass(Form("Error opening file (%s) !",filename.Data()));
817  file->close();
818  delete file;
819  return NULL;
820  }
821 
823 
824  Int_t level = 0;
825 
826  TString strLine;
827  while (strLine.ReadLine(*file)) {
828  if (cfg->ProcessConfigurationLine(strLine, level) == kFALSE)
829  {
830  delete cfg;
831  cfg = 0;
832  break;
833  }
834  }
835 
836  file->close();
837  delete file;
838 
839  return cfg;
840 }
841 
842 //_____________________________________________________________________________
844 {
845  // Loads configuration given as parameter <configuration>
846 
847  if (!configuration)
848  return 0;
849 
851 
852  Int_t level = 0;
853 
854  TObjArray* tokens = TString(configuration).Tokenize("\n");
855  for (Int_t i=0; i<tokens->GetEntries(); i++)
856  {
857  TObjString* str = dynamic_cast<TObjString*>(tokens->At(i));
858  if (!str)
859  continue;
860 
861  if (cfg->ProcessConfigurationLine(str->String(), level) == kFALSE)
862  {
863  delete cfg;
864  cfg = 0;
865  break;
866  }
867  }
868 
869  delete tokens;
870 
871  return cfg;
872 }
873 
874 //_____________________________________________________________________________
876 {
877  // Return an array of configuration in the file
878 
879  TString path;
880  if( !filename[0] ) {
881  path += gSystem->Getenv( "ALICE_ROOT" );
882  path += fgkConfigurationFileName;
883  }
884  else
885  path += filename;
886 
887  if( gSystem->AccessPathName( path.Data() ) ) {
888  AliErrorGeneral( "AliTriggerConfiguration", Form( "file (%s) not found", path.Data() ) );
889  return NULL;
890  }
891 
892  TObjArray* desArray = new TObjArray();
893 
894  TFile file( path.Data(), "READ" );
895  if( file.IsZombie() ) {
896  AliErrorGeneral( "AliTriggerConfiguration", Form( "Error opening file (%s)", path.Data() ) );
897  return NULL;
898  }
899 
900  file.ReadAll();
901 
902  TKey* key;
903  TIter next( file.GetListOfKeys() );
904  while( (key = (TKey*)next()) ) {
905  TObject* obj = key->ReadObj();
906  if( obj->InheritsFrom( "AliTriggerConfiguration" ) ) {
907  desArray->AddLast( obj );
908  }
909  }
910  file.Close();
911 
912  return desArray;
913 }
914 
915 //_____________________________________________________________________________
917 {
918  // Write the configuration
919  TString path;
920  if( !filename[0] ) {
921  path += gSystem->Getenv("ALICE_ROOT");
922  path += fgkConfigurationFileName;
923  }
924  else
925  path += filename;
926 
927  TFile file( path.Data(), "UPDATE" );
928  if( file.IsZombie() ) {
929  AliErrorGeneral( "AliTriggerConfiguration",
930  Form( "Can't open file (%s)", path.Data() ) );
931  return;
932  }
933 
934  Bool_t result = (Write( GetName(), TObject::kOverwrite ) != 0);
935  if( !result )
936  AliErrorGeneral( "AliTriggerConfiguration",
937  Form( "Can't write entry to file <%s>!", path.Data() ) );
938  file.Close();
939 }
940 
941 //_____________________________________________________________________________
942 Int_t AliTriggerConfiguration::GetClassIndexFromName(const char* className) const
943 {
944  //const TObjArray& classes = cfg->GetClasses();
945  Int_t nclasses = (Int_t)fClasses.GetEntriesFast();
946  for (Int_t i=0;i<nclasses;i++) {
947  AliTriggerClass* trgclass = (AliTriggerClass*)fClasses.At(i);
948  if (TString(trgclass->GetName()).CompareTo(className) == 0) {
949  return trgclass->GetIndex();
950  }
951  }
952  return -1;
953 }
954 //_____________________________________________________________________________
955 const char* AliTriggerConfiguration::GetClassNameFromIndex(Int_t classIndex) const
956 {
957  Int_t nclasses = (Int_t)fClasses.GetEntriesFast();
958  for (Int_t i=0;i<nclasses;i++) {
959  AliTriggerClass* trgclass = (AliTriggerClass*)fClasses.At(i);
960  if (trgclass->GetIndex() == classIndex) return trgclass->GetName();
961  }
962  return 0;
963 }
964 //_____________________________________________________________________________
966 {
967  Int_t nclasses = (Int_t)fClasses.GetEntriesFast();
968  for (Int_t i=0;i<nclasses;i++) {
969  AliTriggerClass* trgclass = (AliTriggerClass*)fClasses.At(i);
970  if ( trgclass->GetIndex() == classIndex) return trgclass;
971  }
972  return 0;
973 }
974 //_____________________________________________________________________________
976 {
977  for( Int_t j=0; j<fInputs.GetEntriesFast(); j++ )
978  ((AliTriggerInput*)fInputs.At(j))->Reset();
979 
980  for( Int_t j=0; j<fClasses.GetEntriesFast(); j++ )
981  ((AliTriggerClass*)fClasses.At(j))->Reset();
982 }
983 
984 //_____________________________________________________________________________
985 void AliTriggerConfiguration::Print( const Option_t* ) const
986 {
987  // Print
988  cout << "#################################################" << endl;
989  cout << "Trigger Configuration:" << endl;
990  cout << " Name: " << GetName() << endl;
991  cout << " Description: " << GetTitle() << endl;
992  cout << " Version: " << GetVersion() << endl;
993  cout << " Active Detectors: " << GetActiveDetectors() << endl;
994  cout << " Trigger Detectors: " << GetTriggeringDetectors() << endl;
995 
996  cout << "#################################################" << endl;
997  fInputs.Print();
998  cout << "#################################################" << endl;
999  fInteractions.Print();
1000  cout << "#################################################" << endl;
1001  fFunctions.Print();
1002  cout << "#################################################" << endl;
1003  fDescriptors.Print();
1004  cout << "#################################################" << endl;
1005  fClusters.Print();
1006  cout << "#################################################" << endl;
1007  fPFProtections.Print();
1008  cout << "#################################################" << endl;
1009  fMasks.Print();
1010  cout << "#################################################" << endl;
1011  fClasses.Print();
1012  cout << "#################################################" << endl;
1013 
1014  cout << endl;
1015 }
1016 
1017 
1019 // Helper method
1020 
1021 //_____________________________________________________________________________
1022 Bool_t AliTriggerConfiguration::IsSelected( TString detName, TString& detectors ) const
1023 {
1024  // check whether detName is contained in detectors
1025  // if yes, it is removed from detectors
1026 
1027  // check if all detectors are selected
1028  if( (detectors.CompareTo("ALL") == 0 ) ||
1029  detectors.BeginsWith("ALL ") ||
1030  detectors.EndsWith(" ALL") ||
1031  detectors.Contains(" ALL ") ) {
1032  detectors = "ALL";
1033  return kTRUE;
1034  }
1035 
1036  // search for the given detector
1037  Bool_t result = kFALSE;
1038  if( (detectors.CompareTo( detName ) == 0) ||
1039  detectors.BeginsWith( detName+" " ) ||
1040  detectors.EndsWith( " "+detName ) ||
1041  detectors.Contains( " "+detName+" " ) ) {
1042  detectors.ReplaceAll( detName, "" );
1043  result = kTRUE;
1044  }
1045 
1046  // clean up the detectors string
1047  while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " );
1048  while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 );
1049  while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 );
1050 
1051  return result;
1052 }
Bool_t CheckInputsAndFunctions(const TObjArray &inputs, const TObjArray &functions) const
AliTriggerDescriptor * AddDescriptor(TString &name, TString &cond)
#define TObjArray
AliTriggerClass * AddClass(TString &name, UChar_t index, AliTriggerDescriptor *desc, AliTriggerCluster *clus, AliTriggerPFProtection *pfp, AliTriggerBCMask *mask, UInt_t prescaler, Bool_t allrare)
#define AliErrorGeneral(scope, message)
Definition: AliLog.h:601
static const TString fgkConfigurationFileName
const char * path
Bool_t ProcessConfigurationLine(const char *line, Int_t &level)
AliTriggerInteraction * AddInteraction(TString &name, TString &logic)
Bool_t SetMasks(AliTriggerConfiguration *config, TString &mask)
Bool_t AddPFProtection(AliTriggerPFProtection *pf)
static AliTriggerConfiguration * LoadConfiguration(TString &des)
Bool_t IsSelected(TString detName, TString &detectors) const
void WriteConfiguration(const char *filename="")
#define AliWarning(message)
Definition: AliLog.h:541
Int_t GetClassIndexFromName(const char *className) const
const char * GetDetectorsInCluster() const
#define AliErrorClass(message)
Definition: AliLog.h:596
Bool_t CheckInputs(const TObjArray &inputs) const
AliTriggerInput * AddInput(TString &name, TString &det, UChar_t level, UInt_t signature, UChar_t number)
AliTriggerCluster * AddCluster(TString &name, UChar_t index, TString &detectors)
static TObjArray * GetAvailableConfigurations(const char *filename="")
AliTriggerInteraction * AddFunction(TString &name, TString &logic)
AliTriggerBCMask * AddMask(TString &name, TString &mask)
Int_t GetIndex() const
AliTriggerClass * GetTriggerClass(Int_t classIndex) const
#define AliError(message)
Definition: AliLog.h:591
void Print(const Option_t *opt="") const
static AliTriggerConfiguration * LoadConfigurationFromString(const char *configuration)
const char * GetClassNameFromIndex(Int_t classIndex) const
Bool_t CheckClass(AliTriggerConfiguration *config) const