Line data Source code
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 : ///////////////////////////////////////////////////////////////////////////////
17 : //
18 : // This class which defines defines the Trigger Configuration
19 : //
20 : // Trigger Configuration defines the trigger setup for a particular run
21 : // We have default configurations for each running mode (Pb-Pb, p-p, p-A, Calibration, etc).
22 : // It keep:
23 : // All the information conained in the CTP configuration file used
24 : // online during the data taking
25 : //
26 : // Configurations could be created and stored in local file.
27 : // By default the configuration is loaded from the corresponding GRP entry
28 : // inside the OCDB. There one can have one and only one configuration per run.
29 : //
30 : // Example how to create a Trigger Configuration:
31 : //
32 : // AliTriggerConfiguration config( "TEST", "Test Configuration" );
33 : //
34 : // // Define a Cluster Detector
35 : // config.AddDetectorCluster( "VZERO ZDC MUON" );
36 : //
37 : // // Define the trigger conditions (see AliTriggerCondition.cxx)
38 : // config.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 : // config.AddCondition( "VZERO_TEST2_L0 & MUON_SMinus_HPt_L0 & ZDC_TEST1_L0",
44 : // "VO2_M3_ZDC1",
45 : // "Dummy",
46 : // 0x0200 );
47 : //
48 : // config.AddCondition( "VZERO_TEST3_L0 | MUON_Unlike_LPt_L0 | ZDC_TEST3_L0",
49 : // "VO3_M1_ZDC3",
50 : // "Dummy",
51 : // 0x0400 );
52 : // config.CheckInputsConditions("Config.C");
53 : // config.Print();
54 : //
55 : // // save the configuration to file
56 : // // (default file name $ALICE_ROOT/data/triggerConfigurations.root)
57 : // config.WriteConfiguration(); or config.WriteConfiguration( filename );
58 : //
59 : ///////////////////////////////////////////////////////////////////////////////
60 : #include <Riostream.h>
61 :
62 : #include <TFile.h>
63 : #include <TKey.h>
64 : #include <TObjArray.h>
65 : #include <TObjString.h>
66 : #include <TObject.h>
67 : #include <TROOT.h>
68 : #include <TString.h>
69 : #include <TSystem.h>
70 : #include <TMath.h>
71 :
72 : #include "AliLog.h"
73 : #include "AliTriggerBCMask.h"
74 : #include "AliTriggerClass.h"
75 : #include "AliTriggerCluster.h"
76 : #include "AliTriggerConfiguration.h"
77 : #include "AliTriggerDescriptor.h"
78 : #include "AliTriggerInput.h"
79 : #include "AliTriggerInteraction.h"
80 : #include "AliTriggerPFProtection.h"
81 :
82 : using std::endl;
83 : using std::cout;
84 : using std::ifstream;
85 172 : ClassImp(AliTriggerConfiguration)
86 :
87 172 : const TString AliTriggerConfiguration::fgkConfigurationFileName("/data/triggerConfigurations.root");
88 :
89 : //_____________________________________________________________________________
90 : AliTriggerConfiguration::AliTriggerConfiguration():
91 8 : TNamed(),
92 8 : fInputs(),
93 8 : fInteractions(),
94 8 : fFunctions(),
95 8 : fPFProtections(),
96 8 : fMasks(),
97 8 : fDescriptors(),
98 8 : fClusters(),
99 8 : fClasses(),
100 8 : fVersion(0)
101 40 : {
102 : // Default constructor
103 16 : }
104 :
105 : //_____________________________________________________________________________
106 : AliTriggerConfiguration::AliTriggerConfiguration( TString & name, TString & description ):
107 0 : TNamed( name, description ),
108 0 : fInputs(),
109 0 : fInteractions(),
110 0 : fFunctions(),
111 0 : fPFProtections(),
112 0 : fMasks(),
113 0 : fDescriptors(),
114 0 : fClusters(),
115 0 : fClasses(),
116 0 : fVersion(0)
117 0 : {
118 : // Constructor
119 0 : }
120 :
121 : //_____________________________________________________________________________
122 : AliTriggerConfiguration::~AliTriggerConfiguration()
123 36 : {
124 : // Destructor
125 6 : fInputs.SetOwner();
126 6 : fInputs.Delete();
127 6 : fInteractions.SetOwner();
128 6 : fInteractions.Delete();
129 6 : fFunctions.SetOwner();
130 6 : fFunctions.Delete();
131 6 : fPFProtections.SetOwner();
132 6 : fPFProtections.Delete();
133 6 : fMasks.SetOwner();
134 6 : fMasks.Delete();
135 6 : fDescriptors.SetOwner();
136 6 : fDescriptors.Delete();
137 6 : fClusters.SetOwner();
138 6 : fClusters.Delete();
139 6 : fClasses.SetOwner();
140 6 : fClasses.Delete();
141 18 : }
142 :
143 : //_____________________________________________________________________________
144 : Bool_t AliTriggerConfiguration::AddInput( AliTriggerInput* input )
145 : {
146 : // Add a trigger input to
147 : // the list of the trigger inputs
148 44 : if (fInputs.GetEntries() < kNMaxInputs) {
149 22 : fInputs.AddLast( input );
150 22 : return kTRUE;
151 : }
152 : else {
153 0 : AliError("CTP can handle up to 64 inputs ! Impossible to add the required input !");
154 0 : return kFALSE;
155 : }
156 22 : }
157 :
158 : //_____________________________________________________________________________
159 : AliTriggerInput* AliTriggerConfiguration::AddInput( TString &name, TString &det,
160 : UChar_t level, UInt_t signature,
161 : UChar_t number )
162 : {
163 : // Add a trigger input to
164 : // the list of the trigger inputs
165 110 : AliTriggerInput *input = new AliTriggerInput(name,det,level,signature,number);
166 22 : if (!AddInput(input)) {
167 0 : delete input;
168 0 : return NULL;
169 : }
170 : else
171 22 : return input;
172 22 : }
173 : //_____________________________________________________________________________
174 : AliTriggerInput* AliTriggerConfiguration::AddInput( TString &name, TString &det,
175 : UChar_t level, UInt_t signature,
176 : UInt_t indexCTP, UInt_t indexSwitch )
177 : {
178 : // Add a trigger input to
179 : // the list of the trigger inputs
180 0 : AliTriggerInput *input = new AliTriggerInput(name,det,level,signature,indexCTP,indexSwitch);
181 0 : if (!AddInput(input)) {
182 0 : delete input;
183 0 : return NULL;
184 : }
185 : else
186 0 : return input;
187 0 : }
188 :
189 : //_____________________________________________________________________________
190 : AliTriggerInteraction* AliTriggerConfiguration::AddInteraction(TString &name, TString &logic)
191 : {
192 : // Add a trigger interaction object to
193 : // the list of the trigger interactions
194 4 : AliTriggerInteraction *interact = new AliTriggerInteraction(name,logic);
195 2 : if (!AddInteraction(interact)) {
196 0 : delete interact;
197 0 : return NULL;
198 : }
199 : else
200 2 : return interact;
201 2 : }
202 :
203 : //_____________________________________________________________________________
204 : Bool_t AliTriggerConfiguration::AddInteraction(AliTriggerInteraction *interact)
205 : {
206 : // Add a trigger interaction object to
207 : // the list of the trigger interactions
208 4 : if (fInteractions.GetEntries() < kNMaxInteractions) {
209 2 : if (interact->CheckInputs(fInputs)) {
210 2 : fInteractions.AddLast( interact );
211 2 : return kTRUE;
212 : }
213 : else
214 0 : AliError("Invalid interaction ! Impossible to add it !");
215 0 : }
216 : else
217 0 : AliError("CTP can handle up to 2 interactions ! Impossible to add the required interaction !");
218 :
219 0 : return kFALSE;
220 2 : }
221 :
222 : //_____________________________________________________________________________
223 : AliTriggerInteraction* AliTriggerConfiguration::AddFunction(TString &name, TString &logic)
224 : {
225 : // Add a trigger function object to
226 : // the list of the trigger functions
227 4 : AliTriggerInteraction *func = new AliTriggerInteraction(name,logic);
228 2 : if (!AddFunction(func)) {
229 0 : delete func;
230 0 : return NULL;
231 : }
232 : else
233 2 : return func;
234 2 : }
235 :
236 : //_____________________________________________________________________________
237 : Bool_t AliTriggerConfiguration::AddFunction(AliTriggerInteraction *func)
238 : {
239 : // Add a trigger function object to
240 : // the list of the trigger functions
241 4 : if (fFunctions.GetEntries() < kNMaxFunctions) {
242 2 : if (func->CheckInputs(fInputs)) {
243 2 : fFunctions.AddLast( func );
244 2 : return kTRUE;
245 : }
246 : else
247 0 : AliError("Invalid logical function ! Impossible to add it !");
248 0 : }
249 : else
250 0 : AliError("CTP can handle up to 4 logical functions ! Impossible to add the required interaction !");
251 :
252 0 : return kFALSE;
253 2 : }
254 :
255 : //_____________________________________________________________________________
256 : Bool_t AliTriggerConfiguration::AddPFProtection( AliTriggerPFProtection* pfp )
257 : {
258 : // Add a trigger past-future protection object to
259 : // the list of the trigger past-future protections
260 6 : if (fPFProtections.GetEntries() < kNMaxPFProtections) {
261 : //if (pfp->CheckInteractions(fInteractions)) {
262 : if (1) {
263 3 : fPFProtections.AddLast( pfp );
264 3 : return kTRUE;
265 : }
266 : else
267 : AliError("Invalid past-future protection ! Impossible to add it !");
268 : }
269 : else
270 0 : AliError("CTP can handle up to 4 past-future protections ! Impossible to add the required protection !");
271 :
272 0 : return kFALSE;
273 3 : }
274 :
275 : //_____________________________________________________________________________
276 : AliTriggerBCMask* AliTriggerConfiguration::AddMask( TString &name, TString &mask )
277 : {
278 : // Add a trigger bunch-crossing mask object to
279 : // the list of the trigger bunch-crossing masks
280 6 : AliTriggerBCMask *bcmask = new AliTriggerBCMask(name,mask);
281 3 : if (!AddMask(bcmask)) {
282 0 : delete bcmask;
283 0 : return NULL;
284 : }
285 : else
286 3 : return bcmask;
287 3 : }
288 :
289 : //_____________________________________________________________________________
290 : Bool_t AliTriggerConfiguration::AddMask( AliTriggerBCMask* mask )
291 : {
292 : // Add a trigger bunch-crossing mask object to
293 : // the list of the trigger bunch-crossing masks
294 6 : if (fMasks.GetEntries() < (kNMaxMasks)) {
295 3 : fMasks.AddLast( mask );
296 3 : return kTRUE;
297 : }
298 : else
299 0 : AliError("CTP can handle up to 12 bunch-crossing masks ! Impossible to add the required mask !");
300 :
301 0 : return kFALSE;
302 3 : }
303 :
304 : //_____________________________________________________________________________
305 : AliTriggerCluster* AliTriggerConfiguration::AddCluster( TString &name, UChar_t index, TString &detectors)
306 : {
307 : // Add a trigger detector readout cluster to
308 : // the list of the trigger clusters
309 4 : AliTriggerCluster *clust = new AliTriggerCluster(name,index,detectors);
310 2 : if (!AddCluster(clust)) {
311 0 : delete clust;
312 0 : return NULL;
313 : }
314 : else
315 2 : return clust;
316 :
317 2 : }
318 :
319 : //_____________________________________________________________________________
320 : Bool_t AliTriggerConfiguration::AddCluster( AliTriggerCluster* cluster )
321 : {
322 : // Add a trigger detector readout cluster to
323 : // the list of the trigger clusters
324 4 : if (fClusters.GetEntries() < kNMaxClusters) {
325 2 : TString dets(cluster->GetDetectorsInCluster());
326 4 : if (!(dets.IsNull())) {
327 2 : fClusters.AddLast( cluster );
328 2 : return kTRUE;
329 : }
330 : else
331 0 : AliError("Empty trigger cluster ! Impossible to add it !");
332 2 : }
333 : else
334 0 : AliError("CTP can handle up to 6 different detector clusters ! Impossible to add the required cluster !");
335 :
336 0 : return kFALSE;
337 2 : }
338 :
339 : //_____________________________________________________________________________
340 : TString AliTriggerConfiguration::GetActiveDetectors() const
341 : {
342 : // Return an string with all active detector
343 : // from each cluster
344 :
345 0 : TString activeDet = "";
346 :
347 0 : Int_t nclus = fClusters.GetEntriesFast();
348 0 : if( !nclus ) return activeDet;
349 :
350 0 : for( Int_t j=0; j<nclus; ++j ) {
351 0 : TString detStr = ((AliTriggerCluster*)fClusters.At(j))->GetDetectorsInCluster();
352 0 : TObjArray* det = detStr.Tokenize(" ");
353 0 : Int_t ndet = det->GetEntriesFast();
354 0 : for( Int_t k=0; k<ndet; ++k ) {
355 0 : if( activeDet.Contains( ((TObjString*)det->At(k))->String() ) )continue;
356 0 : activeDet.Append( " " );
357 0 : activeDet.Append( ((TObjString*)det->At(k))->String() );
358 : }
359 0 : delete det;
360 0 : }
361 0 : return activeDet;
362 0 : }
363 :
364 : //_____________________________________________________________________________
365 : TString AliTriggerConfiguration::GetTriggeringDetectors() const
366 : {
367 : // Return an string with all detectors
368 : // used for triggering
369 :
370 0 : TString trDet = "";
371 :
372 0 : Int_t ninputs = fInputs.GetEntriesFast();
373 0 : if( !ninputs ) return trDet;
374 :
375 0 : for( Int_t j=0; j<ninputs; j++ ) {
376 0 : TString detStr = ((AliTriggerInput*)fInputs.At(j))->GetDetector();
377 0 : if( trDet.Contains( detStr ) ) continue;
378 0 : trDet.Append( " " );
379 0 : trDet.Append( detStr );
380 0 : }
381 0 : return trDet;
382 0 : }
383 :
384 : //_____________________________________________________________________________
385 : TString AliTriggerConfiguration::GetTriggeringModules() const
386 : {
387 : // Return an string with all detectors (modules in the AliRoot
388 : // simulation sense) used for triggering
389 :
390 10 : TString trDet = "";
391 :
392 5 : Int_t ninputs = fInputs.GetEntriesFast();
393 5 : if( !ninputs ) return trDet;
394 :
395 230 : for( Int_t j=0; j<ninputs; j++ ) {
396 220 : TString detStr = ((AliTriggerInput*)fInputs.At(j))->GetModule();
397 300 : if( trDet.Contains( detStr ) ) continue;
398 30 : trDet.Append( " " );
399 30 : trDet.Append( detStr );
400 140 : }
401 5 : return trDet;
402 10 : }
403 :
404 : //_____________________________________________________________________________
405 : AliTriggerDescriptor* AliTriggerConfiguration::AddDescriptor( TString &name, TString &cond )
406 : {
407 : // Add a trigger descriptor to
408 : // the list of the trigger descriptors
409 36 : AliTriggerDescriptor *desc = new AliTriggerDescriptor(name,cond);
410 18 : if (!AddDescriptor(desc)) {
411 0 : delete desc;
412 0 : return NULL;
413 : }
414 : else
415 18 : return desc;
416 18 : }
417 :
418 : //_____________________________________________________________________________
419 : Bool_t AliTriggerConfiguration::AddDescriptor( AliTriggerDescriptor *desc )
420 : {
421 : // Add a trigger descriptor to
422 : // the list of the trigger descriptors
423 36 : if (fDescriptors.GetEntries() < kNMaxClasses) {
424 18 : if (desc->CheckInputsAndFunctions(fInputs,fFunctions)) {
425 18 : fDescriptors.AddLast( desc );
426 18 : return kTRUE;
427 : }
428 : else
429 0 : AliError("Invalid trigger desciptor ! Impossible to add it !");
430 0 : }
431 : else
432 0 : AliError("CTP can handle up to 50 different descriptors ! Impossible to add the required descriptor !");
433 :
434 0 : return kFALSE;
435 18 : }
436 :
437 : //_____________________________________________________________________________
438 : Bool_t AliTriggerConfiguration::AddClass( AliTriggerClass *trclass )
439 : {
440 : // Add a trigger class to
441 : // the list of the trigger classes
442 36 : if (fClasses.GetEntries() < kNMaxClasses) {
443 18 : if (trclass->CheckClass(this)) {
444 18 : fClasses.AddLast( trclass );
445 18 : return kTRUE;
446 : }
447 : else
448 0 : AliError("Invalid trigger class ! Impossible to add it !");
449 0 : }
450 : else
451 0 : AliError("CTP can handle up to 50 different classes ! Impossible to add the required class !");
452 :
453 0 : return kFALSE;
454 18 : }
455 :
456 : //_____________________________________________________________________________
457 : AliTriggerClass *AliTriggerConfiguration::AddClass( TString &name, UChar_t index,
458 : AliTriggerDescriptor *desc, AliTriggerCluster *clus,
459 : AliTriggerPFProtection *pfp, AliTriggerBCMask *mask,
460 : UInt_t prescaler, Bool_t allrare)
461 : {
462 : // Add a trigger class to
463 : // the list of the trigger classes
464 0 : if (!fDescriptors.FindObject(desc)) {
465 0 : AliError("Invalid descriptor ! Impossible to add the class !");
466 0 : return NULL;
467 : }
468 0 : if (!fClusters.FindObject(clus)) {
469 0 : AliError("Invalid cluster ! Impossible to add the class !");
470 0 : return NULL;
471 : }
472 0 : if (!fPFProtections.FindObject(pfp)) {
473 0 : AliError("Invalid past-future protection ! Impossible to add the class !");
474 0 : return NULL;
475 : }
476 0 : if (!fMasks.FindObject(mask)) {
477 0 : AliError("Invalid bunch-crossing mask ! Impossible to add the class !");
478 0 : return NULL;
479 : }
480 0 : AliTriggerClass* trclass = new AliTriggerClass( name,index,desc,clus,pfp,mask,prescaler,allrare );
481 0 : if (!AddClass(trclass)) {
482 0 : delete trclass;
483 0 : return NULL;
484 : }
485 : else
486 0 : return trclass;
487 0 : }
488 :
489 : //_____________________________________________________________________________
490 : AliTriggerClass *AliTriggerConfiguration::AddClass( TString &name, UChar_t index,
491 : TString &desc, TString &clus,
492 : TString &pfp, TString &mask,
493 : UInt_t prescaler, Bool_t allrare)
494 : {
495 : // Add a new trigger class
496 0 : if (!fDescriptors.FindObject(desc)) {
497 0 : AliError("Invalid descriptor ! Impossible to add the class !");
498 0 : return NULL;
499 : }
500 0 : if (!fClusters.FindObject(clus)) {
501 0 : AliError("Invalid cluster ! Impossible to add the class !");
502 0 : return NULL;
503 : }
504 0 : if (!fPFProtections.FindObject(pfp)) {
505 0 : AliError("Invalid past-future protection ! Impossible to add the class !");
506 0 : return NULL;
507 : }
508 0 : if (!fMasks.FindObject(mask)) {
509 0 : AliError("Invalid bunch-crossing mask ! Impossible to add the class !");
510 0 : return NULL;
511 : }
512 0 : AliTriggerClass* trclass = new AliTriggerClass( this, name,index,desc,clus,pfp,mask,prescaler,allrare );
513 0 : if (!AddClass(trclass)) {
514 0 : delete trclass;
515 0 : return NULL;
516 : }
517 : else
518 0 : return trclass;
519 0 : }
520 :
521 : //_____________________________________________________________________________
522 : Bool_t AliTriggerConfiguration::ProcessConfigurationLine(const char* line, Int_t& level)
523 : {
524 : // processes one line of configuration
525 :
526 178 : TString strLine(line);
527 :
528 190 : if (strLine.BeginsWith("#")) return kTRUE;
529 154 : if (strLine.BeginsWith("PARTITION:")) {
530 0 : strLine.ReplaceAll("PARTITION:","");
531 0 : SetName(strLine.Data());
532 0 : return kTRUE;
533 : }
534 154 : if (strLine.BeginsWith("VERSION:")) {
535 0 : strLine.ReplaceAll("VERSION:","");
536 0 : fVersion = strLine.Atoi();
537 0 : return kTRUE;
538 : }
539 154 : if (strLine.BeginsWith("INPUTS:")) {
540 1 : level = 1;
541 1 : return kTRUE;
542 : }
543 152 : if (strLine.BeginsWith("INTERACTIONS:")) {
544 1 : level = 2;
545 1 : return kTRUE;
546 : }
547 150 : if (strLine.BeginsWith("DESCRIPTORS:")) {
548 1 : level = 3;
549 1 : return kTRUE;
550 : }
551 148 : if (strLine.BeginsWith("CLUSTERS:")) {
552 1 : level = 4;
553 1 : return kTRUE;
554 : }
555 146 : if (strLine.BeginsWith("PFS:")) {
556 1 : level = 5;
557 1 : return kTRUE;
558 : }
559 144 : if (strLine.BeginsWith("BCMASKS:")) {
560 1 : level = 6;
561 1 : return kTRUE;
562 : }
563 142 : if (strLine.BeginsWith("CLASSES:")) {
564 1 : level = 7;
565 1 : return kTRUE;
566 : }
567 :
568 210 : strLine.ReplaceAll("*",'!');
569 210 : strLine.ReplaceAll("~",'!');
570 210 : TObjArray *tokens = strLine.Tokenize(" \t");
571 70 : Int_t ntokens = tokens->GetEntriesFast();
572 70 : if (ntokens == 0)
573 : {
574 0 : delete tokens;
575 0 : return kTRUE;
576 : }
577 70 : switch (level) {
578 : case 1:
579 : // Read inputs
580 22 : if ((ntokens != 5) && (ntokens !=6)) {
581 0 : AliError(Form("Invalid trigger input syntax (%s)!",strLine.Data()));
582 0 : delete tokens;
583 0 : return kFALSE;
584 : }
585 44 : if(ntokens==5){
586 88 : AddInput(((TObjString*)tokens->At(0))->String(),
587 44 : ((TObjString*)tokens->At(1))->String(),
588 66 : ((TObjString*)tokens->At(2))->String().Atoi(),
589 44 : ((TObjString*)tokens->At(3))->String().Atoi(),
590 66 : ((TObjString*)tokens->At(4))->String().Atoi());
591 : }else{
592 0 : AddInput(((TObjString*)tokens->At(0))->String(),
593 0 : ((TObjString*)tokens->At(1))->String(),
594 0 : ((TObjString*)tokens->At(2))->String().Atoi(),
595 0 : ((TObjString*)tokens->At(3))->String().Atoi(),
596 0 : ((TObjString*)tokens->At(4))->String().Atoi(),
597 0 : ((TObjString*)tokens->At(5))->String().Atoi());
598 : }
599 : break;
600 : case 2:
601 : // Read interaction
602 : {
603 2 : TString inter;
604 2 : if (ntokens < 2) {
605 0 : AliError(Form("Invalid trigger interaction syntax (%s)!",strLine.Data()));
606 0 : delete tokens;
607 0 : return kFALSE;
608 2 : } else if (ntokens == 2) {
609 4 : inter=((TObjString*)tokens->At(1))->String();
610 : } else {
611 0 : AliWarning(Form("Trigger interaction syntax (%s)!",strLine.Data()));
612 0 : for(Int_t i=1;i<ntokens;i++){
613 0 : inter=inter+((TObjString*)tokens->At(i))->String();
614 : }
615 : }
616 4 : AddInteraction(((TObjString*)tokens->At(0))->String(),inter);
617 2 : break;
618 2 : }
619 : case 3:
620 : // Read logical functions and descriptors
621 40 : if (ntokens < 2) {
622 20 : if ((((TObjString*)tokens->At(0))->String().CompareTo("EMPTY") == 0) ||
623 0 : (((TObjString*)tokens->At(0))->String().CompareTo("DTRUE") == 0) ||
624 0 : (((TObjString*)tokens->At(0))->String().CompareTo("DEMPTY") == 0)) {
625 0 : AddDescriptor(((TObjString*)tokens->At(0))->String(),
626 0 : strLine.ReplaceAll(((TObjString*)tokens->At(0))->String(),""));
627 : break;
628 : }
629 : else {
630 0 : AliError(Form("Invalid trigger descriptor syntax (%s)!",strLine.Data()));
631 0 : delete tokens;
632 0 : return kFALSE;
633 : }
634 : }
635 60 : if (((TObjString*)tokens->At(0))->String().BeginsWith("l0f")) {
636 : // function
637 28 : if(!AddFunction(((TObjString*)tokens->At(0))->String(),
638 4 : strLine.ReplaceAll(((TObjString*)tokens->At(0))->String(),""))) {
639 0 : delete tokens;
640 0 : return kFALSE;
641 : }
642 : }
643 : else {
644 72 : if(!AddDescriptor(((TObjString*)tokens->At(0))->String(),
645 36 : strLine.ReplaceAll(((TObjString*)tokens->At(0))->String(),""))) {
646 0 : delete tokens;
647 0 : return kFALSE;
648 : }
649 : }
650 : break;
651 : case 4:
652 : {
653 2 : if (ntokens < 2) {
654 0 : AliError(Form("Invalid trigger cluster syntax (%s)!",strLine.Data()));
655 0 : delete tokens;
656 0 : return kFALSE;
657 : }
658 6 : if (((TObjString*)tokens->At(1))->String().Atoi() <= 0) {
659 0 : AliError(Form("Invalid trigger cluster syntax (%s)!",strLine.Data()));
660 0 : return kFALSE;
661 : }
662 2 : TString strTemp;
663 56 : for(Int_t i = 2; i < ntokens; i++) {
664 52 : strTemp += ((TObjString*)tokens->At(i))->String();
665 26 : strTemp += " ";
666 : }
667 6 : AddCluster(((TObjString*)tokens->At(0))->String(),
668 6 : ((TObjString*)tokens->At(1))->String().Atoi(),
669 : strTemp);
670 2 : }
671 2 : break;
672 : case 5:
673 : {
674 : AliTriggerPFProtection *pfp = NULL;
675 12 : if ((((TObjString*)tokens->At(0))->String().CompareTo("NONE") == 0) ||
676 9 : (((TObjString*)tokens->At(0))->String().CompareTo("NOPF") == 0)) {
677 3 : pfp = new AliTriggerPFProtection(((TObjString*)tokens->At(0))->String());
678 1 : }
679 : else {
680 4 : if ((ntokens == 10) && (fVersion<=7)){
681 8 : pfp = new AliTriggerPFProtection(((TObjString*)tokens->At(0))->String(),
682 4 : ((TObjString*)tokens->At(1))->String(),
683 4 : ((TObjString*)tokens->At(2))->String(),
684 4 : ((TObjString*)tokens->At(3))->String());
685 6 : pfp->SetNa1(((TObjString*)tokens->At(4))->String().Atoi());
686 6 : pfp->SetNa2(((TObjString*)tokens->At(5))->String().Atoi());
687 6 : pfp->SetNb1(((TObjString*)tokens->At(6))->String().Atoi());
688 6 : pfp->SetNb2(((TObjString*)tokens->At(7))->String().Atoi());
689 6 : pfp->SetTa(((TObjString*)tokens->At(8))->String().Atoi());
690 6 : pfp->SetTb(((TObjString*)tokens->At(9))->String().Atoi());
691 2 : }else if((ntokens == 13) && (fVersion<=7)){
692 0 : UInt_t pfdef[12];
693 0 : for(Int_t i=0;i<12;i++){
694 0 : TString ss(((TObjString*)tokens->At(i+1))->String());
695 0 : ss.Remove(0,2);
696 : UInt_t num=0;
697 0 : for(Int_t j=ss.Length()-1;j>=0;j--){
698 0 : UInt_t nn=ss[j];
699 0 : if(nn >= (UInt_t)'0' && nn <= (UInt_t)'9')nn=nn-(UInt_t)'0'; else
700 0 : if(nn >= (UInt_t)'A' && nn <= (UInt_t)'F')nn=10+nn-(UInt_t)'A'; else
701 0 : if(nn >= (UInt_t)'a' && nn <= (UInt_t)'f')nn=10+nn-(UInt_t)'a'; else{
702 0 : AliError(Form("Invalid trigger pfs syntax (%s)!",strLine.Data()));
703 : //return kFALSE;
704 : }
705 0 : num=num+(1<<(ss.Length()-1-j)*4)*nn;
706 : //cout << ss[j] << " 2 " << nn << " " << num << endl;
707 : }
708 0 : pfdef[i]=num;
709 0 : }
710 0 : pfp = new AliTriggerPFProtection(((TObjString*)tokens->At(0))->String(),pfdef);
711 0 : }else if((ntokens==9) && (fVersion>7)){
712 : // new LML0 PF
713 0 : pfp = new AliTriggerPFProtection(
714 0 : ((TObjString*)tokens->At(0))->String(),
715 0 : ((TObjString*)tokens->At(1))->String(),
716 0 : ((TObjString*)tokens->At(2))->String(),
717 0 : ((TObjString*)tokens->At(3))->String().Atoi(),
718 0 : ((TObjString*)tokens->At(4))->String().Atoi(),
719 0 : ((TObjString*)tokens->At(5))->String().Atoi(),
720 0 : ((TObjString*)tokens->At(6))->String().Atoi(),
721 0 : ((TObjString*)tokens->At(7))->String().Atoi(),
722 0 : ((TObjString*)tokens->At(8))->String().Atoi()
723 : );
724 0 : }else{
725 0 : AliError(Form("Invalid trigger pfs syntax (%s)!",strLine.Data()));
726 : //return kFALSE;
727 : }
728 : }
729 3 : AddPFProtection(pfp);
730 : }
731 3 : break;
732 : case 6:
733 3 : if (ntokens > 2) {
734 0 : AliError(Form("Invalid trigger bcmasks syntax (%s)!",strLine.Data()));
735 0 : delete tokens;
736 0 : return kFALSE;
737 : }
738 9 : if (((TObjString*)tokens->At(0))->String().CompareTo("NONE") == 0)
739 : {
740 0 : if(!AddMask(new AliTriggerBCMask(((TObjString*)tokens->At(0))->String()))) {
741 0 : delete tokens;
742 0 : return kFALSE;
743 : }
744 : }
745 : else {
746 12 : if(!AddMask(((TObjString*)tokens->At(0))->String(),((TObjString*)tokens->At(1))->String())) {
747 0 : delete tokens;
748 0 : return kFALSE;
749 : }
750 : }
751 : break;
752 : case 7:
753 : {
754 18 : if ((ntokens !=8) && (ntokens != 10) && (ntokens != 11)) {
755 0 : AliError(Form("Invalid trigger class syntax (%s)!",strLine.Data()));
756 0 : delete tokens;
757 0 : return kFALSE;
758 : }
759 : AliTriggerClass *trclass=0;
760 90 : if(ntokens == 8)trclass = new AliTriggerClass(this,
761 72 : ((TObjString*)tokens->At(0))->String(),((TObjString*)tokens->At(1))->String().Atoi(),
762 54 : ((TObjString*)tokens->At(2))->String(),((TObjString*)tokens->At(3))->String(),
763 54 : ((TObjString*)tokens->At(4))->String(),((TObjString*)tokens->At(5))->String(),
764 90 : ((TObjString*)tokens->At(6))->String().Atoi(),(Bool_t)(((TObjString*)tokens->At(7))->String().Atoi()));
765 0 : else{ trclass = new AliTriggerClass(this,
766 0 : ((TObjString*)tokens->At(0))->String(),((TObjString*)tokens->At(1))->String().Atoi(),
767 0 : ((TObjString*)tokens->At(2))->String(),((TObjString*)tokens->At(3))->String(),
768 0 : ((TObjString*)tokens->At(4))->String(),
769 0 : ((TObjString*)tokens->At(6))->String().Atoi(),(Bool_t)(((TObjString*)tokens->At(7))->String().Atoi()),
770 0 : (((TObjString*)tokens->At(8))->String().Atoi()),(((TObjString*)tokens->At(9))->String().Atoi()));
771 0 : if(!trclass->SetMasks(this,((TObjString*)tokens->At(5))->String())) {
772 0 : delete tokens;
773 0 : return kFALSE;
774 : }
775 : }
776 18 : AddClass(trclass);
777 18 : }
778 : default:
779 : break;
780 : }
781 140 : delete tokens;
782 :
783 70 : return kTRUE;
784 89 : }
785 :
786 : //_____________________________________________________________________________
787 : AliTriggerConfiguration* AliTriggerConfiguration::LoadConfiguration(TString & configuration)
788 : {
789 : // Load one pre-created Configurations from database/file that match
790 : // with the input string 'configuration'
791 : // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL"
792 : // By default the files are stored in GRP/CTP folder.
793 : // The filename is constructed as: GRP/CTP/<configuration>.cfg
794 :
795 : // Load the selected configuration
796 2 : TString filename;
797 3 : if (configuration.EndsWith(".cfg") ||
798 1 : configuration.EndsWith(".shuttle")) {
799 0 : filename = configuration;
800 : }
801 : else {
802 2 : filename = gSystem->Getenv("ALICE_ROOT");
803 1 : filename += "/GRP/CTP/";
804 1 : filename += configuration;
805 1 : filename += ".cfg";
806 : }
807 :
808 3 : if( gSystem->AccessPathName( filename.Data() ) ) {
809 0 : AliErrorClass( Form( "file (%s) not found", filename.Data() ) );
810 0 : return NULL;
811 : }
812 :
813 :
814 3 : ifstream *file = new ifstream ( filename.Data() );
815 2 : if (!*file) {
816 0 : AliErrorClass(Form("Error opening file (%s) !",filename.Data()));
817 0 : file->close();
818 0 : delete file;
819 0 : return NULL;
820 : }
821 :
822 2 : AliTriggerConfiguration *cfg = new AliTriggerConfiguration();
823 :
824 1 : Int_t level = 0;
825 :
826 1 : TString strLine;
827 270 : while (strLine.ReadLine(*file)) {
828 267 : if (cfg->ProcessConfigurationLine(strLine, level) == kFALSE)
829 : {
830 0 : delete cfg;
831 : cfg = 0;
832 0 : break;
833 : }
834 : }
835 :
836 1 : file->close();
837 2 : delete file;
838 :
839 : return cfg;
840 2 : }
841 :
842 : //_____________________________________________________________________________
843 : AliTriggerConfiguration* AliTriggerConfiguration::LoadConfigurationFromString(const char* configuration)
844 : {
845 : // Loads configuration given as parameter <configuration>
846 :
847 0 : if (!configuration)
848 0 : return 0;
849 :
850 0 : AliTriggerConfiguration *cfg = new AliTriggerConfiguration();
851 :
852 0 : Int_t level = 0;
853 :
854 0 : TObjArray* tokens = TString(configuration).Tokenize("\n");
855 0 : for (Int_t i=0; i<tokens->GetEntries(); i++)
856 : {
857 0 : TObjString* str = dynamic_cast<TObjString*>(tokens->At(i));
858 0 : if (!str)
859 0 : continue;
860 :
861 0 : if (cfg->ProcessConfigurationLine(str->String(), level) == kFALSE)
862 : {
863 0 : delete cfg;
864 : cfg = 0;
865 0 : break;
866 : }
867 0 : }
868 :
869 0 : delete tokens;
870 :
871 : return cfg;
872 0 : }
873 :
874 : //_____________________________________________________________________________
875 : TObjArray* AliTriggerConfiguration::GetAvailableConfigurations( const char* filename )
876 : {
877 : // Return an array of configuration in the file
878 :
879 0 : TString path;
880 0 : if( !filename[0] ) {
881 0 : path += gSystem->Getenv( "ALICE_ROOT" );
882 0 : path += fgkConfigurationFileName;
883 : }
884 : else
885 0 : path += filename;
886 :
887 0 : if( gSystem->AccessPathName( path.Data() ) ) {
888 0 : AliErrorGeneral( "AliTriggerConfiguration", Form( "file (%s) not found", path.Data() ) );
889 0 : return NULL;
890 : }
891 :
892 0 : TObjArray* desArray = new TObjArray();
893 :
894 0 : TFile file( path.Data(), "READ" );
895 0 : if( file.IsZombie() ) {
896 0 : AliErrorGeneral( "AliTriggerConfiguration", Form( "Error opening file (%s)", path.Data() ) );
897 0 : return NULL;
898 : }
899 :
900 0 : file.ReadAll();
901 :
902 : TKey* key;
903 0 : TIter next( file.GetListOfKeys() );
904 0 : while( (key = (TKey*)next()) ) {
905 0 : TObject* obj = key->ReadObj();
906 0 : if( obj->InheritsFrom( "AliTriggerConfiguration" ) ) {
907 0 : desArray->AddLast( obj );
908 : }
909 : }
910 0 : file.Close();
911 :
912 : return desArray;
913 0 : }
914 :
915 : //_____________________________________________________________________________
916 : void AliTriggerConfiguration::WriteConfiguration( const char* filename )
917 : {
918 : // Write the configuration
919 0 : TString path;
920 0 : if( !filename[0] ) {
921 0 : path += gSystem->Getenv("ALICE_ROOT");
922 0 : path += fgkConfigurationFileName;
923 : }
924 : else
925 0 : path += filename;
926 :
927 0 : TFile file( path.Data(), "UPDATE" );
928 0 : if( file.IsZombie() ) {
929 0 : AliErrorGeneral( "AliTriggerConfiguration",
930 : Form( "Can't open file (%s)", path.Data() ) );
931 0 : return;
932 : }
933 :
934 0 : Bool_t result = (Write( GetName(), TObject::kOverwrite ) != 0);
935 0 : if( !result )
936 0 : AliErrorGeneral( "AliTriggerConfiguration",
937 : Form( "Can't write entry to file <%s>!", path.Data() ) );
938 0 : file.Close();
939 0 : }
940 :
941 : //_____________________________________________________________________________
942 : Int_t AliTriggerConfiguration::GetClassIndexFromName(const char* className) const
943 : {
944 : //const TObjArray& classes = cfg->GetClasses();
945 0 : Int_t nclasses = (Int_t)fClasses.GetEntriesFast();
946 0 : for (Int_t i=0;i<nclasses;i++) {
947 0 : AliTriggerClass* trgclass = (AliTriggerClass*)fClasses.At(i);
948 0 : if (TString(trgclass->GetName()).CompareTo(className) == 0) {
949 0 : return trgclass->GetIndex();
950 : }
951 0 : }
952 0 : return -1;
953 0 : }
954 : //_____________________________________________________________________________
955 : const char* AliTriggerConfiguration::GetClassNameFromIndex(Int_t classIndex) const
956 : {
957 0 : Int_t nclasses = (Int_t)fClasses.GetEntriesFast();
958 0 : for (Int_t i=0;i<nclasses;i++) {
959 0 : AliTriggerClass* trgclass = (AliTriggerClass*)fClasses.At(i);
960 0 : if (trgclass->GetIndex() == classIndex) return trgclass->GetName();
961 0 : }
962 0 : return 0;
963 0 : }
964 : //_____________________________________________________________________________
965 : AliTriggerClass* AliTriggerConfiguration::GetTriggerClass(Int_t classIndex) const
966 : {
967 0 : Int_t nclasses = (Int_t)fClasses.GetEntriesFast();
968 0 : for (Int_t i=0;i<nclasses;i++) {
969 0 : AliTriggerClass* trgclass = (AliTriggerClass*)fClasses.At(i);
970 0 : if ( trgclass->GetIndex() == classIndex) return trgclass;
971 0 : }
972 0 : return 0;
973 0 : }
974 : //_____________________________________________________________________________
975 : void AliTriggerConfiguration::Reset()
976 : {
977 188 : for( Int_t j=0; j<fInputs.GetEntriesFast(); j++ )
978 88 : ((AliTriggerInput*)fInputs.At(j))->Reset();
979 :
980 152 : for( Int_t j=0; j<fClasses.GetEntriesFast(); j++ )
981 72 : ((AliTriggerClass*)fClasses.At(j))->Reset();
982 4 : }
983 :
984 : //_____________________________________________________________________________
985 : void AliTriggerConfiguration::Print( const Option_t* ) const
986 : {
987 : // Print
988 0 : cout << "#################################################" << endl;
989 0 : cout << "Trigger Configuration:" << endl;
990 0 : cout << " Name: " << GetName() << endl;
991 0 : cout << " Description: " << GetTitle() << endl;
992 0 : cout << " Version: " << GetVersion() << endl;
993 0 : cout << " Active Detectors: " << GetActiveDetectors() << endl;
994 0 : cout << " Trigger Detectors: " << GetTriggeringDetectors() << endl;
995 :
996 0 : cout << "#################################################" << endl;
997 0 : fInputs.Print();
998 0 : cout << "#################################################" << endl;
999 0 : fInteractions.Print();
1000 0 : cout << "#################################################" << endl;
1001 0 : fFunctions.Print();
1002 0 : cout << "#################################################" << endl;
1003 0 : fDescriptors.Print();
1004 0 : cout << "#################################################" << endl;
1005 0 : fClusters.Print();
1006 0 : cout << "#################################################" << endl;
1007 0 : fPFProtections.Print();
1008 0 : cout << "#################################################" << endl;
1009 0 : fMasks.Print();
1010 0 : cout << "#################################################" << endl;
1011 0 : fClasses.Print();
1012 0 : cout << "#################################################" << endl;
1013 :
1014 0 : cout << endl;
1015 0 : }
1016 :
1017 :
1018 : //////////////////////////////////////////////////////////////////////////////
1019 : // Helper method
1020 :
1021 : //_____________________________________________________________________________
1022 : Bool_t AliTriggerConfiguration::IsSelected( TString detName, TString& detectors ) const
1023 : {
1024 : // check whether detName is contained in detectors
1025 : // if yes, it is removed from detectors
1026 :
1027 : // check if all detectors are selected
1028 0 : if( (detectors.CompareTo("ALL") == 0 ) ||
1029 0 : detectors.BeginsWith("ALL ") ||
1030 0 : detectors.EndsWith(" ALL") ||
1031 0 : detectors.Contains(" ALL ") ) {
1032 0 : detectors = "ALL";
1033 0 : return kTRUE;
1034 : }
1035 :
1036 : // search for the given detector
1037 : Bool_t result = kFALSE;
1038 0 : if( (detectors.CompareTo( detName ) == 0) ||
1039 0 : detectors.BeginsWith( detName+" " ) ||
1040 0 : detectors.EndsWith( " "+detName ) ||
1041 0 : detectors.Contains( " "+detName+" " ) ) {
1042 0 : detectors.ReplaceAll( detName, "" );
1043 : result = kTRUE;
1044 0 : }
1045 :
1046 : // clean up the detectors string
1047 0 : while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " );
1048 0 : while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 );
1049 0 : while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 );
1050 :
1051 0 : return result;
1052 0 : }
|