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 Descriptors //
24 // Make a list the trigger detectors involve from the descriptors //
25 // For the each event //
26 // Run the Trigger for the each detector //
28 // Check the condition 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 "AliTriggerCondition.h"
50 #include "AliTriggerDescriptor.h"
51 #include "AliCentralTrigger.h"
52 #include "AliDetectorEventHeader.h"
53 #include "AliHeader.h"
56 ClassImp( AliCentralTrigger )
58 //_____________________________________________________________________________
59 AliCentralTrigger::AliCentralTrigger() :
65 // Default constructor
66 // LoadDescriptor("Pb-Pb");
69 //_____________________________________________________________________________
70 AliCentralTrigger::AliCentralTrigger( TString & descriptor ) :
76 // Default constructor
77 LoadDescriptor( descriptor );
80 //_____________________________________________________________________________
81 AliCentralTrigger::AliCentralTrigger( const AliCentralTrigger& ctp ):
83 fClassMask( ctp.fClassMask ),
89 Int_t ndes = ctp.fDescriptors.GetEntriesFast();
90 for( Int_t j=0; j<ndes; j++ ) {
91 fDescriptors.AddLast( new AliTriggerDescriptor( *(AliTriggerDescriptor*)(ctp.fDescriptors.At( j )) ) );
94 Int_t nInp = ctp.fInputs.GetEntriesFast();
95 for( Int_t j=0; j<nInp; j++ ) {
96 fInputs.AddLast( new AliTriggerInput( *(AliTriggerInput*)(ctp.fInputs.At( j )) ) );
100 //_____________________________________________________________________________
101 AliCentralTrigger::~AliCentralTrigger()
107 //_____________________________________________________________________________
108 void AliCentralTrigger::DeleteDescriptors()
112 fDescriptors.SetOwner();
113 fDescriptors.Delete();
116 //_____________________________________________________________________________
117 void AliCentralTrigger::Reset()
119 // Reset Class Mask and conditions
121 Int_t ndes = fDescriptors.GetEntriesFast();
122 for( Int_t i=0; i<ndes; i++ ) {
123 TObjArray* condArray = ((AliTriggerDescriptor*)fDescriptors.At( i ))->GetTriggerConditions();
124 Int_t ncond = condArray->GetEntriesFast();
125 for( Int_t j=0; j<ncond; j++ ) {
126 AliTriggerCondition* cond = (AliTriggerCondition*)condArray->At( j );
132 //_____________________________________________________________________________
133 void AliCentralTrigger::MakeBranch( TString name, TTree * tree )
135 // Make a branch to store only trigger class mask event by event
138 AliDebug( 1, "Got Tree from folder." );
139 TBranch* branch = tree->GetBranch( name );
140 if( branch == 0x0 ) {
141 AliDebug( 1, "Creating new branch" );
142 branch = tree->Branch( name, &(this->fClassMask), "fClassMask/l" );
143 branch->SetAutoDelete( kFALSE );
146 AliDebug( 1, "Got Branch from Tree" );
147 branch->SetAddress( &(this->fClassMask) );
152 //_____________________________________________________________________________
153 Bool_t AliCentralTrigger::LoadDescriptor( TString & descriptor )
155 // Load one or more pre-created Descriptors from database/file that match
156 // with the input string 'descriptor'
157 // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL"
159 // Delete any descriptor
162 // Load the selected descriptors
163 TObjArray* desArray = descriptor.Tokenize( " " );
164 Int_t ndes = desArray->GetEntriesFast();
165 for( Int_t i=0; i<ndes; i++ ) {
166 TObjString* val = (TObjString*)desArray->At( i );
167 AliTriggerDescriptor* des = AliTriggerDescriptor::LoadDescriptor( val->String() );
169 fDescriptors.AddLast( des );
171 AliWarning( Form( "Descriptor (%s) not found", val->String().Data() ) );
173 Bool_t desfound = kTRUE;
174 if( fDescriptors.GetEntriesFast() == 0 ) desfound = kFALSE;
181 //_____________________________________________________________________________
182 TString AliCentralTrigger::GetDetectors()
184 // return TString with the detectors to be trigger
185 // merging detectors from all descriptors
189 Int_t ndes = fDescriptors.GetEntriesFast();
190 for( Int_t i=0; i<ndes; i++ ) {
191 TString detStr = ((AliTriggerDescriptor*)fDescriptors.At( i ))->GetDetectorCluster();
192 TObjArray* det = detStr.Tokenize(" ");
193 Int_t ndet = det->GetEntriesFast();
194 for( Int_t j=0; j<ndet; j++ ) {
195 if( result.Contains( ((TObjString*)det->At(j))->String() ) )continue;
196 result.Append( " " );
197 result.Append( ((TObjString*)det->At(j))->String() );
204 //_____________________________________________________________________________
205 UChar_t AliCentralTrigger::GetClusterMask()
207 // Return the detector cluster mask following
208 // table 4.3 pag 60, TDR Trigger and DAQ
210 TString detStr = GetDetectors();
211 TObjArray* det = detStr.Tokenize(" ");
212 Int_t ndet = det->GetEntriesFast();
215 if( ndet >= 8 ) { // All detectors, should be 9 but ACORDE is not implemented yet
220 if( ndet >= 7 && !detStr.Contains("MUON") ) { // Central Barrel, All but MUON
225 if( detStr.Contains("MUON") && detStr.Contains("T0") ) { // MUON arm
230 return idmask; // 0 something else!!!
232 //_____________________________________________________________________________
233 Bool_t AliCentralTrigger::RunTrigger( AliRunLoader* runLoader )
237 if( fDescriptors.GetEntriesFast() == 0 ) {
238 AliError( "not trigger descriptor loaded, skipping trigger" );
242 TTree *tree = runLoader->TreeCT();
244 AliError( "not folder with trigger loaded, skipping trigger" );
248 TStopwatch stopwatch;
251 // Process each event
252 for( Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++ ) {
253 AliInfo( Form(" ***** Processing event %d *****\n", iEvent) );
254 runLoader->GetEvent( iEvent );
255 // Get detectors involve
256 TString detStr = GetDetectors();
257 AliInfo( Form(" Cluster Detectors %s \n", detStr.Data() ) );
258 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
261 TObjArray trgdetArray; // use as garbage collector
262 for( Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++ ) {
263 AliModule* det = (AliModule*) detArray->At( iDet );
264 if( !det || !det->IsActive() ) continue;
265 if( IsSelected(det->GetName(), detStr) ) {
267 AliInfo( Form("Triggering from digits for %s", det->GetName() ) );
268 AliTriggerDetector* trgdet = det->CreateTriggerDetector();
269 trgdet->CreateInputs();
270 TStopwatch stopwatchDet;
271 stopwatchDet.Start();
273 AliInfo( Form("Execution time for %s: R:%.2fs C:%.2fs",
274 det->GetName(), stopwatchDet.RealTime(), stopwatchDet.CpuTime() ) );
277 TObjArray* detInp = trgdet->GetInputs();
278 for( Int_t i=0; i<detInp->GetEntriesFast(); i++ ) {
279 fInputs.AddLast( detInp->At(i) );
281 trgdetArray.AddLast( trgdet );
283 // Write trigger detector in Event folder in Digits file
284 TString loadername = det->GetName();
285 loadername.Append( "Loader" );
286 AliLoader * loader = runLoader->GetLoader( loadername );
288 AliDataLoader * dataLoader = loader->GetDigitsDataLoader();
289 if( !dataLoader->IsFileOpen() ) {
290 if( dataLoader->OpenFile( "UPDATE" ) ) {
291 AliWarning( Form( "\n\nCan't write trigger for %s\n", det->GetName() ) );
295 if( gFile && !gFile->IsWritable() ) {
296 gFile->ReOpen( "UPDATE" );
299 trgdet->Write( "Trigger", TObject::kOverwrite );
300 dataLoader->CloseFile();
302 else AliWarning( Form( "Not loader found for %s", det->GetName() ) );
306 // Check trigger conditions and create the trigger class mask
310 // Clear trigger detectors
311 trgdetArray.SetOwner();
312 trgdetArray.Delete();
314 if( (detStr.CompareTo( "ALL" ) != 0) && !detStr.IsNull() ) {
315 AliError( Form("the following detectors were not found: %s",
322 AliInfo( Form("**************** Central Trigger Class Mask:0x%X", fClassMask ) );
326 // cout << endl << " Print " << endl;
330 runLoader->WriteTrigger( "OVERWRITE" );
335 //_____________________________________________________________________________
336 ULong64_t AliCentralTrigger::CheckConditions()
338 // Check trigger conditions and create the trigger class mask
340 Int_t ndes = fDescriptors.GetEntriesFast();
341 for( Int_t i=0; i<ndes; i++ ) {
342 TObjArray* condArray = ((AliTriggerDescriptor*)fDescriptors.At( i ))->GetTriggerConditions();
343 Int_t ncond = condArray->GetEntriesFast();
344 for( Int_t j=0; j<ncond; j++ ) {
345 AliTriggerCondition* cond = (AliTriggerCondition*)condArray->At( j );
346 if( !cond->CheckInputs( fInputs ) ) continue;
347 cond->Trigger( fInputs );
349 fClassMask |= cond->GetValue();
354 //_____________________________________________________________________________
355 TObjArray* AliCentralTrigger::GetResultConditions()
357 // return only the true conditions
359 TObjArray* result = new TObjArray();
361 Int_t ndes = fDescriptors.GetEntriesFast();
362 for( Int_t i=0; i<ndes; i++ ) {
363 TObjArray* condArray = ((AliTriggerDescriptor*)fDescriptors.At( i ))->GetTriggerConditions();
364 Int_t ncond = condArray->GetEntriesFast();
365 for( Int_t j=0; j<ncond; j++ ) {
366 AliTriggerCondition* cond = (AliTriggerCondition*)condArray->At( j );
367 if( cond->GetStatus() ) result->AddLast( cond );
374 //_____________________________________________________________________________
375 void AliCentralTrigger::Print( const Option_t* ) const
378 cout << "Central Trigger: " << endl;
379 cout << " Trigger Class Mask: 0x" << hex << fClassMask << dec << endl;
381 Int_t ndes = fDescriptors.GetEntriesFast();
382 for( Int_t i=0; i<ndes; i++ ) {
383 AliTriggerDescriptor* des = (AliTriggerDescriptor*)fDescriptors.At( i );
384 if( des ) des->Print();
390 //////////////////////////////////////////////////////////////////////////////
393 //_____________________________________________________________________________
394 Bool_t AliCentralTrigger::IsSelected( TString detName, TString& detectors ) const
396 // check whether detName is contained in detectors
397 // if yes, it is removed from detectors
399 // check if all detectors are selected
400 if( (detectors.CompareTo("ALL") == 0 ) ||
401 detectors.BeginsWith("ALL ") ||
402 detectors.EndsWith(" ALL") ||
403 detectors.Contains(" ALL ") ) {
408 // search for the given detector
409 Bool_t result = kFALSE;
410 if( (detectors.CompareTo( detName ) == 0) ||
411 detectors.BeginsWith( detName+" " ) ||
412 detectors.EndsWith( " "+detName ) ||
413 detectors.Contains( " "+detName+" " ) ) {
414 detectors.ReplaceAll( detName, "" );
418 // clean up the detectors string
419 while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " );
420 while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 );
421 while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 );