]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/macros/FindHLTTriggeredEvents.C
Adding macro to find HLT triggered events in raw data.
[u/mrichter/AliRoot.git] / HLT / trigger / macros / FindHLTTriggeredEvents.C
1 /**************************************************************************
2  * This file is property of and copyright by the ALICE HLT Project        *
3  * All rights reserved.                                                   *
4  *                                                                        *
5  * Primary Authors:                                                       *
6  *   Artur Szostak <artursz@iafrica.com>                                  *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17 // $Id: $
18
19 /**
20  * \ingroup macros
21  * \file FindHLTTriggeredEvents.C
22  * \brief Macro for finding event numbers of HLT triggered events.
23  *
24  * This macro is used to generate or print a list of event numbers which had
25  * a positive HLT trigger decision.
26  *
27  * The simplest way to run this macro with defaults (which will process any raw
28  * data in the current directory) is to run the following command from a terminal
29  * shell:
30  * \code
31  *   > aliroot -b -q $ALICE_ROOT/HLT/trigger/macros/FindHLTTriggeredEvents.C
32  * \endcode
33  *
34  * \author Artur Szostak <artursz@iafrica.com>
35  */
36
37 #if !defined(__CINT__) || defined(__MAKECINT__)
38 #include "AliRawReader.h"
39 #include "AliHLTPluginBase.h"
40 #include "AliHLTOUT.h"
41 #include "AliHLTSystem.h"
42 #include "AliHLTComponent.h"
43 #include "AliHLTGlobalTriggerDecision.h"
44 #include "AliLog.h"
45 #include "TSystem.h"
46 #include "TString.h"
47 #include "TFile.h"
48 #include "Riostream.h"
49 #endif
50
51 /**
52  * Finds all the events in raw data that contains a positive HLT decision.
53  *
54  * [in] \param dataSource  This is the path to the raw data or the ROOT/DATE file
55  *     contining the raw data.
56  * [out] \param events  The output list that will be filled with event numbers of
57  *     the events that were triggered by HLT for the given data source.
58  * [in] \param triggerCode  The HLT trigger code to search for. These must be the same as
59  *     the codes defined in the HLT trigger menu used for producing the data source. If
60  *     this parameter is set to NULL then all HLT triggered events are marked. (default NULL)
61  * [in] \param firstEvent  The event number of the first event to process. (default = 0)
62  * [in] \param lastEvent  The event number of the last event to process. If this is
63  *     less than firstEvent then the maximum events available in the data are
64  *     processed automatically. (default = -1)
65  * [in] \param print  Indicates if the found event information should be printed or not.
66  * \returns true if there were no problems accessing the data and false otherwise.
67  */
68 bool FindHLTTriggeredEvents(
69                 const char* dataSource,
70                 TArrayI& events,
71                 const char* triggerCode = NULL,
72                 Int_t firstEvent = 0,
73                 Int_t lastEvent = -1,
74                 bool print = true
75         )
76 {
77         gSystem->Load("libHLTrec.so");
78         // FIXME: Loading the following libraries is a workaround to get rid of warnings from AliHLTOUT.
79         gSystem->Load("libANALYSIS.so");
80         gSystem->Load("libANALYSISalice.so");
81         gSystem->Load("libAliHLTUtil.so");
82         gSystem->Load("libAliHLTTRD.so");
83         gSystem->Load("libAliHLTMUON.so");
84         gSystem->Load("libAliHLTTrigger.so");
85         
86         // Setup the raw reader and HLTOUT handler.
87         AliRawReader* rawReader = AliRawReader::Create(dataSource);
88         if (rawReader == NULL)
89         {
90                 cerr << "ERROR: Could not create raw reader for '" << dataSource << "'." << endl;
91                 return false;
92         }
93         if (! rawReader->IsRawReaderValid())
94         {
95                 cerr << "ERROR: Raw reader is not valid for '" << dataSource << "'." << endl;
96                 delete rawReader;
97                 return false;
98         }
99         AliHLTOUT* hltout = AliHLTOUT::New(rawReader);
100         if (hltout == NULL)
101         {
102                 cerr << "ERROR: Could not create an AliHLTOUT object for '" << dataSource << "'." << endl;
103                 delete rawReader;
104                 return false;
105         }
106         
107         // Check if we need to process all events or not.
108         if (lastEvent < firstEvent) lastEvent = 0x7FFFFFFF;
109         
110         bool decodingOK = true;
111         
112         // Now step through the events.
113         for (Int_t currentEvent = firstEvent, eventLoopResult = rawReader->GotoEvent(firstEvent);
114              currentEvent <= lastEvent && eventLoopResult == kTRUE;
115              ++currentEvent, eventLoopResult = rawReader->NextEvent()
116             )
117         {
118                 int result = hltout->Init();
119                 if (result != 0)
120                 {
121                         cerr << "ERROR: could not initialise HLTOUT. Moving to next event." << endl;
122                         hltout->Reset();
123                         decodingOK = false;
124                         continue;
125                 }
126                 
127                 // Go through all the data blocks, looking for the HLT global trigger object.
128                 for (result = hltout->SelectFirstDataBlock(kAliHLTDataTypeGlobalTrigger);
129                      result >= 0;
130                      result = hltout->SelectNextDataBlock()
131                     )
132                 {
133                         TObject* obj = hltout->GetDataObject();
134                         if (obj == NULL) continue;
135                         if (obj->IsA()->GetBaseClass("AliHLTGlobalTriggerDecision") != NULL)
136                         {
137                                 AliHLTGlobalTriggerDecision* decision = (AliHLTGlobalTriggerDecision*)obj;
138                                 bool hltTriggered = false;
139                                 if (triggerCode != NULL)
140                                 {
141                                         hltTriggered = TString(decision->Description()).Contains(triggerCode);
142                                 }
143                                 else
144                                 {
145                                         hltTriggered = decision->Result();
146                                 }
147                                 if (hltTriggered)
148                                 {
149                                         if (print)
150                                         {
151                                                 cout << "Event " << currentEvent << " in " << dataSource
152                                                         << " with event ID = " << hltout->EventId()
153                                                         << " (0x" << hex << hltout->EventId() << dec << ")"
154                                                         << " was triggered by HLT with \""
155                                                         << (triggerCode != NULL ? triggerCode : decision->Description())
156                                                         << "\"." << endl;
157                                         }
158                                         events.Set(events.GetSize()+1);
159                                         events[events.GetSize()-1] = currentEvent;
160                                 }
161                         }
162                         hltout->ReleaseDataObject(obj);
163                 }
164                 
165                 result = hltout->Reset();
166                 if (result != 0)
167                 {
168                         cerr << "ERROR: could not reset HLTOUT properly." << endl;
169                         decodingOK = false;
170                         continue;
171                 }
172         }
173         
174         AliHLTOUT::Delete(hltout);
175         delete rawReader;
176         return decodingOK;
177 }
178
179
180 bool FindHLTTriggeredEvents(const char* dataSource = "./")
181 {
182         TArrayI events;
183         return FindHLTTriggeredEvents(dataSource, events, NULL, 0, -1, true);
184 }