]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG/muon/TriggerInputsForMuonEventCuts.C
expand particle map when needed
[u/mrichter/AliRoot.git] / PWG / muon / TriggerInputsForMuonEventCuts.C
CommitLineData
183864a0 1#if !defined(__CINT__) || defined(__MAKECINT__)
2
3// ROOT includes
4#include "Riostream.h"
5#include "TString.h"
6#include "TObjArray.h"
7#include "TObjString.h"
8#include "THashList.h"
9#include "TArrayI.h"
10#include "TMath.h"
11
12// STEER includes
13#include "AliCDBManager.h"
14#include "AliCDBEntry.h"
15#include "AliTriggerConfiguration.h"
16#include "AliTriggerInput.h"
17#endif
18
19/// This macro reads the CTP configuration in the OCDB
20/// and returns the trigger inputs for the requested run list.
21/// The output is in a format that suits the AliMuonEventCuts class
22///
23/// The file with the input run list must contain one run number per line
24/// If the user is interested only in a subset of inputs,
25/// he/she can specify them in selectedInputs, separated by commas
26/// e.g "0MSL,0MSH,0MUL,0MLL"
27///
28/// author: Diego Stocco, Subatech, Nantes
29
30void TriggerInputsForMuonEventCuts ( TString runListFilename, TString selectedInputs="", TString defaultStorage = "raw://" )
31{
32 AliCDBManager::Instance()->SetDefaultStorage(defaultStorage.Data());
33 TObjArray inputsList;
34 inputsList.SetOwner();
35
36 TObjArray* selectedInputsList = selectedInputs.Tokenize(",");
37
38 // Read input run list
39 ifstream inFile(runListFilename.Data());
40 TString srun = "";
41 if ( inFile.is_open() ) {
42 while ( ! inFile.eof() ) {
43 srun.ReadLine(inFile,kFALSE);
44 if ( ! srun.IsDigit() ) continue;
45
46 // For each run, read trigger inputs from OCDB
47 Int_t runNumber = srun.Atoi();
48 AliCDBManager::Instance()->SetRun(runNumber);
49
50 // Get trigger class configuration
51 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/CTP/Config");
52 if ( ! entry ) continue;
53
54 THashList* runInputs = new THashList();
55 runInputs->SetOwner();
56 runInputs->SetUniqueID((UInt_t)runNumber);
57 AliTriggerConfiguration* trigConf = (AliTriggerConfiguration*)entry->GetObject();
58 const TObjArray& trigInputsArray = trigConf->GetInputs();
59 AliTriggerInput* trigInput = 0x0;
60 TIter next(&trigInputsArray);
61 while ( ( trigInput = static_cast<AliTriggerInput*>(next()) ) ) {
62 if ( selectedInputsList->GetEntriesFast() > 0 && ! selectedInputsList->FindObject(trigInput->GetName()) ) continue;
63 Int_t inputId = (Int_t)TMath::Log2(trigInput->GetMask());
64 TObjString* currInput = new TObjString(trigInput->GetName());
65 currInput->SetUniqueID(inputId);
66 runInputs->Add(currInput);
67 }
68 inputsList.Add(runInputs);
69 }
70 inFile.close();
71 }
72 delete selectedInputsList;
73
74 // Loop on the trigger inputs
75 // and group runs with an equal list of inputs
76 Int_t nentries = inputsList.GetEntries();
77 TArrayI checkMask(nentries);
78 checkMask.Reset(1);
79 for ( Int_t irun=0; irun<nentries; irun++ ) {
80 if ( checkMask[irun] == 0 ) continue;
81 THashList* currList = static_cast<THashList*>(inputsList.At(irun));
82 TString runRange = Form("Run range: %u", currList->GetUniqueID());
83 for ( Int_t jrun=irun+1; jrun<nentries; jrun++ ) {
84 if ( checkMask[jrun] == 0 ) continue;
85 THashList* checkList = static_cast<THashList*>(inputsList.At(jrun));
86 Bool_t isDifferent = kFALSE;
87 for ( Int_t itrig=0; itrig<currList->GetEntries(); itrig++ ) {
88 TObjString* currInput = static_cast<TObjString*>(currList->At(itrig));
89 TObject* checkInput = checkList->FindObject(currInput->GetName());
90 if ( ! checkInput || checkInput->GetUniqueID() != currInput->GetUniqueID() ) {
91 isDifferent = kTRUE;
92 break;
93 }
94 } // loop on trigger inputs
95 if ( isDifferent ) continue;
96 checkMask[jrun] = 0;
97 runRange += Form(",%u", checkList->GetUniqueID());
98 } // loop on runs
99
100 TString outString = "\nSetTrigInputsMap(\"";
101 for ( Int_t itrig=0; itrig<currList->GetEntries(); itrig++ ) {
102 TObjString* currInput = static_cast<TObjString*>(currList->At(itrig));
103 outString += Form("%s:%u,",currInput->GetString().Data(), currInput->GetUniqueID());
104 }
105 outString.Append("\");\n");
106 outString.ReplaceAll(",\"","\"");
107 outString += runRange;
108 printf("%s\n", outString.Data());
109 } // loop on runs
110}