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