// 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 <TObjString.h>
#include <TObjArray.h>
#include <TStopwatch.h>
+#include <TFile.h>
+#include <TTree.h>
#include "AliLog.h"
#include "AliRun.h"
#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 );
+ LoadConfiguration( config );
}
//_____________________________________________________________________________
AliCentralTrigger::~AliCentralTrigger()
{
- // Destructor
- fDescriptors.SetOwner();
- fDescriptors.Delete();
+ // Destructor
+ DeleteConfiguration();
+}
+
+//_____________________________________________________________________________
+void AliCentralTrigger::DeleteConfiguration()
+{
+ // Delete the active configuration
+ fClassMask = 0;
+ fClusterMask = 0;
+ if (fConfiguration) {
+ if (IsOwner()) delete fConfiguration;
+ fConfiguration = 0x0;
+ }
}
//_____________________________________________________________________________
-Bool_t AliCentralTrigger::LoadDescriptor( TString & descriptor )
+void AliCentralTrigger::Reset()
{
- // 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
- fDescriptors.Delete();
-
- // 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() ) );
+ // Reset Class Mask and classes
+ 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->Reset();
+ }
}
- Bool_t desfound = kTRUE;
- if( fDescriptors.GetEntriesFast() == 0 ) desfound = kFALSE;
+}
- delete desArray;
+//_____________________________________________________________________________
+void AliCentralTrigger::MakeBranch( TString name, TTree * tree )
+{
+ // Make a branch to store only trigger class mask event by event
+
+ if( tree ) {
+ AliDebug( 1, "Got Tree from folder." );
+ TBranch* branch = tree->GetBranch( name );
+ if( branch == 0x0 ) {
+ AliDebug( 1, "Creating new branch" );
+ branch = tree->Branch( name, &(this->fClassMask), "fClassMask/l:fClusterMask/i" );
+ branch->SetAutoDelete( kFALSE );
+ }
+ else {
+ AliDebug( 1, "Got Branch from Tree" );
+ branch->SetAddress( &(this->fClassMask) );
+ }
+ }
+}
- return desfound;
+//_____________________________________________________________________________
+Bool_t AliCentralTrigger::LoadConfiguration( TString & config )
+{
+ // 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;
+ }
+ }
}
//_____________________________________________________________________________
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( "No folder with trigger loaded, skipping trigger" );
return kFALSE;
}
TStopwatch stopwatch;
stopwatch.Start();
-
+
// Process each event
for( Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++ ) {
- AliInfo( Form("\n ***** Processing event %d *****\n", iEvent) );
- runLoader->GetEvent( iEvent );
+ AliInfo( Form(" ***** Processing event %d *****\n", iEvent) );
+ runLoader->GetEvent( iEvent );
// Get detectors involve
TString detStr = GetDetectors();
+ 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;
- TObjArray trgdetArray;
+ 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) ) {
- AliInfo( Form("triggering from digits for %s", det->GetName() ) );
+ if( IsSelected(det->GetName(), detStr) &&
+ IsSelected(det->GetName(), detWithDigits) ) {
+
+ AliInfo( Form("Triggering from digits for %s", det->GetName() ) );
AliTriggerDetector* trgdet = det->CreateTriggerDetector();
- trgdet->CreateInputs();
- trgdetArray.AddLast( trgdet );
+ 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
+ TString loadername = det->GetName();
+ loadername.Append( "Loader" );
+ AliLoader * loader = runLoader->GetLoader( loadername );
+ if( loader ) {
+ AliDataLoader * dataLoader = loader->GetDigitsDataLoader();
+ if( !dataLoader->IsFileOpen() ) {
+ if( dataLoader->OpenFile( "UPDATE" ) ) {
+ AliWarning( Form( "\n\nCan't write trigger for %s\n", det->GetName() ) );
+ }
+ }
+ dataLoader->Cd();
+ if( gFile && !gFile->IsWritable() ) {
+ gFile->ReOpen( "UPDATE" );
+ dataLoader->Cd();
+ }
+ trgdet->Write( "Trigger", TObject::kOverwrite );
+ dataLoader->CloseFile();
}
+ else AliWarning( Form( "Not loader found for %s", det->GetName() ) );
}
}
// Check trigger conditions and create the trigger class mask
- CheckConditions();
+ TriggerClasses();
- fInputs.Clear();
-
// Clear trigger detectors
trgdetArray.SetOwner();
trgdetArray.Delete();
if( (detStr.CompareTo( "ALL" ) != 0) && !detStr.IsNull() ) {
AliError( Form("the following detectors were not found: %s",
detStr.Data()));
- return kFALSE;
+ //JF return kFALSE;
}
- // Write trigger ???? -> Event Header
- // Write();
- Print();
-
+ // Save trigger mask
+ tree->Fill();
+ AliInfo( Form("**************** Central Trigger Class Mask:0x%X", fClassMask ) );
} // end event loop
- return kTRUE;
-}
+ Reset();
+// cout << endl << " Print " << endl;
+// Print();
+
+ // Write
+ runLoader->WriteTrigger( "OVERWRITE" );
+ return kTRUE;
+}
//_____________________________________________________________________________
-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;
}
-
//_____________________________________________________________________________
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; 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;
+}