]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTHOMERBlockDesc.cxx
9eccd4b3c85db7a828c53a7980f687b3efefefa0
[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
34 #include "AliHLTMessage.h"
35
36 #include "TMath.h"
37 #include "TClass.h"
38
39
40 ClassImp(AliHLTHOMERBlockDesc)
41
42 /*
43  * ---------------------------------------------------------------------------------
44  *                            Constructor / Destructor 
45  * --------------------------------------------------------------------------------- 
46  */
47
48 //##################################################################################
49 AliHLTHOMERBlockDesc::AliHLTHOMERBlockDesc() :
50   fData(NULL),
51   fSize(0),
52   fBlockName(),
53   fIsTObject(kFALSE),
54   fIsRawData(kFALSE),
55   fMessage(NULL),
56   fTObject(NULL),
57   fClassName(),
58   fDataType(),
59   fDetector(),
60   fSpecification(0),
61   fSubDetector(0),
62   fSubSubDetector(0),
63   fHasSubDetectorRange(kFALSE),
64   fHasSubSubDetectorRange(kFALSE) {
65   // see header file for class documentation
66   // or
67   // refer to README to build package
68   // or
69   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
70 }
71
72 //##################################################################################
73 AliHLTHOMERBlockDesc::~AliHLTHOMERBlockDesc() {
74   // see header file for class documentation
75
76   if ( fMessage != NULL )
77     delete fMessage;
78   fMessage = NULL;
79
80 }
81
82 /*
83  * ---------------------------------------------------------------------------------
84  *                            Data Handling - Setter - public
85  * --------------------------------------------------------------------------------- 
86  */
87
88 //##################################################################################
89 void AliHLTHOMERBlockDesc::SetBlock( void * data, ULong_t size, TString origin, 
90                                      TString dataType, ULong_t specification ) {
91   // see header file for class documentation
92
93   fData = data;
94   fSize = size;
95   fDetector = origin; 
96   fDataType = dataType;
97   fSpecification = specification; 
98
99   //  fBlockName.Form("%s_%s_0x%08LX", fDetector.Data(), fDataType.Data(), fSpecification ); 
100   fBlockName.Form("%s_%s_0", fDetector.Data(), fDataType.Data() ); 
101
102   // -- Set block parameters
103   SetBlockParameters();
104
105   return;
106 }
107
108 /*
109  * ---------------------------------------------------------------------------------
110  *                            Data Handling - private
111  * --------------------------------------------------------------------------------- 
112  */
113
114 //##################################################################################
115 void AliHLTHOMERBlockDesc::SetBlockParameters() {
116   // see header file for class documentation
117
118   Int_t iResult = 0;
119
120   // ---- SET SPECIFICATIONS ----
121   // ----------------------------
122
123   // **** TPC **** ( has special treatment )
124   if ( ! fDetector.CompareTo("TPC") ) {
125     
126     Int_t minPatch  = (fSpecification & 0x000000FF);
127     Int_t maxPatch  = (fSpecification & 0x0000FF00) >> 8;
128     Int_t minSector = (fSpecification & 0x00FF0000) >> 16 ;
129     Int_t maxSector = (fSpecification & 0xFF000000) >> 24;
130     
131     fSubDetector = minSector;
132     fSubSubDetector = minPatch;
133     
134     // -- check for ranges
135     if ( minSector != maxSector )
136       fHasSubDetectorRange = kTRUE;
137
138     if ( minPatch != maxPatch )
139       fHasSubSubDetectorRange = kTRUE;
140     
141   }
142   // **** OTHER DETECTORS ****
143   else {
144       
145     if ( fSpecification ) {
146         // find the max bin which is set to 1
147       fSubDetector = TMath::FloorNint( TMath::Log2(fSpecification) );
148       
149       // -- check for ranges
150       if ( TMath::Log2(fSpecification) != 
151            static_cast<Double_t>(TMath::FloorNint(TMath::Log2(fSpecification))) )
152         fHasSubDetectorRange = kTRUE;
153     }
154   }
155
156   // ---- SET CLASS NAME, DATA CONTENTS ----
157   // ---------------------------------------
158
159   // -- Check if block contains raw data
160   if ( CheckIfRawData() )
161     return;
162
163   // -- Check if block contains TObject  
164   if ( CheckIfTObject() )
165     return;
166
167   // -- Contains arbitrary data type
168       
169   // **** TPC ****
170   if ( ! fDetector.CompareTo("TPC") ) {
171     
172     if ( ! fDataType.CompareTo("CLUSTERS") )
173       fClassName = "AliHLTTPCSpacePoints";
174     else 
175       iResult = -1;
176   }
177
178   // **** TRD ****
179   else if ( ! fDetector.CompareTo("TRD") ) {
180     iResult = -1;
181   }
182   
183   // **** PHOS ****
184   else if ( ! fDetector.CompareTo("PHOS") ) {
185     iResult = -1;
186   }
187   
188   // **** MUON ****
189   else if ( ! fDetector.CompareTo("MUON") ) {
190     iResult = -1;
191   }
192   
193   // **** OTHER ****
194   else {
195     iResult = -1;
196   }
197   
198   // -- Check if classname has been defined
199   //  if ( iResult < 0 ) {
200     //   AliWarning( Form("The classname for data type %s for the detector %s has not been defined yet.", 
201     //       fDataType.Data(), fDetector.Data()) );
202   // }
203   return;
204 }
205   
206 //##################################################################################
207 Bool_t AliHLTHOMERBlockDesc::CheckIfTObject() {
208   // see header file for class documentation
209
210   // -- Check Length - First 32 bit word of payload contains the length
211   UInt_t len = *( (UInt_t*) fData  );
212   
213   if ( len != ( fSize - sizeof(UInt_t) ) ) 
214     return fIsTObject;
215     
216   // -- set AliHLTMessage
217   if ( fMessage ) 
218     delete fMessage;
219   fMessage = NULL;    
220
221   fMessage = new AliHLTMessage( fData, fSize );
222   
223   // -- Check if TMessage payload is TObject
224   if ( fMessage->What() == kMESS_OBJECT ) {
225     fClassName = fMessage->GetClass()->GetName();
226     fIsTObject = kTRUE;
227     
228     fTObject = fMessage->ReadObject( fMessage->GetClass() );
229   }
230   
231   fMessage->Reset();
232
233   return fIsTObject;
234 }
235
236 //##################################################################################
237 Bool_t AliHLTHOMERBlockDesc::CheckIfRawData() {
238   // see header file for class documentation
239
240   if ( ! fDataType.CompareTo("DDL_RAW") )
241     fIsRawData = kTRUE;
242
243   return fIsRawData;
244 }
245