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", "START", "VZERO", "CRT", "TOF" };
84 const TString AliTriggerDescriptor::fgkDescriptorFileName("/data/triggerDescriptors.root");
86 //_____________________________________________________________________________
87 AliTriggerDescriptor::AliTriggerDescriptor():
88 TNamed(), fDetectorCluster("")
92 //_____________________________________________________________________________
93 AliTriggerDescriptor::AliTriggerDescriptor( TString & name, TString & description ):
94 TNamed( name, description ), fDetectorCluster("")
98 //_____________________________________________________________________________
99 AliTriggerDescriptor::AliTriggerDescriptor( const AliTriggerDescriptor& des ):
100 TNamed( des ), fDetectorCluster( des.fDetectorCluster )
103 Int_t ncond = des.fConditions.GetEntriesFast();
104 for( Int_t j=0; j<ncond; j++ ) {
105 AddCondition( new AliTriggerCondition( *(AliTriggerCondition*)(des.fConditions.At( j )) ) );
109 //______________________________________________________________________________
110 AliTriggerDescriptor& AliTriggerDescriptor::operator=(const AliTriggerDescriptor& des)
112 // AliTriggerDescriptor assignment operator.
115 TNamed::operator=(des);
116 fDetectorCluster = des.fDetectorCluster;
117 fConditions.Delete();
118 Int_t ncond = des.fConditions.GetEntriesFast();
119 for( Int_t j=0; j<ncond; j++ ) {
120 AddCondition( new AliTriggerCondition( *(AliTriggerCondition*)(des.fConditions.At( j )) ) );
126 //_____________________________________________________________________________
127 Bool_t AliTriggerDescriptor::AddDetectorCluster( TString & cluster )
129 // Add a List of Detectors to be read together (Detector Cluster)
130 // Ej "TO VO ZDC MUON" or "ALL"
132 TString olddet = fDetectorCluster;
133 TString newdet = cluster;
134 for( Int_t iDet = 0; iDet < fgkNDetectors; iDet++ ) {
135 if( IsSelected( fgkDetectorName[iDet], newdet ) && !IsSelected( fgkDetectorName[iDet], olddet ) ) {
137 fDetectorCluster.Append( " " );
138 fDetectorCluster.Append( fgkDetectorName[iDet] );
142 // check if there are no trigger detectors (E.g. TPC)
143 if ((newdet.CompareTo("ALL") != 0) && !newdet.IsNull()) {
144 AliError( Form("the following detectors are not trigger detectors: %s",
152 //_____________________________________________________________________________
153 void AliTriggerDescriptor::AddCondition( TString & cond, TString & name, TString & description, ULong64_t mask )
155 // Add a new condition
156 AliTriggerCondition* acond = new AliTriggerCondition( cond, name, description, mask );
157 fConditions.AddLast( acond );
161 //_____________________________________________________________________________
162 AliTriggerDescriptor* AliTriggerDescriptor::LoadDescriptor( TString & descriptor, const char* filename )
164 // Load one pre-created Descriptors from database/file that match
165 // with the input string 'descriptor'
166 // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL"
168 // Load the selected descriptor
171 path += gSystem->Getenv("ALICE_ROOT");
172 path += fgkDescriptorFileName;
177 if( gSystem->AccessPathName( path.Data() ) ) {
178 AliErrorGeneral( "AliTriggerDescriptor", Form( "file (%s) not found", path.Data() ) );
182 TFile file( path.Data(), "READ" );
183 AliTriggerDescriptor* des = (AliTriggerDescriptor*)(file.Get( descriptor.Data() ));
190 //_____________________________________________________________________________
191 TObjArray* AliTriggerDescriptor::GetAvailableDescriptors( const char* filename )
193 // Return an array of descriptor in the file
197 path += gSystem->Getenv( "ALICE_ROOT" );
198 path += fgkDescriptorFileName;
203 if( gSystem->AccessPathName( path.Data() ) ) {
204 AliErrorGeneral( "AliTriggerDescriptor", Form( "file (%s) not found", path.Data() ) );
208 TObjArray* desArray = new TObjArray();
210 TFile file( path.Data(), "READ" );
211 if( file.IsZombie() ) {
212 AliErrorGeneral( "AliTriggerDescriptor", Form( "Error opening file (%s)", path.Data() ) );
219 TIter next( file.GetListOfKeys() );
220 while( (key = (TKey*)next()) ) {
221 TObject* obj = key->ReadObj();
222 if( obj->InheritsFrom( "AliTriggerDescriptor" ) ) {
223 desArray->AddLast( obj );
231 //_____________________________________________________________________________
232 void AliTriggerDescriptor::WriteDescriptor( const char* filename )
234 // Load one pre-created Descriptors from database/file that match
235 // with the input string 'descriptor'
236 // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL"
238 // Load the selected descriptor
241 path += gSystem->Getenv("ALICE_ROOT");
242 path += fgkDescriptorFileName;
247 TFile file( path.Data(), "UPDATE" );
248 if( file.IsZombie() ) {
249 AliErrorGeneral( "AliTriggerDescriptor",
250 Form( "Can't open file (%s)", path.Data() ) );
254 Bool_t result = (Write( GetName(), TObject::kOverwrite ) != 0);
256 AliErrorGeneral( "AliTriggerDescriptor",
257 Form( "Can't write entry to file <%s>!", path.Data() ) );
261 //_____________________________________________________________________________
262 Bool_t AliTriggerDescriptor::CheckInputsConditions( TString& configfile )
264 // To be used on the pre-creation of Descriptors to check if the
265 // conditions have valid inputs names.
267 // Initiate detectors modules from a Config file
268 // Ask to each active module present in the fDetectorCluster
269 // to create a Trigger detector and retrive the inputs from it
270 // to create a list of inputs.
271 // Each condition in the descriptor is then checked agains
272 // the list of inputs
276 AliError( "no gAlice object. Restart aliroot and try again." );
279 if (gAlice->Modules()->GetEntries() > 0) {
280 AliError( "gAlice was already run. Restart aliroot and try again." );
284 AliInfo( Form( "initializing gAlice with config file %s",
285 configfile.Data() ) );
286 StdoutToAliInfo( StderrToAliError(
287 gAlice->Init( configfile.Data() );
290 AliRunLoader* runLoader = gAlice->GetRunLoader();
292 AliError( Form( "gAlice has no run loader object. "
293 "Check your config file: %s", configfile.Data() ) );
297 // get the possible inputs to check the condition
299 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
301 TString detStr = fDetectorCluster;
302 for( Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++ ) {
303 AliModule* det = (AliModule*) detArray->At(iDet);
304 if( !det || !det->IsActive() ) continue;
305 if( IsSelected( det->GetName(), detStr ) ) {
306 AliInfo( Form( "Creating inputs for %s", det->GetName() ) );
307 AliTriggerDetector* dtrg = det->CreateTriggerDetector();
308 dtrg->CreateInputs();
309 TObjArray* detInp = dtrg->GetInputs();
310 for( Int_t i=0; i<detInp->GetEntriesFast(); i++ ) {
311 AliInfo( Form( "Adding input %s", ((AliTriggerInput*)detInp->At(i))->GetName() ) );
312 inputs.AddLast( detInp->At(i) );
317 // check if the condition is compatible with the triggers inputs
318 Int_t ncond = fConditions.GetEntriesFast();
319 Bool_t check = kTRUE;
321 for( Int_t j=0; j<ncond; j++ ) {
322 AliTriggerCondition* cond = (AliTriggerCondition*)(fConditions.At( j ));
323 if( !(cond->CheckInputs( inputs )) ) check = kFALSE;
324 else AliInfo( Form( "Condition (%s) inputs names OK, class mask (0x%Lx)",
325 cond->GetName(), cond->GetMask( ) ) );
326 // check if condition mask is duplicated
327 if( mask & cond->GetMask() ) {
328 AliError( Form("Condition (%s). The class mask (0x%Lx) is ambiguous. It was previous defined",
329 cond->GetName(), cond->GetMask() ) );
332 mask |= cond->GetMask();
339 //_____________________________________________________________________________
340 void AliTriggerDescriptor::Print( const Option_t* ) const
343 cout << "Trigger Descriptor:" << endl;
344 cout << " Name: " << GetName() << endl;
345 cout << " Description: " << GetTitle() << endl;
346 cout << " Detector Cluster: " << fDetectorCluster << endl;
348 // Int_t ninputs = fInputs->GetEntriesFast();
349 // for( Int_t i=0; i<ninputs; i++ ) {
350 // AliTriggerInput* in = (AliTriggerInput*)fInputs->At(i)
354 Int_t ncond = fConditions.GetEntriesFast();
355 for( Int_t i=0; i<ncond; i++ ) {
356 AliTriggerCondition* in = (AliTriggerCondition*)fConditions.At(i);
363 //////////////////////////////////////////////////////////////////////////////
366 //_____________________________________________________________________________
367 Bool_t AliTriggerDescriptor::IsSelected( TString detName, TString& detectors ) const
369 // check whether detName is contained in detectors
370 // if yes, it is removed from detectors
372 // check if all detectors are selected
373 if( (detectors.CompareTo("ALL") == 0 ) ||
374 detectors.BeginsWith("ALL ") ||
375 detectors.EndsWith(" ALL") ||
376 detectors.Contains(" ALL ") ) {
381 // search for the given detector
382 Bool_t result = kFALSE;
383 if( (detectors.CompareTo( detName ) == 0) ||
384 detectors.BeginsWith( detName+" " ) ||
385 detectors.EndsWith( " "+detName ) ||
386 detectors.Contains( " "+detName+" " ) ) {
387 detectors.ReplaceAll( detName, "" );
391 // clean up the detectors string
392 while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " );
393 while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 );
394 while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 );