1 /**************************************************************************
2 * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 // Author: Cvetan Cheshkov 10/10/2005
20 //////////////////////////////////////////////////////////////////////////
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 //
26 //////////////////////////////////////////////////////////////////////////
32 #include <TDataMember.h>
34 #include <TMethodCall.h>
37 #include "AliRawEventHeaderBase.h"
39 #include <Riostream.h>
41 ClassImp(AliRawEventHeaderBase)
43 //______________________________________________________________________________
44 AliRawEventHeaderBase::AliRawEventHeaderBase():
50 fExtendedAllocSize(0),
54 // Default constructor
57 //______________________________________________________________________________
58 void *AliRawEventHeaderBase::HeaderBegin()
60 // Returns the pointer to the first data member
61 // beyond the base class data members
63 TList *datalist = IsA()->GetListOfDataMembers();
65 TDataMember *member = (TDataMember *)next();
67 if(!strcmp(member->GetTypeName(),"TClass"))
68 member = (TDataMember *)next();
70 return (void *)((char *)this+member->GetOffset());
73 //______________________________________________________________________________
74 Int_t AliRawEventHeaderBase::HeaderSize() const
76 // Returns the size of the data members list
77 // beyond the base class data members
81 TList *datalist = IsA()->GetListOfDataMembers();
84 while ((member=(TDataMember *)next()) != 0x0) {
85 if (!strcmp(member->GetTypeName(),"TClass")) continue;
86 UInt_t unitsize = member->GetUnitSize();
87 UInt_t ndim = member->GetArrayDim();
91 for(UInt_t i=0;i<ndim;i++) size += member->GetMaxIndex(i)*unitsize;
97 //______________________________________________________________________________
98 UInt_t AliRawEventHeaderBase::SwapWord(UInt_t x) const
100 // Swap the endianess of the integer value 'x'
102 return (((x & 0x000000ffU) << 24) | ((x & 0x0000ff00U) << 8) |
103 ((x & 0x00ff0000U) >> 8) | ((x & 0xff000000U) >> 24));
106 void AliRawEventHeaderBase::Swap()
108 // Swap base header data.
109 // Update the fIsSwapped flag which
110 // is then use to copy in an appropriate way
111 // the rest of the header data from the raw data stream
115 fSize = SwapWord(fSize);
116 fMagic = SwapWord(fMagic);
117 fHeadSize = SwapWord(fHeadSize);
118 fVersion = SwapWord(fVersion);
122 //______________________________________________________________________________
123 const char *AliRawEventHeaderBase::GetTypeName() const
125 // Get event type as a string.
126 // Will fail in case data header
127 // does not contain eventType field
128 Int_t eventType = Get("Type");
132 return "START_OF_RUN";
137 case kStartOfRunFiles:
138 return "START_OF_RUN_FILES";
141 return "END_OF_RUN_FILES";
144 return "START_OF_BURST";
147 return "END_OF_BURST";
150 return "PHYSICS_EVENT";
152 case kCalibrationEvent:
153 return "CALIBRATION_EVENT";
156 return "EVENT_FORMAT_ERROR";
159 return "START_OF_DATA";
162 return "END_OF_DATA";
164 case kSystemSoftwareTriggerEvent:
165 return "SYSTEM_SOFTWARE_TRIGGER_EVENT";
167 case kDetectorSoftwareTriggerEvent:
168 return "DETECTOR_SOFTWARE_TRIGGER_EVENT";
171 return "UNKNOWN EVENT TYPE NUMBER";
176 //______________________________________________________________________________
177 AliRawEventHeaderBase* AliRawEventHeaderBase::Create(char*& data)
179 // Static method to create AliRawEventHeaderVX object
180 // The actual header class version is taken from the
183 // First create AlirawEVentHeaderBase class object
184 AliRawEventHeaderBase header;
186 // Copy the first common part of the raw data header
187 memcpy(header.HeaderBaseBegin(), data, header.HeaderBaseSize());
189 // Swap header data if needed
190 if (header.IsSwapped())
193 // Is header valid...
194 if (!header.IsValid()) {
195 AliFatalClass("Invalid header format!");
196 // try recovery... how?
200 if (header.GetEventSize() < (UInt_t)header.HeaderBaseSize()) {
201 AliFatalClass("Invalid header base size!");
202 // try recovery... how?
206 // Now check the DATE version and create the corresponding header
208 UInt_t version = header.GetVersion();
209 UInt_t majorversion = (version>>16)&0x0000ffff;
210 UInt_t minorversion = version&0x0000ffff;
212 classname.Form("AliRawEventHeaderV%d_%d",majorversion,minorversion);
214 TClass *tcl = TClass::GetClass(classname.Data());
216 AliFatalClass(Form("Unknown header version (%s)!",classname.Data()));
220 // header.Dump(); tcl->Dump();
222 AliRawEventHeaderBase *hdr = (AliRawEventHeaderBase *)tcl->New();
224 AliFatalClass(Form("Can not create object of class %s",classname.Data()));
228 // Copy the base header data members and initialize other data members
229 memcpy(hdr->HeaderBaseBegin(),header.HeaderBaseBegin(), header.HeaderBaseSize());
230 memset(hdr->HeaderBegin(),0, hdr->HeaderSize());
231 hdr->fIsSwapped = header.fIsSwapped;
234 if (hdr->GetEventSize() < ((UInt_t)hdr->HeaderBaseSize() + (UInt_t)hdr->HeaderSize())) {
235 AliFatalClass(Form("Invalid header size (%d < %d +%d)!",
236 hdr->GetEventSize(),hdr->HeaderBaseSize(),hdr->HeaderSize()));
237 // try recovery... how?
241 // Check for the presence of header extension and its size
242 Int_t extsize = (Int_t)hdr->GetHeadSize() - (hdr->HeaderBaseSize() + hdr->HeaderSize());
244 AliFatalClass(Form("Invalid header size (%d < %d +%d)!",
245 hdr->GetHeadSize(),hdr->HeaderBaseSize(),hdr->HeaderSize()));
246 // try recovery... how?
251 hdr->AllocateExtendedData(extsize);
258 void AliRawEventHeaderBase::SwapData(const void* inbuf, const void* outbuf, UInt_t size) {
259 // The method swaps the contents of the
260 // raw-data event header
261 UInt_t intCount = size/sizeof(UInt_t);
263 UInt_t* buf = (UInt_t*) inbuf; // temporary integers buffer
264 for (UInt_t i=0; i<intCount; i++, buf++) {
265 UInt_t value = SwapWord(*buf);
266 memcpy((UInt_t*)outbuf+i, &value, sizeof(UInt_t));
270 //______________________________________________________________________________
271 Int_t AliRawEventHeaderBase::ReadHeader(char*& data)
273 // Read header info from DATE data stream.
274 // Returns bytes read
276 Long_t start = (Long_t)data;
277 // Swap header data if needed
278 if (DataIsSwapped()) {
279 SwapData(data, HeaderBaseBegin(), HeaderBaseSize());
280 data += HeaderBaseSize();
281 SwapData(data, HeaderBegin(), HeaderSize());
282 data += HeaderSize();
285 memcpy(HeaderBaseBegin(), data, HeaderBaseSize());
286 data += HeaderBaseSize();
287 memcpy(HeaderBegin(), data, HeaderSize());
288 data += HeaderSize();
290 data += ReadExtendedData(data);
292 return (Int_t)((Long_t)data - start);
295 //______________________________________________________________________________
296 void AliRawEventHeaderBase::AllocateExtendedData(Int_t extsize)
298 // Allocate the space for the header
300 if (fExtendedData) delete [] fExtendedData;
302 fExtendedDataSize = fExtendedAllocSize = extsize;
303 fExtendedData = new char[fExtendedAllocSize];
304 memset(fExtendedData,0,fExtendedAllocSize);
307 //______________________________________________________________________________
308 Int_t AliRawEventHeaderBase::ReadExtendedData(char*& data)
310 // Read extended header data
311 // Reallocates memory if the present
312 // buffer is insufficient
313 Int_t extsize = (Int_t)GetHeadSize() - (HeaderBaseSize() + HeaderSize());
316 fExtendedDataSize = 0;
321 AliFatal(Form("Invalid header size (%d < %d +%d)!",
322 GetHeadSize(),HeaderBaseSize(),HeaderSize()));
323 // try recovery... how?
327 fExtendedDataSize = extsize;
328 if (fExtendedDataSize > fExtendedAllocSize)
329 AllocateExtendedData(fExtendedDataSize);
332 SwapData(data, fExtendedData, fExtendedDataSize);
334 memcpy(fExtendedData, data, fExtendedDataSize);
336 return fExtendedDataSize;
339 //______________________________________________________________________________
340 UInt_t AliRawEventHeaderBase::Get(const char *datamember) const
342 // The method to get a data member from the header object
343 // Except for the data members of the base class, all the
344 // other header data should be retrieved ONLY by this method
345 // The name of the data member should be supplied without "f"
349 strcat(buf,datamember);
351 TDataMember *member = IsA()->GetDataMember(buf);
353 AliFatal(Form("No data member %s is found! Check the raw data version!",buf));
357 if (member->GetArrayDim() != 0) {
358 AliFatal(Form("Member %s is an array! Use the GetP() method!",buf));
362 if (strcmp(member->GetTypeName(),"UInt_t") != 0) {
363 AliFatal(Form("Member %s is not of type UInt_t!",buf));
367 const void *pointer = (char *)this+member->GetOffset();
369 return *((UInt_t *)pointer);
372 //______________________________________________________________________________
373 const UInt_t* AliRawEventHeaderBase::GetP(const char *datamember) const
375 // The method to get a data member from the header object
376 // Except for the data members of the base class, all the
377 // other header data should be retrieved ONLY by this method
378 // The name of the data member should be supplied without "f"
382 strcat(buf,datamember);
384 TDataMember *member = IsA()->GetDataMember(buf);
386 AliFatal(Form("No data member %s is found! Check the raw data version!",buf));
390 // if (member->GetArrayDim() == 0) {
391 // AliFatal(Form("Member %s is not an array! Use the Get() method!",buf));
395 if (strcmp(member->GetTypeName(),"UInt_t") != 0) {
396 AliFatal(Form("Member %s is not of type UInt_t*!",buf));
400 const void *pointer = (char *)this+member->GetOffset();
402 return (const UInt_t*)pointer;
405 //_____________________________________________________________________________
406 void AliRawEventHeaderBase::Print( const Option_t* opt ) const
408 // Dumps the event or sub-event
411 cout << opt << " Event size: " << GetEventSize() << endl;
412 cout << opt << " Event header size: " << GetHeadSize() << endl;
413 cout << opt << " Event header version: " << GetMajorVersion() << "." << GetMinorVersion() << endl;
414 cout << opt << " Event type: " << Get("Type") << "( " << GetTypeName() << " )" << endl;
415 cout << opt << " Run Number: " << Get("RunNb") << endl;
416 const UInt_t *id = GetP("Id");
417 cout << opt << " Period: " << (((id)[0]>>4)&0x0fffffff) << " Orbit: " << ((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff)) << " Bunch-crossing: " << ((id)[1]&0x00000fff) << endl;
418 cout << opt << " Trigger pattern: " << GetP("TriggerPattern")[0] << "-" << GetP("TriggerPattern")[1] << endl;
419 cout << opt << " Detector pattern: " << Get("DetectorPattern") << endl;
420 cout << opt << " Type attribute: " << GetP("TypeAttribute")[0] << "-" << GetP("TypeAttribute")[1] << "-" << GetP("TypeAttribute")[2] << endl;
421 cout << opt << " GDC: " << Get("GdcId") << " LDC: " << Get("LdcId") << endl;