]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/MUON/src/AliRoot/TriggerSource.hpp
Additional protection to avoid rare problem related to the simulation of
[u/mrichter/AliRoot.git] / HLT / MUON / src / AliRoot / TriggerSource.hpp
CommitLineData
8356cc1d 1////////////////////////////////////////////////////////////////////////////////
2//
3// Author: Artur Szostak
4// Email: artur@alice.phy.uct.ac.za | artursz@iafrica.com
5//
6////////////////////////////////////////////////////////////////////////////////
7
3a682eae 8/* AliHLTMUONTriggerSource is used to extract L0 trigger information for
9 the muon spectrometer from a simulated event stored in .root files by AliRoot.
10 It is used by the AliHLTMUONMicrodHLT class as a input data set for the
11 dHLT algorithm.
12 */
13
69d7cf2e 14#ifndef ALIHLTMUONTRIGGERSOURCE_H
15#define ALIHLTMUONTRIGGERSOURCE_H
8356cc1d 16
17#include "TROOT.h"
18#include "TObject.h"
19#include "TString.h"
20#include "TClonesArray.h"
21#include "AliRoot/TriggerRecord.hpp"
22
23class AliMUON;
24class AliMUONLocalTrigger;
25class AliMUONDataInterface;
26
27
69d7cf2e 28class AliHLTMUONTriggerSource : public TObject
8356cc1d 29{
30public:
31
32 enum AreaType
33 {
3a682eae 34 kFromWholePlane,
35 kFromLeftHalfPlane,
36 kFromRightHalfPlane
8356cc1d 37 };
38
39 enum SourceType
40 {
3a682eae 41 kFromHits,
42 kFromLocalTriggers
8356cc1d 43 };
44
45
69d7cf2e 46 AliHLTMUONTriggerSource();
8356cc1d 47
48 /* Creates a new trigger source object by filling data from the data interface.
49 */
69d7cf2e 50 AliHLTMUONTriggerSource(AliMUONDataInterface* data);
8356cc1d 51
69d7cf2e 52 virtual ~AliHLTMUONTriggerSource();
8356cc1d 53
54 /* Get and set methods to specify how the FillFrom methods should fill the
55 internal data structures.
56 */
e33f3609 57 void AreaToUse(AreaType value) { fAreaToUse = value; };
8356cc1d 58 AreaType AreaToUse() const { return fAreaToUse; };
e33f3609 59 void DataToUse(SourceType value) { fDataToUse = value; };
8356cc1d 60 SourceType DataToUse() const { return fDataToUse; };
e33f3609 61 void MaxBlockSize(UInt_t value) { fMaxBlockSize = value; };
8356cc1d 62 UInt_t MaxBlockSize() const { return fMaxBlockSize; };
e33f3609 63 void UseLookupTable(Bool_t value) { fUseLookupTable = value; };
8356cc1d 64 Bool_t UseLookupTable() const { return fUseLookupTable; };
65
66 /* Fills the internal data structures from the specified data interface
67 for all the events found in AliMUONDataInterface.
68 */
69 void FillFrom(AliMUONDataInterface* data);
70
71 /* Fills the internal data structures from the specified data interface
72 for the given event.
73 */
e33f3609 74 void FillFrom(AliMUONDataInterface* data, Int_t event);
8356cc1d 75
76 /* Fills the internal data structures from the specified data interface
77 for the given event and trigger number.
78 If 'newblock' is set to true then the new trigger record is added to
79 a new block. Otherwise the point is added to the current block.
80 Note: This method ignores the fAreaToUse and fMaxBlockSize flags.
81 This is very usefull for custom trigger source filling.
82 For the case of adding data from AliMUONHit objects the 'trigger'
83 parameter becomes the track number in TreeH and not the index of the
84 AliMUONLocalTrigger object.
85 */
86 void FillFrom(
87 AliMUONDataInterface* data,
e33f3609 88 Int_t event, Int_t trigger, Bool_t newblock = kFALSE
8356cc1d 89 );
90
91 /* Clears all the internal arrays.
92 */
12ab84fc 93 virtual void Clear(Option_t* option = "");
8356cc1d 94
95 // Get methods.
96 TString FileName() const { return fFilename; };
97 TString FolderName() const { return fFoldername; };
98
99 /* Returns the number of events stored.
100 */
101 Int_t NumberOfEvents() const { return fEventList.GetEntriesFast(); };
102
69d7cf2e 103 /* Fetches the specified event number stored in this AliHLTMUONTriggerSource.
8356cc1d 104 Sets the current block and trigger to the first block and trigger record in
105 the event. If there are no blocks or trigger records then these pointers are
106 set to NULL. kTRUE is returned if the event was found, kFALSE otherwise.
107 */
e33f3609 108 Bool_t GetEvent(Int_t eventnumber) const;
8356cc1d 109
69d7cf2e 110 /* Fetches the first event stored in this AliHLTMUONTriggerSource.
8356cc1d 111 Sets the current block and trigger record to the first block and trigger
112 in the event. If there are no blocks or trigger records then these pointers
113 are set to NULL. kTRUE is returned if the event was found, kFALSE otherwise.
114 */
115 Bool_t GetFirstEvent() const;
116
117 /* Returns kTRUE if there are more events to iterate over.
118 */
119 Bool_t MoreEvents() const;
120
121 /* Fetches the next event stored following the currently selected one.
122 kTRUE is returned if the event was found, kFALSE otherwise.
123 The internal pointers are reset if we reached the last event.
124 */
125 Bool_t GetNextEvent() const;
126
127 /* Returns the corresponding AliRoot event number for the current event.
128 -1 is returned if no event is selected.
129 */
130 Int_t CurrentEvent() const;
131
132 /* Returns the number of trigger record blocks in the current event.
133 -1 is returned if no event is selected.
134 */
135 Int_t NumberOfBlocks() const;
136
137 /* Fetches the index'th block in the current event.
138 Sets the current trigger record to the first trigger in the block.
139 If there are no trigger records then this pointer is set to NULL.
140 kTRUE is returned if the block was found, kFALSE otherwise.
141 */
e33f3609 142 Bool_t GetBlock(Int_t index) const;
8356cc1d 143
144 /* Fetches the first block in the current event.
145 Sets the current trigger record to the first trigger in the block.
146 If there are no trigger records then this pointer is set to NULL.
147 kTRUE is returned if the block was found, kFALSE otherwise.
148 */
149 Bool_t GetFirstBlock() const;
150
151 /* Returns kTRUE if there are more blocks to be traversed.
152 */
153 Bool_t MoreBlocks() const;
154
155 /* Fetches the next block in the current event.
156 kTRUE is returned if the block was found, kFALSE otherwise.
157 */
158 Bool_t GetNextBlock() const;
159
160 /* Returns the currently selected block number.
161 -1 is returned if no blocks are selected.
162 */
163 Int_t CurrentBlock() const { return fBlockIndex; };
164
165 /* Returns the number of trigger records in the current block.
166 -1 is returned if no block is selected.
167 */
168 Int_t NumberOfTriggers() const;
169
170 /* Fetches the trigger record with the specified trigger number from
171 the current block.
172 NULL is returned if the record was not found.
173 */
69d7cf2e 174 const AliHLTMUONTriggerRecord* GetTrigger(Int_t triggernumber) const;
8356cc1d 175
176 /* Fetches the first trigger record in the current block.
177 NULL is returned if the record was not found.
178 */
69d7cf2e 179 const AliHLTMUONTriggerRecord* GetFirstTrigger() const;
8356cc1d 180
181 /* Returns kTRUE if there are more triggers to iterate over.
182 */
183 Bool_t MoreTriggers() const;
184
185 /* Fetches the next trigger record in the current block.
186 NULL is returned if the record was not found.
187 */
69d7cf2e 188 const AliHLTMUONTriggerRecord* GetNextTrigger() const;
8356cc1d 189
190 /* Returns the current trigger record.
191 NULL is returned if the record was not found.
192 */
69d7cf2e 193 const AliHLTMUONTriggerRecord* GetTrigger() const { return fCurrentTrigger; };
8356cc1d 194
195 /* Returns the trigger record number for the currently selected trigger record.
196 This number corresponds to the index'th AliMUONLocalTrigger object for the
197 current event.
198 -1 is returned if no trigger record is selected.
199 */
200 Int_t CurrentTrigger() const;
201
202
203private:
204
3a682eae 205 /* Adds a new AliEventData block to the fEventList and updates the fCurrentEvent,
8356cc1d 206 fCurrentBlock and fCurrentTrigger pointers.
207 */
e33f3609 208 void AddEvent(Int_t eventnumber);
8356cc1d 209
210 /* Adds a new block to the current event and updates fCurrentBlock and fCurrentTrigger.
211 */
212 void AddBlock();
213
214 /* Adds a new trigger record to the current event and block.
215 The fCurrentTrigger is updated appropriately.
216 */
69d7cf2e 217 void AddTrigger(const AliHLTMUONTriggerRecord& data);
8356cc1d 218
69d7cf2e 219 /* Checks if the file and folder names correspond to this AliHLTMUONTriggerSource's
8356cc1d 220 file and folder names. kTRUE is returned if they do.
221 If the file and folder names are empty then they are assigned the names
222 as found in the data interface and kTRUE is returned.
223 */
224 Bool_t FileAndFolderOk(AliMUONDataInterface* data);
225
226 /* Adds the whole event from the data interface to the internal data structures.
227 It is assumed that FileAndFolderOk(data) returns true just before calling
228 this method.
229 */
e33f3609 230 void AddEventFrom(AliMUONDataInterface* data, AliMUON* module, Int_t event);
8356cc1d 231
232 /* Adds the specified trigger record from the given data interface.
233 The data interface should be initialised correctly, that is the event
234 should already be selected before calling this method.
235 */
e33f3609 236 void AddTriggerFrom(AliMUONDataInterface* data, AliMUON* module, Int_t trigger);
8356cc1d 237
238 /* Checks to see if the specified trigger record is in the chamber region
239 we want to fill from.
240 kTRUE is returned if (x, y) is in the region, and kFALSE otherwise.
241 */
3a682eae 242 Bool_t InFillRegion(const AliHLTMUONTriggerRecord& data) const;
8356cc1d 243
244 /* Fills the trigger data from the AliMUONLocalTrigger object.
245 if the fUseLookupTable is set to true then we use the L0 lookup table to
246 fill the Pt value otherwise we use the PtCal method in AliMUONTriggerCircuit.
247 Note the fTriggerNumber parameter is not filled in to 'record'.
248 */
249 void FillTriggerFromLocalTrigger(
69d7cf2e 250 AliMUONLocalTrigger* trigger, AliMUON* module, AliHLTMUONTriggerRecord& record
8356cc1d 251 );
252
253 /* Fills the TriggerRecord structure from AliMUONHit objects.
254 The hits on the last 4 chambers are used (i.e. chambers 11 to 14).
255 kTRUE is returned if the structure was filled successfully.
256 */
69d7cf2e 257 Bool_t FillTriggerFromHits(AliMUONDataInterface* data, Int_t track, AliHLTMUONTriggerRecord& record);
8356cc1d 258
259 /* Fetches the AliMUON module from the AliRun global object. AliRun will be loaded
260 by the runloader if it has not yet been loaded. In such a case the AliRun object
261 will also we unloaded when we are done with it.
262 kTRUE is returned if no error occured and kFALSE otherwise.
3a682eae 263 Note that if fDataToUse is set to kFromHits then gAlice is not loaded and 'module'
8356cc1d 264 will be left untouched. The method will still return kTRUE however since this is
265 not an error. We do not need the AliMUON module when filling from hits.
266 */
267 Bool_t FetchAliMUON(AliMUON*& module);
268
269 /* After one is finished with the AliMUON object returned by GetAliMUON, one
270 should call this method.
271 If the gAlice object was loaded by GetAliMUON then it will be unloaded at
272 this point, otherwise nothing is done.
273 */
274 void FinishedWithAliMUON();
275
276 /* Sets all the current pointers to NULL and indices to -1.
277 */
278 void ResetAllPointers() const;
279
280 /* Sets the block and trigger pointers to NULL and indices to -1.
281 */
282 void ResetBlockPointers() const;
283
284 /* Sets just the current trigger record pointer to NULL and index to -1.
285 */
286 void ResetTriggerPointers() const;
287
288
289public: // Unfortunately ROOT requires the following to be public.
290
3a682eae 291 class AliEventData : public TObject
8356cc1d 292 {
293 public:
3a682eae 294 AliEventData();
295 AliEventData(Int_t eventnumber);
296 virtual ~AliEventData();
297
298 Int_t& EventNumber() { return fEventNumber; }
299 TClonesArray& Blocks() { return fBlocks; }
8356cc1d 300
3a682eae 301 private:
302
8356cc1d 303 Int_t fEventNumber; // Event number in AliMUONDataInterface from which the triggers were taken.
304 TClonesArray fBlocks; // The list of blocks of trigger records.
305
3a682eae 306 ClassDef(AliEventData, 1) // Data per event.
8356cc1d 307 };
308
309private:
310
3a682eae 311 // Do not allow copying of this object.
312 AliHLTMUONTriggerSource(const AliHLTMUONTriggerSource& /*object*/) : TObject() {}
313 AliHLTMUONTriggerSource& operator = (const AliHLTMUONTriggerSource& /*object*/) { return *this; }
314
315
8356cc1d 316 AreaType fAreaToUse; //! The part of the chamber to fill from.
317 SourceType fDataToUse; //! The type of raw AliRoot data to fill from.
318 UInt_t fMaxBlockSize; //! The maximum block size to create in the fill methods.
319 Bool_t fUseLookupTable; //! Set to true if the L0 lookup table should be used for finding Pt.
320
321 TString fFilename; // The file from which the trigger data was taken.
322 TString fFoldername; // The folder name from which trigger data was taken.
323
324 mutable Int_t fEventIndex; //! The index number of the currently selected event.
3a682eae 325 mutable AliEventData* fCurrentEvent; //! Pointer to the currently selected event.
8356cc1d 326 mutable Int_t fBlockIndex; //! The index number of the currently selected block.
327 mutable TClonesArray* fCurrentBlock; //! Pointer to the currently selected block.
328 mutable Int_t fTriggerIndex; //! The index number of the currently selected trigger record.
69d7cf2e 329 mutable AliHLTMUONTriggerRecord* fCurrentTrigger; //! Pointer to the currently selected trigger record.
8356cc1d 330
331 TClonesArray fEventList; // List of trigger records per event.
332
333 Bool_t fHadToLoadgAlice; //! Flag indicating if this object had to load the AliRun object.
334
69d7cf2e 335 ClassDef(AliHLTMUONTriggerSource, 1) // The source of trigger records for dHLT.
8356cc1d 336};
337
338
69d7cf2e 339#endif // ALIHLTMUONTRIGGERSOURCE_H