]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/STEER/AliCentralTrigger.cxx
For objects from special storage the storage paths were not compared in the CheckReco...
[u/mrichter/AliRoot.git] / STEER / STEER / AliCentralTrigger.cxx
CommitLineData
a5a091ce 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// This class for running the Central Trigger Processor //
21// //
22// //
51f6d619 23// Load Configuration //
24// Make a list the trigger detectors involved (from the classes) //
a5a091ce 25// For the each event //
26// Run the Trigger for the each detector //
27// Get the inputs //
51f6d619 28// Check the trigger classes //
a5a091ce 29// Create the class mask //
30// Save result //
31// //
32// //
33///////////////////////////////////////////////////////////////////////////////
34
35#include <TString.h>
36#include <TObjString.h>
37#include <TObjArray.h>
38#include <TStopwatch.h>
bacbe0fd 39#include <TFile.h>
40#include <TTree.h>
a5a091ce 41
42#include "AliLog.h"
43#include "AliRun.h"
44#include "AliRunLoader.h"
c93255fe 45#include "AliLoader.h"
a5a091ce 46#include "AliModule.h"
47
48#include "AliTriggerInput.h"
49#include "AliTriggerDetector.h"
51f6d619 50#include "AliTriggerConfiguration.h"
51#include "AliTriggerClass.h"
52#include "AliTriggerCluster.h"
a5a091ce 53#include "AliCentralTrigger.h"
bacbe0fd 54#include "AliDetectorEventHeader.h"
55#include "AliHeader.h"
56
51f6d619 57#include "AliCDBManager.h"
58#include "AliCDBPath.h"
59#include "AliCDBEntry.h"
a5a091ce 60
66b0310c 61using std::endl;
62using std::cout;
63using std::hex;
64using std::dec;
a5a091ce 65ClassImp( AliCentralTrigger )
66
67//_____________________________________________________________________________
68AliCentralTrigger::AliCentralTrigger() :
69 TObject(),
75e3794b 70 fClassMask(0),
51f6d619 71 fClusterMask(0),
d3f1f232 72 fL0TriggerInputs(0),
73 fL1TriggerInputs(0),
74 fL2TriggerInputs(0),
51f6d619 75 fConfiguration(NULL)
a5a091ce 76{
77 // Default constructor
596735df 78 SetOwner();
a5a091ce 79}
80
81//_____________________________________________________________________________
51f6d619 82AliCentralTrigger::AliCentralTrigger( TString & config ) :
a5a091ce 83 TObject(),
75e3794b 84 fClassMask(0),
51f6d619 85 fClusterMask(0),
d3f1f232 86 fL0TriggerInputs(0),
87 fL1TriggerInputs(0),
88 fL2TriggerInputs(0),
51f6d619 89 fConfiguration(NULL)
a5a091ce 90{
91 // Default constructor
51f6d619 92 LoadConfiguration( config );
bacbe0fd 93}
94
a5a091ce 95//_____________________________________________________________________________
96AliCentralTrigger::~AliCentralTrigger()
97{
51f6d619 98 // Destructor
99 DeleteConfiguration();
bacbe0fd 100}
101
102//_____________________________________________________________________________
51f6d619 103void AliCentralTrigger::DeleteConfiguration()
bacbe0fd 104{
51f6d619 105 // Delete the active configuration
106 fClassMask = 0;
107 fClusterMask = 0;
d3f1f232 108 fL0TriggerInputs = 0;
109 fL1TriggerInputs = 0;
110 fL2TriggerInputs = 0;
596735df 111 if (fConfiguration) {
112 if (IsOwner()) delete fConfiguration;
113 fConfiguration = 0x0;
114 }
a5a091ce 115}
116
bacbe0fd 117//_____________________________________________________________________________
118void AliCentralTrigger::Reset()
119{
51f6d619 120 // Reset Class Mask and classes
bacbe0fd 121 fClassMask = 0;
51f6d619 122 fClusterMask = 0;
d3f1f232 123 fL0TriggerInputs = 0;
124 fL1TriggerInputs = 0;
125 fL2TriggerInputs = 0;
51f6d619 126
127 if (fConfiguration) {
128 const TObjArray& classesArray = fConfiguration->GetClasses();
129 Int_t nclasses = classesArray.GetEntriesFast();
130 for( Int_t j=0; j<nclasses; j++ ) {
131 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
132 trclass->Reset();
133 }
bacbe0fd 134 }
135}
136
137//_____________________________________________________________________________
138void AliCentralTrigger::MakeBranch( TString name, TTree * tree )
139{
140 // Make a branch to store only trigger class mask event by event
141
142 if( tree ) {
143 AliDebug( 1, "Got Tree from folder." );
144 TBranch* branch = tree->GetBranch( name );
145 if( branch == 0x0 ) {
146 AliDebug( 1, "Creating new branch" );
d3f1f232 147 branch = tree->Branch( name, &(this->fClassMask), "fClassMask/l:fClusterMask/i:fL0TriggerInputs/i:fL1TriggerInputs/i:fL2TriggerInputs/s" );
bacbe0fd 148 branch->SetAutoDelete( kFALSE );
149 }
150 else {
151 AliDebug( 1, "Got Branch from Tree" );
152 branch->SetAddress( &(this->fClassMask) );
153 }
154 }
155}
156
a5a091ce 157//_____________________________________________________________________________
51f6d619 158Bool_t AliCentralTrigger::LoadConfiguration( TString & config )
a5a091ce 159{
51f6d619 160 // Load one and only one pre-created COnfiguration from database/file that match
161 // with the input string 'config'
162 // Ej: "p-p", "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL"
163
164 // Delete the active configuration, if any
165 DeleteConfiguration();
166
167 // Load the selected configuration
168 if (!config.IsNull()) {
169 fConfiguration = AliTriggerConfiguration::LoadConfiguration( config );
596735df 170 SetOwner();
51f6d619 171 if(fConfiguration)
172 return kTRUE;
173 else {
174 AliError( Form( "Valid TriggerConfiguration (%s) is not found ! Disabling the trigger simulation !", config.Data() ) );
175 return kFALSE;
176 }
177 }
178 else {
179 // Load one and only one trigger descriptor from CDB
7e88424f 180 AliInfo( "Getting trigger configuration from OCDB!" );
51f6d619 181
182 AliCDBPath path( "GRP", "CTP", "Config" );
183
184 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
596735df 185 SetOwner(kFALSE);
51f6d619 186 if( !entry ) AliFatal( "Couldn't load trigger description data from CDB!" );
187
188 fConfiguration = (AliTriggerConfiguration *)entry->GetObject();
189 if(fConfiguration)
190 return kTRUE;
191 else {
192 AliError( "No valid configuration is found in the CDB ! Disabling the trigger simulation !" );
193 return kFALSE;
194 }
a5a091ce 195 }
a5a091ce 196}
197
198//_____________________________________________________________________________
199TString AliCentralTrigger::GetDetectors()
200{
51f6d619 201 // return TString with the detectors (modules) to be used for triggering
a5a091ce 202
203 TString result;
204
51f6d619 205 if (fConfiguration)
206 result = fConfiguration->GetTriggeringModules();
a5a091ce 207
208 return result;
209}
210
211//_____________________________________________________________________________
8480396b 212Bool_t AliCentralTrigger::RunTrigger( AliRunLoader* runLoader, const char *detectors )
a5a091ce 213{
214 // run the trigger
bacbe0fd 215
51f6d619 216 if( !fConfiguration ) {
217 AliError( "No trigger configuration loaded, skipping trigger" );
bacbe0fd 218 return kFALSE;
219 }
220
221 TTree *tree = runLoader->TreeCT();
222 if( !tree ) {
51f6d619 223 AliError( "No folder with trigger loaded, skipping trigger" );
a5a091ce 224 return kFALSE;
225 }
226
227 TStopwatch stopwatch;
228 stopwatch.Start();
bacbe0fd 229
01eed601 230 AliInfo( Form(" Triggering Detectors: %s \n", GetDetectors().Data() ) );
231 AliInfo( Form(" Detectors with digits: %s \n", detectors ) );
232
a5a091ce 233 // Process each event
234 for( Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++ ) {
bacbe0fd 235 runLoader->GetEvent( iEvent );
a5a091ce 236 // Get detectors involve
237 TString detStr = GetDetectors();
8480396b 238 TString detWithDigits = detectors;
a5a091ce 239 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
240 // Reset Mask
241 fClassMask = 0;
895affe8 242 fClusterMask = 0;
243 // Reset configuration object (inputs and classes)
244 fConfiguration->Reset();
bacbe0fd 245 TObjArray trgdetArray; // use as garbage collector
a5a091ce 246 for( Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++ ) {
247 AliModule* det = (AliModule*) detArray->At( iDet );
248 if( !det || !det->IsActive() ) continue;
8480396b 249 if( IsSelected(det->GetName(), detStr) &&
250 IsSelected(det->GetName(), detWithDigits) ) {
bacbe0fd 251
01eed601 252 AliDebug(1,Form("Triggering from digits for %s", det->GetName() ) );
a5a091ce 253 AliTriggerDetector* trgdet = det->CreateTriggerDetector();
a4d25339 254 trgdet->AssignInputs(fConfiguration->GetInputs());
a5a091ce 255 TStopwatch stopwatchDet;
256 stopwatchDet.Start();
257 trgdet->Trigger();
01eed601 258 AliDebug(1, Form("Execution time for %s: R:%.2fs C:%.2fs",
a5a091ce 259 det->GetName(), stopwatchDet.RealTime(), stopwatchDet.CpuTime() ) );
bacbe0fd 260
bacbe0fd 261 trgdetArray.AddLast( trgdet );
262
263 // Write trigger detector in Event folder in Digits file
264 TString loadername = det->GetName();
265 loadername.Append( "Loader" );
266 AliLoader * loader = runLoader->GetLoader( loadername );
267 if( loader ) {
268 AliDataLoader * dataLoader = loader->GetDigitsDataLoader();
269 if( !dataLoader->IsFileOpen() ) {
270 if( dataLoader->OpenFile( "UPDATE" ) ) {
271 AliWarning( Form( "\n\nCan't write trigger for %s\n", det->GetName() ) );
272 }
273 }
274 dataLoader->Cd();
275 if( gFile && !gFile->IsWritable() ) {
276 gFile->ReOpen( "UPDATE" );
277 dataLoader->Cd();
278 }
279 trgdet->Write( "Trigger", TObject::kOverwrite );
280 dataLoader->CloseFile();
281 }
282 else AliWarning( Form( "Not loader found for %s", det->GetName() ) );
a5a091ce 283 }
284 }
285
286 // Check trigger conditions and create the trigger class mask
51f6d619 287 TriggerClasses();
d3f1f232 288 // Calculate trigger Input pattern
289 TriggerInputs();
bacbe0fd 290
a5a091ce 291 // Clear trigger detectors
292 trgdetArray.SetOwner();
293 trgdetArray.Delete();
294
295 if( (detStr.CompareTo( "ALL" ) != 0) && !detStr.IsNull() ) {
296 AliError( Form("the following detectors were not found: %s",
297 detStr.Data()));
e229562b 298 //JF return kFALSE;
a5a091ce 299 }
300
bacbe0fd 301 // Save trigger mask
302 tree->Fill();
73bbf779 303 AliDebug(1, Form("Event:%d Class Mask:0x%llX", iEvent,fClassMask ) );
a5a091ce 304 } // end event loop
a5a091ce 305
bacbe0fd 306 Reset();
307// cout << endl << " Print " << endl;
308// Print();
309
310 // Write
311 runLoader->WriteTrigger( "OVERWRITE" );
a5a091ce 312
bacbe0fd 313 return kTRUE;
314}
d3f1f232 315//----------------------------------------------------------------------------
316void AliCentralTrigger::TriggerInputs()
317{
318 // Find which inputs are in configuration
319 // and calculate input pattern
320 fL0TriggerInputs=0;
321 fL1TriggerInputs=0;
322 fL2TriggerInputs=0;
323 if(fConfiguration){
324 const TObjArray& inputsArray = fConfiguration->GetInputs();
325 Int_t ninputs = inputsArray.GetEntriesFast();
326 for( Int_t j=0; j<ninputs; j++ ) {
327 AliTriggerInput* input = (AliTriggerInput*)inputsArray.At( j );
328 if(input->GetValue()){
329 UChar_t level=input->GetLevel();
330 if(level == 0) fL0TriggerInputs |= (input->GetMask());
331 else if(level == 1) fL1TriggerInputs |= (input->GetMask());
332 else if(level == 2) fL2TriggerInputs |= (input->GetMask());
333 else{
334 AliError(Form("Unknown input level:%c:",level));
335 }
336 }
337 }
338 }
339}
a5a091ce 340//_____________________________________________________________________________
51f6d619 341ULong64_t AliCentralTrigger::TriggerClasses()
a5a091ce 342{
51f6d619 343 // Check trigger conditions and create the trigger class
344 // and trigger cluster masks
7e88424f 345 fClassMask = 0;
346 fClusterMask = 0;
51f6d619 347 if (fConfiguration) {
348 const TObjArray& classesArray = fConfiguration->GetClasses();
349 Int_t nclasses = classesArray.GetEntriesFast();
350 for( Int_t j=0; j<nclasses; j++ ) {
351 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
352 trclass->Trigger( fConfiguration->GetInputs(), fConfiguration->GetFunctions() );
353 fClassMask |= trclass->GetValue();
7e88424f 354 if (trclass->GetStatus()) {
355 AliTriggerCluster *trclust = trclass->GetCluster();
356 fClusterMask |= AliDAQ::DetectorPattern(trclust->GetDetectorsInCluster());
357 }
51f6d619 358 }
359 }
360 return fClassMask;
a5a091ce 361}
362//_____________________________________________________________________________
51f6d619 363TObjArray* AliCentralTrigger::GetFiredClasses() const
a5a091ce 364{
365 // return only the true conditions
366
367 TObjArray* result = new TObjArray();
368
51f6d619 369 if (fConfiguration) {
370 const TObjArray& classesArray = fConfiguration->GetClasses();
371 Int_t nclasses = classesArray.GetEntriesFast();
372 for( Int_t j=0; j<nclasses; j++ ) {
373 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
374 if( trclass->GetStatus() ) result->AddLast( trclass );
375 }
a5a091ce 376 }
377
378 return result;
379}
380
a5a091ce 381//_____________________________________________________________________________
382void AliCentralTrigger::Print( const Option_t* ) const
383{
384 // Print
385 cout << "Central Trigger: " << endl;
386 cout << " Trigger Class Mask: 0x" << hex << fClassMask << dec << endl;
51f6d619 387 if (fConfiguration) fConfiguration->Print();
a5a091ce 388 cout << endl;
389}
390
391
392//////////////////////////////////////////////////////////////////////////////
393// Helper method
394
395//_____________________________________________________________________________
396Bool_t AliCentralTrigger::IsSelected( TString detName, TString& detectors ) const
397{
398 // check whether detName is contained in detectors
399 // if yes, it is removed from detectors
400
401 // check if all detectors are selected
402 if( (detectors.CompareTo("ALL") == 0 ) ||
403 detectors.BeginsWith("ALL ") ||
404 detectors.EndsWith(" ALL") ||
405 detectors.Contains(" ALL ") ) {
406 detectors = "ALL";
407 return kTRUE;
408 }
409
410 // search for the given detector
411 Bool_t result = kFALSE;
412 if( (detectors.CompareTo( detName ) == 0) ||
413 detectors.BeginsWith( detName+" " ) ||
414 detectors.EndsWith( " "+detName ) ||
415 detectors.Contains( " "+detName+" " ) ) {
416 detectors.ReplaceAll( detName, "" );
417 result = kTRUE;
418 }
419
420 // clean up the detectors string
421 while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " );
422 while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 );
423 while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 );
424
425 return result;
426}
67327b72 427
428//_____________________________________________________________________________
7e88424f 429Bool_t AliCentralTrigger::CheckTriggeredDetectors() const
67327b72 430{
431 // Check the trigger mask, finds which trigger classes
432 // have been fired, load the corresponding trigger clusters and
433 // finally makes a list of the detectors that have been readout
7e88424f 434 // for each particular event. This list is then compared to the
435 // one stored in fClusterMask. Return value:
436 // true = two lists are equal
437 // false = two lists are not equal meaning wrong trigger config
438 // is loaded.
67327b72 439
440 if (!fConfiguration) {
7e88424f 441 AliError("The trigger confiration has not yet been loaded! Cross-check is not possible!");
442 return kFALSE;
67327b72 443 }
7e88424f 444 else {
67327b72 445
7e88424f 446 // Make a cross-check so that to exclude wrong trigger configuration used
447 // Loop over the trigger classes
448 UInt_t clusterMask = 0;
449 const TObjArray& classesArray = fConfiguration->GetClasses();
450 Int_t nclasses = classesArray.GetEntriesFast();
451 for( Int_t j=0; j<nclasses; j++ ) {
452 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
453 if (trclass->GetMask() & fClassMask) { // class was fired
454 AliTriggerCluster *trclust = trclass->GetCluster();
455 clusterMask |= AliDAQ::DetectorPattern(trclust->GetDetectorsInCluster());
67327b72 456 }
457 }
7e88424f 458 // Compare the stored cluster mask with the one
459 // that we get from trigger classes
7e88424f 460 if (clusterMask != fClusterMask) {
454d6738 461 if ((clusterMask & fClusterMask) == clusterMask) {
462 AliInfo(Form("Cluster mask from trigger classes (%x) and from data (%x) differ. Concurrent DAQ run(s) could be the reason.",
463 (UInt_t)clusterMask,(UInt_t)fClusterMask));
464 return kTRUE;
465 }
466 else {
467 AliError(Form("Wrong cluster mask from trigger classes (%x), expecting (%x)! Loaded trigger configuration is possibly wrong!",
468 (UInt_t)clusterMask,(UInt_t)fClusterMask));
469 return kFALSE;
470 }
7e88424f 471 }
67327b72 472 }
473
7e88424f 474 return kTRUE;
67327b72 475}