1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // This class for running the Central Trigger Processor //
23 // Load Configuration //
24 // Make a list the trigger detectors involved (from the classes) //
25 // For the each event //
26 // Run the Trigger for the each detector //
28 // Check the trigger classes //
29 // Create the class mask //
33 ///////////////////////////////////////////////////////////////////////////////
36 #include <TObjString.h>
37 #include <TObjArray.h>
38 #include <TStopwatch.h>
44 #include "AliRunLoader.h"
45 #include "AliModule.h"
47 #include "AliTriggerInput.h"
48 #include "AliTriggerDetector.h"
49 #include "AliTriggerConfiguration.h"
50 #include "AliTriggerClass.h"
51 #include "AliTriggerCluster.h"
52 #include "AliCentralTrigger.h"
53 #include "AliDetectorEventHeader.h"
54 #include "AliHeader.h"
56 #include "AliCDBManager.h"
57 #include "AliCDBPath.h"
58 #include "AliCDBEntry.h"
60 ClassImp( AliCentralTrigger )
62 //_____________________________________________________________________________
63 AliCentralTrigger::AliCentralTrigger() :
69 // Default constructor
72 //_____________________________________________________________________________
73 AliCentralTrigger::AliCentralTrigger( TString & config ) :
79 // Default constructor
80 LoadConfiguration( config );
83 //_____________________________________________________________________________
84 AliCentralTrigger::~AliCentralTrigger()
87 DeleteConfiguration();
90 //_____________________________________________________________________________
91 void AliCentralTrigger::DeleteConfiguration()
93 // Delete the active configuration
96 if (fConfiguration) delete fConfiguration;
99 //_____________________________________________________________________________
100 void AliCentralTrigger::Reset()
102 // Reset Class Mask and classes
106 if (fConfiguration) {
107 const TObjArray& classesArray = fConfiguration->GetClasses();
108 Int_t nclasses = classesArray.GetEntriesFast();
109 for( Int_t j=0; j<nclasses; j++ ) {
110 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
116 //_____________________________________________________________________________
117 void AliCentralTrigger::MakeBranch( TString name, TTree * tree )
119 // Make a branch to store only trigger class mask event by event
122 AliDebug( 1, "Got Tree from folder." );
123 TBranch* branch = tree->GetBranch( name );
124 if( branch == 0x0 ) {
125 AliDebug( 1, "Creating new branch" );
126 branch = tree->Branch( name, &(this->fClassMask), "fClassMask/l" );
127 branch->SetAutoDelete( kFALSE );
130 AliDebug( 1, "Got Branch from Tree" );
131 branch->SetAddress( &(this->fClassMask) );
136 //_____________________________________________________________________________
137 Bool_t AliCentralTrigger::LoadConfiguration( TString & config )
139 // Load one and only one pre-created COnfiguration from database/file that match
140 // with the input string 'config'
141 // Ej: "p-p", "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL"
143 // Delete the active configuration, if any
144 DeleteConfiguration();
146 // Load the selected configuration
147 if (!config.IsNull()) {
148 fConfiguration = AliTriggerConfiguration::LoadConfiguration( config );
152 AliError( Form( "Valid TriggerConfiguration (%s) is not found ! Disabling the trigger simulation !", config.Data() ) );
157 // Load one and only one trigger descriptor from CDB
158 AliInfo( "GETTING TRIGGER DESCRIPTORS FROM CDB!!!" );
160 AliCDBPath path( "GRP", "CTP", "Config" );
162 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
163 if( !entry ) AliFatal( "Couldn't load trigger description data from CDB!" );
165 fConfiguration = (AliTriggerConfiguration *)entry->GetObject();
169 AliError( "No valid configuration is found in the CDB ! Disabling the trigger simulation !" );
175 //_____________________________________________________________________________
176 TString AliCentralTrigger::GetDetectors()
178 // return TString with the detectors (modules) to be used for triggering
183 result = fConfiguration->GetTriggeringModules();
188 //_____________________________________________________________________________
189 Bool_t AliCentralTrigger::RunTrigger( AliRunLoader* runLoader )
193 if( !fConfiguration ) {
194 AliError( "No trigger configuration loaded, skipping trigger" );
198 TTree *tree = runLoader->TreeCT();
200 AliError( "No folder with trigger loaded, skipping trigger" );
204 TStopwatch stopwatch;
207 // Process each event
208 for( Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++ ) {
209 AliInfo( Form(" ***** Processing event %d *****\n", iEvent) );
210 runLoader->GetEvent( iEvent );
211 // Get detectors involve
212 TString detStr = GetDetectors();
213 AliInfo( Form(" Triggering Detectors %s \n", detStr.Data() ) );
214 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
217 TObjArray trgdetArray; // use as garbage collector
218 for( Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++ ) {
219 AliModule* det = (AliModule*) detArray->At( iDet );
220 if( !det || !det->IsActive() ) continue;
221 if( IsSelected(det->GetName(), detStr) ) {
223 AliInfo( Form("Triggering from digits for %s", det->GetName() ) );
224 AliTriggerDetector* trgdet = det->CreateTriggerDetector();
225 trgdet->CreateInputs(fConfiguration->GetInputs());
226 TStopwatch stopwatchDet;
227 stopwatchDet.Start();
229 AliInfo( Form("Execution time for %s: R:%.2fs C:%.2fs",
230 det->GetName(), stopwatchDet.RealTime(), stopwatchDet.CpuTime() ) );
232 trgdetArray.AddLast( trgdet );
234 // Write trigger detector in Event folder in Digits file
235 TString loadername = det->GetName();
236 loadername.Append( "Loader" );
237 AliLoader * loader = runLoader->GetLoader( loadername );
239 AliDataLoader * dataLoader = loader->GetDigitsDataLoader();
240 if( !dataLoader->IsFileOpen() ) {
241 if( dataLoader->OpenFile( "UPDATE" ) ) {
242 AliWarning( Form( "\n\nCan't write trigger for %s\n", det->GetName() ) );
246 if( gFile && !gFile->IsWritable() ) {
247 gFile->ReOpen( "UPDATE" );
250 trgdet->Write( "Trigger", TObject::kOverwrite );
251 dataLoader->CloseFile();
253 else AliWarning( Form( "Not loader found for %s", det->GetName() ) );
257 // Check trigger conditions and create the trigger class mask
260 // Clear trigger detectors
261 trgdetArray.SetOwner();
262 trgdetArray.Delete();
264 if( (detStr.CompareTo( "ALL" ) != 0) && !detStr.IsNull() ) {
265 AliError( Form("the following detectors were not found: %s",
272 AliInfo( Form("**************** Central Trigger Class Mask:0x%X", fClassMask ) );
276 // cout << endl << " Print " << endl;
280 runLoader->WriteTrigger( "OVERWRITE" );
285 //_____________________________________________________________________________
286 ULong64_t AliCentralTrigger::TriggerClasses()
288 // Check trigger conditions and create the trigger class
289 // and trigger cluster masks
290 if (fConfiguration) {
291 const TObjArray& classesArray = fConfiguration->GetClasses();
292 Int_t nclasses = classesArray.GetEntriesFast();
293 for( Int_t j=0; j<nclasses; j++ ) {
294 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
295 trclass->Trigger( fConfiguration->GetInputs(), fConfiguration->GetFunctions() );
296 fClassMask |= trclass->GetValue();
297 if (trclass->GetStatus())
298 fClusterMask |= (trclass->GetCluster())->GetClusterMask();
303 //_____________________________________________________________________________
304 TObjArray* AliCentralTrigger::GetFiredClasses() const
306 // return only the true conditions
308 TObjArray* result = new TObjArray();
310 if (fConfiguration) {
311 const TObjArray& classesArray = fConfiguration->GetClasses();
312 Int_t nclasses = classesArray.GetEntriesFast();
313 for( Int_t j=0; j<nclasses; j++ ) {
314 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
315 if( trclass->GetStatus() ) result->AddLast( trclass );
322 //_____________________________________________________________________________
323 void AliCentralTrigger::Print( const Option_t* ) const
326 cout << "Central Trigger: " << endl;
327 cout << " Trigger Class Mask: 0x" << hex << fClassMask << dec << endl;
328 if (fConfiguration) fConfiguration->Print();
333 //////////////////////////////////////////////////////////////////////////////
336 //_____________________________________________________________________________
337 Bool_t AliCentralTrigger::IsSelected( TString detName, TString& detectors ) const
339 // check whether detName is contained in detectors
340 // if yes, it is removed from detectors
342 // check if all detectors are selected
343 if( (detectors.CompareTo("ALL") == 0 ) ||
344 detectors.BeginsWith("ALL ") ||
345 detectors.EndsWith(" ALL") ||
346 detectors.Contains(" ALL ") ) {
351 // search for the given detector
352 Bool_t result = kFALSE;
353 if( (detectors.CompareTo( detName ) == 0) ||
354 detectors.BeginsWith( detName+" " ) ||
355 detectors.EndsWith( " "+detName ) ||
356 detectors.Contains( " "+detName+" " ) ) {
357 detectors.ReplaceAll( detName, "" );
361 // clean up the detectors string
362 while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " );
363 while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 );
364 while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 );