]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/trigger/macros/FindHLTTriggeredEvents.C
Fixes for coverity
[u/mrichter/AliRoot.git] / HLT / trigger / macros / FindHLTTriggeredEvents.C
CommitLineData
2955f91e 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 *
9d7d3923 34 * It is also possible to use as input a file or a chunk sitting on the GRID.
35 * \code
36 * > aliroot -b -q $ALICE_ROOT/HLT/trigger/macros/FindHLTTriggeredEvents.C'("alien:///alice/data/2010/LHC10h/000137124/raw/10000137124054.10.root")'
37 * > aliroot -b -q $ALICE_ROOT/HLT/trigger/macros/FindHLTTriggeredEvents.C'("raw://run137124")'
2955f91e 38 * \author Artur Szostak <artursz@iafrica.com>
39 */
40
41#if !defined(__CINT__) || defined(__MAKECINT__)
42#include "AliRawReader.h"
43#include "AliHLTPluginBase.h"
44#include "AliHLTOUT.h"
45#include "AliHLTSystem.h"
46#include "AliHLTComponent.h"
47#include "AliHLTGlobalTriggerDecision.h"
48#include "AliLog.h"
49#include "TSystem.h"
50#include "TString.h"
51#include "TFile.h"
52#include "Riostream.h"
53#endif
54
55/**
56 * Finds all the events in raw data that contains a positive HLT decision.
57 *
58 * [in] \param dataSource This is the path to the raw data or the ROOT/DATE file
59 * contining the raw data.
60 * [out] \param events The output list that will be filled with event numbers of
61 * the events that were triggered by HLT for the given data source.
62 * [in] \param triggerCode The HLT trigger code to search for. These must be the same as
63 * the codes defined in the HLT trigger menu used for producing the data source. If
64 * this parameter is set to NULL then all HLT triggered events are marked. (default NULL)
65 * [in] \param firstEvent The event number of the first event to process. (default = 0)
66 * [in] \param lastEvent The event number of the last event to process. If this is
67 * less than firstEvent then the maximum events available in the data are
68 * processed automatically. (default = -1)
69 * [in] \param print Indicates if the found event information should be printed or not.
70 * \returns true if there were no problems accessing the data and false otherwise.
71 */
72bool FindHLTTriggeredEvents(
73 const char* dataSource,
74 TArrayI& events,
75 const char* triggerCode = NULL,
76 Int_t firstEvent = 0,
77 Int_t lastEvent = -1,
78 bool print = true
79 )
80{
81 gSystem->Load("libHLTrec.so");
82 // FIXME: Loading the following libraries is a workaround to get rid of warnings from AliHLTOUT.
83 gSystem->Load("libANALYSIS.so");
84 gSystem->Load("libANALYSISalice.so");
85 gSystem->Load("libAliHLTUtil.so");
86 gSystem->Load("libAliHLTTRD.so");
87 gSystem->Load("libAliHLTMUON.so");
88 gSystem->Load("libAliHLTTrigger.so");
89
9d7d3923 90 TString strfile = dataSource;
91 if(strfile.BeginsWith("alien://") || strfile.BeginsWith("raw://")) TGrid::Connect("alien");
92
2955f91e 93 // Setup the raw reader and HLTOUT handler.
94 AliRawReader* rawReader = AliRawReader::Create(dataSource);
95 if (rawReader == NULL)
96 {
97 cerr << "ERROR: Could not create raw reader for '" << dataSource << "'." << endl;
98 return false;
99 }
100 if (! rawReader->IsRawReaderValid())
101 {
102 cerr << "ERROR: Raw reader is not valid for '" << dataSource << "'." << endl;
103 delete rawReader;
104 return false;
105 }
106 AliHLTOUT* hltout = AliHLTOUT::New(rawReader);
107 if (hltout == NULL)
108 {
109 cerr << "ERROR: Could not create an AliHLTOUT object for '" << dataSource << "'." << endl;
110 delete rawReader;
111 return false;
112 }
113
114 // Check if we need to process all events or not.
115 if (lastEvent < firstEvent) lastEvent = 0x7FFFFFFF;
116
117 bool decodingOK = true;
118
119 // Now step through the events.
120 for (Int_t currentEvent = firstEvent, eventLoopResult = rawReader->GotoEvent(firstEvent);
121 currentEvent <= lastEvent && eventLoopResult == kTRUE;
122 ++currentEvent, eventLoopResult = rawReader->NextEvent()
123 )
124 {
125 int result = hltout->Init();
126 if (result != 0)
127 {
128 cerr << "ERROR: could not initialise HLTOUT. Moving to next event." << endl;
129 hltout->Reset();
130 decodingOK = false;
131 continue;
132 }
133
134 // Go through all the data blocks, looking for the HLT global trigger object.
135 for (result = hltout->SelectFirstDataBlock(kAliHLTDataTypeGlobalTrigger);
136 result >= 0;
137 result = hltout->SelectNextDataBlock()
138 )
139 {
140 TObject* obj = hltout->GetDataObject();
141 if (obj == NULL) continue;
142 if (obj->IsA()->GetBaseClass("AliHLTGlobalTriggerDecision") != NULL)
143 {
144 AliHLTGlobalTriggerDecision* decision = (AliHLTGlobalTriggerDecision*)obj;
145 bool hltTriggered = false;
146 if (triggerCode != NULL)
147 {
148 hltTriggered = TString(decision->Description()).Contains(triggerCode);
149 }
150 else
151 {
152 hltTriggered = decision->Result();
153 }
154 if (hltTriggered)
155 {
156 if (print)
157 {
158 cout << "Event " << currentEvent << " in " << dataSource
159 << " with event ID = " << hltout->EventId()
160 << " (0x" << hex << hltout->EventId() << dec << ")"
161 << " was triggered by HLT with \""
162 << (triggerCode != NULL ? triggerCode : decision->Description())
163 << "\"." << endl;
164 }
165 events.Set(events.GetSize()+1);
166 events[events.GetSize()-1] = currentEvent;
167 }
168 }
169 hltout->ReleaseDataObject(obj);
170 }
171
172 result = hltout->Reset();
173 if (result != 0)
174 {
175 cerr << "ERROR: could not reset HLTOUT properly." << endl;
176 decodingOK = false;
177 continue;
178 }
179 }
180
181 AliHLTOUT::Delete(hltout);
182 delete rawReader;
183 return decodingOK;
184}
185
186
187bool FindHLTTriggeredEvents(const char* dataSource = "./")
188{
189 TArrayI events;
190 return FindHLTTriggeredEvents(dataSource, events, NULL, 0, -1, true);
191}