Adding detailed debug info in case of fatal error during the decoding
[u/mrichter/AliRoot.git] / RAW / AliRawEventHeaderBase.cxx
CommitLineData
f2dc6b20 1// Author: Cvetan Cheshkov 10/10/2005
2
3/**************************************************************************
4 * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Author: The ALICE Off-line Project. *
7 * Contributors are mentioned in the code where appropriate. *
8 * *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
17
18//////////////////////////////////////////////////////////////////////////
19// //
20// AliRawEventHeaderBase //
21// This a new versioning scheme for raw data root-ification and reading //
22// For details look at offline weekly meeting 20/10/2005 //
23// //
24//////////////////////////////////////////////////////////////////////////
25
26#include <unistd.h>
27
28#include <TClass.h>
29#include <TDataMember.h>
30#include <TMethodCall.h>
31
32#include "AliLog.h"
33#include "AliRawEventHeaderBase.h"
34
35
36ClassImp(AliRawEventHeaderBase)
37
38
39//______________________________________________________________________________
40void *AliRawEventHeaderBase::HeaderBegin()
41{
42 // Returns the pointer to the first data member
43 // beyond the base class data members
44
45 TList *datalist = IsA()->GetListOfDataMembers();
46 TIter next(datalist);
47 TDataMember *member = (TDataMember *)next();
48
49 if(!strcmp(member->GetTypeName(),"TClass"))
50 member = (TDataMember *)next();
51
52 return (void *)((char *)this+member->GetOffset());
53}
54
55//______________________________________________________________________________
56Int_t AliRawEventHeaderBase::HeaderSize() const
57{
58 // Returns the size of the data members list
59 // beyond the base class data members
60
61 Int_t size = 0;
62
63 TList *datalist = IsA()->GetListOfDataMembers();
64 TIter next(datalist);
65 TDataMember *member;
66 while ((member=(TDataMember *)next()) != 0x0) {
67 if (!strcmp(member->GetTypeName(),"TClass")) continue;
68 UInt_t unitsize = member->GetUnitSize();
69 UInt_t ndim = member->GetArrayDim();
70 if (ndim == 0)
71 size += unitsize;
72 else
73 for(UInt_t i=0;i<ndim;i++) size += member->GetMaxIndex(i)*unitsize;
74 }
75
76 return size;
77}
78
79//______________________________________________________________________________
80void AliRawEventHeaderBase::Swap()
81{
82 // Swap base header data.
83 // Update the fIsSwapped flag which
84 // is then use to copy in an appropriate way
85 // the rest of the header data from the raw data stream
86
87 if (IsSwapped()) {
88 fIsSwapped = kTRUE;
89 fSize = net2host(fSize);
90 fMagic = net2host(fMagic);
91 fHeadSize = net2host(fHeadSize);
92 fVersion = net2host(fVersion);
93 }
94}
95
96//______________________________________________________________________________
97const char *AliRawEventHeaderBase::GetTypeName()
98{
99 // Get event type as a string.
100 // Will fail in case data header
101 // does not contain eventType field
102 Int_t eventType = Get("Type");
103
104 switch (eventType) {
105 case kStartOfRun:
106 return "START_OF_RUN";
107 break;
108 case kEndOfRun:
109 return "END_OF_RUN";
110 break;
111 case kStartOfRunFiles:
112 return "START_OF_RUN_FILES";
113 break;
114 case kEndOfRunFiles:
115 return "END_OF_RUN_FILES";
116 break;
117 case kStartOfBurst:
118 return "START_OF_BURST";
119 break;
120 case kEndOfBurst:
121 return "END_OF_BURST";
122 break;
123 case kPhysicsEvent:
124 return "PHYSICS_EVENT";
125 break;
126 case kCalibrationEvent:
127 return "CALIBRATION_EVENT";
128 break;
129 case kFormatError:
130 return "EVENT_FORMAT_ERROR";
131 break;
132 default:
133 return "UNKNOWN EVENT TYPE NUMBER";
134 break;
135 }
136}
137
138//______________________________________________________________________________
139AliRawEventHeaderBase* AliRawEventHeaderBase::Create(char*& data)
140{
141 // Static method to create AliRawEventHeaderVX object
142 // The actual header class version is taken from the
143 // raw data
144
145 // First create AlirawEVentHeaderBase class object
146 AliRawEventHeaderBase header;
147
148 // Copy the first common part of the raw data header
149 memcpy(header.HeaderBaseBegin(), data, header.HeaderBaseSize());
150
151 // Swap header data if needed
152 if (header.IsSwapped())
153 header.Swap();
154
155 // Is header valid...
156 if (!header.IsValid()) {
157 AliFatalClass("Invalid header format!");
158 // try recovery... how?
159 return 0x0;
160 }
161
162 if (header.GetEventSize() < (UInt_t)header.HeaderBaseSize()) {
163 AliFatalClass("Invalid header base size!");
164 // try recovery... how?
165 return 0x0;
166 }
167
168 // Now check the DATE version and create the corresponding header
169 // class object
170 UInt_t version = header.GetVersion();
171 UInt_t majorversion = (version>>16)&0x0000ffff;
172 UInt_t minorversion = version&0x0000ffff;
173 TString classname;
174 classname.Form("AliRawEventHeaderV%d_%d",majorversion,minorversion);
175
176 TClass *tcl = TClass::GetClass(classname.Data());
177 if (!tcl) {
178 AliFatalClass(Form("Unknown header version (%s)!",classname.Data()));
179 return 0x0;
180 }
181
182 // header.Dump(); tcl->Dump();
183
184 AliRawEventHeaderBase *hdr = (AliRawEventHeaderBase *)tcl->New();
185 if (!hdr) {
186 AliFatalClass(Form("Can not create object of class %s",classname.Data()));
187 return 0x0;
188 }
189
190 // Copy the base header data members and initialize other data members
191 memcpy(hdr->HeaderBaseBegin(),header.HeaderBaseBegin(), header.HeaderBaseSize());
192 memset(hdr->HeaderBegin(),0, hdr->HeaderSize());
193 hdr->fIsSwapped = header.fIsSwapped;
194
195 // Consistency check
196 if (hdr->GetEventSize() < ((UInt_t)hdr->HeaderBaseSize() + (UInt_t)hdr->HeaderSize())) {
197 AliFatalClass(Form("Invalid header size (%d < %d +%d)!",
198 hdr->GetEventSize(),hdr->HeaderBaseSize(),hdr->HeaderSize()));
199 // try recovery... how?
200 return 0x0;
201 }
202
203 // Check for the presence of header extension and its size
204 Int_t extsize = (Int_t)hdr->GetHeadSize() - (hdr->HeaderBaseSize() + hdr->HeaderSize());
205 if (extsize < 0) {
206 AliFatalClass(Form("Invalid header size (%d < %d +%d)!",
207 hdr->GetHeadSize(),hdr->HeaderBaseSize(),hdr->HeaderSize()));
208 // try recovery... how?
209 return 0x0;
210 }
211 else {
212 if (extsize > 0) {
213 hdr->SetExtendedDataSize(extsize);
214 char *extdata = new char[extsize];
215 memset(extdata,0,extsize);
216 hdr->SetExtendedData(extdata);
217 }
218 }
219
220 return hdr;
221}
222
223//______________________________________________________________________________
224Int_t AliRawEventHeaderBase::ReadHeader(char*& data)
225{
226 // Read header info from DATE data stream.
227 // Returns bytes read
228
229 Long_t start = (Long_t)data;
230 // Swap header data if needed
231 if (DataIsSwapped()) {
232 swab(data,HeaderBaseBegin(), HeaderBaseSize());
233 data += HeaderBaseSize();
234 swab(data, HeaderBegin(), HeaderSize());
235 data += HeaderSize();
236 if(GetExtendedDataSize()>0) {
237 swab(data, GetExtendedData(), GetExtendedDataSize());
238 data += GetExtendedDataSize();
239 }
240 }
241 else {
242 memcpy(HeaderBaseBegin(), data, HeaderBaseSize());
243 data += HeaderBaseSize();
244 memcpy(HeaderBegin(), data, HeaderSize());
245 data += HeaderSize();
246 if(GetExtendedDataSize()>0) {
247 memcpy(GetExtendedData(), data, GetExtendedDataSize());
248 data += GetExtendedDataSize();
249 }
250 }
251
252 return (Int_t)((Long_t)data - start);
253}
254
255//______________________________________________________________________________
256UInt_t AliRawEventHeaderBase::Get(const char *datamember)
257{
258 // The method to get a data member from the header object
259 // Except for the data members of the base class, all the
260 // other header data should be retrieved ONLY by this method
261 // The name of the data member should be supplied without "f"
262 // in front
263
264 char buf[256] = "f";
265 strcat(buf,datamember);
266
267 TDataMember *member = IsA()->GetDataMember(buf);
268 if (!member) {
269 AliFatal(Form("No data member %s is found! Check the raw data version!",buf));
270 return 0;
271 }
272
273 if (member->GetArrayDim() != 0) {
274 AliFatal(Form("Member %s is an array! Use the GetP() method!",buf));
275 return 0;
276 }
277
278 if (strcmp(member->GetTypeName(),"UInt_t") != 0) {
279 AliFatal(Form("Member %s is not of type UInt_t!",buf));
280 return 0;
281 }
282
283 const void *pointer = (char *)this+member->GetOffset();
284
285 return *((UInt_t *)pointer);
286}
287
288//______________________________________________________________________________
289const UInt_t* AliRawEventHeaderBase::GetP(const char *datamember)
290{
291 // The method to get a data member from the header object
292 // Except for the data members of the base class, all the
293 // other header data should be retrieved ONLY by this method
294 // The name of the data member should be supplied without "f"
295 // in front
296
297 char buf[256] = "f";
298 strcat(buf,datamember);
299
300 TDataMember *member = IsA()->GetDataMember(buf);
301 if (!member) {
302 AliFatal(Form("No data member %s is found! Check the raw data version!",buf));
303 return 0;
304 }
305
39848565 306 // if (member->GetArrayDim() == 0) {
307 // AliFatal(Form("Member %s is not an array! Use the Get() method!",buf));
308 // return 0;
309 // }
f2dc6b20 310
311 if (strcmp(member->GetTypeName(),"UInt_t") != 0) {
312 AliFatal(Form("Member %s is not of type UInt_t*!",buf));
313 return 0;
314 }
315
316 const void *pointer = (char *)this+member->GetOffset();
317
318 return (const UInt_t*)pointer;
319}