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 // AliTriggerDescriptor::WriteDescriptor( &descrip );
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" };
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 )
105 //_____________________________________________________________________________
106 Bool_t AliTriggerDescriptor::AddDetectorCluster( TString & cluster )
108 // Add a List of Detectors to be read together (Detector Cluster)
109 // Ej "TO VO ZDC MUON" or "ALL"
111 TString olddet = fDetectorCluster;
112 TString newdet = cluster;
113 for( Int_t iDet = 0; iDet < fgkNDetectors; iDet++ ) {
114 if( IsSelected( fgkDetectorName[iDet], newdet ) && !IsSelected( fgkDetectorName[iDet], olddet ) ) {
116 fDetectorCluster.Append( " " );
117 fDetectorCluster.Append( fgkDetectorName[iDet] );
121 // check if there are no trigger detectors (E.g. TPC)
122 if ((newdet.CompareTo("ALL") != 0) && !newdet.IsNull()) {
123 AliError( Form("the following detectors are not trigger detectors: %s",
131 //_____________________________________________________________________________
132 void AliTriggerDescriptor::AddCondition( TString & cond, TString & name, TString & description, Long_t mask )
134 // Add a new condition
135 AliTriggerCondition* acond = new AliTriggerCondition( cond, name, description, mask );
136 fConditions.AddLast( acond );
140 //_____________________________________________________________________________
141 AliTriggerDescriptor* AliTriggerDescriptor::LoadDescriptor( TString & descriptor, const char* filename )
143 // Load one pre-created Descriptors from database/file that match
144 // with the input string 'descriptor'
145 // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL"
147 // Load the selected descriptor
150 path += gSystem->Getenv("ALICE_ROOT");
151 path += fgkDescriptorFileName;
156 if( gSystem->AccessPathName( path.Data() ) ) {
157 AliErrorGeneral( "AliTriggerDescriptor", Form( "file (%s) not found", path.Data() ) );
161 TFile file( path.Data(), "READ" );
162 AliTriggerDescriptor* des = (AliTriggerDescriptor*)(file.Get( descriptor.Data() ));
169 //_____________________________________________________________________________
170 TObjArray* AliTriggerDescriptor::GetAvailableDescriptors( const char* filename )
172 // Return an array of descriptor in the file
176 path += gSystem->Getenv( "ALICE_ROOT" );
177 path += fgkDescriptorFileName;
182 if( gSystem->AccessPathName( path.Data() ) ) {
183 AliErrorGeneral( "AliTriggerDescriptor", Form( "file (%s) not found", path.Data() ) );
187 TObjArray* desArray = new TObjArray();
189 TFile file( path.Data(), "READ" );
190 if( file.IsZombie() ) {
191 AliErrorGeneral( "AliTriggerDescriptor", Form( "Error opening file (%s)", path.Data() ) );
198 TIter next( file.GetListOfKeys() );
199 while( (key = (TKey*)next()) ) {
200 TObject* obj = key->ReadObj();
201 if( obj->InheritsFrom( "AliTriggerDescriptor" ) ) {
202 desArray->AddLast( obj );
210 //_____________________________________________________________________________
211 void AliTriggerDescriptor::WriteDescriptor( const char* filename )
213 // Load one pre-created Descriptors from database/file that match
214 // with the input string 'descriptor'
215 // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL"
217 // Load the selected descriptor
220 path += gSystem->Getenv("ALICE_ROOT");
221 path += fgkDescriptorFileName;
226 TFile file( path.Data(), "UPDATE" );
227 if( file.IsZombie() ) {
228 AliErrorGeneral( "AliTriggerDescriptor",
229 Form( "Can't open file (%s)", path.Data() ) );
233 Bool_t result = (Write( GetName(), TObject::kOverwrite ) != 0);
235 AliErrorGeneral( "AliTriggerDescriptor",
236 Form( "Can't write entry to file <%s>!", path.Data() ) );
243 //_____________________________________________________________________________
244 Bool_t AliTriggerDescriptor::CheckInputsConditions( TString& configfile )
246 // To be used on the pre-creation of Descriptors to check if the
247 // conditions have valid inputs names.
249 // Initiate detectors modules from a Config file
250 // Ask to each active module present in the fDetectorCluster
251 // to create a Trigger detector and retrive the inputs from it
252 // to create a list of inputs.
253 // Each condition in the descriptor is then checked agains
254 // the list of inputs
258 AliError( "no gAlice object. Restart aliroot and try again." );
261 if (gAlice->Modules()->GetEntries() > 0) {
262 AliError( "gAlice was already run. Restart aliroot and try again." );
266 AliInfo( Form( "initializing gAlice with config file %s",
267 configfile.Data() ) );
268 StdoutToAliInfo( StderrToAliError(
269 gAlice->Init( configfile.Data() );
272 AliRunLoader* runLoader = gAlice->GetRunLoader();
274 AliError( Form( "gAlice has no run loader object. "
275 "Check your config file: %s", configfile.Data() ) );
279 // get the possible inputs to check the condition
281 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
283 TString detStr = fDetectorCluster;
284 for( Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++ ) {
285 AliModule* det = (AliModule*) detArray->At(iDet);
286 if( !det || !det->IsActive() ) continue;
287 if( IsSelected( det->GetName(), detStr ) ) {
288 AliInfo( Form( "Creating inputs for %s", det->GetName() ) );
289 AliTriggerDetector* dtrg = det->CreateTriggerDetector();
290 dtrg->CreateInputs();
291 TObjArray* detInp = dtrg->GetInputs();
292 for( Int_t i=0; i<detInp->GetEntriesFast(); i++ ) {
293 AliInfo( Form( "Adding input %s", ((AliTriggerInput*)detInp->At(i))->GetName() ) );
294 inputs.AddLast( detInp->At(i) );
299 // check if the condition is compatible with the triggers inputs
300 Int_t ncond = fConditions.GetEntriesFast();
301 for( Int_t j=0; j<ncond; j++ ) {
302 AliTriggerCondition* cond = (AliTriggerCondition*)(fConditions.At( j ));
303 if( !(cond->CheckInputs( inputs )) ) return kFALSE;
310 //_____________________________________________________________________________
311 void AliTriggerDescriptor::Print( const Option_t* ) const
314 cout << "Trigger Descriptor:" << endl;
315 cout << " Name: " << GetName() << endl;
316 cout << " Description: " << GetTitle() << endl;
317 cout << " Detector Cluster: " << fDetectorCluster << endl;
319 // Int_t ninputs = fInputs->GetEntriesFast();
320 // for( Int_t i=0; i<ninputs; i++ ) {
321 // AliTriggerInput* in = (AliTriggerInput*)fInputs->At(i)
325 Int_t ncond = fConditions.GetEntriesFast();
326 for( Int_t i=0; i<ncond; i++ ) {
327 AliTriggerCondition* in = (AliTriggerCondition*)fConditions.At(i);
334 //////////////////////////////////////////////////////////////////////////////
337 //_____________________________________________________________________________
338 Bool_t AliTriggerDescriptor::IsSelected( TString detName, TString& detectors ) const
340 // check whether detName is contained in detectors
341 // if yes, it is removed from detectors
343 // check if all detectors are selected
344 if( (detectors.CompareTo("ALL") == 0 ) ||
345 detectors.BeginsWith("ALL ") ||
346 detectors.EndsWith(" ALL") ||
347 detectors.Contains(" ALL ") ) {
352 // search for the given detector
353 Bool_t result = kFALSE;
354 if( (detectors.CompareTo( detName ) == 0) ||
355 detectors.BeginsWith( detName+" " ) ||
356 detectors.EndsWith( " "+detName ) ||
357 detectors.Contains( " "+detName+" " ) ) {
358 detectors.ReplaceAll( detName, "" );
362 // clean up the detectors string
363 while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " );
364 while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 );
365 while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 );