1 /**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
6 * Artur Szostak <artursz@iafrica.com> *
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 **************************************************************************/
21 * \file FindHLTTriggeredEvents.C
22 * \brief Macro for finding event numbers of HLT triggered events.
24 * This macro is used to generate or print a list of event numbers which had
25 * a positive HLT trigger decision.
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
31 * > aliroot -b -q $ALICE_ROOT/HLT/trigger/macros/FindHLTTriggeredEvents.C
34 * \author Artur Szostak <artursz@iafrica.com>
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"
48 #include "Riostream.h"
52 * Finds all the events in raw data that contains a positive HLT decision.
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.
68 bool FindHLTTriggeredEvents(
69 const char* dataSource,
71 const char* triggerCode = NULL,
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");
86 // Setup the raw reader and HLTOUT handler.
87 AliRawReader* rawReader = AliRawReader::Create(dataSource);
88 if (rawReader == NULL)
90 cerr << "ERROR: Could not create raw reader for '" << dataSource << "'." << endl;
93 if (! rawReader->IsRawReaderValid())
95 cerr << "ERROR: Raw reader is not valid for '" << dataSource << "'." << endl;
99 AliHLTOUT* hltout = AliHLTOUT::New(rawReader);
102 cerr << "ERROR: Could not create an AliHLTOUT object for '" << dataSource << "'." << endl;
107 // Check if we need to process all events or not.
108 if (lastEvent < firstEvent) lastEvent = 0x7FFFFFFF;
110 bool decodingOK = true;
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()
118 int result = hltout->Init();
121 cerr << "ERROR: could not initialise HLTOUT. Moving to next event." << endl;
127 // Go through all the data blocks, looking for the HLT global trigger object.
128 for (result = hltout->SelectFirstDataBlock(kAliHLTDataTypeGlobalTrigger);
130 result = hltout->SelectNextDataBlock()
133 TObject* obj = hltout->GetDataObject();
134 if (obj == NULL) continue;
135 if (obj->IsA()->GetBaseClass("AliHLTGlobalTriggerDecision") != NULL)
137 AliHLTGlobalTriggerDecision* decision = (AliHLTGlobalTriggerDecision*)obj;
138 bool hltTriggered = false;
139 if (triggerCode != NULL)
141 hltTriggered = TString(decision->Description()).Contains(triggerCode);
145 hltTriggered = decision->Result();
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())
158 events.Set(events.GetSize()+1);
159 events[events.GetSize()-1] = currentEvent;
162 hltout->ReleaseDataObject(obj);
165 result = hltout->Reset();
168 cerr << "ERROR: could not reset HLTOUT properly." << endl;
174 AliHLTOUT::Delete(hltout);
180 bool FindHLTTriggeredEvents(const char* dataSource = "./")
183 return FindHLTTriggeredEvents(dataSource, events, NULL, 0, -1, true);