#include <TFile.h>
#include <TTree.h>
+#include <TTreeIndex.h>
+#include <TGrid.h>
#include "AliRawReaderRoot.h"
#include "AliRawVEvent.h"
#include "AliRawEventHeaderBase.h"
ClassImp(AliRawReaderRoot)
+Bool_t AliRawReaderRoot::fgUseOrder = kFALSE;
+
AliRawReaderRoot::AliRawReaderRoot() :
fFile(NULL),
fEquipment(NULL),
fRawData(NULL),
fPosition(NULL),
- fEnd(NULL)
+ fEnd(NULL),
+ fIndex(0x0)
{
// default constructor
fEquipment(NULL),
fRawData(NULL),
fPosition(NULL),
- fEnd(NULL)
+ fEnd(NULL),
+ fIndex(0x0)
{
// create an object to read digits from the given input file for the
// event with the given number
TDirectory* dir = gDirectory;
+ TString flStr = fileName;
+ if (flStr.BeginsWith("alien://") && !gGrid) TGrid::Connect("alien://");
fFile = TFile::Open(fileName);
dir->cd();
if (!fFile || !fFile->IsOpen()) {
fEquipment(NULL),
fRawData(NULL),
fPosition(NULL),
- fEnd(NULL)
+ fEnd(NULL),
+ fIndex(0x0)
{
// create an object to read digits from the given raw event
if (!fEvent) fIsValid = kFALSE;
fEquipment(NULL),
fRawData(NULL),
fPosition(NULL),
- fEnd(NULL)
+ fEnd(NULL),
+ fIndex(0x0)
{
// copy constructor
if (rawReader.fFile) {
- TDirectory* dir = gDirectory;
+ TDirectory* dir = gDirectory;
fFile = TFile::Open(rawReader.fFile->GetName());
dir->cd();
if (!fFile || !fFile->IsOpen()) {
fSubEvent = fEvent->GetSubEvent(fSubEventIndex-1);
fEquipment = fSubEvent->GetEquipment(fEquipmentIndex);
fRawData = fEquipment->GetRawData();
- fCount = 0;
+ fCount = 0;
fHeader = (AliRawDataHeader*) ((UChar_t*) fRawData->GetBuffer() +
((UChar_t*) rawReader.fHeader -
(UChar_t*) rawReader.fRawData->GetBuffer()));
+ // Now check the version of the header
+ UChar_t version = 2;
+ if (fHeader) version = fHeader->GetVersion();
+ if (version==3) {
+ fHeader = NULL;
+ fHeaderV3 = (AliRawDataHeaderV3*) ((UChar_t*) fRawData->GetBuffer() +
+ ((UChar_t*) rawReader.fHeaderV3 -
+ (UChar_t*) rawReader.fRawData->GetBuffer()));
+ }
fPosition = (UChar_t*) fRawData->GetBuffer() +
(rawReader.fPosition - (UChar_t*) rawReader.fRawData->GetBuffer());
fEnd = ((UChar_t*) fRawData->GetBuffer()) + fRawData->GetSize();
// "read" the data header
fHeader = (AliRawDataHeader*) fPosition;
+ // Now check the version of the header
+ UChar_t version = 2;
+ if (fHeader) version=fHeader->GetVersion();
+ if (version==2) {
+ #ifndef R__BYTESWAP
+ SwapData((void*) fHeader, (void*) fHeaderSwapped, sizeof(AliRawDataHeader));
+ fHeader=fHeaderSwapped;
+#endif
+ if ((fPosition + fHeader->fSize) != fEnd) {
+ if (fHeader->fSize != 0xFFFFFFFF)
+ Warning("ReadHeader",
+ "Equipment %d : raw data size found in the header is wrong (%d != %ld)! Using the equipment size instead !",
+ fEquipment->GetEquipmentHeader()->GetId(),fHeader->fSize, fEnd - fPosition);
+ fHeader->fSize = fEnd - fPosition;
+ }
+ fPosition += sizeof(AliRawDataHeader);
+ fHeaderV3 = 0;
+ } else if (version==3) {
+ fHeaderV3 = (AliRawDataHeaderV3*) fPosition;
#ifndef R__BYTESWAP
- SwapData((void*) fHeader, (void*) fHeaderSwapped, sizeof(AliRawDataHeader));
- fHeader=fHeaderSwapped;
+ SwapData((void*) fHeaderV3, (void*) fHeaderSwapped, sizeof(AliRawDataHeaderV3));
+ fHeaderV3=fHeaderSwappedV3;
#endif
- if ((fPosition + fHeader->fSize) != fEnd) {
- if (fHeader->fSize != 0xFFFFFFFF)
- Warning("ReadHeader",
- "Equipment %d : raw data size found in the header is wrong (%d != %ld)! Using the equipment size instead !",
- fEquipment->GetEquipmentHeader()->GetId(),fHeader->fSize, fEnd - fPosition);
- fHeader->fSize = fEnd - fPosition;
+ if ((fPosition + fHeaderV3->fSize) != fEnd) {
+ if (fHeaderV3->fSize != 0xFFFFFFFF)
+ Warning("ReadHeader",
+ "Equipment %d : raw data size found in the header is wrong (%d != %ld)! Using the equipment size instead !",
+ fEquipment->GetEquipmentHeader()->GetId(),fHeader->fSize, fEnd - fPosition);
+ fHeaderV3->fSize = fEnd - fPosition;
+ }
+ fPosition += sizeof(AliRawDataHeaderV3);
+ fHeader = 0;
}
- fPosition += sizeof(AliRawDataHeader);
}
if (fHeader && (fHeader->fSize != 0xFFFFFFFF)) {
fCount = fHeader->fSize - sizeof(AliRawDataHeader);
+ // check consistency of data size in the header and in the sub event
+ if (fPosition + fCount > fEnd) {
+ Error("ReadHeader", "size in data header exceeds event size!");
+ Warning("ReadHeader", "skipping %ld bytes", fEnd - fPosition);
+ fEquipment->GetEquipmentHeader()->Dump();
+ fCount = 0;
+ fPosition = fEnd;
+ fErrorCode = kErrSize;
+ continue;
+ }
+ } else if (fHeaderV3 && (fHeaderV3->fSize != 0xFFFFFFFF)) {
+ fCount = fHeaderV3->fSize - sizeof(AliRawDataHeaderV3);
+
// check consistency of data size in the header and in the sub event
if (fPosition + fCount > fEnd) {
Error("ReadHeader", "size in data header exceeds event size!");
fEquipment = NULL;
fRawData = NULL;
fHeader = NULL;
+ fHeaderV3 = NULL;
fCount = 0;
fPosition = fEnd = NULL;
if (!fBranch) return kFALSE;
+ // check if it uses order or not
+ if (fgUseOrder && !fIndex) MakeIndex();
+
do {
delete fEvent;
fEvent = NULL;
fEventHeader = NULL;
fBranch->SetAddress(&fEvent);
- if (fBranch->GetEntry(fEventIndex+1) <= 0)
+ Int_t entryToGet = fEventIndex + 1;
+ if (fgUseOrder
+ && fIndex
+ && entryToGet<fBranch->GetEntries()
+ && entryToGet>-1 ) entryToGet = fIndex[entryToGet];
+ if (fBranch->GetEntry(entryToGet) <= 0)
return kFALSE;
fEventHeader = fEvent->GetHeader();
fEventIndex++;
if (!fBranch) return kFALSE;
+ // check if it uses order or not
+ if (fgUseOrder && !fIndex) MakeIndex();
+
delete fEvent;
fEvent = NULL;
fEventHeader = NULL;
fBranch->SetAddress(&fEvent);
- if (fBranch->GetEntry(event) <= 0)
+ Int_t entryToGet = event;
+ if (fgUseOrder
+ && fIndex
+ && entryToGet<fBranch->GetEntries()
+ && entryToGet>-1 ) entryToGet = fIndex[entryToGet];
+ if (fBranch->GetEntry(entryToGet) <= 0)
return kFALSE;
fEventHeader = fEvent->GetHeader();
fEventIndex = event;
}
return NULL;
}
+
+void AliRawReaderRoot::MakeIndex() {
+ // Make index
+ if (fBranch) {
+ TTree * rawTree = fBranch->GetTree();
+ if (rawTree) {
+ rawTree->BuildIndex("-fEvtHdrs[0].fSize"); // Minus sign to get largest first
+ TTreeIndex * treeInd = (TTreeIndex*)rawTree->GetTreeIndex();
+ if (treeInd) fIndex = treeInd->GetIndex();
+ }
+ }
+}