]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/STEER/AliTriggerUtils.cxx
Added possibility to monitor performance in simulation with respect to geometry and...
[u/mrichter/AliRoot.git] / STEER / STEER / AliTriggerUtils.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 #include "AliTriggerUtils.h"
17 #include "AliTriggerConfiguration.h"
18 #include "AliTriggerClass.h"
19 #include "AliTriggerInput.h"
20 #include "AliRun.h"
21 #include "AliRunLoader.h"
22 #include "AliCDBManager.h"
23 #include "AliPDG.h"
24 #include "AliMC.h"
25 #include "AliModule.h"
26 #include "AliLog.h"
27 #include <TROOT.h>
28 #include <TInterpreter.h>
29 #include <TString.h>
30
31 ClassImp(AliTriggerUtils)
32
33 //_____________________________________________________________________________
34 Bool_t AliTriggerUtils::CheckConfiguration( TString& configfile, AliTriggerConfiguration * cfg )
35 {
36    // To be used on the pre-creation of Configurations to check if the
37    // conditions have valid inputs names.
38    //
39    // Initiate detectors modules from a Config file
40    // Ask to each active module present in the fDetectorCluster
41    // to create a Trigger detector and retrive the inputs from it
42    // to create a list of inputs.
43    // Each condition in the configuration is then checked agains 
44    // the list of inputs
45
46
47    if (!gAlice) {
48       AliError( "no gAlice object. Restart aliroot and try again." );
49       return kFALSE;
50    }
51    if (gAlice->Modules()->GetEntries() > 0) {
52       AliError( "gAlice was already run. Restart aliroot and try again." );
53       return kFALSE;
54    }
55
56    AliInfo( Form( "initializing gAlice with config file %s",
57             configfile.Data() ) );
58 //_______________________________________________________________________
59    gAlice->Announce();
60    
61    gROOT->LoadMacro(configfile.Data());
62    gInterpreter->ProcessLine(gAlice->GetConfigFunction());
63    
64    if(AliCDBManager::Instance()->GetRun() >= 0) { 
65      AliRunLoader::Instance()->SetRunNumber(AliCDBManager::Instance()->GetRun());
66    } else {
67      AliWarning("Run number not initialized!!");
68    }
69   
70    AliRunLoader::Instance()->CdGAFile();
71     
72    AliPDG::AddParticlesToPdgDataBase();  
73
74    gAlice->GetMCApp()->Init();
75    
76    //Must be here because some MCs (G4) adds detectors here and not in Config.C
77    gAlice->InitLoaders();
78    AliRunLoader::Instance()->MakeTree("E");
79    AliRunLoader::Instance()->LoadKinematics("RECREATE");
80    AliRunLoader::Instance()->LoadTrackRefs("RECREATE");
81    AliRunLoader::Instance()->LoadHits("all","RECREATE");
82    //
83    // Save stuff at the beginning of the file to avoid file corruption
84    AliRunLoader::Instance()->CdGAFile();
85    gAlice->Write();
86
87    AliRunLoader* runLoader = AliRunLoader::Instance();
88    if( !runLoader ) {
89       AliError( Form( "gAlice has no run loader object. "
90                       "Check your config file: %s", configfile.Data() ) );
91       return kFALSE;
92    }
93
94    // get the possible inputs to check the condition
95    TObjArray inputs;
96    TObjArray* detArray = runLoader->GetAliRun()->Detectors();
97
98    TString detStr = cfg->GetTriggeringModules();
99
100    for( Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++ ) {
101       AliModule* det = (AliModule*) detArray->At(iDet);
102       if( !det || !det->IsActive() ) continue;
103       if( cfg->IsSelected( det->GetName(), detStr ) ) {
104          AliInfo( Form( "Creating inputs for %s", det->GetName() ) );
105          AliTriggerDetector* dtrg = det->CreateTriggerDetector();
106          dtrg->AssignInputs(cfg->GetInputs());
107          TObjArray* detInp = dtrg->GetInputs();
108          for( Int_t i=0; i<detInp->GetEntriesFast(); i++ ) {
109             AliInfo( Form( "Adding input %s", ((AliTriggerInput*)detInp->At(i))->GetName() ) );
110             inputs.AddLast( detInp->At(i) );
111          }
112       }
113    }
114
115    // check if the condition is compatible with the triggers inputs
116    Int_t ndesc = cfg->GetClasses().GetEntriesFast();
117    Bool_t check = kTRUE;
118    ULong64_t mask = 0L;
119    for( Int_t j=0; j<ndesc; j++ ) {
120      AliTriggerClass *trclass = (AliTriggerClass*)cfg->GetClasses().At( j );
121      if( !(trclass->CheckClass( cfg )) ) check = kFALSE;
122      else {
123        if (trclass->IsActive(cfg->GetInputs(),cfg->GetFunctions())) {
124          AliInfo( Form( "Trigger Class (%s) OK, class mask (0x%llx)",
125                         trclass->GetName(), trclass->GetMask( ) ) );
126        }
127        else {
128          AliWarning( Form( "Trigger Class (%s) is NOT active, class mask (0x%llx)",
129                            trclass->GetName(), trclass->GetMask( ) ) );
130        }
131      }
132      // check if condition mask is duplicated
133      if( mask & trclass->GetMask() ) {
134        AliError( Form("Class (%s). The class mask (0x%llx) is ambiguous. It was already defined",
135                       trclass->GetName(), trclass->GetMask()  ) );
136        check = kFALSE;
137      }
138      mask |= trclass->GetMask();
139    }
140
141    return check;
142 }