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>
71 #include "AliRunLoader.h"
72 #include "AliModule.h"
74 #include "AliCDBManager.h"
75 #include "AliCDBPath.h"
76 #include "AliCDBEntry.h"
78 #include "AliTriggerInput.h"
79 #include "AliTriggerDetector.h"
80 #include "AliTriggerCondition.h"
81 #include "AliTriggerDescriptor.h"
84 ClassImp(AliTriggerDescriptor)
86 //_____________________________________________________________________________
87 const char* AliTriggerDescriptor::fgkDetectorName[AliTriggerDescriptor::fgkNDetectors] =
88 { "ITS", "TRD", "PHOS", "EMCAL", "MUON", "ZDC", "T0", "VZERO", "ACORDE", "TOF" };
90 const TString AliTriggerDescriptor::fgkDescriptorFileName("/data/triggerDescriptors.root");
92 //_____________________________________________________________________________
93 AliTriggerDescriptor::AliTriggerDescriptor():
100 //_____________________________________________________________________________
101 AliTriggerDescriptor::AliTriggerDescriptor( TString & name, TString & description ):
102 TNamed( name, description ),
103 fDetectorCluster(""),
108 //_____________________________________________________________________________
109 AliTriggerDescriptor::AliTriggerDescriptor( const AliTriggerDescriptor& des ):
111 fDetectorCluster( des.fDetectorCluster ),
115 Int_t ncond = des.fConditions.GetEntriesFast();
116 for( Int_t j=0; j<ncond; j++ ) {
117 AddCondition( new AliTriggerCondition( *(AliTriggerCondition*)(des.fConditions.At( j )) ) );
121 //______________________________________________________________________________
122 AliTriggerDescriptor& AliTriggerDescriptor::operator=(const AliTriggerDescriptor& des)
124 // AliTriggerDescriptor assignment operator.
127 TNamed::operator=(des);
128 fDetectorCluster = des.fDetectorCluster;
129 fConditions.Delete();
130 Int_t ncond = des.fConditions.GetEntriesFast();
131 for( Int_t j=0; j<ncond; j++ ) {
132 AddCondition( new AliTriggerCondition( *(AliTriggerCondition*)(des.fConditions.At( j )) ) );
138 //_____________________________________________________________________________
139 Bool_t AliTriggerDescriptor::AddDetectorCluster( TString & cluster )
141 // Add a List of Detectors to be read together (Detector Cluster)
142 // Ej "TO VO ZDC MUON" or "ALL"
144 TString olddet = fDetectorCluster;
145 TString newdet = cluster;
146 for( Int_t iDet = 0; iDet < fgkNDetectors; iDet++ ) {
147 if( IsSelected( fgkDetectorName[iDet], newdet ) && !IsSelected( fgkDetectorName[iDet], olddet ) ) {
149 fDetectorCluster.Append( " " );
150 fDetectorCluster.Append( fgkDetectorName[iDet] );
154 // check if there are no trigger detectors (E.g. TPC)
155 if ((newdet.CompareTo("ALL") != 0) && !newdet.IsNull()) {
156 AliError( Form("the following detectors are not trigger detectors: %s",
164 //_____________________________________________________________________________
165 void AliTriggerDescriptor::AddCondition( TString & cond, TString & name, TString & description, ULong64_t mask )
167 // Add a new condition
168 AliTriggerCondition* acond = new AliTriggerCondition( cond, name, description, mask );
169 fConditions.AddLast( acond );
172 //_____________________________________________________________________________
173 AliTriggerDescriptor* AliTriggerDescriptor::LoadDescriptor( TString & descriptor, const char* filename )
175 // Load one pre-created Descriptors from database/file that match
176 // with the input string 'descriptor'
177 // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL"
178 // Load the selected descriptor
181 path += gSystem->Getenv("ALICE_ROOT");
182 path += fgkDescriptorFileName;
187 if( gSystem->AccessPathName( path.Data() ) ) {
188 AliErrorGeneral( "AliTriggerDescriptor", Form( "file (%s) not found", path.Data() ) );
192 TFile file( path.Data(), "READ" );
193 AliTriggerDescriptor* des = (AliTriggerDescriptor*)(file.Get( descriptor.Data() ));
198 AliTriggerDescriptor *des = 0x0;
199 cout<<"GETTING TRIGGER DESCRIPTORS FROM CDB!!!"<<endl;
201 AliCDBPath path("GRP","CTP","Trigger");
203 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
204 if(!entry) AliFatalClass("Couldn't load trigger description data from CDB!");
206 TList *list = (TList *) entry->GetObject();
207 for(Int_t i = 0; i < list->GetEntries(); i++) {
208 TMap *map = (TMap *)list->At(i);
209 des = (AliTriggerDescriptor *)map->GetValue(descriptor.Data());
216 //_____________________________________________________________________________
217 TObjArray* AliTriggerDescriptor::GetAvailableDescriptors( const char* filename )
219 // Return an array of descriptor in the file
223 path += gSystem->Getenv( "ALICE_ROOT" );
224 path += fgkDescriptorFileName;
229 if( gSystem->AccessPathName( path.Data() ) ) {
230 AliErrorGeneral( "AliTriggerDescriptor", Form( "file (%s) not found", path.Data() ) );
234 TObjArray* desArray = new TObjArray();
236 TFile file( path.Data(), "READ" );
237 if( file.IsZombie() ) {
238 AliErrorGeneral( "AliTriggerDescriptor", Form( "Error opening file (%s)", path.Data() ) );
245 TIter next( file.GetListOfKeys() );
246 while( (key = (TKey*)next()) ) {
247 TObject* obj = key->ReadObj();
248 if( obj->InheritsFrom( "AliTriggerDescriptor" ) ) {
249 desArray->AddLast( obj );
257 //_____________________________________________________________________________
258 void AliTriggerDescriptor::WriteDescriptor( const char* filename )
260 // Load one pre-created Descriptors from database/file that match
261 // with the input string 'descriptor'
262 // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL"
264 // Load the selected descriptor
267 path += gSystem->Getenv("ALICE_ROOT");
268 path += fgkDescriptorFileName;
273 TFile file( path.Data(), "UPDATE" );
274 if( file.IsZombie() ) {
275 AliErrorGeneral( "AliTriggerDescriptor",
276 Form( "Can't open file (%s)", path.Data() ) );
280 Bool_t result = (Write( GetName(), TObject::kOverwrite ) != 0);
282 AliErrorGeneral( "AliTriggerDescriptor",
283 Form( "Can't write entry to file <%s>!", path.Data() ) );
287 //_____________________________________________________________________________
288 Bool_t AliTriggerDescriptor::CheckInputsConditions( TString& configfile )
290 // To be used on the pre-creation of Descriptors to check if the
291 // conditions have valid inputs names.
293 // Initiate detectors modules from a Config file
294 // Ask to each active module present in the fDetectorCluster
295 // to create a Trigger detector and retrive the inputs from it
296 // to create a list of inputs.
297 // Each condition in the descriptor is then checked agains
298 // the list of inputs
302 AliError( "no gAlice object. Restart aliroot and try again." );
305 if (gAlice->Modules()->GetEntries() > 0) {
306 AliError( "gAlice was already run. Restart aliroot and try again." );
310 AliInfo( Form( "initializing gAlice with config file %s",
311 configfile.Data() ) );
312 StdoutToAliInfo( StderrToAliError(
313 gAlice->Init( configfile.Data() );
316 AliRunLoader* runLoader = gAlice->GetRunLoader();
318 AliError( Form( "gAlice has no run loader object. "
319 "Check your config file: %s", configfile.Data() ) );
323 // get the possible inputs to check the condition
325 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
327 TString detStr = fDetectorCluster;
328 for( Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++ ) {
329 AliModule* det = (AliModule*) detArray->At(iDet);
330 if( !det || !det->IsActive() ) continue;
331 if( IsSelected( det->GetName(), detStr ) ) {
332 AliInfo( Form( "Creating inputs for %s", det->GetName() ) );
333 AliTriggerDetector* dtrg = det->CreateTriggerDetector();
334 dtrg->CreateInputs();
335 TObjArray* detInp = dtrg->GetInputs();
336 for( Int_t i=0; i<detInp->GetEntriesFast(); i++ ) {
337 AliInfo( Form( "Adding input %s", ((AliTriggerInput*)detInp->At(i))->GetName() ) );
338 inputs.AddLast( detInp->At(i) );
343 // check if the condition is compatible with the triggers inputs
344 Int_t ncond = fConditions.GetEntriesFast();
345 Bool_t check = kTRUE;
347 for( Int_t j=0; j<ncond; j++ ) {
348 AliTriggerCondition* cond = (AliTriggerCondition*)(fConditions.At( j ));
349 if( !(cond->CheckInputs( inputs )) ) check = kFALSE;
350 else AliInfo( Form( "Condition (%s) inputs names OK, class mask (0x%Lx)",
351 cond->GetName(), cond->GetMask( ) ) );
352 // check if condition mask is duplicated
353 if( mask & cond->GetMask() ) {
354 AliError( Form("Condition (%s). The class mask (0x%Lx) is ambiguous. It was previous defined",
355 cond->GetName(), cond->GetMask() ) );
358 mask |= cond->GetMask();
365 //_____________________________________________________________________________
366 void AliTriggerDescriptor::Print( const Option_t* ) const
369 cout << "Trigger Descriptor:" << endl;
370 cout << " Name: " << GetName() << endl;
371 cout << " Description: " << GetTitle() << endl;
372 cout << " Detector Cluster: " << fDetectorCluster << endl;
374 // Int_t ninputs = fInputs->GetEntriesFast();
375 // for( Int_t i=0; i<ninputs; i++ ) {
376 // AliTriggerInput* in = (AliTriggerInput*)fInputs->At(i)
380 Int_t ncond = fConditions.GetEntriesFast();
381 for( Int_t i=0; i<ncond; i++ ) {
382 AliTriggerCondition* in = (AliTriggerCondition*)fConditions.At(i);
389 //////////////////////////////////////////////////////////////////////////////
392 //_____________________________________________________________________________
393 Bool_t AliTriggerDescriptor::IsSelected( TString detName, TString& detectors ) const
395 // check whether detName is contained in detectors
396 // if yes, it is removed from detectors
398 // check if all detectors are selected
399 if( (detectors.CompareTo("ALL") == 0 ) ||
400 detectors.BeginsWith("ALL ") ||
401 detectors.EndsWith(" ALL") ||
402 detectors.Contains(" ALL ") ) {
407 // search for the given detector
408 Bool_t result = kFALSE;
409 if( (detectors.CompareTo( detName ) == 0) ||
410 detectors.BeginsWith( detName+" " ) ||
411 detectors.EndsWith( " "+detName ) ||
412 detectors.Contains( " "+detName+" " ) ) {
413 detectors.ReplaceAll( detName, "" );
417 // clean up the detectors string
418 while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " );
419 while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 );
420 while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 );