]>
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 | /////////////////////////////////////////////////////////////////////////////// | |
bacbe0fd | 19 | // |
a5a091ce | 20 | // This class for running and define a Trigger Descriptor |
bacbe0fd | 21 | // |
a5a091ce | 22 | // A Trigger Descriptor define a trigger setup for specific runnign |
23 | // condition (Pb-Pb, p-p, p-A, Calibration, etc). | |
24 | // It keep: | |
25 | // - cluster detector (List of detectors involved) | |
bacbe0fd | 26 | // - List of conditions |
a5a091ce | 27 | // |
28 | // Descriptors could be create in advance and store in a file. | |
29 | // | |
30 | // Example how to create a Trigger Descriptor: | |
bacbe0fd | 31 | // |
a5a091ce | 32 | // AliTriggerDescriptor descrip( "TEST", "Test Descriptor" ); |
33 | // | |
34 | // // Define a Cluster Detector | |
35 | // descrip.AddDetectorCluster( "VZERO ZDC MUON" ); | |
36 | // | |
37 | // // Define the trigger conditions (see AliTriggerCondition.cxx) | |
38 | // descrip.AddCondition( "VZERO_TEST1_L0 & MUON_SPlus_LPt_L0 & ZDC_TEST2_L0", // condition | |
39 | // "VO1_M1_ZDC2", // short name | |
40 | // "Dummy", // short description | |
41 | // 0x0100 ); // class mask (set one bit) | |
42 | // | |
43 | // descrip.AddCondition( "VZERO_TEST2_L0 & MUON_SMinus_HPt_L0 & ZDC_TEST1_L0", | |
44 | // "VO2_M3_ZDC1", | |
45 | // "Dummy", | |
46 | // 0x0200 ); | |
bacbe0fd | 47 | // |
a5a091ce | 48 | // descrip.AddCondition( "VZERO_TEST3_L0 | MUON_Unlike_LPt_L0 | ZDC_TEST3_L0", |
49 | // "VO3_M1_ZDC3", | |
50 | // "Dummy", | |
51 | // 0x0400 ); | |
52 | // descrip.CheckInputsConditions("Config.C"); | |
53 | // descrip.Print(); | |
54 | // | |
55 | // // save the descriptor to file | |
56 | // // (default file name $ALICE_ROOT/data/triggerDescriptor.root) | |
bacbe0fd | 57 | // descrip.WriteDescriptor(); or descrip.WriteDescriptor( filename ); |
58 | // | |
a5a091ce | 59 | /////////////////////////////////////////////////////////////////////////////// |
60 | ||
61 | #include <TString.h> | |
62 | #include <TObjArray.h> | |
63 | #include <TSystem.h> | |
64 | #include <TKey.h> | |
65 | #include <TFile.h> | |
66 | ||
67 | #include "AliLog.h" | |
68 | #include "AliRun.h" | |
69 | #include "AliRunLoader.h" | |
70 | #include "AliModule.h" | |
71 | ||
72 | #include "AliTriggerInput.h" | |
73 | #include "AliTriggerDetector.h" | |
74 | #include "AliTriggerCondition.h" | |
75 | #include "AliTriggerDescriptor.h" | |
76 | ||
77 | ||
78 | ClassImp(AliTriggerDescriptor) | |
79 | ||
80 | //_____________________________________________________________________________ | |
81 | const char* AliTriggerDescriptor::fgkDetectorName[AliTriggerDescriptor::fgkNDetectors] = | |
b384f8a4 | 82 | { "ITS", "TRD", "PHOS", "EMCAL", "MUON", "ZDC", "T0", "VZERO", "ACORDE", "TOF" }; |
a5a091ce | 83 | |
84 | const TString AliTriggerDescriptor::fgkDescriptorFileName("/data/triggerDescriptors.root"); | |
85 | ||
86 | //_____________________________________________________________________________ | |
87 | AliTriggerDescriptor::AliTriggerDescriptor(): | |
75e3794b | 88 | TNamed(), |
89 | fDetectorCluster(""), | |
90 | fConditions() | |
a5a091ce | 91 | { |
92 | } | |
93 | ||
94 | //_____________________________________________________________________________ | |
95 | AliTriggerDescriptor::AliTriggerDescriptor( TString & name, TString & description ): | |
75e3794b | 96 | TNamed( name, description ), |
97 | fDetectorCluster(""), | |
98 | fConditions() | |
a5a091ce | 99 | { |
100 | } | |
101 | ||
102 | //_____________________________________________________________________________ | |
103 | AliTriggerDescriptor::AliTriggerDescriptor( const AliTriggerDescriptor& des ): | |
75e3794b | 104 | TNamed( des ), |
105 | fDetectorCluster( des.fDetectorCluster ), | |
106 | fConditions() | |
a5a091ce | 107 | { |
108 | // Copy constructor | |
bacbe0fd | 109 | Int_t ncond = des.fConditions.GetEntriesFast(); |
110 | for( Int_t j=0; j<ncond; j++ ) { | |
111 | AddCondition( new AliTriggerCondition( *(AliTriggerCondition*)(des.fConditions.At( j )) ) ); | |
112 | } | |
113 | } | |
114 | ||
115 | //______________________________________________________________________________ | |
116 | AliTriggerDescriptor& AliTriggerDescriptor::operator=(const AliTriggerDescriptor& des) | |
117 | { | |
118 | // AliTriggerDescriptor assignment operator. | |
119 | ||
120 | if (this != &des) { | |
121 | TNamed::operator=(des); | |
122 | fDetectorCluster = des.fDetectorCluster; | |
123 | fConditions.Delete(); | |
124 | Int_t ncond = des.fConditions.GetEntriesFast(); | |
125 | for( Int_t j=0; j<ncond; j++ ) { | |
126 | AddCondition( new AliTriggerCondition( *(AliTriggerCondition*)(des.fConditions.At( j )) ) ); | |
127 | } | |
128 | } | |
129 | return *this; | |
a5a091ce | 130 | } |
131 | ||
132 | //_____________________________________________________________________________ | |
133 | Bool_t AliTriggerDescriptor::AddDetectorCluster( TString & cluster ) | |
134 | { | |
135 | // Add a List of Detectors to be read together (Detector Cluster) | |
136 | // Ej "TO VO ZDC MUON" or "ALL" | |
137 | ||
138 | TString olddet = fDetectorCluster; | |
139 | TString newdet = cluster; | |
140 | for( Int_t iDet = 0; iDet < fgkNDetectors; iDet++ ) { | |
141 | if( IsSelected( fgkDetectorName[iDet], newdet ) && !IsSelected( fgkDetectorName[iDet], olddet ) ) { | |
142 | // Add the detector | |
143 | fDetectorCluster.Append( " " ); | |
144 | fDetectorCluster.Append( fgkDetectorName[iDet] ); | |
145 | } | |
146 | } | |
147 | ||
148 | // check if there are no trigger detectors (E.g. TPC) | |
149 | if ((newdet.CompareTo("ALL") != 0) && !newdet.IsNull()) { | |
150 | AliError( Form("the following detectors are not trigger detectors: %s", | |
151 | newdet.Data() ) ); | |
152 | return kFALSE; | |
153 | } | |
154 | ||
155 | return kTRUE; | |
156 | } | |
157 | ||
158 | //_____________________________________________________________________________ | |
92c1978f | 159 | void AliTriggerDescriptor::AddCondition( TString & cond, TString & name, TString & description, ULong64_t mask ) |
a5a091ce | 160 | { |
161 | // Add a new condition | |
162 | AliTriggerCondition* acond = new AliTriggerCondition( cond, name, description, mask ); | |
163 | fConditions.AddLast( acond ); | |
164 | } | |
165 | ||
166 | ||
167 | //_____________________________________________________________________________ | |
168 | AliTriggerDescriptor* AliTriggerDescriptor::LoadDescriptor( TString & descriptor, const char* filename ) | |
169 | { | |
170 | // Load one pre-created Descriptors from database/file that match | |
171 | // with the input string 'descriptor' | |
172 | // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL" | |
173 | ||
174 | // Load the selected descriptor | |
175 | TString path; | |
176 | if( !filename[0] ) { | |
177 | path += gSystem->Getenv("ALICE_ROOT"); | |
178 | path += fgkDescriptorFileName; | |
179 | } | |
180 | else | |
181 | path += filename; | |
182 | ||
183 | if( gSystem->AccessPathName( path.Data() ) ) { | |
184 | AliErrorGeneral( "AliTriggerDescriptor", Form( "file (%s) not found", path.Data() ) ); | |
185 | return NULL; | |
186 | } | |
187 | ||
188 | TFile file( path.Data(), "READ" ); | |
189 | AliTriggerDescriptor* des = (AliTriggerDescriptor*)(file.Get( descriptor.Data() )); | |
190 | ||
191 | file.Close(); | |
192 | ||
193 | return des; | |
194 | } | |
195 | ||
196 | //_____________________________________________________________________________ | |
197 | TObjArray* AliTriggerDescriptor::GetAvailableDescriptors( const char* filename ) | |
198 | { | |
199 | // Return an array of descriptor in the file | |
bacbe0fd | 200 | |
a5a091ce | 201 | TString path; |
202 | if( !filename[0] ) { | |
203 | path += gSystem->Getenv( "ALICE_ROOT" ); | |
204 | path += fgkDescriptorFileName; | |
205 | } | |
206 | else | |
207 | path += filename; | |
208 | ||
209 | if( gSystem->AccessPathName( path.Data() ) ) { | |
210 | AliErrorGeneral( "AliTriggerDescriptor", Form( "file (%s) not found", path.Data() ) ); | |
211 | return NULL; | |
212 | } | |
213 | ||
214 | TObjArray* desArray = new TObjArray(); | |
bacbe0fd | 215 | |
a5a091ce | 216 | TFile file( path.Data(), "READ" ); |
217 | if( file.IsZombie() ) { | |
218 | AliErrorGeneral( "AliTriggerDescriptor", Form( "Error opening file (%s)", path.Data() ) ); | |
219 | return NULL; | |
220 | } | |
bacbe0fd | 221 | |
a5a091ce | 222 | file.ReadAll(); |
223 | ||
224 | TKey* key; | |
225 | TIter next( file.GetListOfKeys() ); | |
226 | while( (key = (TKey*)next()) ) { | |
227 | TObject* obj = key->ReadObj(); | |
228 | if( obj->InheritsFrom( "AliTriggerDescriptor" ) ) { | |
229 | desArray->AddLast( obj ); | |
230 | } | |
231 | } | |
232 | file.Close(); | |
233 | ||
234 | return desArray; | |
235 | } | |
236 | ||
237 | //_____________________________________________________________________________ | |
238 | void AliTriggerDescriptor::WriteDescriptor( const char* filename ) | |
239 | { | |
240 | // Load one pre-created Descriptors from database/file that match | |
241 | // with the input string 'descriptor' | |
242 | // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL" | |
243 | ||
244 | // Load the selected descriptor | |
245 | TString path; | |
246 | if( !filename[0] ) { | |
247 | path += gSystem->Getenv("ALICE_ROOT"); | |
248 | path += fgkDescriptorFileName; | |
249 | } | |
250 | else | |
251 | path += filename; | |
252 | ||
253 | TFile file( path.Data(), "UPDATE" ); | |
254 | if( file.IsZombie() ) { | |
255 | AliErrorGeneral( "AliTriggerDescriptor", | |
256 | Form( "Can't open file (%s)", path.Data() ) ); | |
257 | return; | |
258 | } | |
bacbe0fd | 259 | |
a5a091ce | 260 | Bool_t result = (Write( GetName(), TObject::kOverwrite ) != 0); |
261 | if( !result ) | |
262 | AliErrorGeneral( "AliTriggerDescriptor", | |
263 | Form( "Can't write entry to file <%s>!", path.Data() ) ); | |
264 | file.Close(); | |
265 | } | |
266 | ||
a5a091ce | 267 | //_____________________________________________________________________________ |
268 | Bool_t AliTriggerDescriptor::CheckInputsConditions( TString& configfile ) | |
269 | { | |
270 | // To be used on the pre-creation of Descriptors to check if the | |
271 | // conditions have valid inputs names. | |
272 | // | |
273 | // Initiate detectors modules from a Config file | |
274 | // Ask to each active module present in the fDetectorCluster | |
275 | // to create a Trigger detector and retrive the inputs from it | |
276 | // to create a list of inputs. | |
277 | // Each condition in the descriptor is then checked agains | |
278 | // the list of inputs | |
279 | ||
280 | ||
281 | if (!gAlice) { | |
282 | AliError( "no gAlice object. Restart aliroot and try again." ); | |
283 | return kFALSE; | |
284 | } | |
285 | if (gAlice->Modules()->GetEntries() > 0) { | |
286 | AliError( "gAlice was already run. Restart aliroot and try again." ); | |
287 | return kFALSE; | |
288 | } | |
289 | ||
290 | AliInfo( Form( "initializing gAlice with config file %s", | |
291 | configfile.Data() ) ); | |
292 | StdoutToAliInfo( StderrToAliError( | |
293 | gAlice->Init( configfile.Data() ); | |
294 | );); | |
295 | ||
296 | AliRunLoader* runLoader = gAlice->GetRunLoader(); | |
297 | if( !runLoader ) { | |
298 | AliError( Form( "gAlice has no run loader object. " | |
299 | "Check your config file: %s", configfile.Data() ) ); | |
300 | return kFALSE; | |
301 | } | |
302 | ||
303 | // get the possible inputs to check the condition | |
304 | TObjArray inputs; | |
305 | TObjArray* detArray = runLoader->GetAliRun()->Detectors(); | |
306 | ||
307 | TString detStr = fDetectorCluster; | |
308 | for( Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++ ) { | |
309 | AliModule* det = (AliModule*) detArray->At(iDet); | |
310 | if( !det || !det->IsActive() ) continue; | |
311 | if( IsSelected( det->GetName(), detStr ) ) { | |
312 | AliInfo( Form( "Creating inputs for %s", det->GetName() ) ); | |
313 | AliTriggerDetector* dtrg = det->CreateTriggerDetector(); | |
314 | dtrg->CreateInputs(); | |
315 | TObjArray* detInp = dtrg->GetInputs(); | |
316 | for( Int_t i=0; i<detInp->GetEntriesFast(); i++ ) { | |
317 | AliInfo( Form( "Adding input %s", ((AliTriggerInput*)detInp->At(i))->GetName() ) ); | |
318 | inputs.AddLast( detInp->At(i) ); | |
319 | } | |
320 | } | |
321 | } | |
322 | ||
323 | // check if the condition is compatible with the triggers inputs | |
324 | Int_t ncond = fConditions.GetEntriesFast(); | |
92c1978f | 325 | Bool_t check = kTRUE; |
326 | ULong64_t mask = 0L; | |
a5a091ce | 327 | for( Int_t j=0; j<ncond; j++ ) { |
328 | AliTriggerCondition* cond = (AliTriggerCondition*)(fConditions.At( j )); | |
92c1978f | 329 | if( !(cond->CheckInputs( inputs )) ) check = kFALSE; |
330 | else AliInfo( Form( "Condition (%s) inputs names OK, class mask (0x%Lx)", | |
331 | cond->GetName(), cond->GetMask( ) ) ); | |
332 | // check if condition mask is duplicated | |
333 | if( mask & cond->GetMask() ) { | |
334 | AliError( Form("Condition (%s). The class mask (0x%Lx) is ambiguous. It was previous defined", | |
335 | cond->GetName(), cond->GetMask() ) ); | |
336 | check = kFALSE; | |
337 | } | |
338 | mask |= cond->GetMask(); | |
a5a091ce | 339 | } |
340 | ||
92c1978f | 341 | return check; |
a5a091ce | 342 | } |
343 | ||
344 | ||
345 | //_____________________________________________________________________________ | |
346 | void AliTriggerDescriptor::Print( const Option_t* ) const | |
347 | { | |
348 | ||
349 | cout << "Trigger Descriptor:" << endl; | |
350 | cout << " Name: " << GetName() << endl; | |
351 | cout << " Description: " << GetTitle() << endl; | |
352 | cout << " Detector Cluster: " << fDetectorCluster << endl; | |
353 | ||
354 | // Int_t ninputs = fInputs->GetEntriesFast(); | |
355 | // for( Int_t i=0; i<ninputs; i++ ) { | |
356 | // AliTriggerInput* in = (AliTriggerInput*)fInputs->At(i) | |
357 | // in->Print(); | |
358 | // } | |
359 | ||
360 | Int_t ncond = fConditions.GetEntriesFast(); | |
361 | for( Int_t i=0; i<ncond; i++ ) { | |
362 | AliTriggerCondition* in = (AliTriggerCondition*)fConditions.At(i); | |
363 | in->Print(); | |
364 | } | |
365 | cout << endl; | |
366 | } | |
367 | ||
368 | ||
369 | ////////////////////////////////////////////////////////////////////////////// | |
370 | // Helper method | |
371 | ||
372 | //_____________________________________________________________________________ | |
373 | Bool_t AliTriggerDescriptor::IsSelected( TString detName, TString& detectors ) const | |
374 | { | |
375 | // check whether detName is contained in detectors | |
376 | // if yes, it is removed from detectors | |
377 | ||
378 | // check if all detectors are selected | |
379 | if( (detectors.CompareTo("ALL") == 0 ) || | |
380 | detectors.BeginsWith("ALL ") || | |
381 | detectors.EndsWith(" ALL") || | |
382 | detectors.Contains(" ALL ") ) { | |
383 | detectors = "ALL"; | |
384 | return kTRUE; | |
385 | } | |
386 | ||
387 | // search for the given detector | |
388 | Bool_t result = kFALSE; | |
389 | if( (detectors.CompareTo( detName ) == 0) || | |
390 | detectors.BeginsWith( detName+" " ) || | |
391 | detectors.EndsWith( " "+detName ) || | |
392 | detectors.Contains( " "+detName+" " ) ) { | |
393 | detectors.ReplaceAll( detName, "" ); | |
394 | result = kTRUE; | |
395 | } | |
396 | ||
397 | // clean up the detectors string | |
398 | while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " ); | |
399 | while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 ); | |
400 | while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 ); | |
401 | ||
402 | return result; | |
403 | } |