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