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