]>
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 | |
a5a091ce | 70 | } |
71 | ||
72 | //_____________________________________________________________________________ | |
51f6d619 | 73 | AliCentralTrigger::AliCentralTrigger( TString & config ) : |
a5a091ce | 74 | TObject(), |
75e3794b | 75 | fClassMask(0), |
51f6d619 | 76 | fClusterMask(0), |
77 | fConfiguration(NULL) | |
a5a091ce | 78 | { |
79 | // Default constructor | |
51f6d619 | 80 | LoadConfiguration( config ); |
bacbe0fd | 81 | } |
82 | ||
a5a091ce | 83 | //_____________________________________________________________________________ |
84 | AliCentralTrigger::~AliCentralTrigger() | |
85 | { | |
51f6d619 | 86 | // Destructor |
87 | DeleteConfiguration(); | |
bacbe0fd | 88 | } |
89 | ||
90 | //_____________________________________________________________________________ | |
51f6d619 | 91 | void AliCentralTrigger::DeleteConfiguration() |
bacbe0fd | 92 | { |
51f6d619 | 93 | // Delete the active configuration |
94 | fClassMask = 0; | |
95 | fClusterMask = 0; | |
96 | if (fConfiguration) delete fConfiguration; | |
a5a091ce | 97 | } |
98 | ||
bacbe0fd | 99 | //_____________________________________________________________________________ |
100 | void AliCentralTrigger::Reset() | |
101 | { | |
51f6d619 | 102 | // Reset Class Mask and classes |
bacbe0fd | 103 | fClassMask = 0; |
51f6d619 | 104 | fClusterMask = 0; |
105 | ||
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 ); | |
111 | trclass->Reset(); | |
112 | } | |
bacbe0fd | 113 | } |
114 | } | |
115 | ||
116 | //_____________________________________________________________________________ | |
117 | void AliCentralTrigger::MakeBranch( TString name, TTree * tree ) | |
118 | { | |
119 | // Make a branch to store only trigger class mask event by event | |
120 | ||
121 | if( tree ) { | |
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 ); | |
128 | } | |
129 | else { | |
130 | AliDebug( 1, "Got Branch from Tree" ); | |
131 | branch->SetAddress( &(this->fClassMask) ); | |
132 | } | |
133 | } | |
134 | } | |
135 | ||
a5a091ce | 136 | //_____________________________________________________________________________ |
51f6d619 | 137 | Bool_t AliCentralTrigger::LoadConfiguration( TString & config ) |
a5a091ce | 138 | { |
51f6d619 | 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" | |
142 | ||
143 | // Delete the active configuration, if any | |
144 | DeleteConfiguration(); | |
145 | ||
146 | // Load the selected configuration | |
147 | if (!config.IsNull()) { | |
148 | fConfiguration = AliTriggerConfiguration::LoadConfiguration( config ); | |
149 | if(fConfiguration) | |
150 | return kTRUE; | |
151 | else { | |
152 | AliError( Form( "Valid TriggerConfiguration (%s) is not found ! Disabling the trigger simulation !", config.Data() ) ); | |
153 | return kFALSE; | |
154 | } | |
155 | } | |
156 | else { | |
157 | // Load one and only one trigger descriptor from CDB | |
158 | AliInfo( "GETTING TRIGGER DESCRIPTORS FROM CDB!!!" ); | |
159 | ||
160 | AliCDBPath path( "GRP", "CTP", "Config" ); | |
161 | ||
162 | AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath()); | |
163 | if( !entry ) AliFatal( "Couldn't load trigger description data from CDB!" ); | |
164 | ||
165 | fConfiguration = (AliTriggerConfiguration *)entry->GetObject(); | |
166 | if(fConfiguration) | |
167 | return kTRUE; | |
168 | else { | |
169 | AliError( "No valid configuration is found in the CDB ! Disabling the trigger simulation !" ); | |
170 | return kFALSE; | |
171 | } | |
a5a091ce | 172 | } |
a5a091ce | 173 | } |
174 | ||
175 | //_____________________________________________________________________________ | |
176 | TString AliCentralTrigger::GetDetectors() | |
177 | { | |
51f6d619 | 178 | // return TString with the detectors (modules) to be used for triggering |
a5a091ce | 179 | |
180 | TString result; | |
181 | ||
51f6d619 | 182 | if (fConfiguration) |
183 | result = fConfiguration->GetTriggeringModules(); | |
a5a091ce | 184 | |
185 | return result; | |
186 | } | |
187 | ||
188 | //_____________________________________________________________________________ | |
8480396b | 189 | Bool_t AliCentralTrigger::RunTrigger( AliRunLoader* runLoader, const char *detectors ) |
a5a091ce | 190 | { |
191 | // run the trigger | |
bacbe0fd | 192 | |
51f6d619 | 193 | if( !fConfiguration ) { |
194 | AliError( "No trigger configuration loaded, skipping trigger" ); | |
bacbe0fd | 195 | return kFALSE; |
196 | } | |
197 | ||
198 | TTree *tree = runLoader->TreeCT(); | |
199 | if( !tree ) { | |
51f6d619 | 200 | AliError( "No folder with trigger loaded, skipping trigger" ); |
a5a091ce | 201 | return kFALSE; |
202 | } | |
203 | ||
204 | TStopwatch stopwatch; | |
205 | stopwatch.Start(); | |
bacbe0fd | 206 | |
a5a091ce | 207 | // Process each event |
208 | for( Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++ ) { | |
bacbe0fd | 209 | AliInfo( Form(" ***** Processing event %d *****\n", iEvent) ); |
210 | runLoader->GetEvent( iEvent ); | |
a5a091ce | 211 | // Get detectors involve |
212 | TString detStr = GetDetectors(); | |
8480396b | 213 | AliInfo( Form(" Triggering Detectors: %s \n", detStr.Data() ) ); |
214 | TString detWithDigits = detectors; | |
215 | AliInfo( Form(" Detectors with digits: %s \n", detWithDigits.Data() ) ); | |
a5a091ce | 216 | TObjArray* detArray = runLoader->GetAliRun()->Detectors(); |
217 | // Reset Mask | |
218 | fClassMask = 0; | |
bacbe0fd | 219 | TObjArray trgdetArray; // use as garbage collector |
a5a091ce | 220 | for( Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++ ) { |
221 | AliModule* det = (AliModule*) detArray->At( iDet ); | |
222 | if( !det || !det->IsActive() ) continue; | |
8480396b | 223 | if( IsSelected(det->GetName(), detStr) && |
224 | IsSelected(det->GetName(), detWithDigits) ) { | |
bacbe0fd | 225 | |
226 | AliInfo( Form("Triggering from digits for %s", det->GetName() ) ); | |
a5a091ce | 227 | AliTriggerDetector* trgdet = det->CreateTriggerDetector(); |
51f6d619 | 228 | trgdet->CreateInputs(fConfiguration->GetInputs()); |
a5a091ce | 229 | TStopwatch stopwatchDet; |
230 | stopwatchDet.Start(); | |
231 | trgdet->Trigger(); | |
232 | AliInfo( Form("Execution time for %s: R:%.2fs C:%.2fs", | |
233 | det->GetName(), stopwatchDet.RealTime(), stopwatchDet.CpuTime() ) ); | |
bacbe0fd | 234 | |
bacbe0fd | 235 | trgdetArray.AddLast( trgdet ); |
236 | ||
237 | // Write trigger detector in Event folder in Digits file | |
238 | TString loadername = det->GetName(); | |
239 | loadername.Append( "Loader" ); | |
240 | AliLoader * loader = runLoader->GetLoader( loadername ); | |
241 | if( loader ) { | |
242 | AliDataLoader * dataLoader = loader->GetDigitsDataLoader(); | |
243 | if( !dataLoader->IsFileOpen() ) { | |
244 | if( dataLoader->OpenFile( "UPDATE" ) ) { | |
245 | AliWarning( Form( "\n\nCan't write trigger for %s\n", det->GetName() ) ); | |
246 | } | |
247 | } | |
248 | dataLoader->Cd(); | |
249 | if( gFile && !gFile->IsWritable() ) { | |
250 | gFile->ReOpen( "UPDATE" ); | |
251 | dataLoader->Cd(); | |
252 | } | |
253 | trgdet->Write( "Trigger", TObject::kOverwrite ); | |
254 | dataLoader->CloseFile(); | |
255 | } | |
256 | else AliWarning( Form( "Not loader found for %s", det->GetName() ) ); | |
a5a091ce | 257 | } |
258 | } | |
259 | ||
260 | // Check trigger conditions and create the trigger class mask | |
51f6d619 | 261 | TriggerClasses(); |
bacbe0fd | 262 | |
a5a091ce | 263 | // Clear trigger detectors |
264 | trgdetArray.SetOwner(); | |
265 | trgdetArray.Delete(); | |
266 | ||
267 | if( (detStr.CompareTo( "ALL" ) != 0) && !detStr.IsNull() ) { | |
268 | AliError( Form("the following detectors were not found: %s", | |
269 | detStr.Data())); | |
e229562b | 270 | //JF return kFALSE; |
a5a091ce | 271 | } |
272 | ||
bacbe0fd | 273 | // Save trigger mask |
274 | tree->Fill(); | |
275 | AliInfo( Form("**************** Central Trigger Class Mask:0x%X", fClassMask ) ); | |
a5a091ce | 276 | } // end event loop |
a5a091ce | 277 | |
bacbe0fd | 278 | Reset(); |
279 | // cout << endl << " Print " << endl; | |
280 | // Print(); | |
281 | ||
282 | // Write | |
283 | runLoader->WriteTrigger( "OVERWRITE" ); | |
a5a091ce | 284 | |
bacbe0fd | 285 | return kTRUE; |
286 | } | |
a5a091ce | 287 | |
288 | //_____________________________________________________________________________ | |
51f6d619 | 289 | ULong64_t AliCentralTrigger::TriggerClasses() |
a5a091ce | 290 | { |
51f6d619 | 291 | // Check trigger conditions and create the trigger class |
292 | // and trigger cluster masks | |
293 | if (fConfiguration) { | |
294 | const TObjArray& classesArray = fConfiguration->GetClasses(); | |
295 | Int_t nclasses = classesArray.GetEntriesFast(); | |
296 | for( Int_t j=0; j<nclasses; j++ ) { | |
297 | AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j ); | |
298 | trclass->Trigger( fConfiguration->GetInputs(), fConfiguration->GetFunctions() ); | |
299 | fClassMask |= trclass->GetValue(); | |
300 | if (trclass->GetStatus()) | |
301 | fClusterMask |= (trclass->GetCluster())->GetClusterMask(); | |
302 | } | |
303 | } | |
304 | return fClassMask; | |
a5a091ce | 305 | } |
306 | //_____________________________________________________________________________ | |
51f6d619 | 307 | TObjArray* AliCentralTrigger::GetFiredClasses() const |
a5a091ce | 308 | { |
309 | // return only the true conditions | |
310 | ||
311 | TObjArray* result = new TObjArray(); | |
312 | ||
51f6d619 | 313 | if (fConfiguration) { |
314 | const TObjArray& classesArray = fConfiguration->GetClasses(); | |
315 | Int_t nclasses = classesArray.GetEntriesFast(); | |
316 | for( Int_t j=0; j<nclasses; j++ ) { | |
317 | AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j ); | |
318 | if( trclass->GetStatus() ) result->AddLast( trclass ); | |
319 | } | |
a5a091ce | 320 | } |
321 | ||
322 | return result; | |
323 | } | |
324 | ||
a5a091ce | 325 | //_____________________________________________________________________________ |
326 | void AliCentralTrigger::Print( const Option_t* ) const | |
327 | { | |
328 | ||
329 | cout << "Central Trigger: " << endl; | |
330 | cout << " Trigger Class Mask: 0x" << hex << fClassMask << dec << endl; | |
51f6d619 | 331 | if (fConfiguration) fConfiguration->Print(); |
a5a091ce | 332 | cout << endl; |
333 | } | |
334 | ||
335 | ||
336 | ////////////////////////////////////////////////////////////////////////////// | |
337 | // Helper method | |
338 | ||
339 | //_____________________________________________________________________________ | |
340 | Bool_t AliCentralTrigger::IsSelected( TString detName, TString& detectors ) const | |
341 | { | |
342 | // check whether detName is contained in detectors | |
343 | // if yes, it is removed from detectors | |
344 | ||
345 | // check if all detectors are selected | |
346 | if( (detectors.CompareTo("ALL") == 0 ) || | |
347 | detectors.BeginsWith("ALL ") || | |
348 | detectors.EndsWith(" ALL") || | |
349 | detectors.Contains(" ALL ") ) { | |
350 | detectors = "ALL"; | |
351 | return kTRUE; | |
352 | } | |
353 | ||
354 | // search for the given detector | |
355 | Bool_t result = kFALSE; | |
356 | if( (detectors.CompareTo( detName ) == 0) || | |
357 | detectors.BeginsWith( detName+" " ) || | |
358 | detectors.EndsWith( " "+detName ) || | |
359 | detectors.Contains( " "+detName+" " ) ) { | |
360 | detectors.ReplaceAll( detName, "" ); | |
361 | result = kTRUE; | |
362 | } | |
363 | ||
364 | // clean up the detectors string | |
365 | while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " ); | |
366 | while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 ); | |
367 | while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 ); | |
368 | ||
369 | return result; | |
370 | } |