// 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 //
// //
#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 )
//_____________________________________________________________________________
AliCentralTrigger::AliCentralTrigger() :
TObject(),
- fClassMask(0)
+ fClassMask(0),
+ fClusterMask(0),
+ fConfiguration(NULL)
{
// Default constructor
-// LoadDescriptor("Pb-Pb");
+ SetOwner();
}
//_____________________________________________________________________________
-AliCentralTrigger::AliCentralTrigger( TString & descriptor ) :
+AliCentralTrigger::AliCentralTrigger( TString & config ) :
TObject(),
- fClassMask(0)
+ fClassMask(0),
+ fClusterMask(0),
+ fConfiguration(NULL)
{
// Default constructor
- LoadDescriptor( descriptor );
-}
-
-//_____________________________________________________________________________
-AliCentralTrigger::AliCentralTrigger( const AliCentralTrigger& ctp ):
- TObject( ctp ),
- fClassMask( ctp.fClassMask )
-{
- // Copy constructor
-
- Int_t ndes = ctp.fDescriptors.GetEntriesFast();
- for( Int_t j=0; j<ndes; j++ ) {
- fDescriptors.AddLast( new AliTriggerDescriptor( *(AliTriggerDescriptor*)(ctp.fDescriptors.At( j )) ) );
- }
-
- Int_t nInp = ctp.fInputs.GetEntriesFast();
- for( Int_t j=0; j<nInp; j++ ) {
- fInputs.AddLast( new AliTriggerInput( *(AliTriggerInput*)(ctp.fInputs.At( j )) ) );
- }
+ LoadConfiguration( config );
}
//_____________________________________________________________________________
AliCentralTrigger::~AliCentralTrigger()
{
- // Destructor
- DeleteDescriptors();
+ // Destructor
+ DeleteConfiguration();
}
//_____________________________________________________________________________
-void AliCentralTrigger::DeleteDescriptors()
+void AliCentralTrigger::DeleteConfiguration()
{
- // Reset Descriptors
- fClassMask = 0;
- fDescriptors.SetOwner();
- fDescriptors.Delete();
+ // Delete the active configuration
+ fClassMask = 0;
+ fClusterMask = 0;
+ if (fConfiguration) {
+ if (IsOwner()) delete fConfiguration;
+ fConfiguration = 0x0;
+ }
}
//_____________________________________________________________________________
void AliCentralTrigger::Reset()
{
- // Reset Class Mask and conditions
+ // Reset Class Mask and classes
fClassMask = 0;
- Int_t ndes = fDescriptors.GetEntriesFast();
- for( Int_t i=0; i<ndes; i++ ) {
- TObjArray* condArray = ((AliTriggerDescriptor*)fDescriptors.At( i ))->GetTriggerConditions();
- Int_t ncond = condArray->GetEntriesFast();
- for( Int_t j=0; j<ncond; j++ ) {
- AliTriggerCondition* cond = (AliTriggerCondition*)condArray->At( j );
- cond->Reset();
- }
+ fClusterMask = 0;
+
+ if (fConfiguration) {
+ const TObjArray& classesArray = fConfiguration->GetClasses();
+ Int_t nclasses = classesArray.GetEntriesFast();
+ for( Int_t j=0; j<nclasses; j++ ) {
+ AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
+ trclass->Reset();
+ }
}
}
TBranch* branch = tree->GetBranch( name );
if( branch == 0x0 ) {
AliDebug( 1, "Creating new branch" );
- branch = tree->Branch( name, &(this->fClassMask), "fClassMask/l" );
+ branch = tree->Branch( name, &(this->fClassMask), "fClassMask/l:fClusterMask/i" );
branch->SetAutoDelete( kFALSE );
}
else {
}
//_____________________________________________________________________________
-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; i<ndes; i++ ) {
- TObjString* val = (TObjString*)desArray->At( 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 );
+ SetOwner();
+ 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 configuration from OCDB!" );
+
+ AliCDBPath path( "GRP", "CTP", "Config" );
+
+ AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
+ SetOwner(kFALSE);
+ 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; i<ndes; i++ ) {
- TString detStr = ((AliTriggerDescriptor*)fDescriptors.At( i ))->GetDetectorCluster();
- TObjArray* det = detStr.Tokenize(" ");
- Int_t ndet = det->GetEntriesFast();
- for( Int_t j=0; j<ndet; j++ ) {
- if( result.Contains( ((TObjString*)det->At(j))->String() ) )continue;
- result.Append( " " );
- result.Append( ((TObjString*)det->At(j))->String() );
- }
- }
+ if (fConfiguration)
+ result = fConfiguration->GetTriggeringModules();
return result;
}
//_____________________________________________________________________________
-Bool_t AliCentralTrigger::RunTrigger( AliRunLoader* runLoader )
+Bool_t AliCentralTrigger::RunTrigger( AliRunLoader* runLoader, const char *detectors )
{
// 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;
}
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() ) );
+ TString detWithDigits = detectors;
+ AliInfo( Form(" Detectors with digits: %s \n", detWithDigits.Data() ) );
TObjArray* detArray = runLoader->GetAliRun()->Detectors();
// Reset Mask
fClassMask = 0;
+ fClusterMask = 0;
+ // Reset configuration object (inputs and classes)
+ fConfiguration->Reset();
TObjArray trgdetArray; // use as garbage collector
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) ) {
+ if( IsSelected(det->GetName(), detStr) &&
+ IsSelected(det->GetName(), detWithDigits) ) {
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; i<detInp->GetEntriesFast(); i++ ) {
- fInputs.AddLast( detInp->At(i) );
- }
trgdetArray.AddLast( trgdet );
// Write trigger detector in Event folder in Digits file
}
// Check trigger conditions and create the trigger class mask
- CheckConditions();
- fInputs.Clear();
+ TriggerClasses();
// Clear trigger detectors
trgdetArray.SetOwner();
if( (detStr.CompareTo( "ALL" ) != 0) && !detStr.IsNull() ) {
AliError( Form("the following detectors were not found: %s",
detStr.Data()));
- return kFALSE;
+ //JF return kFALSE;
}
// Save trigger mask
}
//_____________________________________________________________________________
-Long_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; i<ndes; i++ ) {
- TObjArray* condArray = ((AliTriggerDescriptor*)fDescriptors.At( i ))->GetTriggerConditions();
- Int_t ncond = condArray->GetEntriesFast();
- for( Int_t j=0; j<ncond; j++ ) {
- AliTriggerCondition* cond = (AliTriggerCondition*)condArray->At( j );
- if( !cond->CheckInputs( fInputs ) ) continue;
- cond->Trigger( fInputs );
- // cond->Print();
- fClassMask |= cond->GetValue();
+ // Check trigger conditions and create the trigger class
+ // and trigger cluster masks
+ fClassMask = 0;
+ fClusterMask = 0;
+ if (fConfiguration) {
+ const TObjArray& classesArray = fConfiguration->GetClasses();
+ Int_t nclasses = classesArray.GetEntriesFast();
+ for( Int_t j=0; j<nclasses; j++ ) {
+ AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
+ trclass->Trigger( fConfiguration->GetInputs(), fConfiguration->GetFunctions() );
+ fClassMask |= trclass->GetValue();
+ if (trclass->GetStatus()) {
+ AliTriggerCluster *trclust = trclass->GetCluster();
+ fClusterMask |= AliDAQ::DetectorPattern(trclust->GetDetectorsInCluster());
}
- }
- return fClassMask;
+ }
+ }
+ 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; i<ndes; i++ ) {
- TObjArray* condArray = ((AliTriggerDescriptor*)fDescriptors.At( i ))->GetTriggerConditions();
- Int_t ncond = condArray->GetEntriesFast();
- for( Int_t j=0; j<ncond; j++ ) {
- AliTriggerCondition* cond = (AliTriggerCondition*)condArray->At( j );
- if( cond->GetStatus() ) result->AddLast( cond );
- }
+ if (fConfiguration) {
+ const TObjArray& classesArray = fConfiguration->GetClasses();
+ Int_t nclasses = classesArray.GetEntriesFast();
+ for( Int_t j=0; j<nclasses; j++ ) {
+ AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
+ if( trclass->GetStatus() ) result->AddLast( trclass );
+ }
}
return result;
// Print
cout << "Central Trigger: " << endl;
cout << " Trigger Class Mask: 0x" << hex << fClassMask << dec << endl;
-
- Int_t ndes = fDescriptors.GetEntriesFast();
- for( Int_t i=0; i<ndes; i++ ) {
- AliTriggerDescriptor* des = (AliTriggerDescriptor*)fDescriptors.At( i );
- if( des ) des->Print();
- }
+ if (fConfiguration) fConfiguration->Print();
cout << endl;
}
return result;
}
+
+//_____________________________________________________________________________
+Bool_t AliCentralTrigger::CheckTriggeredDetectors() const
+{
+ // Check the trigger mask, finds which trigger classes
+ // have been fired, load the corresponding trigger clusters and
+ // finally makes a list of the detectors that have been readout
+ // for each particular event. This list is then compared to the
+ // one stored in fClusterMask. Return value:
+ // true = two lists are equal
+ // false = two lists are not equal meaning wrong trigger config
+ // is loaded.
+
+ if (!fConfiguration) {
+ AliError("The trigger confiration has not yet been loaded! Cross-check is not possible!");
+ return kFALSE;
+ }
+ else {
+
+ // Make a cross-check so that to exclude wrong trigger configuration used
+ // Loop over the trigger classes
+ UInt_t clusterMask = 0;
+ const TObjArray& classesArray = fConfiguration->GetClasses();
+ Int_t nclasses = classesArray.GetEntriesFast();
+ for( Int_t j=0; j<nclasses; j++ ) {
+ AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
+ if (trclass->GetMask() & fClassMask) { // class was fired
+ AliTriggerCluster *trclust = trclass->GetCluster();
+ clusterMask |= AliDAQ::DetectorPattern(trclust->GetDetectorsInCluster());
+ }
+ }
+ // Compare the stored cluster mask with the one
+ // that we get from trigger classes
+ // To be enables after we store the cluster mask in the trigger tree
+ if (clusterMask != fClusterMask) {
+ AliError(Form("Wrong cluster mask from trigger classes (%x), expecting (%x)! Loaded trigger configuration is possibly wrong!",
+ (UInt_t)clusterMask,(UInt_t)fClusterMask));
+ return kFALSE;
+ }
+ }
+
+ return kTRUE;
+}