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
73 //_____________________________________________________________________________
74 AliCentralTrigger::AliCentralTrigger( TString & config ) :
80 // Default constructor
81 LoadConfiguration( config );
84 //_____________________________________________________________________________
85 AliCentralTrigger::~AliCentralTrigger()
88 DeleteConfiguration();
91 //_____________________________________________________________________________
92 void AliCentralTrigger::DeleteConfiguration()
94 // Delete the active configuration
98 if (IsOwner()) delete fConfiguration;
103 //_____________________________________________________________________________
104 void AliCentralTrigger::Reset()
106 // Reset Class Mask and classes
110 if (fConfiguration) {
111 const TObjArray& classesArray = fConfiguration->GetClasses();
112 Int_t nclasses = classesArray.GetEntriesFast();
113 for( Int_t j=0; j<nclasses; j++ ) {
114 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
120 //_____________________________________________________________________________
121 void AliCentralTrigger::MakeBranch( TString name, TTree * tree )
123 // Make a branch to store only trigger class mask event by event
126 AliDebug( 1, "Got Tree from folder." );
127 TBranch* branch = tree->GetBranch( name );
128 if( branch == 0x0 ) {
129 AliDebug( 1, "Creating new branch" );
130 branch = tree->Branch( name, &(this->fClassMask), "fClassMask/l:fClusterMask/i" );
131 branch->SetAutoDelete( kFALSE );
134 AliDebug( 1, "Got Branch from Tree" );
135 branch->SetAddress( &(this->fClassMask) );
140 //_____________________________________________________________________________
141 Bool_t AliCentralTrigger::LoadConfiguration( TString & config )
143 // Load one and only one pre-created COnfiguration from database/file that match
144 // with the input string 'config'
145 // Ej: "p-p", "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL"
147 // Delete the active configuration, if any
148 DeleteConfiguration();
150 // Load the selected configuration
151 if (!config.IsNull()) {
152 fConfiguration = AliTriggerConfiguration::LoadConfiguration( config );
157 AliError( Form( "Valid TriggerConfiguration (%s) is not found ! Disabling the trigger simulation !", config.Data() ) );
162 // Load one and only one trigger descriptor from CDB
163 AliInfo( "Getting trigger configuration from OCDB!" );
165 AliCDBPath path( "GRP", "CTP", "Config" );
167 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
169 if( !entry ) AliFatal( "Couldn't load trigger description data from CDB!" );
171 fConfiguration = (AliTriggerConfiguration *)entry->GetObject();
175 AliError( "No valid configuration is found in the CDB ! Disabling the trigger simulation !" );
181 //_____________________________________________________________________________
182 TString AliCentralTrigger::GetDetectors()
184 // return TString with the detectors (modules) to be used for triggering
189 result = fConfiguration->GetTriggeringModules();
194 //_____________________________________________________________________________
195 Bool_t AliCentralTrigger::RunTrigger( AliRunLoader* runLoader, const char *detectors )
199 if( !fConfiguration ) {
200 AliError( "No trigger configuration loaded, skipping trigger" );
204 TTree *tree = runLoader->TreeCT();
206 AliError( "No folder with trigger loaded, skipping trigger" );
210 TStopwatch stopwatch;
213 // Process each event
214 for( Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++ ) {
215 AliInfo( Form(" ***** Processing event %d *****\n", iEvent) );
216 runLoader->GetEvent( iEvent );
217 // Get detectors involve
218 TString detStr = GetDetectors();
219 AliInfo( Form(" Triggering Detectors: %s \n", detStr.Data() ) );
220 TString detWithDigits = detectors;
221 AliInfo( Form(" Detectors with digits: %s \n", detWithDigits.Data() ) );
222 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
226 // Reset configuration object (inputs and classes)
227 fConfiguration->Reset();
228 TObjArray trgdetArray; // use as garbage collector
229 for( Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++ ) {
230 AliModule* det = (AliModule*) detArray->At( iDet );
231 if( !det || !det->IsActive() ) continue;
232 if( IsSelected(det->GetName(), detStr) &&
233 IsSelected(det->GetName(), detWithDigits) ) {
235 AliInfo( Form("Triggering from digits for %s", det->GetName() ) );
236 AliTriggerDetector* trgdet = det->CreateTriggerDetector();
237 trgdet->CreateInputs(fConfiguration->GetInputs());
238 TStopwatch stopwatchDet;
239 stopwatchDet.Start();
241 AliInfo( Form("Execution time for %s: R:%.2fs C:%.2fs",
242 det->GetName(), stopwatchDet.RealTime(), stopwatchDet.CpuTime() ) );
244 trgdetArray.AddLast( trgdet );
246 // Write trigger detector in Event folder in Digits file
247 TString loadername = det->GetName();
248 loadername.Append( "Loader" );
249 AliLoader * loader = runLoader->GetLoader( loadername );
251 AliDataLoader * dataLoader = loader->GetDigitsDataLoader();
252 if( !dataLoader->IsFileOpen() ) {
253 if( dataLoader->OpenFile( "UPDATE" ) ) {
254 AliWarning( Form( "\n\nCan't write trigger for %s\n", det->GetName() ) );
258 if( gFile && !gFile->IsWritable() ) {
259 gFile->ReOpen( "UPDATE" );
262 trgdet->Write( "Trigger", TObject::kOverwrite );
263 dataLoader->CloseFile();
265 else AliWarning( Form( "Not loader found for %s", det->GetName() ) );
269 // Check trigger conditions and create the trigger class mask
272 // Clear trigger detectors
273 trgdetArray.SetOwner();
274 trgdetArray.Delete();
276 if( (detStr.CompareTo( "ALL" ) != 0) && !detStr.IsNull() ) {
277 AliError( Form("the following detectors were not found: %s",
284 AliInfo( Form("**************** Central Trigger Class Mask:0x%X", fClassMask ) );
288 // cout << endl << " Print " << endl;
292 runLoader->WriteTrigger( "OVERWRITE" );
297 //_____________________________________________________________________________
298 ULong64_t AliCentralTrigger::TriggerClasses()
300 // Check trigger conditions and create the trigger class
301 // and trigger cluster masks
304 if (fConfiguration) {
305 const TObjArray& classesArray = fConfiguration->GetClasses();
306 Int_t nclasses = classesArray.GetEntriesFast();
307 for( Int_t j=0; j<nclasses; j++ ) {
308 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
309 trclass->Trigger( fConfiguration->GetInputs(), fConfiguration->GetFunctions() );
310 fClassMask |= trclass->GetValue();
311 if (trclass->GetStatus()) {
312 AliTriggerCluster *trclust = trclass->GetCluster();
313 fClusterMask |= AliDAQ::DetectorPattern(trclust->GetDetectorsInCluster());
319 //_____________________________________________________________________________
320 TObjArray* AliCentralTrigger::GetFiredClasses() const
322 // return only the true conditions
324 TObjArray* result = new TObjArray();
326 if (fConfiguration) {
327 const TObjArray& classesArray = fConfiguration->GetClasses();
328 Int_t nclasses = classesArray.GetEntriesFast();
329 for( Int_t j=0; j<nclasses; j++ ) {
330 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
331 if( trclass->GetStatus() ) result->AddLast( trclass );
338 //_____________________________________________________________________________
339 void AliCentralTrigger::Print( const Option_t* ) const
342 cout << "Central Trigger: " << endl;
343 cout << " Trigger Class Mask: 0x" << hex << fClassMask << dec << endl;
344 if (fConfiguration) fConfiguration->Print();
349 //////////////////////////////////////////////////////////////////////////////
352 //_____________________________________________________________________________
353 Bool_t AliCentralTrigger::IsSelected( TString detName, TString& detectors ) const
355 // check whether detName is contained in detectors
356 // if yes, it is removed from detectors
358 // check if all detectors are selected
359 if( (detectors.CompareTo("ALL") == 0 ) ||
360 detectors.BeginsWith("ALL ") ||
361 detectors.EndsWith(" ALL") ||
362 detectors.Contains(" ALL ") ) {
367 // search for the given detector
368 Bool_t result = kFALSE;
369 if( (detectors.CompareTo( detName ) == 0) ||
370 detectors.BeginsWith( detName+" " ) ||
371 detectors.EndsWith( " "+detName ) ||
372 detectors.Contains( " "+detName+" " ) ) {
373 detectors.ReplaceAll( detName, "" );
377 // clean up the detectors string
378 while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " );
379 while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 );
380 while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 );
385 //_____________________________________________________________________________
386 Bool_t AliCentralTrigger::CheckTriggeredDetectors() const
388 // Check the trigger mask, finds which trigger classes
389 // have been fired, load the corresponding trigger clusters and
390 // finally makes a list of the detectors that have been readout
391 // for each particular event. This list is then compared to the
392 // one stored in fClusterMask. Return value:
393 // true = two lists are equal
394 // false = two lists are not equal meaning wrong trigger config
397 if (!fConfiguration) {
398 AliError("The trigger confiration has not yet been loaded! Cross-check is not possible!");
403 // Make a cross-check so that to exclude wrong trigger configuration used
404 // Loop over the trigger classes
405 UInt_t clusterMask = 0;
406 const TObjArray& classesArray = fConfiguration->GetClasses();
407 Int_t nclasses = classesArray.GetEntriesFast();
408 for( Int_t j=0; j<nclasses; j++ ) {
409 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
410 if (trclass->GetMask() & fClassMask) { // class was fired
411 AliTriggerCluster *trclust = trclass->GetCluster();
412 clusterMask |= AliDAQ::DetectorPattern(trclust->GetDetectorsInCluster());
415 // Compare the stored cluster mask with the one
416 // that we get from trigger classes
417 // To be enables after we store the cluster mask in the trigger tree
418 if (clusterMask != fClusterMask) {
419 AliError(Form("Wrong cluster mask from trigger classes (%x), expecting (%x)! Loaded trigger configuration is possibly wrong!",
420 (UInt_t)clusterMask,(UInt_t)fClusterMask));