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