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