From 51f6d61973bbef5a0be8d2c6d25254022fd5a09d Mon Sep 17 00:00:00 2001 From: cvetan Date: Thu, 22 Nov 2007 11:43:14 +0000 Subject: [PATCH] New revision of the CTP configuration and simulation. For more details look in the slides at the weekly offline meeting (22/11/2007) --- STEER/AliCentralTrigger.cxx | 258 ++++----- STEER/AliCentralTrigger.h | 30 +- STEER/AliExpression.cxx | 6 +- STEER/AliExpression.h | 4 +- STEER/AliSimulation.cxx | 25 +- STEER/AliTriggerBCMask.cxx | 26 +- STEER/AliTriggerBCMask.h | 13 +- STEER/AliTriggerClass.cxx | 209 ++++++++ STEER/AliTriggerClass.h | 69 +++ STEER/AliTriggerCluster.cxx | 131 +++++ STEER/AliTriggerCluster.h | 42 ++ STEER/AliTriggerConfiguration.cxx | 855 ++++++++++++++++++++++++++++++ STEER/AliTriggerConfiguration.h | 127 +++++ STEER/AliTriggerDescriptor.cxx | 469 +++++----------- STEER/AliTriggerDescriptor.h | 61 +-- STEER/AliTriggerDetector.cxx | 96 +++- STEER/AliTriggerDetector.h | 8 +- STEER/AliTriggerInput.cxx | 113 +++- STEER/AliTriggerInput.h | 61 ++- STEER/AliTriggerInteraction.cxx | 157 ++++++ STEER/AliTriggerInteraction.h | 37 ++ STEER/AliTriggerPFProtection.cxx | 117 ++++ STEER/AliTriggerPFProtection.h | 94 ++++ STEER/STEERLinkDef.h | 12 +- STEER/libSTEER.pkg | 7 +- 25 files changed, 2387 insertions(+), 640 deletions(-) create mode 100644 STEER/AliTriggerClass.cxx create mode 100644 STEER/AliTriggerClass.h create mode 100644 STEER/AliTriggerCluster.cxx create mode 100644 STEER/AliTriggerCluster.h create mode 100755 STEER/AliTriggerConfiguration.cxx create mode 100755 STEER/AliTriggerConfiguration.h create mode 100644 STEER/AliTriggerInteraction.cxx create mode 100644 STEER/AliTriggerInteraction.h create mode 100644 STEER/AliTriggerPFProtection.cxx create mode 100644 STEER/AliTriggerPFProtection.h diff --git a/STEER/AliCentralTrigger.cxx b/STEER/AliCentralTrigger.cxx index 41d581e94ad..5d9cc854da1 100644 --- a/STEER/AliCentralTrigger.cxx +++ b/STEER/AliCentralTrigger.cxx @@ -20,12 +20,12 @@ // This class for running the Central Trigger Processor // // // // // -// Load Descriptors // -// Make a list the trigger detectors involve from the descriptors // +// Load Configuration // +// Make a list the trigger detectors involved (from the classes) // // For the each event // // Run the Trigger for the each detector // // Get the inputs // -// Check the condition classes // +// Check the trigger classes // // Create the class mask // // Save result // // // @@ -46,12 +46,16 @@ #include "AliTriggerInput.h" #include "AliTriggerDetector.h" -#include "AliTriggerCondition.h" -#include "AliTriggerDescriptor.h" +#include "AliTriggerConfiguration.h" +#include "AliTriggerClass.h" +#include "AliTriggerCluster.h" #include "AliCentralTrigger.h" #include "AliDetectorEventHeader.h" #include "AliHeader.h" +#include "AliCDBManager.h" +#include "AliCDBPath.h" +#include "AliCDBEntry.h" ClassImp( AliCentralTrigger ) @@ -59,73 +63,53 @@ ClassImp( AliCentralTrigger ) AliCentralTrigger::AliCentralTrigger() : TObject(), fClassMask(0), - fDescriptors(), - fInputs() + fClusterMask(0), + fConfiguration(NULL) { // Default constructor -// LoadDescriptor("Pb-Pb"); } //_____________________________________________________________________________ -AliCentralTrigger::AliCentralTrigger( TString & descriptor ) : +AliCentralTrigger::AliCentralTrigger( TString & config ) : TObject(), fClassMask(0), - fDescriptors(), - fInputs() + fClusterMask(0), + fConfiguration(NULL) { // Default constructor - LoadDescriptor( descriptor ); -} - -//_____________________________________________________________________________ -AliCentralTrigger::AliCentralTrigger( const AliCentralTrigger& ctp ): - TObject( ctp ), - fClassMask( ctp.fClassMask ), - fDescriptors(), - fInputs() -{ - // Copy constructor - - Int_t ndes = ctp.fDescriptors.GetEntriesFast(); - for( Int_t j=0; jGetTriggerConditions(); - Int_t ncond = condArray->GetEntriesFast(); - for( Int_t j=0; jAt( j ); - cond->Reset(); - } + fClusterMask = 0; + + if (fConfiguration) { + const TObjArray& classesArray = fConfiguration->GetClasses(); + Int_t nclasses = classesArray.GetEntriesFast(); + for( Int_t j=0; jReset(); + } } } @@ -150,98 +134,70 @@ void AliCentralTrigger::MakeBranch( TString name, TTree * tree ) } //_____________________________________________________________________________ -Bool_t AliCentralTrigger::LoadDescriptor( TString & descriptor ) +Bool_t AliCentralTrigger::LoadConfiguration( TString & config ) { - // Load one or more pre-created Descriptors from database/file that match - // with the input string 'descriptor' - // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL" - - // Delete any descriptor - Reset(); - - // Load the selected descriptors - TObjArray* desArray = descriptor.Tokenize( " " ); - Int_t ndes = desArray->GetEntriesFast(); - for( Int_t i=0; iAt( i ); - AliTriggerDescriptor* des = AliTriggerDescriptor::LoadDescriptor( val->String() ); - if( des ) - fDescriptors.AddLast( des ); - else - AliWarning( Form( "Descriptor (%s) not found", val->String().Data() ) ); + // Load one and only one pre-created COnfiguration from database/file that match + // with the input string 'config' + // Ej: "p-p", "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL" + + // Delete the active configuration, if any + DeleteConfiguration(); + + // Load the selected configuration + if (!config.IsNull()) { + fConfiguration = AliTriggerConfiguration::LoadConfiguration( config ); + if(fConfiguration) + return kTRUE; + else { + AliError( Form( "Valid TriggerConfiguration (%s) is not found ! Disabling the trigger simulation !", config.Data() ) ); + return kFALSE; + } + } + else { + // Load one and only one trigger descriptor from CDB + AliInfo( "GETTING TRIGGER DESCRIPTORS FROM CDB!!!" ); + + AliCDBPath path( "GRP", "CTP", "Config" ); + + AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath()); + if( !entry ) AliFatal( "Couldn't load trigger description data from CDB!" ); + + fConfiguration = (AliTriggerConfiguration *)entry->GetObject(); + if(fConfiguration) + return kTRUE; + else { + AliError( "No valid configuration is found in the CDB ! Disabling the trigger simulation !" ); + return kFALSE; + } } - Bool_t desfound = kTRUE; - if( fDescriptors.GetEntriesFast() == 0 ) desfound = kFALSE; - - delete desArray; - - return desfound; } //_____________________________________________________________________________ TString AliCentralTrigger::GetDetectors() { - // return TString with the detectors to be trigger - // merging detectors from all descriptors + // return TString with the detectors (modules) to be used for triggering TString result; - Int_t ndes = fDescriptors.GetEntriesFast(); - for( Int_t i=0; iGetDetectorCluster(); - TObjArray* det = detStr.Tokenize(" "); - Int_t ndet = det->GetEntriesFast(); - for( Int_t j=0; jAt(j))->String() ) )continue; - result.Append( " " ); - result.Append( ((TObjString*)det->At(j))->String() ); - } - } + if (fConfiguration) + result = fConfiguration->GetTriggeringModules(); return result; } -//_____________________________________________________________________________ -UChar_t AliCentralTrigger::GetClusterMask() -{ - // Return the detector cluster mask following - // table 4.3 pag 60, TDR Trigger and DAQ - - TString detStr = GetDetectors(); - TObjArray* det = detStr.Tokenize(" "); - Int_t ndet = det->GetEntriesFast(); - - UInt_t idmask = 0; - if( ndet >= 8 ) { // All detectors, should be 9 but ACORDE is not implemented yet - idmask = 1; - return idmask; - } - - if( ndet >= 7 && !detStr.Contains("MUON") ) { // Central Barrel, All but MUON - idmask = 2; - return idmask; - } - - if( detStr.Contains("MUON") && detStr.Contains("T0") ) { // MUON arm - idmask = 4; - return idmask; - } - - return idmask; // 0 something else!!! -} //_____________________________________________________________________________ Bool_t AliCentralTrigger::RunTrigger( AliRunLoader* runLoader ) { // run the trigger - if( fDescriptors.GetEntriesFast() == 0 ) { - AliError( "not trigger descriptor loaded, skipping trigger" ); + if( !fConfiguration ) { + AliError( "No trigger configuration loaded, skipping trigger" ); return kFALSE; } TTree *tree = runLoader->TreeCT(); if( !tree ) { - AliError( "not folder with trigger loaded, skipping trigger" ); + AliError( "No folder with trigger loaded, skipping trigger" ); return kFALSE; } @@ -254,7 +210,7 @@ Bool_t AliCentralTrigger::RunTrigger( AliRunLoader* runLoader ) runLoader->GetEvent( iEvent ); // Get detectors involve TString detStr = GetDetectors(); - AliInfo( Form(" Cluster Detectors %s \n", detStr.Data() ) ); + AliInfo( Form(" Triggering Detectors %s \n", detStr.Data() ) ); TObjArray* detArray = runLoader->GetAliRun()->Detectors(); // Reset Mask fClassMask = 0; @@ -266,18 +222,13 @@ Bool_t AliCentralTrigger::RunTrigger( AliRunLoader* runLoader ) AliInfo( Form("Triggering from digits for %s", det->GetName() ) ); AliTriggerDetector* trgdet = det->CreateTriggerDetector(); - trgdet->CreateInputs(); + trgdet->CreateInputs(fConfiguration->GetInputs()); TStopwatch stopwatchDet; stopwatchDet.Start(); trgdet->Trigger(); AliInfo( Form("Execution time for %s: R:%.2fs C:%.2fs", det->GetName(), stopwatchDet.RealTime(), stopwatchDet.CpuTime() ) ); - // Get the inputs - TObjArray* detInp = trgdet->GetInputs(); - for( Int_t i=0; iGetEntriesFast(); i++ ) { - fInputs.AddLast( detInp->At(i) ); - } trgdetArray.AddLast( trgdet ); // Write trigger detector in Event folder in Digits file @@ -304,8 +255,7 @@ Bool_t AliCentralTrigger::RunTrigger( AliRunLoader* runLoader ) } // Check trigger conditions and create the trigger class mask - CheckConditions(); - fInputs.Clear(); + TriggerClasses(); // Clear trigger detectors trgdetArray.SetOwner(); @@ -333,42 +283,37 @@ Bool_t AliCentralTrigger::RunTrigger( AliRunLoader* runLoader ) } //_____________________________________________________________________________ -ULong64_t AliCentralTrigger::CheckConditions() +ULong64_t AliCentralTrigger::TriggerClasses() { - // Check trigger conditions and create the trigger class mask - - Int_t ndes = fDescriptors.GetEntriesFast(); - for( Int_t i=0; iGetTriggerConditions(); - Int_t ncond = condArray->GetEntriesFast(); - for( Int_t j=0; jAt( j ); - if( !cond->CheckInputs( fInputs ) ) { - AliError( Form("Condition %s is not OK",cond->GetName())); - //JF continue; - } - cond->Trigger( fInputs ); - // cond->Print(); - fClassMask |= cond->GetValue(); - } - } - return fClassMask; + // Check trigger conditions and create the trigger class + // and trigger cluster masks + if (fConfiguration) { + const TObjArray& classesArray = fConfiguration->GetClasses(); + Int_t nclasses = classesArray.GetEntriesFast(); + for( Int_t j=0; jTrigger( fConfiguration->GetInputs(), fConfiguration->GetFunctions() ); + fClassMask |= trclass->GetValue(); + if (trclass->GetStatus()) + fClusterMask |= (trclass->GetCluster())->GetClusterMask(); + } + } + return fClassMask; } //_____________________________________________________________________________ -TObjArray* AliCentralTrigger::GetResultConditions() +TObjArray* AliCentralTrigger::GetFiredClasses() const { // return only the true conditions TObjArray* result = new TObjArray(); - Int_t ndes = fDescriptors.GetEntriesFast(); - for( Int_t i=0; iGetTriggerConditions(); - Int_t ncond = condArray->GetEntriesFast(); - for( Int_t j=0; jAt( j ); - if( cond->GetStatus() ) result->AddLast( cond ); - } + if (fConfiguration) { + const TObjArray& classesArray = fConfiguration->GetClasses(); + Int_t nclasses = classesArray.GetEntriesFast(); + for( Int_t j=0; jGetStatus() ) result->AddLast( trclass ); + } } return result; @@ -380,12 +325,7 @@ void AliCentralTrigger::Print( const Option_t* ) const // Print cout << "Central Trigger: " << endl; cout << " Trigger Class Mask: 0x" << hex << fClassMask << dec << endl; - - Int_t ndes = fDescriptors.GetEntriesFast(); - for( Int_t i=0; iPrint(); - } + if (fConfiguration) fConfiguration->Print(); cout << endl; } diff --git a/STEER/AliCentralTrigger.h b/STEER/AliCentralTrigger.h index 12b0d6fe672..dfd278ae3c9 100644 --- a/STEER/AliCentralTrigger.h +++ b/STEER/AliCentralTrigger.h @@ -11,12 +11,12 @@ // This class for running the Central Trigger Processor // // // // // -// Load Descriptors // -// Make a list the trigger detectors involve from the descriptors // +// Load Configuration // +// Make a list the trigger detectors involved ( from the configuration) // // For the each event // // Run the Trigger for the each detector // // Get the inputs // -// Check the condition classes // +// Check the trigger classes // // Create the class mask // // Save result // // // @@ -27,38 +27,38 @@ class TTree; class AliRunLoader; +class AliTriggerConfiguration; class AliCentralTrigger : public TObject { public: AliCentralTrigger(); - AliCentralTrigger( TString & descriptor ); - AliCentralTrigger( const AliCentralTrigger& ctp ); + AliCentralTrigger( TString & config ); virtual ~AliCentralTrigger(); - Bool_t LoadDescriptor( TString & descriptor ); + Bool_t LoadConfiguration( TString & config ); Bool_t RunTrigger( AliRunLoader * runloader ); - ULong64_t CheckConditions(); + ULong64_t TriggerClasses(); void Reset(); - void DeleteDescriptors(); + void DeleteConfiguration(); void MakeBranch( TString name, TTree * tree ); // Getters TString GetDetectors(); ULong64_t GetClassMask() const { return fClassMask; } - UChar_t GetClusterMask(); - TObjArray* GetLoadedDescriptors() { return &fDescriptors; } - TObjArray* GetResultConditions(); + UChar_t GetClusterMask() const { return fClusterMask; } + AliTriggerConfiguration* GetConfiguration() { return fConfiguration; } + TObjArray* GetFiredClasses() const; void Print( const Option_t* opt ="" ) const; protected: - // TString fRunCondition; // Running modes Ej. Pb-Pb, p-p, p-A ULong64_t fClassMask; // UID ( bitwise OR of conditions mask ) - TObjArray fDescriptors; // Array of Trigger Descriptors (AliTriggerDescriptor) - TObjArray fInputs; //! Array of Trigger Inputs + UChar_t fClusterMask; // UID ( bitwise OR of clusters mask ) + AliTriggerConfiguration* fConfiguration; // Trigger Configuration used private: Bool_t IsSelected( TString detName, TString& detectors ) const; + AliCentralTrigger( const AliCentralTrigger& ctp ); - ClassDef( AliCentralTrigger, 1 ) // class for running the Central Trigger Processor + ClassDef( AliCentralTrigger, 2 ) // class for running the Central Trigger Processor }; diff --git a/STEER/AliExpression.cxx b/STEER/AliExpression.cxx index 86637ee68c0..44d1bb50067 100644 --- a/STEER/AliExpression.cxx +++ b/STEER/AliExpression.cxx @@ -20,7 +20,7 @@ // AliExpression Class // // // // // Helper class to evaluate the condition expressions in // -// AliTriggerCondition // +// AliTrigger* classes // // Implements a simple recursive-descent parser // // // /////////////////////////////////////////////////////////////////////////////// @@ -103,7 +103,7 @@ AliExpression::AliExpression( int op, AliExpression* a ) : } //______________________________________________________________________________ -Bool_t AliExpression::Value( TObjArray &vars ) +Bool_t AliExpression::Value( const TObjArray &vars ) { // Evaluate the expression if ( fArg2 == 0 && fVname.IsNull() ) { @@ -354,7 +354,7 @@ AliExpression* AliExpression::Expression( TObjArray &st,Int_t &i ) ClassImp( AliVariableExpression ) //______________________________________________________________________________ -Bool_t AliVariableExpression::Value( TObjArray& pgm ) +Bool_t AliVariableExpression::Value( const TObjArray& pgm ) { // return the value TObject* dd = pgm.FindObject( fVname.Data() ); diff --git a/STEER/AliExpression.h b/STEER/AliExpression.h index 745f2a7555a..e90262df859 100644 --- a/STEER/AliExpression.h +++ b/STEER/AliExpression.h @@ -34,7 +34,7 @@ public: fOperator(exp.fOperator) {} AliExpression& operator=(const AliExpression& exp); - virtual Bool_t Value( TObjArray & vars ); + virtual Bool_t Value( const TObjArray & vars ); virtual TString Unparse() const; TString fVname; // Variable name @@ -64,7 +64,7 @@ class AliVariableExpression: public AliExpression { public: AliVariableExpression( TString a ): AliExpression() { fVname = a; }; ~AliVariableExpression() {} - virtual Bool_t Value( TObjArray& pgm ); + virtual Bool_t Value( const TObjArray& pgm ); virtual TString Unparse() const { return fVname; } ClassDef( AliVariableExpression, 2 ) // Class to define a variable expression diff --git a/STEER/AliSimulation.cxx b/STEER/AliSimulation.cxx index f79129c5670..2f990cd90d6 100644 --- a/STEER/AliSimulation.cxx +++ b/STEER/AliSimulation.cxx @@ -713,7 +713,7 @@ Bool_t AliSimulation::Run(Int_t nEvents) } //_____________________________________________________________________________ -Bool_t AliSimulation::RunTrigger(const char* descriptors) +Bool_t AliSimulation::RunTrigger(const char* config) { // run the trigger @@ -734,28 +734,27 @@ Bool_t AliSimulation::RunTrigger(const char* descriptors) AliRunLoader* runLoader = LoadRun("READ"); if (!runLoader) return kFALSE; - TString des = descriptors; + TString trconfiguration = config; - if (des.IsNull()) { + if (trconfiguration.IsNull()) { if (gAlice->GetTriggerDescriptor() != "") { - des = gAlice->GetTriggerDescriptor(); - } - else { - AliWarning("No trigger descriptor is specified. Skipping the trigger simulation..."); - return kTRUE; + trconfiguration = gAlice->GetTriggerDescriptor(); } + else + AliWarning("No trigger descriptor is specified. Loading the one that is the CDB."); } runLoader->MakeTree( "GG" ); AliCentralTrigger* aCTP = runLoader->GetTrigger(); - // Load Descriptors - aCTP->LoadDescriptor( des ); + // Load Configuration + if (!aCTP->LoadConfiguration( trconfiguration )) + return kFALSE; - // digits -> trigger + // digits -> trigger if( !aCTP->RunTrigger( runLoader ) ) { if (fStopOnError) { - // delete aCTP; - return kFALSE; + // delete aCTP; + return kFALSE; } } diff --git a/STEER/AliTriggerBCMask.cxx b/STEER/AliTriggerBCMask.cxx index ef40c32b95c..f408a044af1 100644 --- a/STEER/AliTriggerBCMask.cxx +++ b/STEER/AliTriggerBCMask.cxx @@ -19,6 +19,7 @@ // // /////////////////////////////////////////////////////////////////////////////// +#include #include "AliTriggerBCMask.h" @@ -33,11 +34,19 @@ AliTriggerBCMask::AliTriggerBCMask(): } //_____________________________________________________________________________ -AliTriggerBCMask::AliTriggerMask( TString & name, UChar_t *mask ): +AliTriggerBCMask::AliTriggerBCMask( TString & name ): TNamed( name, name ) { // Constructor - for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = mask[i]; + for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = 255; +} + +//_____________________________________________________________________________ +AliTriggerBCMask::AliTriggerBCMask( TString & name, TString & mask ): + TNamed( name, mask ) +{ + // Constructor + CreateMask(mask); } //_____________________________________________________________________________ AliTriggerBCMask::~AliTriggerBCMask() @@ -46,7 +55,7 @@ AliTriggerBCMask::~AliTriggerBCMask() } //_____________________________________________________________________________ AliTriggerBCMask::AliTriggerBCMask( const AliTriggerBCMask& mask ): - TNamed( mask ), + TNamed( mask ) { // Copy constructor for (Int_t i = 0; i < kNBytesPerBCMask; i++) fBCMask[i] = mask.fBCMask[i]; @@ -65,7 +74,7 @@ AliTriggerBCMask& AliTriggerBCMask::operator=(const AliTriggerBCMask& mask) } //_____________________________________________________________________________ -Bool_t AliTriggerBCMask::GetMask( UShort_t index) +Bool_t AliTriggerBCMask::GetMask( UShort_t index) const { // Return true or false whenever the mask is active // for the bunch-crossing # = index @@ -74,3 +83,12 @@ Bool_t AliTriggerBCMask::GetMask( UShort_t index) UChar_t offset = index%8; return (fBCMask[position] & (0x1 << offset)); } + +//_____________________________________________________________________________ +void AliTriggerBCMask::Print( const Option_t* ) const +{ + // Print + cout << "Trigger bunch-crossing mask:" << endl; + cout << " Name: " << GetName() << endl; + cout << " Mask: " << GetTitle() << endl; +} diff --git a/STEER/AliTriggerBCMask.h b/STEER/AliTriggerBCMask.h index 62de3919351..4a65b6cbb0c 100644 --- a/STEER/AliTriggerBCMask.h +++ b/STEER/AliTriggerBCMask.h @@ -13,25 +13,28 @@ // // /////////////////////////////////////////////////////////////////////////////// -class TNamed; - +#include class AliTriggerBCMask : public TNamed { public: AliTriggerBCMask(); - AliTriggerBCMask( TString & name, UChar_t *mask = NULL ); + AliTriggerBCMask( TString & name); + AliTriggerBCMask( TString & name, TString & mask ); AliTriggerBCMask( const AliTriggerBCMask& mask ); virtual ~AliTriggerBCMask(); AliTriggerBCMask& operator=(const AliTriggerBCMask& mask); - UChar_t* GetFullMask () const {return &fBCMask; } + const UChar_t* GetFullMask () const {return fBCMask; } Bool_t GetMask(UShort_t index) const; + void Print( const Option_t* ) const; enum {kNBytesPerBCMask = 446}; // Number of bytes to store the 3565 bits of BC mask private: - UChar_t fBCMask[kNBytesPerBCMask]; // Bunch cross mask (3565 bit) + void CreateMask(TString &mask) {} + + UChar_t fBCMask[kNBytesPerBCMask]; // Bunch cross mask (3565 bit) ClassDef( AliTriggerBCMask, 1 ) // Define a trigger bunch-crossing mask }; diff --git a/STEER/AliTriggerClass.cxx b/STEER/AliTriggerClass.cxx new file mode 100644 index 00000000000..3f0d9518da5 --- /dev/null +++ b/STEER/AliTriggerClass.cxx @@ -0,0 +1,209 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/////////////////////////////////////////////////////////////////////////////// +// +// This class which defines the trigger classes objects +// +// +/////////////////////////////////////////////////////////////////////////////// +#include +#include + +#include "AliLog.h" +#include "AliTriggerClass.h" +#include "AliTriggerConfiguration.h" +#include "AliTriggerDescriptor.h" +#include "AliTriggerCluster.h" +#include "AliTriggerPFProtection.h" +#include "AliTriggerBCMask.h" + +ClassImp(AliTriggerClass) + +//_____________________________________________________________________________ +AliTriggerClass::AliTriggerClass(): + TNamed(), + fClassMask(0), + fDescriptor(NULL), + fCluster(NULL), + fPFProtection(NULL), + fMask(NULL), + fPrescaler(0), + fAllRare(kFALSE), + fStatus(kFALSE) +{ + // Default constructor +} + +//_____________________________________________________________________________ +AliTriggerClass::AliTriggerClass( TString & name, UChar_t index, + AliTriggerDescriptor *desc, AliTriggerCluster *clus, + AliTriggerPFProtection *pfp, AliTriggerBCMask *mask, + UInt_t prescaler, Bool_t allrare) : + TNamed( name, name ), + fClassMask( 1 << (index-1)), + fDescriptor( desc ), + fCluster( clus ), + fPFProtection( pfp ), + fMask( mask ), + fPrescaler( prescaler ), + fAllRare( allrare ), + fStatus(kFALSE) +{ + // Constructor +} + +//_____________________________________________________________________________ +AliTriggerClass::AliTriggerClass( AliTriggerConfiguration *config, + TString & name, UChar_t index, + TString &desc, TString &clus, + TString &pfp, TString &mask, + UInt_t prescaler, Bool_t allrare) : + TNamed( name, name ), + fClassMask( 1 << (index-1)), + fDescriptor( NULL ), + fCluster( NULL ), + fPFProtection( NULL ), + fMask( NULL ), + fPrescaler( prescaler ), + fAllRare( allrare ), + fStatus(kFALSE) +{ + fDescriptor = (AliTriggerDescriptor*)config->GetDescriptors().FindObject(desc); + fCluster = (AliTriggerCluster*)config->GetClusters().FindObject(clus); + pfp.ReplaceAll("{",""); + pfp.ReplaceAll("}",""); + fPFProtection = (AliTriggerPFProtection*)config->GetPFProtections().FindObject(pfp); + mask.ReplaceAll("{",""); + mask.ReplaceAll("}",""); + fMask = (AliTriggerBCMask*)config->GetMasks().FindObject(mask); +} + +//_____________________________________________________________________________ +AliTriggerClass::~AliTriggerClass() +{ + // Destructor +} +//_____________________________________________________________________________ +AliTriggerClass::AliTriggerClass( const AliTriggerClass& trclass ): + TNamed( trclass ), + fClassMask(trclass.fClassMask), + fDescriptor(trclass.fDescriptor), + fCluster(trclass.fCluster), + fPFProtection(trclass.fPFProtection), + fMask(trclass.fMask), + fPrescaler(trclass.fPrescaler), + fAllRare(trclass.fAllRare), + fStatus(trclass.fStatus) +{ + // Copy constructor +} + +//______________________________________________________________________________ +AliTriggerClass& AliTriggerClass::operator=(const AliTriggerClass& trclass) +{ + // AliTriggerClass assignment operator. + + if (this != &trclass) { + TNamed::operator=(trclass); + fClassMask = trclass.fClassMask; + fDescriptor = trclass.fDescriptor; + fCluster = trclass.fCluster; + fPFProtection = trclass.fPFProtection; + fMask = trclass.fMask; + fPrescaler = trclass.fPrescaler; + fAllRare = trclass.fAllRare; + fStatus = trclass.fStatus; + } + return *this; +} + +//_____________________________________________________________________________ +Bool_t AliTriggerClass::CheckClass(AliTriggerConfiguration* config) const +{ + // Check the existance of trigger inputs and functions + // and the logic used. + // Return false in case of wrong class + // definition. + + if (!fClassMask) { + AliError(Form("The class (%s) has invalid mask pattern !",GetName())); + return kFALSE; + } + + if (!config->GetDescriptors().FindObject(fDescriptor)) { + AliError(Form("The class (%s) contains invalid descriptor !",GetName())); + return kFALSE; + } + else { + if (!(fDescriptor->CheckInputsAndFunctions(config->GetInputs(),config->GetFunctions()))) { + AliError(Form("The class (%s) contains bad descriptor !",GetName())); + return kFALSE; + } + } + + if (!config->GetClusters().FindObject(fCluster)) { + AliError(Form("The class (%s) contains invalid cluster !",GetName())); + return kFALSE; + } + + if (!config->GetPFProtections().FindObject(fPFProtection)) { + AliError(Form("The class (%s) contains invalid past-future protection !",GetName())); + return kFALSE; + } + + if (!config->GetMasks().FindObject(fMask)) { + AliError(Form("The class (%s) contains invalid BC mask !",GetName())); + return kFALSE; + } + + return kTRUE; +} + +//_____________________________________________________________________________ +void AliTriggerClass::Trigger( const TObjArray& inputs , const TObjArray& functions) +{ + // Check if the inputs satify the trigger class conditions + fStatus = fDescriptor->Trigger(inputs,functions); +} + +//_____________________________________________________________________________ +Bool_t AliTriggerClass::IsActive( const TObjArray& inputs, const TObjArray& functions) const +{ + // Check if the inputs satify the trigger class conditions + if (fDescriptor) + return fDescriptor->IsActive(inputs,functions); + + return kFALSE; +} + +//_____________________________________________________________________________ +void AliTriggerClass::Print( const Option_t* ) const +{ + // Print + cout << "Trigger Class:" << endl; + cout << " Name: " << GetName() << endl; + cout << " Index: " << (Int_t)TMath::Log2(fClassMask) + 1 << endl; + cout << " Descriptor: " << fDescriptor->GetName() << endl; + cout << " Cluster: " << fCluster->GetName() << endl; + cout << " PF Protection:" << fPFProtection->GetName() << endl; + cout << " BC Mask: " << fMask->GetName() << endl; + cout << " Prescaler: " << fPrescaler << endl; + cout << " AllRare: " << fAllRare << endl; + if (fStatus) + cout << " Class is fired " << endl; + else + cout << " Class is not fired " << endl; +} diff --git a/STEER/AliTriggerClass.h b/STEER/AliTriggerClass.h new file mode 100644 index 00000000000..49868b9247f --- /dev/null +++ b/STEER/AliTriggerClass.h @@ -0,0 +1,69 @@ +#ifndef ALITRIGGERCLASS_H +#define ALITRIGGERCLASS_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// This class represents the CTP class objects // +// // +// The Class consists of Name, descriptor, mask, protection, index in the // +// trigger mask // +// // +// // +/////////////////////////////////////////////////////////////////////////////// + +#include + +class AliTriggerConfiguration; +class AliTriggerDescriptor; +class AliTriggerCluster; +class AliTriggerPFProtection; +class AliTriggerBCMask; + +class AliTriggerClass : public TNamed { + +public: + AliTriggerClass(); + AliTriggerClass( TString & name, UChar_t index, + AliTriggerDescriptor *desc, AliTriggerCluster *clus, + AliTriggerPFProtection *pfp, AliTriggerBCMask *mask, + UInt_t prescaler, Bool_t allrare); + AliTriggerClass( AliTriggerConfiguration *config, + TString & name, UChar_t index, + TString &desc, TString &clus, + TString &pfp, TString &mask, + UInt_t prescaler, Bool_t allrare); + + AliTriggerClass( const AliTriggerClass& trclass ); + virtual ~AliTriggerClass(); + AliTriggerClass& operator=(const AliTriggerClass& trclass); + + void Reset() { fStatus = kFALSE; } + + ULong64_t GetValue() const { return (fStatus) ? fClassMask : 0; } + Bool_t GetStatus() const { return fStatus; } + ULong64_t GetMask() const { return fClassMask; } + AliTriggerDescriptor* GetDescriptor() const { return fDescriptor; } + AliTriggerCluster* GetCluster() const { return fCluster; } + + void Trigger( const TObjArray& inputs , const TObjArray& functions); + void Print( const Option_t* ) const; + + Bool_t CheckClass(AliTriggerConfiguration *config) const; + Bool_t IsActive( const TObjArray& inputs, const TObjArray& functions) const; +private: + ULong64_t fClassMask; // position of the class in the trigger pattern + AliTriggerDescriptor* fDescriptor; // pointer to the descriptor + AliTriggerCluster* fCluster; // pointer to the cluster + AliTriggerPFProtection* fPFProtection; // pointer to the past-future protection + AliTriggerBCMask* fMask; // pointer to bunch-crossing mask + UInt_t fPrescaler; // Downscaling factor + Bool_t fAllRare; // All or Rare trigger + Bool_t fStatus; //! true = Condition has been satisfied after Trigger + + ClassDef( AliTriggerClass, 1 ) // Define a trigger class object +}; + +#endif diff --git a/STEER/AliTriggerCluster.cxx b/STEER/AliTriggerCluster.cxx new file mode 100644 index 00000000000..1c208f011ad --- /dev/null +++ b/STEER/AliTriggerCluster.cxx @@ -0,0 +1,131 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// +// Class to define a Trigger Cluster +// +// A Trigger Cluster is a group of detector to be trigger together +// +/////////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include + +#include "AliLog.h" +#include "AliDAQ.h" +#include "AliTriggerCluster.h" +#include "AliTriggerInput.h" + +ClassImp( AliTriggerCluster ) + +//_____________________________________________________________________________ +AliTriggerCluster::AliTriggerCluster(): + TNamed(), + fClusterMask(0) +{ +} + +//_____________________________________________________________________________ +AliTriggerCluster::AliTriggerCluster( TString & name, UChar_t index, TString & detectors ) : + TNamed(name,detectors), + fClusterMask((index <=6) ? 1 << (index-1) : 0) +{ + TString detClus; + for( Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++ ) { + if( IsSelected( AliTriggerInput::fgkCTPDetectorName[iDet], fTitle )) { + // Add the detector + detClus.Append( " " ); + detClus.Append( AliDAQ::DetectorName(iDet) ); + } + } + SetTitle(detClus.Data()); +} + +//_____________________________________________________________________________ +AliTriggerCluster::AliTriggerCluster( const AliTriggerCluster &clus ): + TNamed(clus), + fClusterMask(clus.fClusterMask) +{ + // Copy constructor +} + +//_____________________________________________________________________________ +Bool_t AliTriggerCluster::IsDetectorInCluster( TString & detName ) +{ + // search for the given detector + Bool_t result = kFALSE; + if( (fTitle.CompareTo( detName ) == 0) || + fTitle.BeginsWith( detName+" " ) || + fTitle.EndsWith( " "+detName ) || + fTitle.Contains( " "+detName+" " ) ) { + result = kTRUE; + } + return result; +} + + +//_____________________________________________________________________________ +void AliTriggerCluster::Print( const Option_t* ) const +{ + // Print + cout << "Detector Cluster:" << endl; + cout << " Name: " << GetName() << endl; + cout << " Cluster index: " << (Int_t)TMath::Log2(fClusterMask) + 1 << endl; + cout << " Detectors: " << GetDetectorsInCluster() << endl; +} + + +////////////////////////////////////////////////////////////////////////////// +// Helper method + +//_____________________________________________________________________________ +Bool_t AliTriggerCluster::IsSelected( TString detName, TString& detectors ) const +{ + // check whether detName is contained in detectors + // if yes, it is removed from detectors + + // check if all detectors are selected + if( (detectors.CompareTo("ALL") == 0 ) || + detectors.BeginsWith("ALL ") || + detectors.EndsWith(" ALL") || + detectors.Contains(" ALL ") ) { + detectors = "ALL"; + return kTRUE; + } + + // search for the given detector + Bool_t result = kFALSE; + if( (detectors.CompareTo( detName ) == 0) || + detectors.BeginsWith( detName+" " ) || + detectors.EndsWith( " "+detName ) || + detectors.Contains( " "+detName+" " ) ) { + detectors.ReplaceAll( detName, "" ); + result = kTRUE; + } + + // clean up the detectors string + while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " ); + while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 ); + while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 ); + + return result; +} diff --git a/STEER/AliTriggerCluster.h b/STEER/AliTriggerCluster.h new file mode 100644 index 00000000000..255b9a4d545 --- /dev/null +++ b/STEER/AliTriggerCluster.h @@ -0,0 +1,42 @@ +#ifndef ALITRIGGERCLUSTER_H +#define ALITRIGGERCLUSTER_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// +// Class to define a Trigger Cluster +// +// A Trigger Cluster is a group of detector to be trigger together +// +////////////////////////////////////////////////////////////////////////////// +class TObject; +class TString; + +class AliTriggerCluster : public TNamed { + +public: + AliTriggerCluster(); + AliTriggerCluster( TString & name, UChar_t index, TString & detectors ); + AliTriggerCluster( const AliTriggerCluster &clus ); + virtual ~AliTriggerCluster() {} + + // Getters + const char* GetDetectorsInCluster() const { return GetTitle(); } + Bool_t IsDetectorInCluster( TString & det ); + UChar_t GetClusterMask() const { return fClusterMask; } + + virtual void Print( const Option_t* opt ="" ) const; + +private: + UChar_t fClusterMask; // The trigger cluster mask pattern + Bool_t IsSelected( TString detName, TString & detectors ) const; + AliTriggerCluster& operator=(const AliTriggerCluster& clus); + + ClassDef( AliTriggerCluster, 1 ) // Define a Trigger Cluster +}; + +#endif diff --git a/STEER/AliTriggerConfiguration.cxx b/STEER/AliTriggerConfiguration.cxx new file mode 100755 index 00000000000..14d3fb3da6b --- /dev/null +++ b/STEER/AliTriggerConfiguration.cxx @@ -0,0 +1,855 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/////////////////////////////////////////////////////////////////////////////// +// +// This class which defines defines the Trigger Configuration +// +// Trigger Configuration defines the trigger setup for a particular run +// We have default configurations for each running mode (Pb-Pb, p-p, p-A, Calibration, etc). +// It keep: +// All the information conained in the CTP configuration file used +// online during the data taking +// +// Configurations could be created and stored in local file. +// By default the configuration is loaded from the corresponding GRP entry +// inside the OCDB. There one can have one and only one configuration per run. +// +// Example how to create a Trigger Configuration: +// +// AliTriggerConfiguration config( "TEST", "Test Configuration" ); +// +// // Define a Cluster Detector +// config.AddDetectorCluster( "VZERO ZDC MUON" ); +// +// // Define the trigger conditions (see AliTriggerCondition.cxx) +// config.AddCondition( "VZERO_TEST1_L0 & MUON_SPlus_LPt_L0 & ZDC_TEST2_L0", // condition +// "VO1_M1_ZDC2", // short name +// "Dummy", // short description +// 0x0100 ); // class mask (set one bit) +// +// config.AddCondition( "VZERO_TEST2_L0 & MUON_SMinus_HPt_L0 & ZDC_TEST1_L0", +// "VO2_M3_ZDC1", +// "Dummy", +// 0x0200 ); +// +// config.AddCondition( "VZERO_TEST3_L0 | MUON_Unlike_LPt_L0 | ZDC_TEST3_L0", +// "VO3_M1_ZDC3", +// "Dummy", +// 0x0400 ); +// config.CheckInputsConditions("Config.C"); +// config.Print(); +// +// // save the configuration to file +// // (default file name $ALICE_ROOT/data/triggerConfigurations.root) +// config.WriteConfiguration(); or config.WriteConfiguration( filename ); +// +/////////////////////////////////////////////////////////////////////////////// +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "AliLog.h" +#include "AliRun.h" +#include "AliRunLoader.h" +#include "AliModule.h" + +#include "AliTriggerInput.h" +//#include "AliTriggerDetector.h" +#include "AliTriggerInteraction.h" +#include "AliTriggerBCMask.h" +#include "AliTriggerCluster.h" +#include "AliTriggerPFProtection.h" +#include "AliTriggerDescriptor.h" +#include "AliTriggerClass.h" +#include "AliTriggerConfiguration.h" + +ClassImp(AliTriggerConfiguration) + +const TString AliTriggerConfiguration::fgkConfigurationFileName("/data/triggerConfigurations.root"); + +//_____________________________________________________________________________ +AliTriggerConfiguration::AliTriggerConfiguration(): + TNamed(), + fInputs(), + fInteractions(), + fFunctions(), + fPFProtections(), + fMasks(), + fDescriptors(), + fClusters(), + fClasses() +{ + // Default constructor +} + +//_____________________________________________________________________________ +AliTriggerConfiguration::AliTriggerConfiguration( TString & name, TString & description ): + TNamed( name, description ), + fInputs(), + fInteractions(), + fFunctions(), + fPFProtections(), + fMasks(), + fDescriptors(), + fClusters(), + fClasses() +{ + // Constructor +} + +//_____________________________________________________________________________ +AliTriggerConfiguration::~AliTriggerConfiguration() +{ + fInputs.SetOwner(); + fInputs.Delete(); + fInteractions.SetOwner(); + fInteractions.Delete(); + fFunctions.SetOwner(); + fFunctions.Delete(); + fPFProtections.SetOwner(); + fPFProtections.Delete(); + fMasks.SetOwner(); + fMasks.Delete(); + fDescriptors.SetOwner(); + fDescriptors.Delete(); + fClusters.SetOwner(); + fClusters.Delete(); + fClasses.SetOwner(); + fClasses.Delete(); +} + +//_____________________________________________________________________________ +Bool_t AliTriggerConfiguration::AddInput( AliTriggerInput* input ) +{ + if (fInputs.GetEntries() < kNMaxInputs) { + fInputs.AddLast( input ); + return kTRUE; + } + else { + AliError("CTP can handle up to 50 inputs ! Impossible to add the required input !"); + return kFALSE; + } +} + +//_____________________________________________________________________________ +AliTriggerInput* AliTriggerConfiguration::AddInput( TString &name, TString &det, + UChar_t level, UInt_t signature, + UChar_t number ) +{ + AliTriggerInput *input = new AliTriggerInput(name,det,level,signature,number); + if (!AddInput(input)) { + delete input; + return NULL; + } + else + return input; +} + +//_____________________________________________________________________________ +AliTriggerInteraction* AliTriggerConfiguration::AddInteraction(TString &name, TString &logic) +{ + AliTriggerInteraction *interact = new AliTriggerInteraction(name,logic); + if (!AddInteraction(interact)) { + delete interact; + return NULL; + } + else + return interact; +} + +//_____________________________________________________________________________ +Bool_t AliTriggerConfiguration::AddInteraction(AliTriggerInteraction *interact) +{ + if (fInteractions.GetEntries() < kNMaxInteractions) { + if (interact->CheckInputs(fInputs)) { + fInteractions.AddLast( interact ); + return kTRUE; + } + else + AliError("Invalid interaction ! Impossible to add it !"); + } + else + AliError("CTP can handle up to 2 interactions ! Impossible to add the required interaction !"); + + return kFALSE; +} + +//_____________________________________________________________________________ +AliTriggerInteraction* AliTriggerConfiguration::AddFunction(TString &name, TString &logic) +{ + AliTriggerInteraction *func = new AliTriggerInteraction(name,logic); + if (!AddFunction(func)) { + delete func; + return NULL; + } + else + return func; +} + +//_____________________________________________________________________________ +Bool_t AliTriggerConfiguration::AddFunction(AliTriggerInteraction *func) +{ + if (fFunctions.GetEntries() < kNMaxFunctions) { + if (func->CheckInputs(fInputs)) { + fFunctions.AddLast( func ); + return kTRUE; + } + else + AliError("Invalid logical function ! Impossible to add it !"); + } + else + AliError("CTP can handle up to 2 logical functions ! Impossible to add the required interaction !"); + + return kFALSE; +} + +//_____________________________________________________________________________ +Bool_t AliTriggerConfiguration::AddPFProtection( AliTriggerPFProtection* pfp ) +{ + if (fPFProtections.GetEntries() < kNMaxPFProtections) { + if (pfp->CheckInteractions(fInteractions)) { + fPFProtections.AddLast( pfp ); + return kTRUE; + } + else + AliError("Invalid past-future protection ! Impossible to add it !"); + } + else + AliError("CTP can handle up to 4 past-future protections ! Impossible to add the required protection !"); + + return kFALSE; +} + +//_____________________________________________________________________________ +AliTriggerBCMask* AliTriggerConfiguration::AddMask( TString &name, TString &mask ) +{ + AliTriggerBCMask *bcmask = new AliTriggerBCMask(name,mask); + if (!AddMask(bcmask)) { + delete bcmask; + return NULL; + } + else + return bcmask; +} + +//_____________________________________________________________________________ +Bool_t AliTriggerConfiguration::AddMask( AliTriggerBCMask* mask ) +{ + if (fMasks.GetEntries() < kNMaxMasks) { + fMasks.AddLast( mask ); + return kTRUE; + } + else + AliError("CTP can handle up to 4 bunch-crossing masks ! Impossible to add the required mask !"); + + return kFALSE; +} + +//_____________________________________________________________________________ +AliTriggerCluster* AliTriggerConfiguration::AddCluster( TString &name, UChar_t index, TString &detectors) +{ + AliTriggerCluster *clust = new AliTriggerCluster(name,index,detectors); + if (!AddCluster(clust)) { + delete clust; + return NULL; + } + else + return clust; + +} + +//_____________________________________________________________________________ +Bool_t AliTriggerConfiguration::AddCluster( AliTriggerCluster* cluster ) +{ + if (fClusters.GetEntries() < kNMaxClusters) { + TString dets(cluster->GetDetectorsInCluster()); + if (!(dets.IsNull())) { + fClusters.AddLast( cluster ); + return kTRUE; + } + else + AliError("Empty trigger cluster ! Impossible to add it !"); + } + else + AliError("CTP can handle up to 6 different detector clusters ! Impossible to add the required cluster !"); + + return kFALSE; +} + +//_____________________________________________________________________________ +TString AliTriggerConfiguration::GetActiveDetectors() const +{ + // Return an string with all active detector from each cluster + + TString activeDet = ""; + + Int_t nclus = fClusters.GetEntriesFast(); + if( !nclus ) return activeDet; + + for( Int_t j=0; jGetDetectorsInCluster(); + TObjArray* det = detStr.Tokenize(" "); + Int_t ndet = det->GetEntriesFast(); + for( Int_t j=0; jAt(j))->String() ) )continue; + activeDet.Append( " " ); + activeDet.Append( ((TObjString*)det->At(j))->String() ); + } + } + return activeDet; +} + +//_____________________________________________________________________________ +TString AliTriggerConfiguration::GetTriggeringDetectors() const +{ + // Return an string with all detectors used for triggering + + TString trDet = ""; + + Int_t ninputs = fInputs.GetEntriesFast(); + if( !ninputs ) return trDet; + + for( Int_t j=0; jGetDetector(); + if( trDet.Contains( detStr ) ) continue; + trDet.Append( " " ); + trDet.Append( detStr ); + } + return trDet; +} + +//_____________________________________________________________________________ +TString AliTriggerConfiguration::GetTriggeringModules() const +{ + // Return an string with all detectors (modules in the AliRoot + // simulation sense) used for triggering + + TString trDet = ""; + + Int_t ninputs = fInputs.GetEntriesFast(); + if( !ninputs ) return trDet; + + for( Int_t j=0; jGetModule(); + if( trDet.Contains( detStr ) ) continue; + trDet.Append( " " ); + trDet.Append( detStr ); + } + return trDet; +} + +//_____________________________________________________________________________ +AliTriggerDescriptor* AliTriggerConfiguration::AddDescriptor( TString &name, TString &cond ) +{ + AliTriggerDescriptor *desc = new AliTriggerDescriptor(name,cond); + if (!AddDescriptor(desc)) { + delete desc; + return NULL; + } + else + return desc; +} + +//_____________________________________________________________________________ +Bool_t AliTriggerConfiguration::AddDescriptor( AliTriggerDescriptor *desc ) +{ + if (fDescriptors.GetEntries() < kNMaxClasses) { + if (desc->CheckInputsAndFunctions(fInputs,fFunctions)) { + fDescriptors.AddLast( desc ); + return kTRUE; + } + else + AliError("Invalid trigger desciptor ! Impossible to add it !"); + } + else + AliError("CTP can handle up to 50 different descriptors ! Impossible to add the required descriptor !"); + + return kFALSE; +} + +//_____________________________________________________________________________ +Bool_t AliTriggerConfiguration::AddClass( AliTriggerClass *trclass ) +{ + if (fClasses.GetEntries() < kNMaxClasses) { + if (trclass->CheckClass(this)) { + fClasses.AddLast( trclass ); + return kTRUE; + } + else + AliError("Invalid trigger class ! Impossible to add it !"); + } + else + AliError("CTP can handle up to 50 different classes ! Impossible to add the required class !"); + + return kFALSE; +} + +//_____________________________________________________________________________ +AliTriggerClass *AliTriggerConfiguration::AddClass( TString &name, UChar_t index, + AliTriggerDescriptor *desc, AliTriggerCluster *clus, + AliTriggerPFProtection *pfp, AliTriggerBCMask *mask, + UInt_t prescaler, Bool_t allrare) +{ + // Add a new trigger class + if (!fDescriptors.FindObject(desc)) { + AliError("Invalid descriptor ! Impossible to add the class !"); + return NULL; + } + if (!fClusters.FindObject(clus)) { + AliError("Invalid cluster ! Impossible to add the class !"); + return NULL; + } + if (!fPFProtections.FindObject(pfp)) { + AliError("Invalid past-future protection ! Impossible to add the class !"); + return NULL; + } + if (!fMasks.FindObject(mask)) { + AliError("Invalid bunch-crossing mask ! Impossible to add the class !"); + return NULL; + } + AliTriggerClass* trclass = new AliTriggerClass( name,index,desc,clus,pfp,mask,prescaler,allrare ); + if (!AddClass(trclass)) { + delete trclass; + return NULL; + } + else + return trclass; +} + +//_____________________________________________________________________________ +AliTriggerClass *AliTriggerConfiguration::AddClass( TString &name, UChar_t index, + TString &desc, TString &clus, + TString &pfp, TString &mask, + UInt_t prescaler, Bool_t allrare) +{ + // Add a new trigger class + if (!fDescriptors.FindObject(desc)) { + AliError("Invalid descriptor ! Impossible to add the class !"); + return NULL; + } + if (!fClusters.FindObject(clus)) { + AliError("Invalid cluster ! Impossible to add the class !"); + return NULL; + } + if (!fPFProtections.FindObject(pfp)) { + AliError("Invalid past-future protection ! Impossible to add the class !"); + return NULL; + } + if (!fMasks.FindObject(mask)) { + AliError("Invalid bunch-crossing mask ! Impossible to add the class !"); + return NULL; + } + AliTriggerClass* trclass = new AliTriggerClass( this, name,index,desc,clus,pfp,mask,prescaler,allrare ); + if (!AddClass(trclass)) { + delete trclass; + return NULL; + } + else + return trclass; +} + +//_____________________________________________________________________________ +AliTriggerConfiguration* AliTriggerConfiguration::LoadConfiguration( TString & configuration) +{ + // Load one pre-created Configurations from database/file that match + // with the input string 'configuration' + // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL" + // By default the files are stored in GRP/CTP folder. + // The filename is constructed as: GRP/CTP/.cfg + + // Load the selected configuration + TString filename = gSystem->Getenv("ALICE_ROOT"); + filename += "/GRP/CTP/"; + filename += configuration; + filename += ".cfg"; + + if( gSystem->AccessPathName( filename.Data() ) ) { + AliErrorClass( Form( "file (%s) not found", filename.Data() ) ); + return NULL; + } + + + ifstream *file = new ifstream ( filename.Data() ); + if (!*file) { + AliErrorClass(Form("Error opening file (%s) !",filename.Data())); + file->close(); + delete file; + return NULL; + } + + AliTriggerConfiguration *cfg = new AliTriggerConfiguration(); + + Int_t level = 0; + TString strLine; + while (strLine.ReadLine(*file)) { + if (strLine.BeginsWith("#")) continue; + if (strLine.BeginsWith("INPUTS:")) { + level = 1; + continue; + } + if (strLine.BeginsWith("INTERACTIONS:")) { + level = 2; + continue; + } + if (strLine.BeginsWith("DESCRIPTORS:")) { + level = 3; + continue; + } + if (strLine.BeginsWith("CLUSTERS:")) { + level = 4; + continue; + } + if (strLine.BeginsWith("PFS:")) { + level = 5; + continue; + } + if (strLine.BeginsWith("BCMASKS:")) { + level = 6; + continue; + } + if (strLine.BeginsWith("CLASSES:")) { + level = 7; + continue; + } + strLine.ReplaceAll("*",'!'); + TObjArray *tokens = strLine.Tokenize(" \t"); + Int_t ntokens = tokens->GetEntriesFast(); + switch (level) { + case 1: + // Read inputs + if (ntokens != 5) { + AliErrorClass(Form("Invalid trigger input syntax (%s)!",strLine.Data())); + file->close(); + delete file; + return NULL; + } + cfg->AddInput(((TObjString*)tokens->At(0))->String(), + ((TObjString*)tokens->At(1))->String(), + ((TObjString*)tokens->At(2))->String().Atoi(), + ((TObjString*)tokens->At(3))->String().Atoi(), + ((TObjString*)tokens->At(4))->String().Atoi()); + break; + case 2: + // Read intreractions + cfg->AddInteraction(((TObjString*)tokens->At(0))->String(), + ((TObjString*)tokens->At(1))->String()); + break; + case 3: + // Read logical functions and descriptors + if (((TObjString*)tokens->At(0))->String().BeginsWith("l0f")) { + // function + cfg->AddFunction(((TObjString*)tokens->At(0))->String(), + strLine.ReplaceAll(((TObjString*)tokens->At(0))->String(),"")); + } + else { + cfg->AddDescriptor(((TObjString*)tokens->At(0))->String(), + strLine.ReplaceAll(((TObjString*)tokens->At(0))->String(),"")); + } + break; + case 4: + { + TString strTemp; + for(Int_t i = 2; i < ntokens; i++) { + strTemp += ((TObjString*)tokens->At(i))->String(); + strTemp += " "; + } + cfg->AddCluster(((TObjString*)tokens->At(0))->String(), + ((TObjString*)tokens->At(1))->String().Atoi(), + strTemp); + } + break; + case 5: + { + AliTriggerPFProtection *pfp = NULL; + if (((TObjString*)tokens->At(0))->String().CompareTo("NONE") == 0) { + pfp = new AliTriggerPFProtection(((TObjString*)tokens->At(0))->String()); + } + else { + pfp = new AliTriggerPFProtection(((TObjString*)tokens->At(0))->String(), + ((TObjString*)tokens->At(1))->String(), + ((TObjString*)tokens->At(2))->String(), + ((TObjString*)tokens->At(3))->String()); + pfp->SetNa1(((TObjString*)tokens->At(4))->String().Atoi()); + pfp->SetNa2(((TObjString*)tokens->At(5))->String().Atoi()); + pfp->SetNb1(((TObjString*)tokens->At(6))->String().Atoi()); + pfp->SetNb2(((TObjString*)tokens->At(7))->String().Atoi()); + pfp->SetTa(((TObjString*)tokens->At(8))->String().Atoi()); + pfp->SetTb(((TObjString*)tokens->At(9))->String().Atoi()); + } + cfg->AddPFProtection(pfp); + } + break; + case 6: + if (((TObjString*)tokens->At(0))->String().CompareTo("NONE") == 0) + cfg->AddMask(new AliTriggerBCMask(((TObjString*)tokens->At(0))->String())); + else { + cfg->AddMask(((TObjString*)tokens->At(0))->String(), + ((TObjString*)tokens->At(1))->String()); + } + break; + case 7: + { + AliTriggerClass *trclass = new AliTriggerClass(cfg, + ((TObjString*)tokens->At(0))->String(),((TObjString*)tokens->At(1))->String().Atoi(), + ((TObjString*)tokens->At(2))->String(),((TObjString*)tokens->At(3))->String(), + ((TObjString*)tokens->At(4))->String(),((TObjString*)tokens->At(5))->String(), + ((TObjString*)tokens->At(6))->String().Atoi(),(Bool_t)(((TObjString*)tokens->At(0))->String().Atoi())); + cfg->AddClass(trclass); + } + default: + break; + } + delete tokens; + } + + file->close(); + delete file; + + return cfg; + +} + +//_____________________________________________________________________________ +TObjArray* AliTriggerConfiguration::GetAvailableConfigurations( const char* filename ) +{ + // Return an array of configuration in the file + + TString path; + if( !filename[0] ) { + path += gSystem->Getenv( "ALICE_ROOT" ); + path += fgkConfigurationFileName; + } + else + path += filename; + + if( gSystem->AccessPathName( path.Data() ) ) { + AliErrorGeneral( "AliTriggerConfiguration", Form( "file (%s) not found", path.Data() ) ); + return NULL; + } + + TObjArray* desArray = new TObjArray(); + + TFile file( path.Data(), "READ" ); + if( file.IsZombie() ) { + AliErrorGeneral( "AliTriggerConfiguration", Form( "Error opening file (%s)", path.Data() ) ); + return NULL; + } + + file.ReadAll(); + + TKey* key; + TIter next( file.GetListOfKeys() ); + while( (key = (TKey*)next()) ) { + TObject* obj = key->ReadObj(); + if( obj->InheritsFrom( "AliTriggerConfiguration" ) ) { + desArray->AddLast( obj ); + } + } + file.Close(); + + return desArray; +} + +//_____________________________________________________________________________ +void AliTriggerConfiguration::WriteConfiguration( const char* filename ) +{ + // Write the configuration + TString path; + if( !filename[0] ) { + path += gSystem->Getenv("ALICE_ROOT"); + path += fgkConfigurationFileName; + } + else + path += filename; + + TFile file( path.Data(), "UPDATE" ); + if( file.IsZombie() ) { + AliErrorGeneral( "AliTriggerConfiguration", + Form( "Can't open file (%s)", path.Data() ) ); + return; + } + + Bool_t result = (Write( GetName(), TObject::kOverwrite ) != 0); + if( !result ) + AliErrorGeneral( "AliTriggerConfiguration", + Form( "Can't write entry to file <%s>!", path.Data() ) ); + file.Close(); +} + +//_____________________________________________________________________________ +Bool_t AliTriggerConfiguration::CheckConfiguration( TString& configfile ) +{ + // To be used on the pre-creation of Configurations to check if the + // conditions have valid inputs names. + // + // Initiate detectors modules from a Config file + // Ask to each active module present in the fDetectorCluster + // to create a Trigger detector and retrive the inputs from it + // to create a list of inputs. + // Each condition in the configuration is then checked agains + // the list of inputs + + + if (!gAlice) { + AliError( "no gAlice object. Restart aliroot and try again." ); + return kFALSE; + } + if (gAlice->Modules()->GetEntries() > 0) { + AliError( "gAlice was already run. Restart aliroot and try again." ); + return kFALSE; + } + + AliInfo( Form( "initializing gAlice with config file %s", + configfile.Data() ) ); + StdoutToAliInfo( StderrToAliError( + gAlice->Init( configfile.Data() ); + );); + + AliRunLoader* runLoader = gAlice->GetRunLoader(); + if( !runLoader ) { + AliError( Form( "gAlice has no run loader object. " + "Check your config file: %s", configfile.Data() ) ); + return kFALSE; + } + + // get the possible inputs to check the condition + TObjArray inputs; + TObjArray* detArray = runLoader->GetAliRun()->Detectors(); + + TString detStr = GetTriggeringModules(); + + for( Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++ ) { + AliModule* det = (AliModule*) detArray->At(iDet); + if( !det || !det->IsActive() ) continue; + if( IsSelected( det->GetName(), detStr ) ) { + AliInfo( Form( "Creating inputs for %s", det->GetName() ) ); + AliTriggerDetector* dtrg = det->CreateTriggerDetector(); + dtrg->CreateInputs(GetInputs()); + TObjArray* detInp = dtrg->GetInputs(); + for( Int_t i=0; iGetEntriesFast(); i++ ) { + AliInfo( Form( "Adding input %s", ((AliTriggerInput*)detInp->At(i))->GetName() ) ); + inputs.AddLast( detInp->At(i) ); + } + } + } + + // check if the condition is compatible with the triggers inputs + Int_t ndesc = fClasses.GetEntriesFast(); + Bool_t check = kTRUE; + ULong64_t mask = 0L; + for( Int_t j=0; jCheckClass( this )) ) check = kFALSE; + else { + if (trclass->IsActive(this->GetInputs(),this->GetFunctions())) { + AliInfo( Form( "Trigger Class (%s) OK, class mask (0x%Lx)", + trclass->GetName(), trclass->GetMask( ) ) ); + } + else { + AliWarning( Form( "Trigger Class (%s) is NOT active, class mask (0x%Lx)", + trclass->GetName(), trclass->GetMask( ) ) ); + } + } + // check if condition mask is duplicated + if( mask & trclass->GetMask() ) { + AliError( Form("Class (%s). The class mask (0x%Lx) is ambiguous. It was already defined", + trclass->GetName(), trclass->GetMask() ) ); + check = kFALSE; + } + mask |= trclass->GetMask(); + } + + return check; +} + + +//_____________________________________________________________________________ +void AliTriggerConfiguration::Print( const Option_t* ) const +{ + // Print + cout << "#################################################" << endl; + cout << "Trigger Configuration:" << endl; + cout << " Name: " << GetName() << endl; + cout << " Description: " << GetTitle() << endl; + cout << " Active Detectors: " << GetActiveDetectors() << endl; + cout << " Trigger Detectors: " << GetTriggeringDetectors() << endl; + + cout << "#################################################" << endl; + fInputs.Print(); + cout << "#################################################" << endl; + fInteractions.Print(); + cout << "#################################################" << endl; + fFunctions.Print(); + cout << "#################################################" << endl; + fDescriptors.Print(); + cout << "#################################################" << endl; + fClusters.Print(); + cout << "#################################################" << endl; + fPFProtections.Print(); + cout << "#################################################" << endl; + fMasks.Print(); + cout << "#################################################" << endl; + fClasses.Print(); + cout << "#################################################" << endl; + + cout << endl; +} + + +////////////////////////////////////////////////////////////////////////////// +// Helper method + +//_____________________________________________________________________________ +Bool_t AliTriggerConfiguration::IsSelected( TString detName, TString& detectors ) const +{ + // check whether detName is contained in detectors + // if yes, it is removed from detectors + + // check if all detectors are selected + if( (detectors.CompareTo("ALL") == 0 ) || + detectors.BeginsWith("ALL ") || + detectors.EndsWith(" ALL") || + detectors.Contains(" ALL ") ) { + detectors = "ALL"; + return kTRUE; + } + + // search for the given detector + Bool_t result = kFALSE; + if( (detectors.CompareTo( detName ) == 0) || + detectors.BeginsWith( detName+" " ) || + detectors.EndsWith( " "+detName ) || + detectors.Contains( " "+detName+" " ) ) { + detectors.ReplaceAll( detName, "" ); + result = kTRUE; + } + + // clean up the detectors string + while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " ); + while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 ); + while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 ); + + return result; +} diff --git a/STEER/AliTriggerConfiguration.h b/STEER/AliTriggerConfiguration.h new file mode 100755 index 00000000000..774cef10258 --- /dev/null +++ b/STEER/AliTriggerConfiguration.h @@ -0,0 +1,127 @@ +#ifndef ALITRIGGERCONFIGURATION_H +#define ALITRIGGERCONFIGURATION_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// This class represents the CTP configuration // +// // +// // +// A Trigger Configuration define a trigger setup for particula run // +// We have default one for different running modes // +// (Pb-Pb, p-p, p-A, Calibration, etc). // +// It keep: // +// All the information contained in the real CTP configuration file // +// used online during the data taking. // +// // +// // +/////////////////////////////////////////////////////////////////////////////// + +#include +#include +class TString; + +class AliTriggerCluster; +class AliTriggerDescriptor; +class AliTriggerInput; +class AliTriggerInteraction; +class AliTriggerPFProtection; +class AliTriggerBCMask; +class AliTriggerDescriptor; +class AliTriggerClass; + +class AliTriggerConfiguration : public TNamed { + +public: + AliTriggerConfiguration(); + AliTriggerConfiguration( TString & name, TString & description ); + virtual ~AliTriggerConfiguration(); + // Setters + AliTriggerInput* AddInput(TString &name, TString &det, UChar_t level, UInt_t signature, UChar_t number); + Bool_t AddInput(AliTriggerInput *input); + + AliTriggerInteraction* AddInteraction(TString &name, TString &logic); + Bool_t AddInteraction(AliTriggerInteraction *interact); + + AliTriggerInteraction* AddFunction(TString &name, TString &logic); + Bool_t AddFunction(AliTriggerInteraction *func); + + Bool_t AddPFProtection( AliTriggerPFProtection* pf ); + + AliTriggerBCMask* AddMask( TString &name, TString &mask ); + Bool_t AddMask( AliTriggerBCMask* mask ); + + AliTriggerCluster* AddCluster( TString &name, UChar_t index, TString &detectors ); + Bool_t AddCluster( AliTriggerCluster* cluster ); + + AliTriggerDescriptor* AddDescriptor( TString & name, TString & cond); + Bool_t AddDescriptor( AliTriggerDescriptor* desc ); + + AliTriggerClass* AddClass( TString &name, UChar_t index, + AliTriggerDescriptor *desc, AliTriggerCluster *clus, + AliTriggerPFProtection *pfp, AliTriggerBCMask *mask, + UInt_t prescaler, Bool_t allrare); + AliTriggerClass* AddClass( TString &name, UChar_t index, + TString &desc, TString &clus, + TString &pfp, TString &mask, + UInt_t prescaler, Bool_t allrare); + Bool_t AddClass( AliTriggerClass *trclass); + + // Getters + TString GetActiveDetectors() const; + TString GetTriggeringDetectors() const; + TString GetTriggeringModules() const; + + const TObjArray& GetInputs() const { return fInputs; } + const TObjArray& GetInteractions() const { return fInteractions; } + const TObjArray& GetFunctions() const { return fFunctions; } + const TObjArray& GetPFProtections() const { return fPFProtections; } + const TObjArray& GetMasks() const { return fMasks; } + const TObjArray& GetClusters() const { return fClusters; } + const TObjArray& GetDescriptors() const { return fDescriptors; } + const TObjArray& GetClasses() const { return fClasses; } + + // AliTriggerCluster* GetTriggerCluster(UInt_t index) + // { return (index < kNMaxClusters) ? (AliTriggerCluster*)fClusters[index] : NULL; } + + //AliTriggerPFProtection* GetPFProtection(UInt_t index) + // { return (index < kNMaxPFProtections) ? (AliTriggerPFProtection*)fPFProtections[index] : NULL; } + Bool_t CheckConfiguration( TString & configfile ); + void Print( const Option_t* opt ="" ) const; + + // Configurations Database (root file) + void WriteConfiguration( const char* filename="" ); + static TObjArray* GetAvailableConfigurations( const char* filename="" ); + static + AliTriggerConfiguration* LoadConfiguration( TString & des); + + enum {kNMaxInputs = 50}; // CTP handles up to 50 trigger detector inputs + enum {kNMaxInteractions = 2}; // CTP handles up to two different interactions + enum {kNMaxFunctions = 2}; // CTP handles up to two different logical functions + enum {kNMaxClasses = 50}; // Maximum number of trigger classes = 50 + enum {kNMaxClusters = 6}; // Maximum number of different detector clusters that can be handled by CTP + enum {kNMaxPFProtections = 4}; // Maximum number of different past-future protections that can be handled by CTP + enum {kNMaxMasks = 4}; // CTP handles up to 4 different BC masks + +private: + TObjArray fInputs; // Array with active CTP inputs + TObjArray fInteractions; // Array with the trigger interactions + TObjArray fFunctions; // Array with the logical functions of the first 4 inputs + TObjArray fPFProtections; // Array of Past-Future Protections + TObjArray fMasks; // Array with BC masks + TObjArray fDescriptors; // Array with trigger descriptors + TObjArray fClusters; // Array of Detector Trigger Clusters + TObjArray fClasses; // Array of Trigger Classes + + Bool_t IsSelected( TString detName, TString & detectors ) const; + static const TString fgkConfigurationFileName; //! name of default configurations file + + AliTriggerConfiguration& operator=(const AliTriggerConfiguration& des); + AliTriggerConfiguration( const AliTriggerConfiguration& des ); + + ClassDef( AliTriggerConfiguration, 1 ) // Define a trigger configuration +}; + +#endif diff --git a/STEER/AliTriggerDescriptor.cxx b/STEER/AliTriggerDescriptor.cxx index a9efa9c1009..68f7351dd6f 100644 --- a/STEER/AliTriggerDescriptor.cxx +++ b/STEER/AliTriggerDescriptor.cxx @@ -13,411 +13,188 @@ * provided "as is" without express or implied warranty. * **************************************************************************/ -/* $Id$ */ - /////////////////////////////////////////////////////////////////////////////// // -// This class for running and define a Trigger Descriptor -// -// A Trigger Descriptor define a trigger setup for specific runnign -// condition (Pb-Pb, p-p, p-A, Calibration, etc). -// It keep: -// - cluster detector (List of detectors involved) -// - List of conditions -// -// Descriptors could be create in advance and store in a file. -// -// Example how to create a Trigger Descriptor: -// -// AliTriggerDescriptor descrip( "TEST", "Test Descriptor" ); -// -// // Define a Cluster Detector -// descrip.AddDetectorCluster( "VZERO ZDC MUON" ); +// This class which defines the trigger descriptor objects // -// // Define the trigger conditions (see AliTriggerCondition.cxx) -// descrip.AddCondition( "VZERO_TEST1_L0 & MUON_SPlus_LPt_L0 & ZDC_TEST2_L0", // condition -// "VO1_M1_ZDC2", // short name -// "Dummy", // short description -// 0x0100 ); // class mask (set one bit) -// -// descrip.AddCondition( "VZERO_TEST2_L0 & MUON_SMinus_HPt_L0 & ZDC_TEST1_L0", -// "VO2_M3_ZDC1", -// "Dummy", -// 0x0200 ); -// -// descrip.AddCondition( "VZERO_TEST3_L0 | MUON_Unlike_LPt_L0 | ZDC_TEST3_L0", -// "VO3_M1_ZDC3", -// "Dummy", -// 0x0400 ); -// descrip.CheckInputsConditions("Config.C"); -// descrip.Print(); -// -// // save the descriptor to file -// // (default file name $ALICE_ROOT/data/triggerDescriptor.root) -// descrip.WriteDescriptor(); or descrip.WriteDescriptor( filename ); // /////////////////////////////////////////////////////////////////////////////// -#include +#include #include -#include -#include -#include -#include -#include +#include #include "AliLog.h" -#include "AliRun.h" -#include "AliRunLoader.h" -#include "AliModule.h" - -#include "AliCDBManager.h" -#include "AliCDBPath.h" -#include "AliCDBEntry.h" - -#include "AliTriggerInput.h" -#include "AliTriggerDetector.h" -#include "AliTriggerCondition.h" #include "AliTriggerDescriptor.h" - +#include "AliTriggerInput.h" +#include "AliTriggerInteraction.h" ClassImp(AliTriggerDescriptor) -//_____________________________________________________________________________ -const char* AliTriggerDescriptor::fgkDetectorName[AliTriggerDescriptor::fgkNDetectors] = - { "ITS", "TRD", "PHOS", "EMCAL", "MUON", "ZDC", "T0", "VZERO", "ACORDE", "TOF" }; - -const TString AliTriggerDescriptor::fgkDescriptorFileName("/data/triggerDescriptors.root"); - //_____________________________________________________________________________ AliTriggerDescriptor::AliTriggerDescriptor(): - TNamed(), - fDetectorCluster(""), - fConditions() + TNamed() { + // Default constructor } //_____________________________________________________________________________ -AliTriggerDescriptor::AliTriggerDescriptor( TString & name, TString & description ): - TNamed( name, description ), - fDetectorCluster(""), - fConditions() +AliTriggerDescriptor::AliTriggerDescriptor( TString & name, TString &cond ): + TNamed( name, cond ) { + // Constructor } - //_____________________________________________________________________________ -AliTriggerDescriptor::AliTriggerDescriptor( const AliTriggerDescriptor& des ): - TNamed( des ), - fDetectorCluster( des.fDetectorCluster ), - fConditions() +AliTriggerDescriptor::~AliTriggerDescriptor() +{ + // Destructor +} +//_____________________________________________________________________________ +AliTriggerDescriptor::AliTriggerDescriptor( const AliTriggerDescriptor& desc ): + TNamed( desc ) { // Copy constructor - Int_t ncond = des.fConditions.GetEntriesFast(); - for( Int_t j=0; jGetEntriesFast(); + for( Int_t i=0; iAt( i ); + if (functions.FindObject(iname->String())) { + // Logical function of the first 4 inputs + if (IsInput) { + AliError("Logical functions can not follow inputs, they are always declared first !"); + delete tokens; + return kFALSE; + } + IsInput = kFALSE; + continue; } - } - - // check if there are no trigger detectors (E.g. TPC) - if ((newdet.CompareTo("ALL") != 0) && !newdet.IsNull()) { - AliError( Form("the following detectors are not trigger detectors: %s", - newdet.Data() ) ); + if (inputs.FindObject(iname->String())) { + // already a trigger input + IsInput = kTRUE; + continue; + } + AliError(Form("Invalid trigger input or function (%s)",iname->String().Data())); + delete tokens; return kFALSE; } + delete tokens; return kTRUE; } //_____________________________________________________________________________ -void AliTriggerDescriptor::AddCondition( TString & cond, TString & name, TString & description, ULong64_t mask ) -{ - // Add a new condition - AliTriggerCondition* acond = new AliTriggerCondition( cond, name, description, mask ); - fConditions.AddLast( acond ); -} - -//_____________________________________________________________________________ -AliTriggerDescriptor* AliTriggerDescriptor::LoadDescriptor( TString & descriptor, const char* filename ) -{ - // Load one pre-created Descriptors from database/file that match - // with the input string 'descriptor' - // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL" - // Load the selected descriptor - /*TString path; - if( !filename[0] ) { - path += gSystem->Getenv("ALICE_ROOT"); - path += fgkDescriptorFileName; - } - else - path += filename; - - if( gSystem->AccessPathName( path.Data() ) ) { - AliErrorGeneral( "AliTriggerDescriptor", Form( "file (%s) not found", path.Data() ) ); - return NULL; - } - - TFile file( path.Data(), "READ" ); - AliTriggerDescriptor* des = (AliTriggerDescriptor*)(file.Get( descriptor.Data() )); - - file.Close(); - - return des;*/ - AliTriggerDescriptor *des = 0x0; - cout<<"GETTING TRIGGER DESCRIPTORS FROM CDB!!!"<Get(path.GetPath()); - if(!entry) AliFatalClass("Couldn't load trigger description data from CDB!"); - - TList *list = (TList *) entry->GetObject(); - for(Int_t i = 0; i < list->GetEntries(); i++) { - TMap *map = (TMap *)list->At(i); - des = (AliTriggerDescriptor *)map->GetValue(descriptor.Data()); - if(des) return des; - } - - return des; -} - -//_____________________________________________________________________________ -TObjArray* AliTriggerDescriptor::GetAvailableDescriptors( const char* filename ) +Bool_t AliTriggerDescriptor::IsActive(const TObjArray &inputs, const TObjArray &functions) const { - // Return an array of descriptor in the file - - TString path; - if( !filename[0] ) { - path += gSystem->Getenv( "ALICE_ROOT" ); - path += fgkDescriptorFileName; - } - else - path += filename; - - if( gSystem->AccessPathName( path.Data() ) ) { - AliErrorGeneral( "AliTriggerDescriptor", Form( "file (%s) not found", path.Data() ) ); - return NULL; - } - - TObjArray* desArray = new TObjArray(); - - TFile file( path.Data(), "READ" ); - if( file.IsZombie() ) { - AliErrorGeneral( "AliTriggerDescriptor", Form( "Error opening file (%s)", path.Data() ) ); - return NULL; - } - - file.ReadAll(); - - TKey* key; - TIter next( file.GetListOfKeys() ); - while( (key = (TKey*)next()) ) { - TObject* obj = key->ReadObj(); - if( obj->InheritsFrom( "AliTriggerDescriptor" ) ) { - desArray->AddLast( obj ); + // Check if the trigger inputs and functions + // are active + // Return false in case one or more inputs + // are disabled + TString condition( GetTitle() ); + TObjArray* tokens = condition.Tokenize(" !&|()\t"); + + Int_t ntokens = tokens->GetEntriesFast(); + for( Int_t i=0; iAt( i ); + AliTriggerInteraction *interact = (AliTriggerInteraction *)functions.FindObject(iname->String()); + if (interact) { + if (!interact->IsActive(inputs)) { + AliWarning(Form("The descriptor (%s) will be disabled, because the function (%s) is disabled", + GetName(),iname->String().Data())); + delete tokens; + return kFALSE; + } + continue; } + AliTriggerInput *inp = (AliTriggerInput *)inputs.FindObject(iname->String()); + if (inp) { + if (!inp->IsActive()) { + AliWarning(Form("The descriptor (%s) will be disabled, because the input (%s) is disabled", + GetName(),iname->String().Data())); + delete tokens; + return kFALSE; + } + continue; + } + AliError(Form("Desciptor (%s) contains invalid trigger input or function (%s)", + GetName(),iname->String().Data())); + delete tokens; + return kFALSE; } - file.Close(); - - return desArray; -} - -//_____________________________________________________________________________ -void AliTriggerDescriptor::WriteDescriptor( const char* filename ) -{ - // Load one pre-created Descriptors from database/file that match - // with the input string 'descriptor' - // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL" - - // Load the selected descriptor - TString path; - if( !filename[0] ) { - path += gSystem->Getenv("ALICE_ROOT"); - path += fgkDescriptorFileName; - } - else - path += filename; - TFile file( path.Data(), "UPDATE" ); - if( file.IsZombie() ) { - AliErrorGeneral( "AliTriggerDescriptor", - Form( "Can't open file (%s)", path.Data() ) ); - return; - } + delete tokens; + return kTRUE; - Bool_t result = (Write( GetName(), TObject::kOverwrite ) != 0); - if( !result ) - AliErrorGeneral( "AliTriggerDescriptor", - Form( "Can't write entry to file <%s>!", path.Data() ) ); - file.Close(); } //_____________________________________________________________________________ -Bool_t AliTriggerDescriptor::CheckInputsConditions( TString& configfile ) +Bool_t AliTriggerDescriptor::Trigger( const TObjArray &inputs, const TObjArray &functions) const { - // To be used on the pre-creation of Descriptors to check if the - // conditions have valid inputs names. - // - // Initiate detectors modules from a Config file - // Ask to each active module present in the fDetectorCluster - // to create a Trigger detector and retrive the inputs from it - // to create a list of inputs. - // Each condition in the descriptor is then checked agains - // the list of inputs - - - if (!gAlice) { - AliError( "no gAlice object. Restart aliroot and try again." ); - return kFALSE; - } - if (gAlice->Modules()->GetEntries() > 0) { - AliError( "gAlice was already run. Restart aliroot and try again." ); - return kFALSE; - } - - AliInfo( Form( "initializing gAlice with config file %s", - configfile.Data() ) ); - StdoutToAliInfo( StderrToAliError( - gAlice->Init( configfile.Data() ); - );); - - AliRunLoader* runLoader = gAlice->GetRunLoader(); - if( !runLoader ) { - AliError( Form( "gAlice has no run loader object. " - "Check your config file: %s", configfile.Data() ) ); - return kFALSE; - } - - // get the possible inputs to check the condition - TObjArray inputs; - TObjArray* detArray = runLoader->GetAliRun()->Detectors(); - - TString detStr = fDetectorCluster; - for( Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++ ) { - AliModule* det = (AliModule*) detArray->At(iDet); - if( !det || !det->IsActive() ) continue; - if( IsSelected( det->GetName(), detStr ) ) { - AliInfo( Form( "Creating inputs for %s", det->GetName() ) ); - AliTriggerDetector* dtrg = det->CreateTriggerDetector(); - dtrg->CreateInputs(); - TObjArray* detInp = dtrg->GetInputs(); - for( Int_t i=0; iGetEntriesFast(); i++ ) { - AliInfo( Form( "Adding input %s", ((AliTriggerInput*)detInp->At(i))->GetName() ) ); - inputs.AddLast( detInp->At(i) ); - } + // Check if the inputs and functions + // satify the descriptor conditions + + TString condition( GetTitle() ); + TObjArray* tokens = condition.Tokenize(" !&|()\t"); + + Int_t ntokens = tokens->GetEntriesFast(); + for( Int_t i=0; iAt( i ); + AliTriggerInteraction *interact = (AliTriggerInteraction *)functions.FindObject(iname->String()); + if (interact) { + if (!interact->Trigger(inputs)) { + delete tokens; + return kFALSE; } - } - - // check if the condition is compatible with the triggers inputs - Int_t ncond = fConditions.GetEntriesFast(); - Bool_t check = kTRUE; - ULong64_t mask = 0L; - for( Int_t j=0; jCheckInputs( inputs )) ) check = kFALSE; - else AliInfo( Form( "Condition (%s) inputs names OK, class mask (0x%Lx)", - cond->GetName(), cond->GetMask( ) ) ); - // check if condition mask is duplicated - if( mask & cond->GetMask() ) { - AliError( Form("Condition (%s). The class mask (0x%Lx) is ambiguous. It was previous defined", - cond->GetName(), cond->GetMask() ) ); - check = kFALSE; + continue; + } + AliTriggerInput *inp = (AliTriggerInput *)inputs.FindObject(iname->String()); + if (inp) { + if (!inp->Status()) { + delete tokens; + return kFALSE; } - mask |= cond->GetMask(); - } - - return check; -} - - -//_____________________________________________________________________________ -void AliTriggerDescriptor::Print( const Option_t* ) const -{ - // Print - cout << "Trigger Descriptor:" << endl; - cout << " Name: " << GetName() << endl; - cout << " Description: " << GetTitle() << endl; - cout << " Detector Cluster: " << fDetectorCluster << endl; + continue; + } + AliError(Form("Desciptor (%s) contains invalid trigger input or function (%s)", + GetName(),iname->String().Data())); + delete tokens; + return kFALSE; + } -// Int_t ninputs = fInputs->GetEntriesFast(); -// for( Int_t i=0; iAt(i) -// in->Print(); -// } + delete tokens; + return kTRUE; - Int_t ncond = fConditions.GetEntriesFast(); - for( Int_t i=0; iPrint(); - } - cout << endl; } - -////////////////////////////////////////////////////////////////////////////// -// Helper method - //_____________________________________________________________________________ -Bool_t AliTriggerDescriptor::IsSelected( TString detName, TString& detectors ) const +void AliTriggerDescriptor::Print( const Option_t* ) const { - // check whether detName is contained in detectors - // if yes, it is removed from detectors - - // check if all detectors are selected - if( (detectors.CompareTo("ALL") == 0 ) || - detectors.BeginsWith("ALL ") || - detectors.EndsWith(" ALL") || - detectors.Contains(" ALL ") ) { - detectors = "ALL"; - return kTRUE; - } - - // search for the given detector - Bool_t result = kFALSE; - if( (detectors.CompareTo( detName ) == 0) || - detectors.BeginsWith( detName+" " ) || - detectors.EndsWith( " "+detName ) || - detectors.Contains( " "+detName+" " ) ) { - detectors.ReplaceAll( detName, "" ); - result = kTRUE; - } - - // clean up the detectors string - while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " ); - while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 ); - while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 ); - - return result; + // Print + cout << "Trigger Descriptor:" << endl; + cout << " Name: " << GetName() << endl; + cout << " Logic: " << GetTitle() << endl; } diff --git a/STEER/AliTriggerDescriptor.h b/STEER/AliTriggerDescriptor.h index d766a5a0d49..7b625b039f5 100644 --- a/STEER/AliTriggerDescriptor.h +++ b/STEER/AliTriggerDescriptor.h @@ -4,68 +4,35 @@ /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * * See cxx source for full Copyright notice */ -/* $Id$ */ - /////////////////////////////////////////////////////////////////////////////// // // -// This class for running a Trigger Descriptor // -// // +// This class represents the CTP descriptor objects // // // -// A Trigger Descriptor define a trigger setup for specific runnign -// condition (Pb-Pb, p-p, p-A, Calibration, etc). -// It keep: -// - cluster detector (List of detectors involved) -// - List of conditions +// The Descriptor consists of Name and 1 or Logical function of 4 CTP inputs+// +// additional inputs (added with an AND operator) // // // // // /////////////////////////////////////////////////////////////////////////////// -class TNamed; +#include -class TString; -class TObjArray; -class AliRunLoader; class AliTriggerDescriptor : public TNamed { public: AliTriggerDescriptor(); - AliTriggerDescriptor( TString & name, TString & description ); - AliTriggerDescriptor( const AliTriggerDescriptor& des ); - virtual ~AliTriggerDescriptor() { fConditions.SetOwner(); fConditions.Delete(); } - AliTriggerDescriptor& operator=(const AliTriggerDescriptor& des); - - // Setters - Bool_t AddDetectorCluster( TString & cluster ); - void AddCondition( TString & cond, TString & name, - TString & description, ULong64_t mask ); - void AddCondition( AliTriggerCondition* cond ) { fConditions.AddLast( cond ); } - // Getters - TString GetDetectorCluster() const { return fDetectorCluster; } - TObjArray* GetTriggerConditions() { return &fConditions; } - Bool_t CheckInputsConditions( TString & configfile ); - void Print( const Option_t* opt ="" ) const; - // Descriptors Database (root file) - void WriteDescriptor( const char* filename="" ); - static TObjArray* GetAvailableDescriptors( const char* filename="" ); - static - AliTriggerDescriptor* LoadDescriptor( TString & des, const char* filename="" ); - //TODO static Bool_t RemoveDescriptor( AliTriggerDescriptor* descriptor, const char* filename="" ); - //TODO static Bool_t RemoveDescriptor( TString* descriptor, const char* filename="" ); - -protected: - // TString fRunCondition; // Running modes Ej. Pb-Pb, p-p, p-A - TString fDetectorCluster; // Array of Detector Trigger - TObjArray fConditions; // Array of Trigger Condition (AliTriggerCondition) - - static const Int_t fgkNDetectors = 10; //! number possible trigger detectors - static const char* fgkDetectorName[fgkNDetectors]; //! names of detectors - + AliTriggerDescriptor( TString & name, TString & cond ); + AliTriggerDescriptor( const AliTriggerDescriptor& desc ); + virtual ~AliTriggerDescriptor(); + AliTriggerDescriptor& operator=(const AliTriggerDescriptor& desc); + + Bool_t CheckInputsAndFunctions(const TObjArray &inputs,const TObjArray &functions) const; + Bool_t IsActive(const TObjArray &inputs,const TObjArray &functions) const; + Bool_t Trigger( const TObjArray &inputs, const TObjArray &functions) const; + virtual void Print( const Option_t* opt ="" ) const; private: - Bool_t IsSelected( TString detName, TString & detectors ) const; - static const TString fgkDescriptorFileName; //! name of default descriptors file - ClassDef( AliTriggerDescriptor, 2 ) // Define a trigger descriptor + ClassDef( AliTriggerDescriptor, 1 ) // Define a trigger descriptor object }; #endif diff --git a/STEER/AliTriggerDetector.cxx b/STEER/AliTriggerDetector.cxx index 9843aa5bac2..9bd01f4f6a5 100644 --- a/STEER/AliTriggerDetector.cxx +++ b/STEER/AliTriggerDetector.cxx @@ -52,6 +52,80 @@ AliTriggerDetector::AliTriggerDetector() : // Default constructor } +//_____________________________________________________________________________ +AliTriggerDetector::AliTriggerDetector(const AliTriggerDetector & de ): + TNamed(de), + fMask(de.fMask), + fInputs(de.fInputs) +{ + // Copy constructor + +} + +//_____________________________________________________________________________ +AliTriggerDetector::~AliTriggerDetector() +{ + // Destructor + // Delete only inputs that are not + // associated to the CTP + Int_t ninputs = fInputs.GetEntriesFast(); + for(Int_t i = 0; i < ninputs; i++) { + AliTriggerInput *inp = (AliTriggerInput *)fInputs.At(i); + if (inp->GetSignature() == -1 && + inp->GetMask() == 0) + delete fInputs.RemoveAt(i); + } +} + +//_____________________________________________________________________________ +void AliTriggerDetector::CreateInputs(const TObjArray &inputs) +{ + // Define the inputs to the Central Trigger Processor + // This is a dummy version + + // Check if we have to create the inputs first + if( fInputs.GetEntriesFast() == 0 ) { + // Create the inputs that the detector can provide + CreateInputs(); + } + + TString name = GetName(); + + // Pointer to the available inputs provided by the detector + TObjArray* availInputs = &fInputs; + + Int_t ninputs = inputs.GetEntriesFast(); + for( Int_t j=0; jGetModule().Data()) ) continue; + + TObject *tempObj = availInputs->FindObject(inp->GetInputName().Data()); + if ( tempObj ) { + Int_t tempIndex = availInputs->IndexOf(tempObj); + delete availInputs->Remove(tempObj); + fInputs.AddAt( inp, tempIndex ); + inp->Enable(); + AliInfo(Form("Trigger input (%s) is found in the CTP configuration. Therefore it is enabled for trigger detector (%s)", + inp->GetInputName().Data(),name.Data())); + } + else { + AliWarning(Form("Trigger Input (%s) is not implemented for the trigger detector (%s) ! It will be disabled !", + inp->GetInputName().Data(),name.Data())); + } + } + + for( Int_t j=0; jGetSignature() == -1 && + inp->GetMask() == 0) + inp->Enable(); + AliInfo(Form("Trigger input (%s) was not found in the CTP configuration. Therefore it will be run in a stand-alone mode", + inp->GetInputName().Data())); + } + + fInputs.SetOwner(kFALSE); +} + //_____________________________________________________________________________ void AliTriggerDetector::CreateInputs() { @@ -61,10 +135,9 @@ void AliTriggerDetector::CreateInputs() // Do not create inputs again!! if( fInputs.GetEntriesFast() > 0 ) return; - TString name = GetName(); - fInputs.AddLast( new AliTriggerInput( name+"_TEST1_L0", "Dummy input 1", 0x01 ) ); - fInputs.AddLast( new AliTriggerInput( name+"_TEST2_L0", "Dummy input 2", 0x02 ) ); - fInputs.AddLast( new AliTriggerInput( name+"_TEST3_L0", "Dummy input 3", 0x04 ) ); + fInputs.AddLast( new AliTriggerInput( "TEST1_L0", "TEST", 0 ) ); + fInputs.AddLast( new AliTriggerInput( "TEST2_L0", "TEST", 0 ) ); + fInputs.AddLast( new AliTriggerInput( "TEST3_L0", "TEST", 0 ) ); } //_____________________________________________________________________________ @@ -122,21 +195,6 @@ void AliTriggerDetector::SetInput( const char * name ) AliError( Form( "There is not input named %s", name ) ); } -//_____________________________________________________________________________ -void AliTriggerDetector::SetInput( Int_t mask ) -{ - // Set Input by mask - Int_t nInputs = fInputs.GetEntriesFast(); - for( Int_t j=0; jGetMask() == mask ) { - in->Set(); - fMask |= in->GetValue(); - break; - } - } -} - //_____________________________________________________________________________ void AliTriggerDetector::Print( const Option_t* opt ) const { diff --git a/STEER/AliTriggerDetector.h b/STEER/AliTriggerDetector.h index 07c8f9a4c2b..8d7cadc38e3 100644 --- a/STEER/AliTriggerDetector.h +++ b/STEER/AliTriggerDetector.h @@ -22,15 +22,16 @@ class AliTriggerDetector : public TNamed { public: AliTriggerDetector(); - virtual ~AliTriggerDetector() { fInputs.SetOwner(); fInputs.Delete(); } + virtual ~AliTriggerDetector(); + AliTriggerDetector(const AliTriggerDetector & de ); + void CreateInputs(const TObjArray& inputs); virtual void CreateInputs(); virtual void Trigger(); // Setters void AddInput( TObject * input ) { fInputs.AddLast( input ); } void SetInput( TString & name ); void SetInput( const char * name ); - void SetInput( Int_t mask ); // Getters TObjArray* GetInputs() { return &fInputs; } Long_t GetMask() const { return fMask; } @@ -47,6 +48,9 @@ protected: Long_t fMask; // Trigger Mask ( bitwise OR of trigger inputs ) TObjArray fInputs; // Array of Triggers Inputs (AliTriggerInput class) +private: + AliTriggerDetector& operator=(const AliTriggerDetector& de); + ClassDef( AliTriggerDetector, 1 ) // Base Class for Detector specific Trigger }; diff --git a/STEER/AliTriggerInput.cxx b/STEER/AliTriggerInput.cxx index c9e37359bed..4370c5a6c11 100644 --- a/STEER/AliTriggerInput.cxx +++ b/STEER/AliTriggerInput.cxx @@ -28,7 +28,8 @@ // // The name must be globaly unique. Spaces are not allowed. // As convention should start with detector name then an id -// and the trigger level (L0, L1, L2) +// and the trigger level (L0, L1, L2) separated by "_" +// for valid detector names see AliTriggerCluster::fgkDetectorName // // A maximun of 60 inputs trigger are allow. // So, the id mask should set only bit from the position 1 to 60. @@ -36,17 +37,123 @@ /////////////////////////////////////////////////////////////////////////////// #include +#include +#include "AliLog.h" #include "AliTriggerInput.h" ClassImp( AliTriggerInput ) +Bool_t AliTriggerInput::fgkIsTriggerDetector[AliDAQ::kNDetectors] = {1,0,0,0,1,1,0,1,0,0,0,1,0,1,1,1,1,1,1,0}; +const char* AliTriggerInput::fgkCTPDetectorName[AliDAQ::kNDetectors] = { + "SPD", + "SDD", + "SSD", + "TPC", + "TRD", + "TOF", + "HMPID", + "PHOS", + "CPV", + "PMD", + "MUON_TRK", + "MUON_TRG", + "FMD", + "T0", + "V0", + "ZDC", + "ACORDE", + "CTP", + "EMCal", + "HLT" +}; + +const char* AliTriggerInput::fgkOfflineModuleName[AliDAQ::kNDetectors] = { + "ITS", + "ITS", + "ITS", + "TPC", + "TRD", + "TOF", + "HMPID", + "PHOS", + "CPV", + "PMD", + "MUON", + "MUON", + "FMD", + "T0", + "VZERO", + "ZDC", + "ACORDE", + "CTP", + "EMCAL", + "HLT" +}; + +//_____________________________________________________________________________ + AliTriggerInput::AliTriggerInput( TString name, TString det, UChar_t level, Int_t signature, Char_t number ): + TNamed( name.Data(), det.Data() ), + fMask((number >= 0) ? 1 << number : 0 ), + fValue(0), + fSignature(signature), + fLevel(level), + fDetectorId(-1), + fIsActive(kFALSE) +{ + // Standard constructor + // + // The name must be globaly unique. Spaces are not allowed. + // For valid detector names see AliDAQ::fgkDetectorName + + // Check for valid detector name + Int_t iDet = 0; + for( iDet = 0; iDet < AliDAQ::kNDetectors; iDet++ ) { + if( !fgkIsTriggerDetector[iDet] ) continue; + if( det.CompareTo( fgkCTPDetectorName[iDet] ) == 0 ) { + fTitle = AliDAQ::DetectorName(iDet); + fDetectorId = iDet; + break; + } + if( det.CompareTo( AliDAQ::DetectorName(iDet) ) == 0 ) { + fDetectorId = iDet; + break; + } + } + if( iDet == AliDAQ::kNDetectors ) { + AliError( Form( "%s is not a valid trigger input, it must contain a valid trigger detector name instead of (%s)", name.Data(), det.Data() ) ); + } +} + //_____________________________________________________________________________ void AliTriggerInput::Print( const Option_t* ) const { // Print cout << "Trigger Input:" << endl; cout << " Name: " << GetName() << endl; - cout << " Description: " << GetTitle() << endl; - cout << " Value: " << hex << "Ox" << fValue << dec << endl; + cout << " Detector: " << GetTitle() << "(Id=" << (Int_t)fDetectorId << ")" << endl; + cout << " Level: " << fLevel << endl; + cout << " Signature: " << fSignature << endl; + cout << " Number: " << (Int_t)TMath::Log2(fMask) << endl; + if (IsActive()) + cout << " Input is active " << endl; + else + cout << " Input is not active " << endl; + if (Status()) + cout << " Input is fired " << endl; + else + cout << " Input is not fired " << endl; +} + +//_____________________________________________________________________________ +TString AliTriggerInput::GetModule() const +{ + // Get the detector module name (in AliRoot simulation sense) + TString name = ""; + if (fDetectorId >= 0 && fDetectorId < AliDAQ::kNDetectors) + name = fgkOfflineModuleName[(Int_t)fDetectorId]; + else + AliError(Form("Invalid detector Id (%d)",(Int_t)fDetectorId)); + + return name; } diff --git a/STEER/AliTriggerInput.h b/STEER/AliTriggerInput.h index 807dfd47550..6d83a243c74 100644 --- a/STEER/AliTriggerInput.h +++ b/STEER/AliTriggerInput.h @@ -30,40 +30,63 @@ #include #endif +#include "AliDAQ.h" + class AliTriggerInput : public TNamed { public: AliTriggerInput(): TNamed(), - fMask( 0 ), - fValue( 0 ) {} - AliTriggerInput( TString name, TString description, Long_t mask ) - : TNamed( name.Data(), description.Data() ), - fMask( mask ), - fValue( 0 ) {} + fMask( 0 ), + fValue( 0 ), + fSignature( -1), + fLevel(0), + fDetectorId(-1), + fIsActive(kFALSE) + {} + AliTriggerInput( TString name, TString det, UChar_t level, Int_t signature = -1, Char_t number = -1); AliTriggerInput( AliTriggerInput & inp ) - : TNamed( inp ), - fMask( inp.fMask ), - fValue( inp.fValue ) {} + : TNamed( inp ), + fMask( inp.fMask ), + fValue( inp.fValue ), + fSignature( inp.fSignature ), + fLevel( inp.fLevel), + fDetectorId( inp.fDetectorId), + fIsActive(kFALSE) + {} virtual ~AliTriggerInput() {} // Setters - virtual void Set() { fValue = fMask; } - virtual void Reset() { fValue = 0; } + void Set() { if (fIsActive) fValue = fMask; } + void Reset() { fValue = 0; } + void Enable() { fIsActive = kTRUE; } // Getters Bool_t Status() const { return (Bool_t)fValue; } - Long_t GetValue() const { return fValue; } - Int_t GetMask() const { return fMask; } - // ULong_t Hash() const { return TMath::Hash( GetName().Data() ); }; + ULong64_t GetValue() const { return fValue; } + ULong64_t GetMask() const { return fMask; } + Int_t GetSignature() const { return fSignature; } + TString GetInputName() const { return GetName(); } + TString GetDetector() const { return GetTitle(); } + TString GetModule() const; + Char_t GetDetectorId() const { return fDetectorId; } + UChar_t GetLevel() const { return fLevel; } + Bool_t IsActive() const { return fIsActive; } - virtual void Print( const Option_t* opt ="" ) const; + virtual void Print( const Option_t* opt ="" ) const; + static Bool_t fgkIsTriggerDetector[AliDAQ::kNDetectors]; // List of trigger detectors + static const char* fgkCTPDetectorName[AliDAQ::kNDetectors]; + static const char* fgkOfflineModuleName[AliDAQ::kNDetectors]; protected: - Long_t fMask; // Trigger ID mask (1 bit) - Long_t fValue; // Trigger Signal (0 = false, > 1 = true = fMask ) - // Int_t fLevel; // Trigger Level (L0, L1, L2) + ULong64_t fMask; // Trigger ID mask (1 bit) + ULong64_t fValue; // Trigger Signal (0 = false, > 1 = true = fMask ) + Int_t fSignature; // 8 bit signature (internal CTP inputs can have longer signature) + UChar_t fLevel; // L0, L1 or L2 + Char_t fDetectorId; // Alice-wide detector id, see AliDAQ class for details + Bool_t fIsActive; // Is trigger input active (during simulation) +// void fDectParameterTable; //-> link to detector parameter table???? - ClassDef( AliTriggerInput, 1 ) // Define a Trigger Input + ClassDef( AliTriggerInput, 3 ) // Define a Trigger Input }; diff --git a/STEER/AliTriggerInteraction.cxx b/STEER/AliTriggerInteraction.cxx new file mode 100644 index 00000000000..50af7fde5e3 --- /dev/null +++ b/STEER/AliTriggerInteraction.cxx @@ -0,0 +1,157 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/////////////////////////////////////////////////////////////////////////////// +// +// This class which defines the trigger interaction objects +// +// +/////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include + +#include "AliTriggerInteraction.h" +#include "AliTriggerInput.h" +#include "AliExpression.h" +#include "AliLog.h" + +ClassImp(AliTriggerInteraction) + +//_____________________________________________________________________________ +AliTriggerInteraction::AliTriggerInteraction(): + TNamed() +{ + // Default constructor +} + +//_____________________________________________________________________________ +AliTriggerInteraction::AliTriggerInteraction( TString & name, TString &logic ): + TNamed( name, logic ) +{ + // Constructor +} +//_____________________________________________________________________________ +AliTriggerInteraction::~AliTriggerInteraction() +{ + // Destructor +} +//_____________________________________________________________________________ +AliTriggerInteraction::AliTriggerInteraction( const AliTriggerInteraction& interact ): + TNamed( interact ) +{ + // Copy constructor +} + +//______________________________________________________________________________ +AliTriggerInteraction& AliTriggerInteraction::operator=(const AliTriggerInteraction& interact) +{ + // AliTriggerInteraction assignment operator. + + if (this != &interact) { + TNamed::operator=(interact); + } + return *this; +} + +//_____________________________________________________________________________ +Bool_t AliTriggerInteraction::CheckInputs(const TObjArray &inputs) const +{ + // Check the existance of trigger inputs + // and the logic used. + // Return false in case of wrong interaction + // definition. + + TString logic( GetTitle() ); + TObjArray* tokens = logic.Tokenize(" !&|()\t"); + + Int_t ntokens = tokens->GetEntriesFast(); + for( Int_t i=0; iAt( i ); + + AliTriggerInput *inp = (AliTriggerInput*)inputs.FindObject(iname->String().Data()); + if (!inp) { + AliError( Form( "The trigger input (%s) is not available for Interaction (%s)", + iname->String().Data(), GetName() ) ); + delete tokens; + return kFALSE; + } + if (inp->GetMask() == 0 || inp->GetMask() > 16) { + AliError( Form( "The trigger input (%s) is not among the first 4 trigger inputs used to create interactions. Interaction (%s) is invalid", + iname->String().Data(), GetName() ) ); + delete tokens; + return kFALSE; + } + } + + delete tokens; + return kTRUE; +} + +//_____________________________________________________________________________ +Bool_t AliTriggerInteraction::IsActive(const TObjArray &inputs) const +{ + // Check if the trigger inputs + // are active + // Return false in one or more inputs + // are disabled + + TString logic( GetTitle() ); + TObjArray* tokens = logic.Tokenize(" !&|()\t"); + + Int_t ntokens = tokens->GetEntriesFast(); + for( Int_t i=0; iAt( i ); + + AliTriggerInput *inp = (AliTriggerInput *)inputs.FindObject(iname->String()); + if (!inp) { + AliError( Form( "The trigger input (%s) is not available for Interaction (%s)", + iname->String().Data(), GetName() ) ); + delete tokens; + return kFALSE; + } + else { + if (!inp->IsActive()) { + AliWarning(Form("The interaction/function (%s) will be disabled, because the input (%s) is disabled", + GetName(),iname->String().Data())); + delete tokens; + return kFALSE; + } + } + } + + delete tokens; + return kTRUE; +} + +//_____________________________________________________________________________ +Bool_t AliTriggerInteraction::Trigger(const TObjArray& inputs ) const +{ + // Check if the inputs satify the interaction expression condition + AliExpression* exp = new AliExpression( GetTitle() ); + Bool_t status = exp->Value( inputs ); + delete exp; + return status; +} + +//_____________________________________________________________________________ +void AliTriggerInteraction::Print( const Option_t* ) const +{ + // Print + cout << "Trigger Interaction:" << endl; + cout << " Name: " << GetName() << endl; + cout << " Logic: " << GetTitle() << endl; +} diff --git a/STEER/AliTriggerInteraction.h b/STEER/AliTriggerInteraction.h new file mode 100644 index 00000000000..1a6a592a763 --- /dev/null +++ b/STEER/AliTriggerInteraction.h @@ -0,0 +1,37 @@ +#ifndef ALITRIGGERINTERACTION_H +#define ALITRIGGERINTERACTION_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// This class represents the CTP interaction objects // +// // +// The Interaction consists of Name and Logical function of 4 CTP inputs. // +// // +// // +/////////////////////////////////////////////////////////////////////////////// + +#include + + +class AliTriggerInteraction : public TNamed { + +public: + AliTriggerInteraction(); + AliTriggerInteraction( TString & name, TString & logic ); + AliTriggerInteraction( const AliTriggerInteraction& interact ); + virtual ~AliTriggerInteraction(); + AliTriggerInteraction& operator=(const AliTriggerInteraction& interact); + + Bool_t CheckInputs(const TObjArray &inputs) const; + Bool_t IsActive(const TObjArray &inputs) const; + Bool_t Trigger(const TObjArray& inputs ) const; + virtual void Print( const Option_t* opt ="" ) const; +private: + + ClassDef( AliTriggerInteraction, 1 ) // Define a trigger interaction object +}; + +#endif diff --git a/STEER/AliTriggerPFProtection.cxx b/STEER/AliTriggerPFProtection.cxx new file mode 100644 index 00000000000..abb0f74c789 --- /dev/null +++ b/STEER/AliTriggerPFProtection.cxx @@ -0,0 +1,117 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// +// Class to define a Trigger Past Future Protection +// +// name description INT1 INT2 +// Ej: +// AliTriggerPFProtection sc( "BARREL", "BARREL DET Pb-Pb", "SC","PE" ); +// sc.SetINTa("PE"); // Peripheral +// sc.SetINTb("SC"); // Semicentral +// sc.SetINT("PE"); +// sc.SetNa1( 5 ); +// sc.SetNa2( 5 ); +// sc.SetTa( 88 ); +// sc.SetNb1( 1 ); +// sc.SetNb2( 0 ); +// sc.SetTb( 88 ); +// +/////////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include + +#include "AliLog.h" +#include "AliTriggerPFProtection.h" + +ClassImp( AliTriggerPFProtection ) + +//_____________________________________________________________________________ +void AliTriggerPFProtection::Print( const Option_t* ) const +{ + // Print + cout << "Trigger Past-Future Protection: " << endl; + cout << " Name: " << GetName() << endl; + cout << " Interaction_a: " << fINTa.Data() << endl; + cout << " Interaction_b: " << fINTb.Data() << endl; + cout << " Interaction: " << fINT.Data() << endl; + cout << " Na1: " << fNa1 << " Na2: " << fNa2 << " Ta: " << fTa << endl; + cout << " Nb1: " << fNb1 << " Nb2: " << fNb2 << " Tb: " << fTb << endl; +} + +//_____________________________________________________________________________ +Bool_t AliTriggerPFProtection::CheckInteractions(TObjArray &interactions) const +{ + // Check if the interactions are valid + { + TString logic( GetINTa() ); + TObjArray* tokens = logic.Tokenize(" !&|()\t"); + + Int_t ntokens = tokens->GetEntriesFast(); + for( Int_t i=0; iAt( i ); + + if (!interactions.FindObject(iname->String().Data())) { + AliError( Form( "The trigger interaction (%s) is not available for past-future protection (%s)", + iname->String().Data(), GetName() ) ); + delete tokens; + return kFALSE; + } + } + delete tokens; + } + { + TString logic( GetINTb() ); + TObjArray* tokens = logic.Tokenize(" !&|()\t"); + + Int_t ntokens = tokens->GetEntriesFast(); + for( Int_t i=0; iAt( i ); + + if (!interactions.FindObject(iname->String().Data())) { + AliError( Form( "The trigger interaction (%s) is not available for past-future protection (%s)", + iname->String().Data(), GetName() ) ); + delete tokens; + return kFALSE; + } + } + delete tokens; + } + { + TString logic( GetINT() ); + TObjArray* tokens = logic.Tokenize(" !&|()\t"); + + Int_t ntokens = tokens->GetEntriesFast(); + for( Int_t i=0; iAt( i ); + + if (!interactions.FindObject(iname->String().Data())) { + AliError( Form( "The trigger interaction (%s) is not available for past-future protection (%s)", + iname->String().Data(), GetName() ) ); + delete tokens; + return kFALSE; + } + } + delete tokens; + } + return kTRUE; +} diff --git a/STEER/AliTriggerPFProtection.h b/STEER/AliTriggerPFProtection.h new file mode 100644 index 00000000000..8580afd83ae --- /dev/null +++ b/STEER/AliTriggerPFProtection.h @@ -0,0 +1,94 @@ +#ifndef ALITRIGGERPFPROTECTION_H +#define ALITRIGGERPFPROTECTION_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/////////////////////////////////////////////////////////////////////////////// +// +// Class to define a Trigger Past Future Protection +// +// name description INT1 INT2 +// Ej: +// AliTriggerPFProtection sc( "BARREL", "BARREL DET Pb-Pb", "SC","PE" ); +// sc.SetINTa("PE"); // Peripheral +// sc.SetINTb("SC"); // Semicentral +// sc.SetINT("PE"); +// sc.SetNa1( 5 ); +// sc.SetNa2( 5 ); +// sc.SetTa( 88 ); +// sc.SetNb1( 1 ); +// sc.SetNb2( 0 ); +// sc.SetTb( 88 ); +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef ROOT_TNamed +#include +#endif + +class AliTriggerPFProtection : public TNamed { + +public: + AliTriggerPFProtection() : + TNamed(), + fINTa(), fINTb(),fINT(), + fNa1(0),fNa2(0),fTa(0), + fNb1(0),fNb2(0),fTb(0) {} + AliTriggerPFProtection( TString & name) : + TNamed(name, name), + fINTa(), fINTb(),fINT(), + fNa1(0),fNa2(0),fTa(0), + fNb1(0),fNb2(0),fTb(0) {} + AliTriggerPFProtection( TString & name, + TString & inta, TString & intb, TString & interaction ) : + TNamed(name, name), + fINTa(inta), fINTb(intb),fINT(interaction), + fNa1(0),fNa2(0),fTa(0), + fNb1(0),fNb2(0),fTb(0) {} + virtual ~AliTriggerPFProtection() {} + + // Setters + void SetINTa( TString& inta ) { fINTa = inta; } + void SetINTb( TString& intb ) { fINTb = intb; } + void SetINT ( TString& inti ) { fINT = inti; } + void SetNa1 ( UInt_t n ) { fNa1 = n; } + void SetNa2 ( UInt_t n ) { fNa2 = n; } + void SetTa ( UInt_t n ) { fTa = n; } + void SetNb1 ( UInt_t n ) { fNb1 = n; } + void SetNb2 ( UInt_t n ) { fNb2 = n; } + void SetTb ( UInt_t n ) { fTb = n; } + // Getters + + const TString& GetINTa() const { return fINTa; } + const TString& GetINTb() const { return fINTb; } + const TString& GetINT () const { return fINT; } + UInt_t GetNa1 () const { return fNa1; } + UInt_t GetNa2 () const { return fNa2; } + UInt_t GetTa () const { return fTa ; } + UInt_t GetNb1 () const { return fNb1; } + UInt_t GetNb2 () const { return fNb2; } + UInt_t GetTb () const { return fTb ; } + + Bool_t CheckInteractions(TObjArray &interactions) const; + virtual void Print( const Option_t* opt ="" ) const; + +private: + TString fINTa; // Logical function of INT1 and INT2; + TString fINTb; // Logical function of INT1 and INT2; + TString fINT; // Logical function of INT1 and INT2; + UInt_t fNa1; // Max number of INTa for the event of type INT + UInt_t fNa2; // max number of INTa for the event of type NOT INT + UInt_t fTa; // mprotection interval for INTa + UInt_t fNb1; // mmax number of INTb for the event of type INT + UInt_t fNb2; // mmax number of INTb for the event of type NOT INT + UInt_t fTb; // mprotection interval for INTb + + AliTriggerPFProtection(const AliTriggerPFProtection & inp ); + AliTriggerPFProtection& operator = (const AliTriggerPFProtection& inp); + + ClassDef( AliTriggerPFProtection, 1 ) // Define a Trigger Past Future Protection +}; + + +#endif diff --git a/STEER/STEERLinkDef.h b/STEER/STEERLinkDef.h index b0a652d30c0..20afc169301 100644 --- a/STEER/STEERLinkDef.h +++ b/STEER/STEERLinkDef.h @@ -77,9 +77,14 @@ #pragma link C++ class AliVariableExpression+; #pragma link C++ class AliTriggerInput+; #pragma link C++ class AliTriggerDetector+; -#pragma link C++ class AliTriggerCondition+; +#pragma link C++ class AliTriggerConfiguration+; +#pragma link C++ class AliTriggerBCMask+; +#pragma link C++ class AliTriggerInteraction+; #pragma link C++ class AliTriggerDescriptor+; +#pragma link C++ class AliTriggerClass+; #pragma link C++ class AliCentralTrigger+; +#pragma link C++ class AliTriggerCluster+; +#pragma link C++ class AliTriggerPFProtection+; #pragma link C++ class AliGeomManager+; #pragma link C++ class AliAlignObj+; @@ -106,8 +111,11 @@ #pragma link C++ class AliVariableExpression+; #pragma link C++ class AliTriggerInput+; #pragma link C++ class AliTriggerDetector+; -#pragma link C++ class AliTriggerCondition+; +#pragma link C++ class AliTriggerConfiguration+; +#pragma link C++ class AliTriggerBCMask+; +#pragma link C++ class AliTriggerInteraction+; #pragma link C++ class AliTriggerDescriptor+; +#pragma link C++ class AliTriggerClass+; #pragma link C++ class AliCentralTrigger+; #pragma link C++ class AliCTPRawStream+; #pragma link C++ class AliMathBase+; diff --git a/STEER/libSTEER.pkg b/STEER/libSTEER.pkg index 6bf3e028315..569a7448d06 100644 --- a/STEER/libSTEER.pkg +++ b/STEER/libSTEER.pkg @@ -25,8 +25,13 @@ AliGeomManager.cxx \ AliAlignObj.cxx AliAlignObjParams.cxx AliAlignObjMatrix.cxx \ AliTriggerInput.cxx \ AliTriggerDetector.cxx \ -AliTriggerCondition.cxx \ +AliTriggerConfiguration.cxx \ +AliTriggerBCMask.cxx \ +AliTriggerInteraction.cxx \ AliTriggerDescriptor.cxx \ +AliTriggerClass.cxx \ +AliTriggerCluster.cxx \ +AliTriggerPFProtection.cxx \ AliCentralTrigger.cxx AliRieman.cxx\ AliTrackFitter.cxx AliTrackFitterRieman.cxx AliTrackFitterKalman.cxx\ AliTrackFitterStraight.cxx\ -- 2.39.3