]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTHOMERBlockDesc.cxx
Minor cleanup of code.
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTHOMERBlockDesc.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de>                *
5  *          for The ALICE HLT Project.                                    *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /** @file   AliHLTHOMERBlockDesc.cxx
17     @author Jochen Thaeder
18     @date   
19     @brief  Container for HOMER Blocks
20 */
21
22 // see header file for class documentation
23 // or
24 // refer to README to build package
25 // or
26 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
27
28 #if __GNUC__>= 3
29    using namespace std;
30 #endif
31
32 #include "AliHLTHOMERBlockDesc.h"
33 #include "AliHLTMessage.h"
34
35 #include "TMath.h"
36 #include "TClass.h"
37
38
39 ClassImp(AliHLTHOMERBlockDesc)
40
41 //##################################################################################
42 AliHLTHOMERBlockDesc::AliHLTHOMERBlockDesc() :
43   fData(NULL),
44   fSize(0),
45   fIsTObject(kFALSE),
46   fIsRawData(kFALSE),
47   fMessage(NULL),
48   fTObject(NULL),
49   fClassName(),
50   fDetector(),
51   fSubDetector(),
52   fSubSubDetector(),
53   fSpecification(0),
54   fDataType(),
55   fHasSubDetectorRange(kFALSE),
56   fHasSubSubDetectorRange(kFALSE) {
57   // see header file for class documentation
58   // or
59   // refer to README to build package
60   // or
61   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
62 }
63
64 //##################################################################################
65 AliHLTHOMERBlockDesc::AliHLTHOMERBlockDesc( void * data, ULong_t size, TString origin, 
66                                             TString dataType, ULong_t specification ) :
67   fData(data),
68   fSize(size),
69   fIsTObject(kFALSE),
70   fIsRawData(kFALSE),
71   fMessage(NULL),
72   fTObject(NULL),
73   fClassName(),
74   fDetector(origin),
75   fSubDetector(),
76   fSubSubDetector(), 
77   fSpecification(specification),
78   fDataType(dataType),
79   fHasSubDetectorRange(kFALSE),
80   fHasSubSubDetectorRange(kFALSE) {
81   // see header file for class documentation
82   
83   // -- Set block parameters
84   SetBlockParameters();
85
86
87
88 //##################################################################################
89 AliHLTHOMERBlockDesc::~AliHLTHOMERBlockDesc() {
90   // see header file for class documentation
91
92   if ( fMessage != NULL )
93     delete fMessage;
94   fMessage = NULL;
95
96 }
97
98 //##################################################################################
99 void AliHLTHOMERBlockDesc::SetBlock( void * data, ULong_t size, TString origin, 
100                                      TString dataType, ULong_t specification ) {
101   // see header file for class documentation
102
103   fData = data;
104   fSize = size;
105   fDetector = origin; 
106   fDataType = dataType;
107   fSpecification = specification; 
108
109   // -- Set block parameters
110   SetBlockParameters();
111
112   return;
113 }
114
115 //##################################################################################
116 void AliHLTHOMERBlockDesc::SetBlockParameters() {
117   // see header file for class documentation
118
119   Int_t iError = 0;
120
121   // ---- SET CLASS NAME, DATA CONTENTS ----
122
123   // -- Check if block contains raw data
124   if ( ! CheckIfRawData() ) {
125
126     // -- Check if block contains TObject  
127     if ( ! CheckIfTObject() ) {
128
129       // -- Contains arbitrary data type
130       
131       // **** TPC ****
132       if ( ! fDetector.CompareTo("TPC") ) {
133         
134         if ( ! fDataType.CompareTo("CLUSTERS") )
135           fClassName = "AliHLTTPCSpacePoints";
136         else 
137           iError = 1;
138       }
139
140       // **** TRD ****
141       
142       else if ( ! fDetector.CompareTo("TRD") ) {
143         iError = 1;
144       }
145
146       // **** PHOS ****
147       
148       else if ( ! fDetector.CompareTo("PHOS") ) {
149         iError = 1;
150       }
151
152       // **** MUON ****
153       
154       else if ( ! fDetector.CompareTo("MUON") ) {
155         iError = 1;
156       }
157
158       // **** OTHER ****
159
160       else {
161         iError = 1;
162       }
163     }
164   } // if ( ! CheckIfRawData() ) {
165   
166   // -- Check if Data Type has been defined
167   if ( iError ) {
168     //AliError( Form("The data type %s for the detector %s has not been defined yet.", 
169     //             fDataType.Data(), fDetector.Data()) );
170   }
171   
172   // ---- SET SPECIFICATIONS ----
173   // -- Convert Specification to "SubDetector/SubSubDetector"
174
175   // **** TPC **** ( has special treatment )
176
177   if ( ! fDetector.CompareTo("TPC") ) {
178
179     Int_t minPatch  = (fSpecification & 0x000000FF);
180     Int_t maxPatch  = (fSpecification & 0x0000FF00) >> 8;
181     Int_t minSector = (fSpecification & 0x00FF0000) >> 16 ;
182     Int_t maxSector = (fSpecification & 0xFF000000) >> 24;
183     
184     fSubDetector += minSector;
185     fSubSubDetector += minPatch;
186   
187     // -- check for ranges
188     if ( minSector != maxSector )
189       fHasSubDetectorRange = kTRUE;
190
191     if ( minPatch != maxPatch )
192       fHasSubSubDetectorRange = kTRUE;
193   }
194   
195   // **** OTHER DETECTORS ****
196   
197   else {
198     
199     if ( fSpecification ) {
200       // find the max bin which is set to 1
201       fSubDetector += TMath::FloorNint( TMath::Log2(fSpecification) );
202
203       // -- check for ranges
204       if ( TMath::Log2(fSpecification) != ( (Double_t) TMath::FloorNint( TMath::Log2(fSpecification) ) ) )
205         fHasSubDetectorRange = kTRUE;
206
207     }
208   }
209
210   return;
211 }
212   
213 //##################################################################################
214 Bool_t AliHLTHOMERBlockDesc::CheckIfTObject() {
215   // see header file for class documentation
216
217   // -- Check Length - First 32 bit word of payload contains the length
218   UInt_t len = *( (UInt_t*) fData  );
219   
220   if ( len != ( fSize - sizeof(UInt_t) ) ) 
221     return fIsTObject;
222     
223   // -- set AliHLTMessage
224   if ( fMessage ) 
225     delete fMessage;
226   fMessage = NULL;    
227
228   fMessage = new AliHLTMessage( fData, fSize );
229   
230   // -- Check if TMessage payload is TObject
231   if ( fMessage->What() == kMESS_OBJECT ) {
232     fClassName = fMessage->GetClass()->GetName();
233     fIsTObject = kTRUE;
234     
235     fTObject = fMessage->ReadObject( fMessage->GetClass() );
236   }
237   
238   fMessage->Reset();
239
240   return fIsTObject;
241 }
242
243 //##################################################################################
244 Bool_t AliHLTHOMERBlockDesc::CheckIfRawData() {
245   // see header file for class documentation
246
247   if ( ! fDataType.CompareTo("DDL_RAW") )
248     fIsRawData = kTRUE;
249
250   return fIsRawData;
251 }
252