1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // This class for running and define a Trigger Descriptor
22 // A Trigger Descriptor define a trigger setup for specific runnign
23 // condition (Pb-Pb, p-p, p-A, Calibration, etc).
25 // - cluster detector (List of detectors involved)
26 // - List of conditions
28 // Descriptors could be create in advance and store in a file.
30 // Example how to create a Trigger Descriptor:
32 // AliTriggerDescriptor descrip( "TEST", "Test Descriptor" );
34 // // Define a Cluster Detector
35 // descrip.AddDetectorCluster( "VZERO ZDC MUON" );
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)
43 // descrip.AddCondition( "VZERO_TEST2_L0 & MUON_SMinus_HPt_L0 & ZDC_TEST1_L0",
48 // descrip.AddCondition( "VZERO_TEST3_L0 | MUON_Unlike_LPt_L0 | ZDC_TEST3_L0",
52 // descrip.CheckInputsConditions("Config.C");
55 // // save the descriptor to file
56 // // (default file name $ALICE_ROOT/data/triggerDescriptor.root)
57 // descrip.WriteDescriptor(); or descrip.WriteDescriptor( filename );
59 ///////////////////////////////////////////////////////////////////////////////
62 #include <TObjArray.h>
69 #include "AliRunLoader.h"
70 #include "AliModule.h"
72 #include "AliTriggerInput.h"
73 #include "AliTriggerDetector.h"
74 #include "AliTriggerCondition.h"
75 #include "AliTriggerDescriptor.h"
78 ClassImp(AliTriggerDescriptor)
80 //_____________________________________________________________________________
81 const char* AliTriggerDescriptor::fgkDetectorName[AliTriggerDescriptor::fgkNDetectors] =
82 { "ITS", "TRD", "PHOS", "EMCAL", "MUON", "ZDC", "T0", "VZERO", "ACORDE", "TOF" };
84 const TString AliTriggerDescriptor::fgkDescriptorFileName("/data/triggerDescriptors.root");
86 //_____________________________________________________________________________
87 AliTriggerDescriptor::AliTriggerDescriptor():
94 //_____________________________________________________________________________
95 AliTriggerDescriptor::AliTriggerDescriptor( TString & name, TString & description ):
96 TNamed( name, description ),
102 //_____________________________________________________________________________
103 AliTriggerDescriptor::AliTriggerDescriptor( const AliTriggerDescriptor& des ):
105 fDetectorCluster( des.fDetectorCluster ),
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 )) ) );
115 //______________________________________________________________________________
116 AliTriggerDescriptor& AliTriggerDescriptor::operator=(const AliTriggerDescriptor& des)
118 // AliTriggerDescriptor assignment operator.
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 )) ) );
132 //_____________________________________________________________________________
133 Bool_t AliTriggerDescriptor::AddDetectorCluster( TString & cluster )
135 // Add a List of Detectors to be read together (Detector Cluster)
136 // Ej "TO VO ZDC MUON" or "ALL"
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 ) ) {
143 fDetectorCluster.Append( " " );
144 fDetectorCluster.Append( fgkDetectorName[iDet] );
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",
158 //_____________________________________________________________________________
159 void AliTriggerDescriptor::AddCondition( TString & cond, TString & name, TString & description, ULong64_t mask )
161 // Add a new condition
162 AliTriggerCondition* acond = new AliTriggerCondition( cond, name, description, mask );
163 fConditions.AddLast( acond );
167 //_____________________________________________________________________________
168 AliTriggerDescriptor* AliTriggerDescriptor::LoadDescriptor( TString & descriptor, const char* filename )
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"
174 // Load the selected descriptor
177 path += gSystem->Getenv("ALICE_ROOT");
178 path += fgkDescriptorFileName;
183 if( gSystem->AccessPathName( path.Data() ) ) {
184 AliErrorGeneral( "AliTriggerDescriptor", Form( "file (%s) not found", path.Data() ) );
188 TFile file( path.Data(), "READ" );
189 AliTriggerDescriptor* des = (AliTriggerDescriptor*)(file.Get( descriptor.Data() ));
196 //_____________________________________________________________________________
197 TObjArray* AliTriggerDescriptor::GetAvailableDescriptors( const char* filename )
199 // Return an array of descriptor in the file
203 path += gSystem->Getenv( "ALICE_ROOT" );
204 path += fgkDescriptorFileName;
209 if( gSystem->AccessPathName( path.Data() ) ) {
210 AliErrorGeneral( "AliTriggerDescriptor", Form( "file (%s) not found", path.Data() ) );
214 TObjArray* desArray = new TObjArray();
216 TFile file( path.Data(), "READ" );
217 if( file.IsZombie() ) {
218 AliErrorGeneral( "AliTriggerDescriptor", Form( "Error opening file (%s)", path.Data() ) );
225 TIter next( file.GetListOfKeys() );
226 while( (key = (TKey*)next()) ) {
227 TObject* obj = key->ReadObj();
228 if( obj->InheritsFrom( "AliTriggerDescriptor" ) ) {
229 desArray->AddLast( obj );
237 //_____________________________________________________________________________
238 void AliTriggerDescriptor::WriteDescriptor( const char* filename )
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"
244 // Load the selected descriptor
247 path += gSystem->Getenv("ALICE_ROOT");
248 path += fgkDescriptorFileName;
253 TFile file( path.Data(), "UPDATE" );
254 if( file.IsZombie() ) {
255 AliErrorGeneral( "AliTriggerDescriptor",
256 Form( "Can't open file (%s)", path.Data() ) );
260 Bool_t result = (Write( GetName(), TObject::kOverwrite ) != 0);
262 AliErrorGeneral( "AliTriggerDescriptor",
263 Form( "Can't write entry to file <%s>!", path.Data() ) );
267 //_____________________________________________________________________________
268 Bool_t AliTriggerDescriptor::CheckInputsConditions( TString& configfile )
270 // To be used on the pre-creation of Descriptors to check if the
271 // conditions have valid inputs names.
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
282 AliError( "no gAlice object. Restart aliroot and try again." );
285 if (gAlice->Modules()->GetEntries() > 0) {
286 AliError( "gAlice was already run. Restart aliroot and try again." );
290 AliInfo( Form( "initializing gAlice with config file %s",
291 configfile.Data() ) );
292 StdoutToAliInfo( StderrToAliError(
293 gAlice->Init( configfile.Data() );
296 AliRunLoader* runLoader = gAlice->GetRunLoader();
298 AliError( Form( "gAlice has no run loader object. "
299 "Check your config file: %s", configfile.Data() ) );
303 // get the possible inputs to check the condition
305 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
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) );
323 // check if the condition is compatible with the triggers inputs
324 Int_t ncond = fConditions.GetEntriesFast();
325 Bool_t check = kTRUE;
327 for( Int_t j=0; j<ncond; j++ ) {
328 AliTriggerCondition* cond = (AliTriggerCondition*)(fConditions.At( j ));
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() ) );
338 mask |= cond->GetMask();
345 //_____________________________________________________________________________
346 void AliTriggerDescriptor::Print( const Option_t* ) const
349 cout << "Trigger Descriptor:" << endl;
350 cout << " Name: " << GetName() << endl;
351 cout << " Description: " << GetTitle() << endl;
352 cout << " Detector Cluster: " << fDetectorCluster << endl;
354 // Int_t ninputs = fInputs->GetEntriesFast();
355 // for( Int_t i=0; i<ninputs; i++ ) {
356 // AliTriggerInput* in = (AliTriggerInput*)fInputs->At(i)
360 Int_t ncond = fConditions.GetEntriesFast();
361 for( Int_t i=0; i<ncond; i++ ) {
362 AliTriggerCondition* in = (AliTriggerCondition*)fConditions.At(i);
369 //////////////////////////////////////////////////////////////////////////////
372 //_____________________________________________________________________________
373 Bool_t AliTriggerDescriptor::IsSelected( TString detName, TString& detectors ) const
375 // check whether detName is contained in detectors
376 // if yes, it is removed from detectors
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 ") ) {
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, "" );
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 );