1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 ///////////////////////////////////////////////////////////////////////////////
18 // This class which defines defines the Trigger Configuration
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).
23 // All the information conained in the CTP configuration file used
24 // online during the data taking
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.
30 // Example how to create a Trigger Configuration:
32 // AliTriggerConfiguration config( "TEST", "Test Configuration" );
34 // // Define a Cluster Detector
35 // config.AddDetectorCluster( "VZERO ZDC MUON" );
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)
43 // config.AddCondition( "VZERO_TEST2_L0 & MUON_SMinus_HPt_L0 & ZDC_TEST1_L0",
48 // config.AddCondition( "VZERO_TEST3_L0 | MUON_Unlike_LPt_L0 | ZDC_TEST3_L0",
52 // config.CheckInputsConditions("Config.C");
55 // // save the configuration to file
56 // // (default file name $ALICE_ROOT/data/triggerConfigurations.root)
57 // config.WriteConfiguration(); or config.WriteConfiguration( filename );
59 ///////////////////////////////////////////////////////////////////////////////
60 #include <Riostream.h>
65 #include <TObjString.h>
66 #include <TObjArray.h>
75 #include "AliRunLoader.h"
76 #include "AliModule.h"
78 #include "AliTriggerInput.h"
79 //#include "AliTriggerDetector.h"
80 #include "AliTriggerInteraction.h"
81 #include "AliTriggerBCMask.h"
82 #include "AliTriggerCluster.h"
83 #include "AliTriggerPFProtection.h"
84 #include "AliTriggerDescriptor.h"
85 #include "AliTriggerClass.h"
86 #include "AliTriggerConfiguration.h"
88 ClassImp(AliTriggerConfiguration)
90 const TString AliTriggerConfiguration::fgkConfigurationFileName("/data/triggerConfigurations.root");
92 //_____________________________________________________________________________
93 AliTriggerConfiguration::AliTriggerConfiguration():
104 // Default constructor
107 //_____________________________________________________________________________
108 AliTriggerConfiguration::AliTriggerConfiguration( TString & name, TString & description ):
109 TNamed( name, description ),
122 //_____________________________________________________________________________
123 AliTriggerConfiguration::~AliTriggerConfiguration()
127 fInteractions.SetOwner();
128 fInteractions.Delete();
129 fFunctions.SetOwner();
131 fPFProtections.SetOwner();
132 fPFProtections.Delete();
135 fDescriptors.SetOwner();
136 fDescriptors.Delete();
137 fClusters.SetOwner();
143 //_____________________________________________________________________________
144 Bool_t AliTriggerConfiguration::AddInput( AliTriggerInput* input )
146 if (fInputs.GetEntries() < kNMaxInputs) {
147 fInputs.AddLast( input );
151 AliError("CTP can handle up to 50 inputs ! Impossible to add the required input !");
156 //_____________________________________________________________________________
157 AliTriggerInput* AliTriggerConfiguration::AddInput( TString &name, TString &det,
158 UChar_t level, UInt_t signature,
161 AliTriggerInput *input = new AliTriggerInput(name,det,level,signature,number);
162 if (!AddInput(input)) {
170 //_____________________________________________________________________________
171 AliTriggerInteraction* AliTriggerConfiguration::AddInteraction(TString &name, TString &logic)
173 AliTriggerInteraction *interact = new AliTriggerInteraction(name,logic);
174 if (!AddInteraction(interact)) {
182 //_____________________________________________________________________________
183 Bool_t AliTriggerConfiguration::AddInteraction(AliTriggerInteraction *interact)
185 if (fInteractions.GetEntries() < kNMaxInteractions) {
186 if (interact->CheckInputs(fInputs)) {
187 fInteractions.AddLast( interact );
191 AliError("Invalid interaction ! Impossible to add it !");
194 AliError("CTP can handle up to 2 interactions ! Impossible to add the required interaction !");
199 //_____________________________________________________________________________
200 AliTriggerInteraction* AliTriggerConfiguration::AddFunction(TString &name, TString &logic)
202 AliTriggerInteraction *func = new AliTriggerInteraction(name,logic);
203 if (!AddFunction(func)) {
211 //_____________________________________________________________________________
212 Bool_t AliTriggerConfiguration::AddFunction(AliTriggerInteraction *func)
214 if (fFunctions.GetEntries() < kNMaxFunctions) {
215 if (func->CheckInputs(fInputs)) {
216 fFunctions.AddLast( func );
220 AliError("Invalid logical function ! Impossible to add it !");
223 AliError("CTP can handle up to 2 logical functions ! Impossible to add the required interaction !");
228 //_____________________________________________________________________________
229 Bool_t AliTriggerConfiguration::AddPFProtection( AliTriggerPFProtection* pfp )
231 if (fPFProtections.GetEntries() < kNMaxPFProtections) {
232 if (pfp->CheckInteractions(fInteractions)) {
233 fPFProtections.AddLast( pfp );
237 AliError("Invalid past-future protection ! Impossible to add it !");
240 AliError("CTP can handle up to 4 past-future protections ! Impossible to add the required protection !");
245 //_____________________________________________________________________________
246 AliTriggerBCMask* AliTriggerConfiguration::AddMask( TString &name, TString &mask )
248 AliTriggerBCMask *bcmask = new AliTriggerBCMask(name,mask);
249 if (!AddMask(bcmask)) {
257 //_____________________________________________________________________________
258 Bool_t AliTriggerConfiguration::AddMask( AliTriggerBCMask* mask )
260 if (fMasks.GetEntries() < kNMaxMasks) {
261 fMasks.AddLast( mask );
265 AliError("CTP can handle up to 4 bunch-crossing masks ! Impossible to add the required mask !");
270 //_____________________________________________________________________________
271 AliTriggerCluster* AliTriggerConfiguration::AddCluster( TString &name, UChar_t index, TString &detectors)
273 AliTriggerCluster *clust = new AliTriggerCluster(name,index,detectors);
274 if (!AddCluster(clust)) {
283 //_____________________________________________________________________________
284 Bool_t AliTriggerConfiguration::AddCluster( AliTriggerCluster* cluster )
286 if (fClusters.GetEntries() < kNMaxClusters) {
287 TString dets(cluster->GetDetectorsInCluster());
288 if (!(dets.IsNull())) {
289 fClusters.AddLast( cluster );
293 AliError("Empty trigger cluster ! Impossible to add it !");
296 AliError("CTP can handle up to 6 different detector clusters ! Impossible to add the required cluster !");
301 //_____________________________________________________________________________
302 TString AliTriggerConfiguration::GetActiveDetectors() const
304 // Return an string with all active detector from each cluster
306 TString activeDet = "";
308 Int_t nclus = fClusters.GetEntriesFast();
309 if( !nclus ) return activeDet;
311 for( Int_t j=0; j<nclus; j++ ) {
312 TString detStr = ((AliTriggerCluster*)fClusters.At(j))->GetDetectorsInCluster();
313 TObjArray* det = detStr.Tokenize(" ");
314 Int_t ndet = det->GetEntriesFast();
315 for( Int_t j=0; j<ndet; j++ ) {
316 if( activeDet.Contains( ((TObjString*)det->At(j))->String() ) )continue;
317 activeDet.Append( " " );
318 activeDet.Append( ((TObjString*)det->At(j))->String() );
324 //_____________________________________________________________________________
325 TString AliTriggerConfiguration::GetTriggeringDetectors() const
327 // Return an string with all detectors used for triggering
331 Int_t ninputs = fInputs.GetEntriesFast();
332 if( !ninputs ) return trDet;
334 for( Int_t j=0; j<ninputs; j++ ) {
335 TString detStr = ((AliTriggerInput*)fInputs.At(j))->GetDetector();
336 if( trDet.Contains( detStr ) ) continue;
338 trDet.Append( detStr );
343 //_____________________________________________________________________________
344 TString AliTriggerConfiguration::GetTriggeringModules() const
346 // Return an string with all detectors (modules in the AliRoot
347 // simulation sense) used for triggering
351 Int_t ninputs = fInputs.GetEntriesFast();
352 if( !ninputs ) return trDet;
354 for( Int_t j=0; j<ninputs; j++ ) {
355 TString detStr = ((AliTriggerInput*)fInputs.At(j))->GetModule();
356 if( trDet.Contains( detStr ) ) continue;
358 trDet.Append( detStr );
363 //_____________________________________________________________________________
364 AliTriggerDescriptor* AliTriggerConfiguration::AddDescriptor( TString &name, TString &cond )
366 AliTriggerDescriptor *desc = new AliTriggerDescriptor(name,cond);
367 if (!AddDescriptor(desc)) {
375 //_____________________________________________________________________________
376 Bool_t AliTriggerConfiguration::AddDescriptor( AliTriggerDescriptor *desc )
378 if (fDescriptors.GetEntries() < kNMaxClasses) {
379 if (desc->CheckInputsAndFunctions(fInputs,fFunctions)) {
380 fDescriptors.AddLast( desc );
384 AliError("Invalid trigger desciptor ! Impossible to add it !");
387 AliError("CTP can handle up to 50 different descriptors ! Impossible to add the required descriptor !");
392 //_____________________________________________________________________________
393 Bool_t AliTriggerConfiguration::AddClass( AliTriggerClass *trclass )
395 if (fClasses.GetEntries() < kNMaxClasses) {
396 if (trclass->CheckClass(this)) {
397 fClasses.AddLast( trclass );
401 AliError("Invalid trigger class ! Impossible to add it !");
404 AliError("CTP can handle up to 50 different classes ! Impossible to add the required class !");
409 //_____________________________________________________________________________
410 AliTriggerClass *AliTriggerConfiguration::AddClass( TString &name, UChar_t index,
411 AliTriggerDescriptor *desc, AliTriggerCluster *clus,
412 AliTriggerPFProtection *pfp, AliTriggerBCMask *mask,
413 UInt_t prescaler, Bool_t allrare)
415 // Add a new trigger class
416 if (!fDescriptors.FindObject(desc)) {
417 AliError("Invalid descriptor ! Impossible to add the class !");
420 if (!fClusters.FindObject(clus)) {
421 AliError("Invalid cluster ! Impossible to add the class !");
424 if (!fPFProtections.FindObject(pfp)) {
425 AliError("Invalid past-future protection ! Impossible to add the class !");
428 if (!fMasks.FindObject(mask)) {
429 AliError("Invalid bunch-crossing mask ! Impossible to add the class !");
432 AliTriggerClass* trclass = new AliTriggerClass( name,index,desc,clus,pfp,mask,prescaler,allrare );
433 if (!AddClass(trclass)) {
441 //_____________________________________________________________________________
442 AliTriggerClass *AliTriggerConfiguration::AddClass( TString &name, UChar_t index,
443 TString &desc, TString &clus,
444 TString &pfp, TString &mask,
445 UInt_t prescaler, Bool_t allrare)
447 // Add a new trigger class
448 if (!fDescriptors.FindObject(desc)) {
449 AliError("Invalid descriptor ! Impossible to add the class !");
452 if (!fClusters.FindObject(clus)) {
453 AliError("Invalid cluster ! Impossible to add the class !");
456 if (!fPFProtections.FindObject(pfp)) {
457 AliError("Invalid past-future protection ! Impossible to add the class !");
460 if (!fMasks.FindObject(mask)) {
461 AliError("Invalid bunch-crossing mask ! Impossible to add the class !");
464 AliTriggerClass* trclass = new AliTriggerClass( this, name,index,desc,clus,pfp,mask,prescaler,allrare );
465 if (!AddClass(trclass)) {
473 //_____________________________________________________________________________
474 AliTriggerConfiguration* AliTriggerConfiguration::LoadConfiguration( TString & configuration)
476 // Load one pre-created Configurations from database/file that match
477 // with the input string 'configuration'
478 // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL"
479 // By default the files are stored in GRP/CTP folder.
480 // The filename is constructed as: GRP/CTP/<configuration>.cfg
482 // Load the selected configuration
483 TString filename = gSystem->Getenv("ALICE_ROOT");
484 filename += "/GRP/CTP/";
485 filename += configuration;
488 if( gSystem->AccessPathName( filename.Data() ) ) {
489 AliErrorClass( Form( "file (%s) not found", filename.Data() ) );
494 ifstream *file = new ifstream ( filename.Data() );
496 AliErrorClass(Form("Error opening file (%s) !",filename.Data()));
502 AliTriggerConfiguration *cfg = new AliTriggerConfiguration();
506 while (strLine.ReadLine(*file)) {
507 if (strLine.BeginsWith("#")) continue;
508 if (strLine.BeginsWith("INPUTS:")) {
512 if (strLine.BeginsWith("INTERACTIONS:")) {
516 if (strLine.BeginsWith("DESCRIPTORS:")) {
520 if (strLine.BeginsWith("CLUSTERS:")) {
524 if (strLine.BeginsWith("PFS:")) {
528 if (strLine.BeginsWith("BCMASKS:")) {
532 if (strLine.BeginsWith("CLASSES:")) {
536 strLine.ReplaceAll("*",'!');
537 TObjArray *tokens = strLine.Tokenize(" \t");
538 Int_t ntokens = tokens->GetEntriesFast();
543 AliErrorClass(Form("Invalid trigger input syntax (%s)!",strLine.Data()));
548 cfg->AddInput(((TObjString*)tokens->At(0))->String(),
549 ((TObjString*)tokens->At(1))->String(),
550 ((TObjString*)tokens->At(2))->String().Atoi(),
551 ((TObjString*)tokens->At(3))->String().Atoi(),
552 ((TObjString*)tokens->At(4))->String().Atoi());
555 // Read intreractions
556 cfg->AddInteraction(((TObjString*)tokens->At(0))->String(),
557 ((TObjString*)tokens->At(1))->String());
560 // Read logical functions and descriptors
561 if (((TObjString*)tokens->At(0))->String().BeginsWith("l0f")) {
563 cfg->AddFunction(((TObjString*)tokens->At(0))->String(),
564 strLine.ReplaceAll(((TObjString*)tokens->At(0))->String(),""));
567 cfg->AddDescriptor(((TObjString*)tokens->At(0))->String(),
568 strLine.ReplaceAll(((TObjString*)tokens->At(0))->String(),""));
574 for(Int_t i = 2; i < ntokens; i++) {
575 strTemp += ((TObjString*)tokens->At(i))->String();
578 cfg->AddCluster(((TObjString*)tokens->At(0))->String(),
579 ((TObjString*)tokens->At(1))->String().Atoi(),
585 AliTriggerPFProtection *pfp = NULL;
586 if (((TObjString*)tokens->At(0))->String().CompareTo("NONE") == 0) {
587 pfp = new AliTriggerPFProtection(((TObjString*)tokens->At(0))->String());
590 pfp = new AliTriggerPFProtection(((TObjString*)tokens->At(0))->String(),
591 ((TObjString*)tokens->At(1))->String(),
592 ((TObjString*)tokens->At(2))->String(),
593 ((TObjString*)tokens->At(3))->String());
594 pfp->SetNa1(((TObjString*)tokens->At(4))->String().Atoi());
595 pfp->SetNa2(((TObjString*)tokens->At(5))->String().Atoi());
596 pfp->SetNb1(((TObjString*)tokens->At(6))->String().Atoi());
597 pfp->SetNb2(((TObjString*)tokens->At(7))->String().Atoi());
598 pfp->SetTa(((TObjString*)tokens->At(8))->String().Atoi());
599 pfp->SetTb(((TObjString*)tokens->At(9))->String().Atoi());
601 cfg->AddPFProtection(pfp);
605 if (((TObjString*)tokens->At(0))->String().CompareTo("NONE") == 0)
606 cfg->AddMask(new AliTriggerBCMask(((TObjString*)tokens->At(0))->String()));
608 cfg->AddMask(((TObjString*)tokens->At(0))->String(),
609 ((TObjString*)tokens->At(1))->String());
614 AliTriggerClass *trclass = new AliTriggerClass(cfg,
615 ((TObjString*)tokens->At(0))->String(),((TObjString*)tokens->At(1))->String().Atoi(),
616 ((TObjString*)tokens->At(2))->String(),((TObjString*)tokens->At(3))->String(),
617 ((TObjString*)tokens->At(4))->String(),((TObjString*)tokens->At(5))->String(),
618 ((TObjString*)tokens->At(6))->String().Atoi(),(Bool_t)(((TObjString*)tokens->At(0))->String().Atoi()));
619 cfg->AddClass(trclass);
634 //_____________________________________________________________________________
635 TObjArray* AliTriggerConfiguration::GetAvailableConfigurations( const char* filename )
637 // Return an array of configuration in the file
641 path += gSystem->Getenv( "ALICE_ROOT" );
642 path += fgkConfigurationFileName;
647 if( gSystem->AccessPathName( path.Data() ) ) {
648 AliErrorGeneral( "AliTriggerConfiguration", Form( "file (%s) not found", path.Data() ) );
652 TObjArray* desArray = new TObjArray();
654 TFile file( path.Data(), "READ" );
655 if( file.IsZombie() ) {
656 AliErrorGeneral( "AliTriggerConfiguration", Form( "Error opening file (%s)", path.Data() ) );
663 TIter next( file.GetListOfKeys() );
664 while( (key = (TKey*)next()) ) {
665 TObject* obj = key->ReadObj();
666 if( obj->InheritsFrom( "AliTriggerConfiguration" ) ) {
667 desArray->AddLast( obj );
675 //_____________________________________________________________________________
676 void AliTriggerConfiguration::WriteConfiguration( const char* filename )
678 // Write the configuration
681 path += gSystem->Getenv("ALICE_ROOT");
682 path += fgkConfigurationFileName;
687 TFile file( path.Data(), "UPDATE" );
688 if( file.IsZombie() ) {
689 AliErrorGeneral( "AliTriggerConfiguration",
690 Form( "Can't open file (%s)", path.Data() ) );
694 Bool_t result = (Write( GetName(), TObject::kOverwrite ) != 0);
696 AliErrorGeneral( "AliTriggerConfiguration",
697 Form( "Can't write entry to file <%s>!", path.Data() ) );
701 //_____________________________________________________________________________
702 Bool_t AliTriggerConfiguration::CheckConfiguration( TString& configfile )
704 // To be used on the pre-creation of Configurations to check if the
705 // conditions have valid inputs names.
707 // Initiate detectors modules from a Config file
708 // Ask to each active module present in the fDetectorCluster
709 // to create a Trigger detector and retrive the inputs from it
710 // to create a list of inputs.
711 // Each condition in the configuration is then checked agains
712 // the list of inputs
716 AliError( "no gAlice object. Restart aliroot and try again." );
719 if (gAlice->Modules()->GetEntries() > 0) {
720 AliError( "gAlice was already run. Restart aliroot and try again." );
724 AliInfo( Form( "initializing gAlice with config file %s",
725 configfile.Data() ) );
726 StdoutToAliInfo( StderrToAliError(
727 gAlice->Init( configfile.Data() );
730 AliRunLoader* runLoader = gAlice->GetRunLoader();
732 AliError( Form( "gAlice has no run loader object. "
733 "Check your config file: %s", configfile.Data() ) );
737 // get the possible inputs to check the condition
739 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
741 TString detStr = GetTriggeringModules();
743 for( Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++ ) {
744 AliModule* det = (AliModule*) detArray->At(iDet);
745 if( !det || !det->IsActive() ) continue;
746 if( IsSelected( det->GetName(), detStr ) ) {
747 AliInfo( Form( "Creating inputs for %s", det->GetName() ) );
748 AliTriggerDetector* dtrg = det->CreateTriggerDetector();
749 dtrg->CreateInputs(GetInputs());
750 TObjArray* detInp = dtrg->GetInputs();
751 for( Int_t i=0; i<detInp->GetEntriesFast(); i++ ) {
752 AliInfo( Form( "Adding input %s", ((AliTriggerInput*)detInp->At(i))->GetName() ) );
753 inputs.AddLast( detInp->At(i) );
758 // check if the condition is compatible with the triggers inputs
759 Int_t ndesc = fClasses.GetEntriesFast();
760 Bool_t check = kTRUE;
762 for( Int_t j=0; j<ndesc; j++ ) {
763 AliTriggerClass *trclass = (AliTriggerClass*)fClasses.At( j );
764 if( !(trclass->CheckClass( this )) ) check = kFALSE;
766 if (trclass->IsActive(this->GetInputs(),this->GetFunctions())) {
767 AliInfo( Form( "Trigger Class (%s) OK, class mask (0x%Lx)",
768 trclass->GetName(), trclass->GetMask( ) ) );
771 AliWarning( Form( "Trigger Class (%s) is NOT active, class mask (0x%Lx)",
772 trclass->GetName(), trclass->GetMask( ) ) );
775 // check if condition mask is duplicated
776 if( mask & trclass->GetMask() ) {
777 AliError( Form("Class (%s). The class mask (0x%Lx) is ambiguous. It was already defined",
778 trclass->GetName(), trclass->GetMask() ) );
781 mask |= trclass->GetMask();
788 //_____________________________________________________________________________
789 void AliTriggerConfiguration::Print( const Option_t* ) const
792 cout << "#################################################" << endl;
793 cout << "Trigger Configuration:" << endl;
794 cout << " Name: " << GetName() << endl;
795 cout << " Description: " << GetTitle() << endl;
796 cout << " Active Detectors: " << GetActiveDetectors() << endl;
797 cout << " Trigger Detectors: " << GetTriggeringDetectors() << endl;
799 cout << "#################################################" << endl;
801 cout << "#################################################" << endl;
802 fInteractions.Print();
803 cout << "#################################################" << endl;
805 cout << "#################################################" << endl;
806 fDescriptors.Print();
807 cout << "#################################################" << endl;
809 cout << "#################################################" << endl;
810 fPFProtections.Print();
811 cout << "#################################################" << endl;
813 cout << "#################################################" << endl;
815 cout << "#################################################" << endl;
821 //////////////////////////////////////////////////////////////////////////////
824 //_____________________________________________________________________________
825 Bool_t AliTriggerConfiguration::IsSelected( TString detName, TString& detectors ) const
827 // check whether detName is contained in detectors
828 // if yes, it is removed from detectors
830 // check if all detectors are selected
831 if( (detectors.CompareTo("ALL") == 0 ) ||
832 detectors.BeginsWith("ALL ") ||
833 detectors.EndsWith(" ALL") ||
834 detectors.Contains(" ALL ") ) {
839 // search for the given detector
840 Bool_t result = kFALSE;
841 if( (detectors.CompareTo( detName ) == 0) ||
842 detectors.BeginsWith( detName+" " ) ||
843 detectors.EndsWith( " "+detName ) ||
844 detectors.Contains( " "+detName+" " ) ) {
845 detectors.ReplaceAll( detName, "" );
849 // clean up the detectors string
850 while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " );
851 while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 );
852 while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 );