From: hristov Date: Thu, 19 Jan 2006 11:23:47 +0000 (+0000) Subject: First prototype of the trigger classes (E. Lopez Torres) X-Git-Url: http://git.uio.no/git/?a=commitdiff_plain;ds=sidebyside;h=a5a091ce9205fc32733378e12a6f11a8bae0c63d;p=u%2Fmrichter%2FAliRoot.git First prototype of the trigger classes (E. Lopez Torres) --- diff --git a/STEER/AliCentralTrigger.cxx b/STEER/AliCentralTrigger.cxx new file mode 100644 index 00000000000..5ad12eb6355 --- /dev/null +++ b/STEER/AliCentralTrigger.cxx @@ -0,0 +1,290 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// This class for running the Central Trigger Processor // +// // +// // +// Load Descriptors // +// Make a list the trigger detectors involve from the descriptors // +// For the each event // +// Run the Trigger for the each detector // +// Get the inputs // +// Check the condition classes // +// Create the class mask // +// Save result // +// // +// // +/////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include + +#include "AliLog.h" +#include "AliRun.h" +#include "AliRunLoader.h" +#include "AliModule.h" + +#include "AliTriggerInput.h" +#include "AliTriggerDetector.h" +#include "AliTriggerCondition.h" +#include "AliTriggerDescriptor.h" +#include "AliCentralTrigger.h" + +ClassImp( AliCentralTrigger ) + +//_____________________________________________________________________________ +AliCentralTrigger::AliCentralTrigger() : + TObject(), + fClassMask(0) +{ + // Default constructor +// LoadDescriptor("Pb-Pb"); +} + +//_____________________________________________________________________________ +AliCentralTrigger::AliCentralTrigger( TString & descriptor ) : + TObject(), + fClassMask(0) +{ + // Default constructor + LoadDescriptor( descriptor ); +} + +//_____________________________________________________________________________ +AliCentralTrigger::~AliCentralTrigger() +{ + // Destructor + fDescriptors.SetOwner(); + fDescriptors.Delete(); +} + +//_____________________________________________________________________________ +Bool_t AliCentralTrigger::LoadDescriptor( TString & descriptor ) +{ + // Load one or more pre-created Descriptors from database/file that match + // with the input string 'descriptor' + // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL" + + // Delete any descriptor + fDescriptors.Delete(); + + // Load the selected descriptors + TObjArray* desArray = descriptor.Tokenize( " " ); + Int_t ndes = desArray->GetEntriesFast(); + for( Int_t i=0; iAt( i ); + AliTriggerDescriptor* des = AliTriggerDescriptor::LoadDescriptor( val->String() ); + if( des ) + fDescriptors.AddLast( des ); + else + AliWarning( Form( "Descriptor (%s) not found", val->String().Data() ) ); + } + Bool_t desfound = kTRUE; + if( fDescriptors.GetEntriesFast() == 0 ) desfound = kFALSE; + + delete desArray; + + return desfound; +} + +//_____________________________________________________________________________ +TString AliCentralTrigger::GetDetectors() +{ + // return TString with the detectors to be trigger + // merging detectors from all descriptors + + TString result; + + Int_t ndes = fDescriptors.GetEntriesFast(); + for( Int_t i=0; iGetDetectorCluster(); + TObjArray* det = detStr.Tokenize(" "); + Int_t ndet = det->GetEntriesFast(); + for( Int_t j=0; jAt(j))->String() ) )continue; + result.Append( " " ); + result.Append( ((TObjString*)det->At(j))->String() ); + } + } + + return result; +} + +//_____________________________________________________________________________ +Bool_t AliCentralTrigger::RunTrigger( AliRunLoader* runLoader ) +{ + // run the trigger + + if( fDescriptors.GetEntriesFast() == 0 ) { + AliError("not trigger descriptor loaded, skipping trigger"); + return kFALSE; + } + + TStopwatch stopwatch; + stopwatch.Start(); + + // Process each event + for( Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++ ) { + AliInfo( Form("\n ***** Processing event %d *****\n", iEvent) ); + runLoader->GetEvent( iEvent ); + // Get detectors involve + TString detStr = GetDetectors(); + TObjArray* detArray = runLoader->GetAliRun()->Detectors(); + // Reset Mask + fClassMask = 0; + TObjArray trgdetArray; + for( Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++ ) { + AliModule* det = (AliModule*) detArray->At( iDet ); + if( !det || !det->IsActive() ) continue; + if( IsSelected(det->GetName(), detStr) ) { + AliInfo( Form("triggering from digits for %s", det->GetName() ) ); + AliTriggerDetector* trgdet = det->CreateTriggerDetector(); + trgdet->CreateInputs(); + trgdetArray.AddLast( trgdet ); + TStopwatch stopwatchDet; + stopwatchDet.Start(); + trgdet->Trigger(); + AliInfo( Form("Execution time for %s: R:%.2fs C:%.2fs", + det->GetName(), stopwatchDet.RealTime(), stopwatchDet.CpuTime() ) ); + // Get the inputs + TObjArray* detInp = trgdet->GetInputs(); + for( Int_t i=0; iGetEntriesFast(); i++ ) { + fInputs.AddLast( detInp->At(i) ); + } + } + } + + // Check trigger conditions and create the trigger class mask + CheckConditions(); + + fInputs.Clear(); + + // Clear trigger detectors + trgdetArray.SetOwner(); + trgdetArray.Delete(); + + if( (detStr.CompareTo( "ALL" ) != 0) && !detStr.IsNull() ) { + AliError( Form("the following detectors were not found: %s", + detStr.Data())); + return kFALSE; + } + + // Write trigger ???? -> Event Header + // Write(); + Print(); + + } // end event loop + return kTRUE; +} + + + +//_____________________________________________________________________________ +Long_t AliCentralTrigger::CheckConditions() +{ + // Check trigger conditions and create the trigger class mask + + Int_t ndes = fDescriptors.GetEntriesFast(); + for( Int_t i=0; iGetTriggerConditions(); + Int_t ncond = condArray->GetEntriesFast(); + for( Int_t j=0; jAt( j ); + if( !cond->CheckInputs( fInputs ) ) continue; + cond->Trigger( fInputs ); + // cond->Print(); + fClassMask |= cond->GetValue(); + } + } + return fClassMask; +} +//_____________________________________________________________________________ +TObjArray* AliCentralTrigger::GetResultConditions() +{ + // return only the true conditions + + TObjArray* result = new TObjArray(); + + Int_t ndes = fDescriptors.GetEntriesFast(); + for( Int_t i=0; iGetTriggerConditions(); + Int_t ncond = condArray->GetEntriesFast(); + for( Int_t j=0; jAt( j ); + if( cond->GetStatus() ) result->AddLast( cond ); + } + } + + return result; +} + + +//_____________________________________________________________________________ +void AliCentralTrigger::Print( const Option_t* ) const +{ + // Print + cout << "Central Trigger: " << endl; + cout << " Trigger Class Mask: 0x" << hex << fClassMask << dec << endl; + + Int_t ndes = fDescriptors.GetEntriesFast(); + for( Int_t i=0; iPrint(); + } + cout << endl; +} + + +////////////////////////////////////////////////////////////////////////////// +// Helper method + +//_____________________________________________________________________________ +Bool_t AliCentralTrigger::IsSelected( TString detName, TString& detectors ) const +{ + // check whether detName is contained in detectors + // if yes, it is removed from detectors + + // check if all detectors are selected + if( (detectors.CompareTo("ALL") == 0 ) || + detectors.BeginsWith("ALL ") || + detectors.EndsWith(" ALL") || + detectors.Contains(" ALL ") ) { + detectors = "ALL"; + return kTRUE; + } + + // search for the given detector + Bool_t result = kFALSE; + if( (detectors.CompareTo( detName ) == 0) || + detectors.BeginsWith( detName+" " ) || + detectors.EndsWith( " "+detName ) || + detectors.Contains( " "+detName+" " ) ) { + detectors.ReplaceAll( detName, "" ); + result = kTRUE; + } + + // clean up the detectors string + while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " ); + while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 ); + while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 ); + + return result; +} diff --git a/STEER/AliCentralTrigger.h b/STEER/AliCentralTrigger.h new file mode 100644 index 00000000000..cc8f6e51346 --- /dev/null +++ b/STEER/AliCentralTrigger.h @@ -0,0 +1,57 @@ +#ifndef ALICENTRALTRIGGER_H +#define ALICENTRALTRIGGER_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// This class for running the Central Trigger Processor // +// // +// // +// Load Descriptors // +// Make a list the trigger detectors involve from the descriptors // +// For the each event // +// Run the Trigger for the each detector // +// Get the inputs // +// Check the condition classes // +// Create the class mask // +// Save result // +// // +/////////////////////////////////////////////////////////////////////////////// + +#include +#include + +class AliCentralTrigger : public TObject { + +public: + AliCentralTrigger(); + AliCentralTrigger( TString & descriptor ); + virtual ~AliCentralTrigger(); + + Bool_t LoadDescriptor( TString & descriptor ); + Bool_t RunTrigger( AliRunLoader * runloader ); + Long_t CheckConditions(); + // Getters + TString GetDetectors(); + Long_t GetClassMask() const { return fClassMask; } + TObjArray* GetLoadedDescriptors() { return &fDescriptors; } + TObjArray* GetResultConditions(); + void Print( const Option_t* opt ="" ) const; +protected: + // TString fRunCondition; // Running modes Ej. Pb-Pb, p-p, p-A + Long_t fClassMask; // UID ( bitwise OR of conditions mask ) + TObjArray fDescriptors; // Array of Trigger Descriptors (AliTriggerDescriptor) + TObjArray fInputs; //! Array of Trigger Inputs + +private: + Bool_t IsSelected( TString detName, TString& detectors ) const; + + ClassDef( AliCentralTrigger, 1 ) // class for running the Central Trigger Processor +}; + + +#endif diff --git a/STEER/AliExpression.cxx b/STEER/AliExpression.cxx new file mode 100644 index 00000000000..0d0bbe40a37 --- /dev/null +++ b/STEER/AliExpression.cxx @@ -0,0 +1,344 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// AliExpression Class // // +// // +// Helper class to evaluate the condition expressions in // +// AliTriggerCondition // +// Implements a simple recursive-descent parser // +// // +/////////////////////////////////////////////////////////////////////////////// + +//#include +#include +#include +#include + +#include "AliLog.h" +#include "AliExpression.h" +#include "AliTriggerInput.h" + +ClassImp( AliExpression ) + +//______________________________________________________________________________ +AliExpression::AliExpression( TString exp ) +{ + // Default constructor + TObjArray* tokens = Tokenize( exp ); + + Int_t i = -1; + AliExpression* e = Expression( *tokens, i ); + // Copy !!! + fArg1 = e->fArg1; e->fArg1 = 0; + fArg2 = e->fArg2; e->fArg2 = 0; + fOperator = e->fOperator; + delete e; + delete tokens; +} + +//______________________________________________________________________________ +AliExpression::~AliExpression() +{ + if( fArg1 ) delete fArg1; + if( fArg2 ) delete fArg2; +} + +//______________________________________________________________________________ +AliExpression& AliExpression::operator=(const AliExpression& e) +{ + // AliExpression assignment operator. + + if( this != &e ) { + TObject::operator=(e); + fArg1 = e.fArg1; + fArg2 = e.fArg2; + fOperator = e.fOperator; + } + return *this; +} + +//______________________________________________________________________________ +AliExpression::AliExpression( int op, AliExpression* a, AliExpression* b ) +{ + // Create a new expression + fArg1 = a; + fArg2 = b; + fOperator = op; +} + +//______________________________________________________________________________ +AliExpression::AliExpression( int op, AliExpression* a ) +{ + // Create a unary expression. + fArg1 = 0; + fArg2 = a; + fOperator = op; +} + +//______________________________________________________________________________ +Bool_t AliExpression::Value( TObjArray &vars ) +{ + // Evaluate the expression + if ( fArg2 == 0 ) { + AliError( "Expression undefined." ); + return kFALSE; + } + + switch (fOperator) { + + case kOpOR : + return fArg1->Value(vars) || fArg2->Value(vars); + + case kOpAND : + return fArg1->Value(vars) && fArg2->Value(vars); + + case kOpNOT : + return !(fArg2->Value(vars)); + + default: + AliError( "Illegal operator in expression!"); + + } + return kFALSE; +} + + +//______________________________________________________________________________ +TString AliExpression::Unparse() const +{ + // Unparse the expression + + TString opVals[4] = { "&", "|","!" }; + if ( fArg2 == 0 ) { + AliError( "Expression undefined." ); + return "Error"; + } + + if (fArg1 == 0 && fArg2) { + return opVals[fOperator]+fArg2->Unparse(); + } + return "("+fArg1->Unparse()+" "+opVals[fOperator]+" "+fArg2->Unparse()+")"; +} + +//______________________________________________________________________________ +TObjArray* AliExpression::Tokenize( TString str ) const +{ + // tokenize the expression + + // Remove spaces + TString str1; + for( Int_t i=0; iGetEntriesFast(); + TString sumval; + for( Int_t i=0; iAt( i ); + sumval.Append( val->String() ); + } + // get the operator tokens + TObjArray* optok = str1.Tokenize( sumval.Data() ); + // put all operator in one string + TString operators; + Int_t nopt = optok->GetEntriesFast(); + for( Int_t i=0; iAt( i ); + operators.Append( val1->String() ); + } + // add more room to be safe + TObjString* blank = new TObjString(" "); + operators.Append( " " ); + valtok->AddLast( blank ); + // Now put var. and oper. together + TObjArray* tokens = new TObjArray( valtok->GetEntriesFast() + operators.Length() ); + int io = 0,iv = 0; + int index = 0; + while( 1 ) { + TString so = operators[io]; + int indexO = str1.Index( so, index ); + TString val2 = ((TObjString*)valtok->At( iv ))->String(); + int indexV = str1.Index( val2, index ); + if( (indexO < indexV || indexV < 0) && indexO >=0 ) { + tokens->AddLast( new TObjString( so ) ); + index += so.Length(); + io++; + } + if( (indexV < indexO || indexO < 0) && indexV >=0 ) { + tokens->AddLast( new TObjString( val2 ) ); + index += val2.Length(); + iv++; + } + if( index >= str1.Length() ) break; + } + +// Debug -> Print the tokens +// Int_t nt = tokens->GetEntriesFast(); +// for( Int_t i=0; iAt( i ); +// cout << i << " " << val3->String() << endl; +// } + delete valtok; + delete optok; + + return tokens; +} + + +//______________________________________________________________________________ +AliExpression* AliExpression::Element( TObjArray &st, Int_t &i ) +{ + // create an element + + AliExpression* result = 0; + + Int_t nt = st.GetEntriesFast(); + TString token = "@"; + TObjString* valt; + // next token + if( i < nt-1 ) { + i++; + valt = (TObjString*)st.At( i ); + token = valt->String(); + } + // token type + char ttok = ( token[0]!='|' && token[0]!='&' && + token[0]!='!' && token[0]!='('&& token[0]!=')') ? 'w' : token[0]; + switch( ttok ) { + case 'w' : + result = new AliVariableExpression( token ); + break; + case '(' : + result = Expression(st, i); + // next token + if( i < nt-1 ) { + i++; + valt = (TObjString*)st.At( i ); + token = valt->String(); + } + if( token[0] != ')' ) { + // i--; // push back + AliErrorGeneral( "AliExpression::Element", "Mismatched parenthesis." ); + delete result; + result = new AliExpression; + } + break; + default: + i--; // push back + AliErrorGeneral( "AliExpression::Element", Form("Unexpected symbol on input. %s", token.Data()) ); + if( result ) delete result; + result = new AliExpression; + } + return result; +} + +//______________________________________________________________________________ +AliExpression* AliExpression::Primary( TObjArray &st, Int_t &i ) +{ + // create a primary + + Int_t nt = st.GetEntriesFast(); + TString token = "@"; + TObjString* valt; + // next token + if( i < nt-1 ) { + i++; + valt = (TObjString*)st.At( i ); + token = valt->String(); + } + + switch (token[0]) { + case '!' : + return new AliExpression( kOpNOT, Primary( st, i ) ); + default: + i--; // push back + return Element( st, i ); + } +} + +//______________________________________________________________________________ +AliExpression* AliExpression::Expression( TObjArray &st,Int_t &i ) +{ + // create an expression + + AliExpression* result = 0; + Bool_t done = kFALSE; + TString token; + TObjString* valt; + + static int stack = 0; + stack++; + Int_t nt = st.GetEntriesFast(); + + result = Primary( st, i ); +// cout <<"i "<Unparse() << endl; + while (! done) { + // next token + if( i < nt-1 ) i++; + else break; + valt = (TObjString*)st.At( i ); + token = valt->String(); + switch (token[0]) { + case '&' : + result = new AliExpression( kOpAND, result, Primary( st, i ) ); +// cout <<"i "<Unparse() << endl; + break; + case '|' : + result = new AliExpression( kOpOR, result, Primary( st, i ) ); +// cout <<"i "<Unparse() << endl; + break; + default: + done = kTRUE; + i--; // push back + break; + } + } + stack--; + if( stack == 0 && !token.IsNull() && token[0] == ')' ) { + AliErrorGeneral( "AliExpression::Expression", "To many closing parenthesis." ); + delete result; + result = new AliExpression; + } else + if( stack == 0 && i< nt-1 ) { + AliErrorGeneral( "AliExpression::Expression", Form( "Unexpected symbol on input. %s", token.Data() ) ); + delete result; + result = new AliExpression; + } + return result; +} + +//////////////////////////////////////////////////////////////////////////////// + +ClassImp( AliVariableExpression ) + +//______________________________________________________________________________ +Bool_t AliVariableExpression::Value( TObjArray& pgm ) +{ + // return the value + TObject* dd = pgm.FindObject( fVname.Data() ); + if( dd == NULL ) { + AliError( fVname + " is undefined" ); + return 0; + } + return ((AliTriggerInput*)dd)->GetValue(); +} + diff --git a/STEER/AliExpression.h b/STEER/AliExpression.h new file mode 100644 index 00000000000..ada82a6fb4b --- /dev/null +++ b/STEER/AliExpression.h @@ -0,0 +1,72 @@ +#ifndef ALIEXPRESSION_H +#define ALIEXPRESSION_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// AliExpression Class // // +// // +/////////////////////////////////////////////////////////////////////////////// + +#include +class TString; +class TObjArray; + +// These are the valid operators types. + +enum { kOpAND, // AND '&' + kOpOR, // OR '|' + kOpNOT }; // Unary negation '!' + +class AliExpression : public TObject { + +public: + AliExpression() : fArg1(0), fArg2(0), fOperator(0) {} + AliExpression( TString exp ); + virtual ~AliExpression(); + AliExpression( const AliExpression& exp ) : TObject( exp ), + fArg1(exp.fArg1), fArg2(exp.fArg2), fOperator(exp.fOperator) {} + AliExpression& operator=(const AliExpression& exp); + + virtual Bool_t Value( TObjArray & vars ); + virtual TString Unparse() const; + +private: + AliExpression* fArg1; // left argument + AliExpression* fArg2; // right argument + Int_t fOperator; // operator + + AliExpression( int op, AliExpression* a ); + AliExpression( int op, AliExpression* a, AliExpression* b ); + + TObjArray* Tokenize( TString str ) const; + static AliExpression* Element( TObjArray &st, Int_t &i ); + static AliExpression* Primary( TObjArray &st, Int_t &i ); + static AliExpression* Expression( TObjArray &st, Int_t &i ); + + ClassDef( AliExpression, 1 ) // Class to evaluate an expression +}; + + + + +/////////////////////////////////////////////////////////////////////////// + +class AliVariableExpression: public AliExpression { +public: + AliVariableExpression( TString a ): AliExpression(), fVname(a) {}; + ~AliVariableExpression() {} + virtual Bool_t Value( TObjArray& pgm ); + virtual TString Unparse() const { return fVname; } + +private: + TString fVname; // Variable name + + ClassDef( AliVariableExpression, 1 ) // Class to define a variable expression +}; + +#endif diff --git a/STEER/AliModule.h b/STEER/AliModule.h index 3546e5bc28f..d77678f7294 100644 --- a/STEER/AliModule.h +++ b/STEER/AliModule.h @@ -18,6 +18,7 @@ #include #include "AliRndm.h" +#include "AliTriggerDetector.h" class TClonesArray; class TBrowser; @@ -92,6 +93,8 @@ public: virtual void Hits2SDigits() {} virtual AliDigitizer* CreateDigitizer(AliRunDigitizer* /*manager*/) const {return NULL;} + virtual AliTriggerDetector* CreateTriggerDetector() const + { AliTriggerDetector* det = new AliTriggerDetector(); det->SetName(GetName()); return det;} virtual void SDigits2Digits() {} virtual void Hits2Digits() {} virtual void Digits2Reco() {} diff --git a/STEER/AliSimulation.cxx b/STEER/AliSimulation.cxx index 7e3812cf61b..49fbe1b92a9 100644 --- a/STEER/AliSimulation.cxx +++ b/STEER/AliSimulation.cxx @@ -118,6 +118,7 @@ #include "AliRunLoader.h" #include "AliSimulation.h" #include "AliVertexGenFile.h" +#include "AliCentralTrigger.h" #include "AliDAQConfig.h" #include "AliAlignObj.h" @@ -136,6 +137,7 @@ AliSimulation::AliSimulation(const char* configFileName, fRunSimulation(kTRUE), fMakeSDigits("ALL"), fMakeDigits("ALL"), + fMakeTrigger(""), fMakeDigitsFromHits(""), fWriteRawData(""), fRawDataFileName(""), @@ -163,6 +165,7 @@ AliSimulation::AliSimulation(const AliSimulation& sim) : fRunSimulation(sim.fRunSimulation), fMakeSDigits(sim.fMakeSDigits), fMakeDigits(sim.fMakeDigits), + fMakeTrigger(sim.fMakeTrigger), fMakeDigitsFromHits(sim.fMakeDigitsFromHits), fWriteRawData(sim.fWriteRawData), fRawDataFileName(""), @@ -400,6 +403,13 @@ Bool_t AliSimulation::Run(Int_t nEvents) } } + // digits -> trigger + if (!fMakeTrigger.IsNull()) { + if (!RunTrigger(fMakeTrigger)) { + if (fStopOnError) return kFALSE; + } + } + // digits -> raw data if (!fWriteRawData.IsNull()) { if (!WriteRawData(fWriteRawData, fRawDataFileName, @@ -411,6 +421,84 @@ Bool_t AliSimulation::Run(Int_t nEvents) return kTRUE; } +//_____________________________________________________________________________ +Bool_t AliSimulation::RunTrigger(const char* descriptors) +{ + // run the trigger + + TStopwatch stopwatch; + stopwatch.Start(); + + AliRunLoader* runLoader = LoadRun("READ"); + if (!runLoader) return kFALSE; + TString des = descriptors; + // Load Descriptors + AliCentralTrigger* aCTP = new AliCentralTrigger( des ); + + // digits -> trigger + if( !aCTP->RunTrigger( runLoader ) ) { + if (fStopOnError) { + delete aCTP; + return kFALSE; + } + } + +/* + // Process each event + for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) { + AliInfo(Form("processing event %d", iEvent)); + runLoader->GetEvent(iEvent); + + TObjArray* detArray = runLoader->GetAliRun()->Detectors(); + for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) { + AliModule* det = (AliModule*) detArray->At(iDet); + if (!det || !det->IsActive()) continue; + if (IsSelected(det->GetName(), detStr)) { + AliInfo(Form("triggering from digits for %s", det->GetName())); + + // AliLoader* loader = fLoader[iDet]; + // loader->LoadDigits("read"); + // TTree* digitsTree = loader->TreeD(); + // det->Trigger( digitsTree ); + // or + AliTriggerDetector* tdet = det->CreateTriggerDetector(); + TObjArray* detInp = dtrg->GetTriggerInputs(); + for( Int_t i=0; iGetEntriesFast(); i++ ) + fInputs.AddLast( detInp->At(i) ); + + AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs", + det->GetName(),stopwatchDet.RealTime(),stopwatchDet.CpuTime())); + } + } + + if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) { + AliError(Form("the following detectors were not found: %s", + detStr.Data())); + if (fStopOnError) { + delete centralTP; + return kFALSE; + } + } + + // Check trigger conditions + centralTP->TriggerConditions(); + + // Write trigger ???? + centralTP->Write(); + + } */ + + AliInfo(Form("Execution time: R:%.2fs C:%.2fs", + stopwatch.RealTime(),stopwatch.CpuTime())); + + delete aCTP; + delete runLoader; + + return kTRUE; +} + + + //_____________________________________________________________________________ Bool_t AliSimulation::RunSimulation(Int_t nEvents) { diff --git a/STEER/AliSimulation.h b/STEER/AliSimulation.h index b0625eb0f8a..a43276c0c67 100644 --- a/STEER/AliSimulation.h +++ b/STEER/AliSimulation.h @@ -50,6 +50,8 @@ public: void SetRegionOfInterest(Bool_t flag) {fRegionOfInterest = flag;}; void SetMakeDigits(const char* detectors) {fMakeDigits = detectors;}; + void SetMakeTrigger(const char* descriptors) + {fMakeTrigger = descriptors;}; void SetMakeDigitsFromHits(const char* detectors) {fMakeDigitsFromHits = detectors;}; void SetWriteRawData(const char* detectors, @@ -70,6 +72,7 @@ public: virtual Bool_t RunSimulation(Int_t nEvents = 0); virtual Bool_t RunSDigitization(const char* detectors = "ALL"); + virtual Bool_t RunTrigger(const char* descriptors ="" ); virtual Bool_t RunDigitization(const char* detectors = "ALL", const char* excludeDetectors = ""); virtual Bool_t RunHitsDigitization(const char* detectors = "ALL"); @@ -90,6 +93,7 @@ private: Bool_t fRunSimulation; // simulate detectors (hits) or not TString fMakeSDigits; // create sdigits for these detectors TString fMakeDigits; // create digits for these detectors + TString fMakeTrigger; // run trigger for these descriptors TString fMakeDigitsFromHits; // create digits from hits for these detectors TString fWriteRawData; // write raw data for these detectors TString fRawDataFileName; // file name for the raw data file diff --git a/STEER/AliTriggerCondition.cxx b/STEER/AliTriggerCondition.cxx new file mode 100644 index 00000000000..05ec093c71a --- /dev/null +++ b/STEER/AliTriggerCondition.cxx @@ -0,0 +1,160 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// +// Class to define a Trigger Condition // +// +// Ej Condition name Description class mask +// inputs names ___ _________ _________ +// | | | +// AliTriggerCondition("(T0_L0 & VZERO_MB_L0 & TRD_PRE_L0)", "MB", "Minimum Bias", 0x0100 ); +// +// A Trigger condition is defined from logical combination of trigger +// inputs names (boolean expression), trigger inputs names must match +// with the inputs defined in AliTriggerDetector classes +// +// Allow operators: +// & => and +// | => or +// ! => not +// +// The name must be globally unique. Spaces are not allowed. +// +// A maximun of 50 diffentes trigger signatures ("trigger classes" or conditions) +// are allow to run simultaneously. +// So, the "class mask" should set only 1 bit from the position 1 to 50. +// +// +/////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include + +#include "AliLog.h" +#include "AliExpression.h" +#include "AliTriggerInput.h" +#include "AliTriggerCondition.h" + +ClassImp( AliTriggerCondition ) + +//_____________________________________________________________________________ +AliTriggerCondition::AliTriggerCondition() : + TNamed(), + fClassMask( 0 ), + fCondition( "" ), + fStatus( kFALSE ) +{ + // Default ctor +} + +//______________________________________________________________________________ +AliTriggerCondition::AliTriggerCondition(const AliTriggerCondition &cond) : + TNamed( cond ), + fClassMask( cond.fClassMask ), + fCondition( cond.fCondition ), + fStatus( cond.fStatus ) +{ + // AliTriggerCondition copy ctor. +} + +//______________________________________________________________________________ +AliTriggerCondition& AliTriggerCondition::operator=(const AliTriggerCondition& rhs) +{ + // AliTriggerCondition assignment operator. + + if (this != &rhs) { + TObject::operator=(rhs); + fClassMask = rhs.fClassMask; + fCondition = rhs.fCondition; + } + return *this; +} + +//_____________________________________________________________________________ +AliTriggerCondition::AliTriggerCondition( TString & condition, TString & name, + TString & description, Long_t mask ) : + TNamed( name, description ), + fClassMask( mask ), + fCondition( condition ), + fStatus( kFALSE ) +{ + // Default Constructor + + // check the expression + AliExpression* exp = new AliExpression( fCondition ); + delete exp; +} + + +//_____________________________________________________________________________ +Bool_t AliTriggerCondition::CheckInputs( TObjArray& inputs ) +{ + // The "inputs" array should be the list of all possible inputs + // so each input in the condition is checked to be present in the array + // return false if one input is missing + + TString condition( fCondition ); + TObjArray* tokens = condition.Tokenize(".&+| "); + + Int_t ntokens = tokens->GetEntriesFast(); + for( Int_t i=0; iAt( i ); + Int_t nInputs = inputs.GetEntriesFast(); + Int_t j; + for( j=0; jString()).CompareTo( in->GetName() ) == 0 ) break; + } + + if( j >= nInputs ) { + AliWarning( Form( "The trigger input (%s) is not available for Condition (%s)", + iname->String().Data(), GetName() ) ); + delete tokens; + return kFALSE; + } + } + + delete tokens; + return kTRUE; +} + +//_____________________________________________________________________________ +void AliTriggerCondition::Trigger( TObjArray& inputs ) +{ + // Check if the inputs satify the expression condition + + AliExpression* exp = new AliExpression( fCondition ); +// cout << exp->Unparse() << endl; + fStatus = exp->Value( inputs ); + delete exp; +} + +//_____________________________________________________________________________ +void AliTriggerCondition::Print( const Option_t* ) const +{ + // Print + cout << "Trigger Condition:" << endl; + cout << " Name: " << GetName() << endl; + cout << " Description: " << GetTitle() << endl; + cout << " Condition: " << fCondition << endl; + cout << " Class Mask: " << "0x" << hex << fClassMask << dec << endl; + cout << " Value: " << GetValue() << endl; +} diff --git a/STEER/AliTriggerCondition.h b/STEER/AliTriggerCondition.h new file mode 100644 index 00000000000..1b7e15c8e24 --- /dev/null +++ b/STEER/AliTriggerCondition.h @@ -0,0 +1,48 @@ +#ifndef ALITRIGGERCONDITION_H +#define ALITRIGGERCONDITION_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// +// Class to define a Trigger Condition +// // +// A Trigger condition is defined from logical combination of trigger +// inputs names (boolean expression) +// +/////////////////////////////////////////////////////////////////////////////// + +class TNamed; +class TObjArray; +class TString; + +class AliTriggerCondition : public TNamed { + +public: + AliTriggerCondition(); + AliTriggerCondition( const AliTriggerCondition &cond ); + AliTriggerCondition( TString & condition, TString & name, + TString & description, Long_t mask ); + virtual ~AliTriggerCondition() {} + AliTriggerCondition& operator=(const AliTriggerCondition& rhs); + + void Trigger( TObjArray & inputs ); + Bool_t CheckInputs( TObjArray & inputs ); + // Setters + void Reset() { fStatus = kFALSE; } + // Getters + Long_t GetValue() const { return (fStatus) ? fClassMask : 0; } + Bool_t GetStatus() const { return fStatus; } + virtual void Print( const Option_t* opt ="" ) const; +protected: + Long_t fClassMask; // UID "class mask" should set only 1 bit from the position 0 to 50 + TString fCondition; // Definition of the condition + Bool_t fStatus; // true = Condition has been satisfied after Trigger + + ClassDef( AliTriggerCondition, 1 ) // Define a Trigger Condition +}; + +#endif diff --git a/STEER/AliTriggerDescriptor.cxx b/STEER/AliTriggerDescriptor.cxx new file mode 100644 index 00000000000..feab539cb32 --- /dev/null +++ b/STEER/AliTriggerDescriptor.cxx @@ -0,0 +1,368 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// +// This class for running and define a Trigger Descriptor +// +// A Trigger Descriptor define a trigger setup for specific runnign +// condition (Pb-Pb, p-p, p-A, Calibration, etc). +// It keep: +// - cluster detector (List of detectors involved) +// - List of conditions +// +// Descriptors could be create in advance and store in a file. +// +// Example how to create a Trigger Descriptor: +// +// AliTriggerDescriptor descrip( "TEST", "Test Descriptor" ); +// +// // Define a Cluster Detector +// descrip.AddDetectorCluster( "VZERO ZDC MUON" ); +// +// // Define the trigger conditions (see AliTriggerCondition.cxx) +// descrip.AddCondition( "VZERO_TEST1_L0 & MUON_SPlus_LPt_L0 & ZDC_TEST2_L0", // condition +// "VO1_M1_ZDC2", // short name +// "Dummy", // short description +// 0x0100 ); // class mask (set one bit) +// +// descrip.AddCondition( "VZERO_TEST2_L0 & MUON_SMinus_HPt_L0 & ZDC_TEST1_L0", +// "VO2_M3_ZDC1", +// "Dummy", +// 0x0200 ); +// +// descrip.AddCondition( "VZERO_TEST3_L0 | MUON_Unlike_LPt_L0 | ZDC_TEST3_L0", +// "VO3_M1_ZDC3", +// "Dummy", +// 0x0400 ); +// descrip.CheckInputsConditions("Config.C"); +// descrip.Print(); +// +// // save the descriptor to file +// // (default file name $ALICE_ROOT/data/triggerDescriptor.root) +// AliTriggerDescriptor::WriteDescriptor( &descrip ); +// +/////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +#include "AliLog.h" +#include "AliRun.h" +#include "AliRunLoader.h" +#include "AliModule.h" + +#include "AliTriggerInput.h" +#include "AliTriggerDetector.h" +#include "AliTriggerCondition.h" +#include "AliTriggerDescriptor.h" + + +ClassImp(AliTriggerDescriptor) + +//_____________________________________________________________________________ +const char* AliTriggerDescriptor::fgkDetectorName[AliTriggerDescriptor::fgkNDetectors] = + { "ITS", "TRD", "PHOS", "EMCAL", "MUON", "ZDC", "START", "VZERO", "CRT" }; + +const TString AliTriggerDescriptor::fgkDescriptorFileName("/data/triggerDescriptors.root"); + +//_____________________________________________________________________________ +AliTriggerDescriptor::AliTriggerDescriptor(): +TNamed(), fDetectorCluster("") +{ +} + +//_____________________________________________________________________________ +AliTriggerDescriptor::AliTriggerDescriptor( TString & name, TString & description ): +TNamed( name, description ), fDetectorCluster("") +{ +} + +//_____________________________________________________________________________ +AliTriggerDescriptor::AliTriggerDescriptor( const AliTriggerDescriptor& des ): +TNamed( des ), fDetectorCluster( des.fDetectorCluster ) +{ + // Copy constructor +} + +//_____________________________________________________________________________ +Bool_t AliTriggerDescriptor::AddDetectorCluster( TString & cluster ) +{ + // Add a List of Detectors to be read together (Detector Cluster) + // Ej "TO VO ZDC MUON" or "ALL" + + TString olddet = fDetectorCluster; + TString newdet = cluster; + for( Int_t iDet = 0; iDet < fgkNDetectors; iDet++ ) { + if( IsSelected( fgkDetectorName[iDet], newdet ) && !IsSelected( fgkDetectorName[iDet], olddet ) ) { + // Add the detector + fDetectorCluster.Append( " " ); + fDetectorCluster.Append( fgkDetectorName[iDet] ); + } + } + + // check if there are no trigger detectors (E.g. TPC) + if ((newdet.CompareTo("ALL") != 0) && !newdet.IsNull()) { + AliError( Form("the following detectors are not trigger detectors: %s", + newdet.Data() ) ); + return kFALSE; + } + + return kTRUE; +} + +//_____________________________________________________________________________ +void AliTriggerDescriptor::AddCondition( TString & cond, TString & name, TString & description, Long_t mask ) +{ + // Add a new condition + AliTriggerCondition* acond = new AliTriggerCondition( cond, name, description, mask ); + fConditions.AddLast( acond ); +} + + +//_____________________________________________________________________________ +AliTriggerDescriptor* AliTriggerDescriptor::LoadDescriptor( TString & descriptor, const char* filename ) +{ + // Load one pre-created Descriptors from database/file that match + // with the input string 'descriptor' + // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL" + + // Load the selected descriptor + TString path; + if( !filename[0] ) { + path += gSystem->Getenv("ALICE_ROOT"); + path += fgkDescriptorFileName; + } + else + path += filename; + + if( gSystem->AccessPathName( path.Data() ) ) { + AliErrorGeneral( "AliTriggerDescriptor", Form( "file (%s) not found", path.Data() ) ); + return NULL; + } + + TFile file( path.Data(), "READ" ); + AliTriggerDescriptor* des = (AliTriggerDescriptor*)(file.Get( descriptor.Data() )); + + file.Close(); + + return des; +} + +//_____________________________________________________________________________ +TObjArray* AliTriggerDescriptor::GetAvailableDescriptors( const char* filename ) +{ + // Return an array of descriptor in the file + + TString path; + if( !filename[0] ) { + path += gSystem->Getenv( "ALICE_ROOT" ); + path += fgkDescriptorFileName; + } + else + path += filename; + + if( gSystem->AccessPathName( path.Data() ) ) { + AliErrorGeneral( "AliTriggerDescriptor", Form( "file (%s) not found", path.Data() ) ); + return NULL; + } + + TObjArray* desArray = new TObjArray(); + + TFile file( path.Data(), "READ" ); + if( file.IsZombie() ) { + AliErrorGeneral( "AliTriggerDescriptor", Form( "Error opening file (%s)", path.Data() ) ); + return NULL; + } + + file.ReadAll(); + + TKey* key; + TIter next( file.GetListOfKeys() ); + while( (key = (TKey*)next()) ) { + TObject* obj = key->ReadObj(); + if( obj->InheritsFrom( "AliTriggerDescriptor" ) ) { + desArray->AddLast( obj ); + } + } + file.Close(); + + return desArray; +} + +//_____________________________________________________________________________ +void AliTriggerDescriptor::WriteDescriptor( const char* filename ) +{ + // Load one pre-created Descriptors from database/file that match + // with the input string 'descriptor' + // Ej: "Pb-Pb" or "p-p-DIMUON CALIBRATION-CENTRAL-BARREL" + + // Load the selected descriptor + TString path; + if( !filename[0] ) { + path += gSystem->Getenv("ALICE_ROOT"); + path += fgkDescriptorFileName; + } + else + path += filename; + + TFile file( path.Data(), "UPDATE" ); + if( file.IsZombie() ) { + AliErrorGeneral( "AliTriggerDescriptor", + Form( "Can't open file (%s)", path.Data() ) ); + return; + } + + Bool_t result = (Write( GetName(), TObject::kOverwrite ) != 0); + if( !result ) + AliErrorGeneral( "AliTriggerDescriptor", + Form( "Can't write entry to file <%s>!", path.Data() ) ); + file.Close(); +} + + + + +//_____________________________________________________________________________ +Bool_t AliTriggerDescriptor::CheckInputsConditions( TString& configfile ) +{ + // To be used on the pre-creation of Descriptors to check if the + // conditions have valid inputs names. + // + // Initiate detectors modules from a Config file + // Ask to each active module present in the fDetectorCluster + // to create a Trigger detector and retrive the inputs from it + // to create a list of inputs. + // Each condition in the descriptor is then checked agains + // the list of inputs + + + if (!gAlice) { + AliError( "no gAlice object. Restart aliroot and try again." ); + return kFALSE; + } + if (gAlice->Modules()->GetEntries() > 0) { + AliError( "gAlice was already run. Restart aliroot and try again." ); + return kFALSE; + } + + AliInfo( Form( "initializing gAlice with config file %s", + configfile.Data() ) ); + StdoutToAliInfo( StderrToAliError( + gAlice->Init( configfile.Data() ); + );); + + AliRunLoader* runLoader = gAlice->GetRunLoader(); + if( !runLoader ) { + AliError( Form( "gAlice has no run loader object. " + "Check your config file: %s", configfile.Data() ) ); + return kFALSE; + } + + // get the possible inputs to check the condition + TObjArray inputs; + TObjArray* detArray = runLoader->GetAliRun()->Detectors(); + + TString detStr = fDetectorCluster; + for( Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++ ) { + AliModule* det = (AliModule*) detArray->At(iDet); + if( !det || !det->IsActive() ) continue; + if( IsSelected( det->GetName(), detStr ) ) { + AliInfo( Form( "Creating inputs for %s", det->GetName() ) ); + AliTriggerDetector* dtrg = det->CreateTriggerDetector(); + dtrg->CreateInputs(); + TObjArray* detInp = dtrg->GetInputs(); + for( Int_t i=0; iGetEntriesFast(); i++ ) { + AliInfo( Form( "Adding input %s", ((AliTriggerInput*)detInp->At(i))->GetName() ) ); + inputs.AddLast( detInp->At(i) ); + } + } + } + + // check if the condition is compatible with the triggers inputs + Int_t ncond = fConditions.GetEntriesFast(); + for( Int_t j=0; jCheckInputs( inputs )) ) return kFALSE; + } + + return kTRUE; +} + + +//_____________________________________________________________________________ +void AliTriggerDescriptor::Print( const Option_t* ) const +{ + // Print + cout << "Trigger Descriptor:" << endl; + cout << " Name: " << GetName() << endl; + cout << " Description: " << GetTitle() << endl; + cout << " Detector Cluster: " << fDetectorCluster << endl; + +// Int_t ninputs = fInputs->GetEntriesFast(); +// for( Int_t i=0; iAt(i) +// in->Print(); +// } + + Int_t ncond = fConditions.GetEntriesFast(); + for( Int_t i=0; iPrint(); + } + cout << endl; +} + + +////////////////////////////////////////////////////////////////////////////// +// Helper method + +//_____________________________________________________________________________ +Bool_t AliTriggerDescriptor::IsSelected( TString detName, TString& detectors ) const +{ + // check whether detName is contained in detectors + // if yes, it is removed from detectors + + // check if all detectors are selected + if( (detectors.CompareTo("ALL") == 0 ) || + detectors.BeginsWith("ALL ") || + detectors.EndsWith(" ALL") || + detectors.Contains(" ALL ") ) { + detectors = "ALL"; + return kTRUE; + } + + // search for the given detector + Bool_t result = kFALSE; + if( (detectors.CompareTo( detName ) == 0) || + detectors.BeginsWith( detName+" " ) || + detectors.EndsWith( " "+detName ) || + detectors.Contains( " "+detName+" " ) ) { + detectors.ReplaceAll( detName, "" ); + result = kTRUE; + } + + // clean up the detectors string + while( detectors.Contains(" ") ) detectors.ReplaceAll( " ", " " ); + while( detectors.BeginsWith(" ") ) detectors.Remove( 0, 1 ); + while( detectors.EndsWith(" ") ) detectors.Remove( detectors.Length()-1, 1 ); + + return result; +} diff --git a/STEER/AliTriggerDescriptor.h b/STEER/AliTriggerDescriptor.h new file mode 100644 index 00000000000..824ac92fe75 --- /dev/null +++ b/STEER/AliTriggerDescriptor.h @@ -0,0 +1,69 @@ +#ifndef ALITRIGGERDESCRIPTOR_H +#define ALITRIGGERDESCRIPTOR_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// This class for running a Trigger Descriptor // +// // +// // +// A Trigger Descriptor define a trigger setup for specific runnign +// condition (Pb-Pb, p-p, p-A, Calibration, etc). +// It keep: +// - cluster detector (List of detectors involved) +// - List of conditions +// // +// // +/////////////////////////////////////////////////////////////////////////////// + +class TNamed; + +class TString; +class TObjArray; +class AliRunLoader; + +class AliTriggerDescriptor : public TNamed { + +public: + AliTriggerDescriptor(); + AliTriggerDescriptor( TString & name, TString & description ); + AliTriggerDescriptor( const AliTriggerDescriptor& des ); + virtual ~AliTriggerDescriptor() { fConditions.SetOwner(); fConditions.Delete(); } + // Setters + Bool_t AddDetectorCluster( TString & cluster ); + void AddCondition( TString & cond, TString & name, + TString & description, Long_t mask ); + void AddCondition( AliTriggerCondition* cond ) { fConditions.AddLast( cond ); } + // Getters + TString GetDetectorCluster() const { return fDetectorCluster; } + TObjArray* GetTriggerConditions() { return &fConditions; } + Bool_t CheckInputsConditions( TString & configfile ); + void Print( const Option_t* opt ="" ) const; + // Descriptors Database (root file) + void WriteDescriptor( const char* filename="" ); + static TObjArray* GetAvailableDescriptors( const char* filename="" ); + static + AliTriggerDescriptor* LoadDescriptor( TString & des, const char* filename="" ); + //TODO static Bool_t RemoveDescriptor( AliTriggerDescriptor* descriptor, const char* filename="" ); + //TODO static Bool_t RemoveDescriptor( TString* descriptor, const char* filename="" ); + +protected: + // TString fRunCondition; // Running modes Ej. Pb-Pb, p-p, p-A + TString fDetectorCluster; // Array of Detector Trigger + TObjArray fConditions; // Array of Trigger Condition (AliTriggerCondition) + + static const Int_t fgkNDetectors = 9; //! number possible trigger detectors + static const char* fgkDetectorName[fgkNDetectors]; //! names of detectors + +private: + Bool_t IsSelected( TString detName, TString & detectors ) const; + static const TString fgkDescriptorFileName; //! name of default descriptors file + + ClassDef( AliTriggerDescriptor, 1 ) // Define a trigger descriptor +}; + +#endif diff --git a/STEER/AliTriggerDetector.cxx b/STEER/AliTriggerDetector.cxx new file mode 100644 index 00000000000..3f02d7d4144 --- /dev/null +++ b/STEER/AliTriggerDetector.cxx @@ -0,0 +1,135 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// Base Class for Detector specific Trigger // // +// // +// // +// // +// // +// // +/////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include + + +#include "AliLog.h" +#include "AliRun.h" +#include "AliRunLoader.h" + +#include "AliTriggerInput.h" +#include "AliTriggerDetector.h" + + + +ClassImp( AliTriggerDetector ) + +//_____________________________________________________________________________ +AliTriggerDetector::AliTriggerDetector() : TNamed() +{ + // Default constructor + fMask = 0; +} + +//_____________________________________________________________________________ +void AliTriggerDetector::CreateInputs() +{ + // Define the inputs to the Central Trigger Processor + // This is a dummy version + + // Do not create inputs again!! + if( fInputs.GetEntriesFast() > 0 ) return; + + TString name = GetName(); + fInputs.AddLast( new AliTriggerInput( name+"_TEST1_L0", "Dummy input 1", 0x01 ) ); + fInputs.AddLast( new AliTriggerInput( name+"_TEST2_L0", "Dummy input 2", 0x02 ) ); + fInputs.AddLast( new AliTriggerInput( name+"_TEST3_L0", "Dummy input 3", 0x04 ) ); +} + +//_____________________________________________________________________________ +void AliTriggerDetector::Trigger() +{ + // This is a dummy version set all inputs in a random way + + AliWarning( Form( "Triggering dummy detector %s", GetName() ) ); + + // ********** Get Digits for the current event ********** + AliRunLoader* runLoader = gAlice->GetRunLoader(); + AliInfo( Form( "Event %d", runLoader->GetEventNumber() ) ); + + TString loadername = GetName(); + loadername.Append( "Loader" ); + AliLoader * loader = runLoader->GetLoader( loadername.Data() ); + if( loader ) { + loader->LoadDigits( "READ" ); + TTree* digits = loader->TreeD(); + // Do something with the digits !!! + if( digits ) { +// digits->Print(); + } + loader->UnloadDigits(); + } + // ****************************************************** + + // set all inputs in a random way + Int_t nInputs = fInputs.GetEntriesFast(); + for( Int_t j=0; jRndm() > 0.5 ) { + in->Set(); + fMask |= in->GetValue(); + } + } +} + +//_____________________________________________________________________________ +void AliTriggerDetector::SetInput( TString& name ) +{ + // Set Input by name + AliTriggerInput* in = ((AliTriggerInput*)fInputs.FindObject( name.Data() )); + in->Set(); + fMask |= in->GetValue(); +} + +//_____________________________________________________________________________ +void AliTriggerDetector::SetInput( const char * name ) +{ + // Set Input by name + AliTriggerInput* in = ((AliTriggerInput*)fInputs.FindObject( name )); + in->Set(); + fMask |= in->GetValue(); +} + +//_____________________________________________________________________________ +void AliTriggerDetector::SetInput( Int_t mask ) +{ + // Set Input by mask + Int_t nInputs = fInputs.GetEntriesFast(); + for( Int_t j=0; jGetMask() == mask ) { + in->Set(); + fMask |= in->GetValue(); + break; + } + } +} + diff --git a/STEER/AliTriggerDetector.h b/STEER/AliTriggerDetector.h new file mode 100644 index 00000000000..77ec3d659c1 --- /dev/null +++ b/STEER/AliTriggerDetector.h @@ -0,0 +1,51 @@ +#ifndef ALITRIGGERDETECTOR_H +#define ALITRIGGERDETECTOR_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// Base Class for Detector specific Trigger // // +// // +/////////////////////////////////////////////////////////////////////////////// + +#include +class TNamed; +class TString; +class AliTriggerInput; + + +class AliTriggerDetector : public TNamed { + +public: + AliTriggerDetector(); + virtual ~AliTriggerDetector() { fInputs.SetOwner(); fInputs.Delete(); } + + virtual void CreateInputs(); + virtual void Trigger(); + // Setters + void AddInput( TObject * input ) { fInputs.AddLast( input ); } + void SetInput( TString & name ); + void SetInput( const char * name ); + void SetInput( Int_t mask ); + // Getters + TObjArray* GetInputs() { return &fInputs; } + Long_t GetMask() const { return fMask; } + + AliTriggerInput* GetInput( TString & name ) { + return ((AliTriggerInput*)fInputs.FindObject( name.Data() )); + } + AliTriggerInput* GetInput( const char * name ) { + return ((AliTriggerInput*)fInputs.FindObject( name )); + } +protected: + Long_t fMask; // Trigger Mask ( bitwise OR of trigger inputs ) + TObjArray fInputs; // Array of Triggers Inputs (AliTriggerInput class) + + ClassDef( AliTriggerDetector, 1 ) // Base Class for Detector specific Trigger +}; + +#endif diff --git a/STEER/AliTriggerInput.cxx b/STEER/AliTriggerInput.cxx new file mode 100644 index 00000000000..abe9e2ef39e --- /dev/null +++ b/STEER/AliTriggerInput.cxx @@ -0,0 +1,52 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// +// Class to define a Trigger Input from an specific detector // +// +// +// name description id mask +// Ej: +// AliTriggerInput( "V0_MB_L0", "VO minimum bias", 0x01 ); +// AliTriggerInput( "V0_SC_L0", "VO semi central", 0x02 ); +// AliTriggerInput( "V0_C_L0", "VO central", 0x04 ); +// +// The name must be globaly unique. Spaces are not allowed. +// As convention should start with detector name then an id +// and the trigger level (L0, L1, L2) +// +// A maximun of 60 inputs trigger are allow. +// So, the id mask should set only bit from the position 1 to 60. +// +/////////////////////////////////////////////////////////////////////////////// + +#include + +#include "AliTriggerInput.h" + +ClassImp( AliTriggerInput ) + +//_____________________________________________________________________________ +void AliTriggerInput::Print( const Option_t* ) const +{ + // Print + cout << "Trigger Input:" << endl; + cout << " Name: " << GetName() << endl; + cout << " Description: " << GetTitle() << endl; + cout << " Value: " << hex << fValue << dec << endl; +} diff --git a/STEER/AliTriggerInput.h b/STEER/AliTriggerInput.h new file mode 100644 index 00000000000..78046c28648 --- /dev/null +++ b/STEER/AliTriggerInput.h @@ -0,0 +1,64 @@ +#ifndef ALITRIGGERINPUT_H +#define ALITRIGGERINPUT_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// +// Class to define a Trigger Input from an specific detector // +// +// +// name description id mask +// Ej: +// AliTriggerInput( "V0_MB_L0", "VO minimum bias", 0x01 ); +// AliTriggerInput( "V0_SC_L0", "VO semi central", 0x02 ); +// AliTriggerInput( "V0_C_L0", "VO central", 0x04 ); + +// The name must be globaly unique. Spaces are not allowed. +// As convention should start with detector name then an id +// and the trigger level (L0, L1, L2) +// +// A maximun of 60 inputs trigger are allow. +// So, the id mask should set only bit from the position 1 to 60. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef ROOT_TNamed +#include +#endif + +class AliTriggerInput : public TNamed { + +public: + AliTriggerInput() {} + AliTriggerInput( TString name, TString description, Long_t mask ) + : TNamed( name.Data(), description.Data() ), + fMask( mask ), + fValue( 0 ) {} + virtual ~AliTriggerInput() {} + + // Setters + virtual void Set() { fValue = fMask; } + virtual void Reset() { fValue = 0; } + + // Getters + Bool_t Status() const { return (Bool_t)fValue; } + Long_t GetValue() const { return fValue; } + Int_t GetMask() const { return fMask; } + // ULong_t Hash() const { return TMath::Hash( GetName().Data() ); }; + + virtual void Print( const Option_t* opt ="" ) const; + +protected: + Long_t fMask; // Trigger ID mask (1 bit) + Long_t fValue; // Trigger Signal (0 = false, > 1 = true = fMask ) + // Int_t fLevel; // Trigger Level (L0, L1, L2) + + ClassDef( AliTriggerInput, 1 ) // Define a Trigger Input +}; + + +#endif diff --git a/STEER/STEERLinkDef.h b/STEER/STEERLinkDef.h index f9f329544ce..fbbc2f25338 100644 --- a/STEER/STEERLinkDef.h +++ b/STEER/STEERLinkDef.h @@ -109,4 +109,12 @@ #pragma link C++ class TTreeSRedirector+; #pragma link C++ class AliRieman; + +#pragma link C++ class AliExpression+; +#pragma link C++ class AliVariableExpression+; +#pragma link C++ class AliTriggerInput+; +#pragma link C++ class AliTriggerDetector+; +#pragma link C++ class AliTriggerCondition+; +#pragma link C++ class AliTriggerDescriptor+; +#pragma link C++ class AliCentralTrigger+; #endif diff --git a/STEER/libSTEER.pkg b/STEER/libSTEER.pkg index 027722cb6dd..5c5f6ad033c 100644 --- a/STEER/libSTEER.pkg +++ b/STEER/libSTEER.pkg @@ -27,7 +27,13 @@ AliAlignObj.cxx AliAlignObjAngles.cxx AliAlignObjMatrix.cxx \ AliRieman.cxx\ AliTrackFitter.cxx AliTrackFitterRieman.cxx\ AliTrackResiduals.cxx AliTrackResidualsChi2.cxx\ -AliAlignmentTracks.cxx +AliAlignmentTracks.cxx \ +AliExpression.cxx \ +AliTriggerInput.cxx \ +AliTriggerDetector.cxx \ +AliTriggerCondition.cxx \ +AliTriggerDescriptor.cxx \ +AliCentralTrigger.cxx HDRS:= $(SRCS:.cxx=.h)