// @(#) $Id$
-
-// Author: Uli Frankenfeld <mailto:franken@fi.uib.no>, Anders Vestbo <mailto:vestbo$fi.uib.no>, C. Loizides <mailto:loizides@ikf.uni-frankfurt.de>
-//*-- Copyright © ALICE HLT Group
+// Original: AliHLTFileHandler.cxx,v 1.49 2005/06/23 17:46:55 hristov
+
+/**************************************************************************
+ * This file is property of and copyright by the ALICE HLT Project *
+ * ALICE Experiment at CERN, All rights reserved. *
+ * *
+ * Primary Authors: U. Frankenfeld, A. Vestbo, C. Loizides *
+ * Matthias Richter <Matthias.Richter@ift.uib.no> *
+ * for The ALICE HLT Project. *
+ * *
+ * Permission to use, copy, modify and distribute this software and its *
+ * documentation strictly for non-commercial purposes is hereby granted *
+ * without fee, provided that the above copyright notice appears in all *
+ * copies and that both the copyright notice and this permission notice *
+ * appear in the supporting documentation. The authors make no claims *
+ * about the suitability of this software for any purpose. It is *
+ * provided "as is" without express or implied warranty. *
+ **************************************************************************/
+
+/** @file AliHLTTPCFileHandler.cxx
+ @author U. Frankenfeld, A. Vestbo, C. Loizides, maintained by
+ Matthias Richter
+ @date
+ @brief file input for the TPC tracking code before migration to the
+ HLT component framework
+
+// see below for class documentation
+// or
+// refer to README to build package
+// or
+// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+ */
#include <TClonesArray.h>
#include <TSystem.h>
#include <TMath.h>
-#ifdef use_newio
#include <AliRunLoader.h>
-#endif
+#include <TObject.h>
+#include <TFile.h>
+#include <TTree.h>
#include <AliTPCParamSR.h>
#include <AliTPCDigitsArray.h>
#include <AliTPCClustersArray.h>
#include "AliHLTTPCLogging.h"
#include "AliHLTTPCTransform.h"
-#include "AliHLTTPCMemHandler.h"
#include "AliHLTTPCDigitData.h"
-#include "AliHLTTPCTrackSegmentData.h"
+//#include "AliHLTTPCTrackSegmentData.h"
#include "AliHLTTPCSpacePointData.h"
-#include "AliHLTTPCTrackArray.h"
+//#include "AliHLTTPCTrackArray.h"
#include "AliHLTTPCFileHandler.h"
#if __GNUC__ >= 3
using namespace std;
#endif
-/** \class AliHLTTPCFileHandler
+/**
<pre>
//_____________________________________________________________
// AliHLTTPCFileHandler
ClassImp(AliHLTTPCFileHandler)
+AliHLTTPCFileHandler::AliHLTTPCFileHandler(Bool_t b)
+ :
+ fInAli(NULL),
+ fUseRunLoader(kFALSE),
+ fParam(NULL),
+ fDigits(NULL),
+ fDigitsTree(NULL),
+ fMC(NULL),
+ fIndexCreated(kFALSE),
+ fUseStaticIndex(b)
+{
+ //Default constructor
+
+ for(Int_t i=0;i<AliHLTTPCTransform::GetNSlice();i++)
+ for(Int_t j=0;j<AliHLTTPCTransform::GetNRows();j++)
+ fIndex[i][j]=-1;
+
+ if(fUseStaticIndex&&!fgStaticIndexCreated) CleanStaticIndex();
+}
+
+AliHLTTPCFileHandler::~AliHLTTPCFileHandler()
+{
+ //Destructor
+ if(fMC) CloseMCOutput();
+ FreeDigitsTree();
+ if(fInAli) CloseAliInput();
+}
+
// of course on start up the index is not created
Bool_t AliHLTTPCFileHandler::fgStaticIndexCreated=kFALSE;
Int_t AliHLTTPCFileHandler::fgStaticIndex[36][159];
return 0;
}
-AliHLTTPCFileHandler::AliHLTTPCFileHandler(Bool_t b)
-{
- //Default constructor
- fInAli = 0;
-#ifdef use_newio
- fUseRunLoader = kFALSE;
-#endif
- fParam = 0;
- fMC =0;
- fDigits=0;
- fDigitsTree=0;
- fIndexCreated=kFALSE;
- fUseStaticIndex=b;
-
- for(Int_t i=0;i<AliHLTTPCTransform::GetNSlice();i++)
- for(Int_t j=0;j<AliHLTTPCTransform::GetNRows();j++)
- fIndex[i][j]=-1;
-
- if(fUseStaticIndex&&!fgStaticIndexCreated) CleanStaticIndex();
-}
-
-AliHLTTPCFileHandler::~AliHLTTPCFileHandler()
-{
- //Destructor
- if(fMC) CloseMCOutput();
- FreeDigitsTree();
- if(fInAli) CloseAliInput();
-}
-
void AliHLTTPCFileHandler::FreeDigitsTree()
{
//free digits tree
}
delete fDigits;
fDigits=0;
-#ifndef use_newio
- fDigitsTree->Delete();
-#endif
fDigitsTree=0;
for(Int_t i=0;i<AliHLTTPCTransform::GetNSlice();i++){
Bool_t AliHLTTPCFileHandler::SetAliInput()
{
//set ali input
-#ifdef use_newio
fInAli->CdGAFile();
fParam = (AliTPCParam*)gFile->Get("75x40_100x60_150x60");
if(!fParam){
<<"No AliTPCParam "<<AliHLTTPCTransform::GetParamName()<<" in File "<<gFile->GetName()<<ENDLOG;
return kFALSE;
}
-#else
- if(!fInAli->IsOpen()){
- LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::SetAliInput","File Open")
- <<"Ali File "<<fInAli->GetName()<<" does not exist"<<ENDLOG;
- return kFALSE;
- }
- fParam = (AliTPCParam*)fInAli->Get(AliHLTTPCTransform::GetParamName());
- if(!fParam){
- LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::SetAliInput","File")
- <<"No TPC parameters found in \""<<fInAli->GetName()
- <<"\", creating standard parameters "
- <<"which might not be what you want!"<<ENDLOG;
- fParam = new AliTPCParamSR;
- }
- if(!fParam){
- LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::SetAliInput","File Open")
- <<"No AliTPCParam "<<AliHLTTPCTransform::GetParamName()<<" in File "<<fInAli->GetName()<<ENDLOG;
- return kFALSE;
- }
-#endif
return kTRUE;
}
Bool_t AliHLTTPCFileHandler::SetAliInput(Char_t *name)
{
//Open the AliROOT file with name.
-#ifdef use_newio
fInAli= AliRunLoader::Open(name);
-#else
- fInAli= new TFile(name,"READ");
-#endif
if(!fInAli){
LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::SetAliInput","File Open")
<<"Pointer to fInAli = 0x0 "<<ENDLOG;
return SetAliInput();
}
-#ifdef use_newio
Bool_t AliHLTTPCFileHandler::SetAliInput(AliRunLoader *runLoader)
{
//set ali input as runloader
}
return SetAliInput();
}
-#endif
-
-#ifdef use_newio
-Bool_t AliHLTTPCFileHandler::SetAliInput(TFile */*file*/)
-{
- //Specify already opened AliROOT file to use as an input.
- LOG(AliHLTTPCLog::kFatal,"AliHLTTPCFileHandler::SetAliInput","File Open")
- <<"This function is not supported for NEWIO, check ALIHLT_USENEWIO settings in Makefile.conf"<<ENDLOG;
- return kFALSE;
-}
-#else
-Bool_t AliHLTTPCFileHandler::SetAliInput(TFile *file)
-{
- //Specify already opened AliROOT file to use as an input.
- fInAli=file;
- if(!fInAli){
- LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::SetAliInput","File Open")
- <<"Pointer to fInAli = 0x0 "<<ENDLOG;
- return kFALSE;
- }
- return SetAliInput();
-}
-#endif
void AliHLTTPCFileHandler::CloseAliInput()
{
//close ali input
-#ifdef use_newio
if(fUseRunLoader) return;
-#endif
if(!fInAli){
LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::CloseAliInput","RunLoader")
<<"Nothing to Close"<<ENDLOG;
return;
}
-#ifndef use_newio
- if(fInAli->IsOpen()) fInAli->Close();
-#endif
delete fInAli;
fInAli = 0;
<<"Pointer to fInAli = 0x0 "<<ENDLOG;
return kTRUE; //maybe you are using binary input which is Digits!
}
-#ifdef use_newio
AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader");
if(!tpcLoader){
LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandlerNewIO::IsDigit","File")
fInAli->GetEvent(event);
tpcLoader->LoadDigits();
TTree *t=tpcLoader->TreeD();
-#else
- Char_t name[1024];
- sprintf(name,"TreeD_%s_%d",AliHLTTPCTransform::GetParamName(),event);
- TTree *t=(TTree*)fInAli->Get(name);
-#endif
if(t){
LOG(AliHLTTPCLog::kInformational,"AliHLTTPCFileHandlerNewIO::IsDigit","File Type")
<<"Found Digit Tree -> Use Fast Cluster Finder"<<ENDLOG;
}
///////////////////////////////////////// Digit IO
-Bool_t AliHLTTPCFileHandler::AliDigits2Binary(Int_t event,Bool_t altro)
+Bool_t AliHLTTPCFileHandler::AliDigits2BinaryFile(Int_t event,Bool_t altro)
{
//save alidigits as binary
Bool_t out = kTRUE;
data = AliAltroDigits2Memory(nrow,event);
else
data = AliDigits2Memory(nrow,event);
- out = Memory2Binary(nrow,data);
+ out = Memory2BinaryFile(nrow,data);
Free();
return out;
}
return kTRUE;
}
-AliHLTTPCDigitRowData * AliHLTTPCFileHandler::AliDigits2Memory(UInt_t & nrow,Int_t event)
+AliHLTTPCDigitRowData * AliHLTTPCFileHandler::AliDigits2Memory(UInt_t & nrow,Int_t event, Byte_t* tgtBuffer, UInt_t *pTgtSize)
{
- //Read data from AliROOT file into memory, and store it in the HLT data format.
+ //Read data from AliROOT file into memory, and store it in the HLT data format
+ //in the provided buffer or an allocated buffer.
//Returns a pointer to the data.
AliHLTTPCDigitRowData *data = 0;
return 0;
}
-#ifndef use_newio
- if(!fInAli->IsOpen()){
- LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliDigits2Memory","File")
- <<"No Input avalible: TFile not opened"<<ENDLOG;
- return 0;
- }
-#endif
-
if(!fDigitsTree)
if(!GetDigitsTree(event)) return 0;
<<"No TPC digits (entries==0)!"<<ENDLOG;
nrow = (UInt_t)(fRowMax-fRowMin+1);
Int_t size = nrow*sizeof(AliHLTTPCDigitRowData);
- data=(AliHLTTPCDigitRowData*) Allocate(size);
+ if (tgtBuffer!=NULL && pTgtSize!=NULL && *pTgtSize>0) {
+ if (size<=*pTgtSize) {
+ data=reinterpret_cast<AliHLTTPCDigitRowData*>(tgtBuffer);
+ } else {
+ }
+ } else {
+ data=reinterpret_cast<AliHLTTPCDigitRowData*>(Allocate(size));
+ }
AliHLTTPCDigitRowData *tempPt = data;
+ if (data) {
+ if (pTgtSize) *pTgtSize=size;
for(Int_t r=fRowMin;r<=fRowMax;r++){
tempPt->fRow = r;
tempPt->fNDigit = 0;
tempPt++;
}
+ }
return data;
}
Int_t * ndigits = new Int_t[fRowMax+1];
Float_t xyz[3];
+ // The digits of the current event have been indexed: all digits are organized in
+ // rows, all digits of one row are stored in a AliSimDigits object (fDigit) which
+ // are stored in the digit tree.
+ // The index map relates the AliSimDigits objects in the tree to dedicated pad rows
+ // in the TPC
+ // This loop filters the pad rows according to the slice no set via Init
for(Int_t r=fRowMin;r<=fRowMax;r++){
Int_t n=fIndex[fSlice][r];
- if(n!=-1){ //data on that row
+ if(n!=-1){ // there is data on that row available
fDigitsTree->GetEvent(n);
fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
AliHLTTPCTransform::Sector2Slice(lslice,lrow,sector,row);
LOG(AliHLTTPCLog::kDebug,"AliHLTTPCFileHandler::AliDigits2Memory","Digits")
<<AliHLTTPCLog::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG;
- data=(AliHLTTPCDigitRowData*) Allocate(size);
+ if (tgtBuffer!=NULL && pTgtSize!=NULL && *pTgtSize>0) {
+ if (size<=*pTgtSize) {
+ data=reinterpret_cast<AliHLTTPCDigitRowData*>(tgtBuffer);
+ } else {
+ }
+ } else {
+ data=reinterpret_cast<AliHLTTPCDigitRowData*>(Allocate(size));
+ }
+ if (pTgtSize) *pTgtSize=size;
+ if (data==NULL) return NULL;
nrow = (UInt_t)nrows;
AliHLTTPCDigitRowData *tempPt = data;
tempPt->fDigitData[localcount].fCharge=dig;
tempPt->fDigitData[localcount].fPad=pad;
tempPt->fDigitData[localcount].fTime=time;
-#ifdef do_mc
tempPt->fDigitData[localcount].fTrackID[0] = fDigits->GetTrackID(time,pad,0);
tempPt->fDigitData[localcount].fTrackID[1] = fDigits->GetTrackID(time,pad,1);
tempPt->fDigitData[localcount].fTrackID[2] = fDigits->GetTrackID(time,pad,2);
-#endif
localcount++;
} while (fDigits->Next());
}
<<"No Input avalible: Pointer to TFile == NULL"<<ENDLOG;
return 0;
}
-#ifndef use_newio
- if(!fInAli->IsOpen()){
- LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliAltroDigits2Memory","File")
- <<"No Input avalible: TFile not opened"<<ENDLOG;
- return 0;
- }
-#endif
if(eventmerge == kTRUE && event >= 1024)
{
LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliAltroDigits2Memory","TrackIDs")
}
delete fDigits;
fDigits=0;
-#ifdef use_newio
/* Dont understand why we have to do
reload the tree, but otherwise the code crashes */
fDigitsTree=0;
if(!GetDigitsTree(event)) return 0;
-#else
- if(!fDigitsTree){
- if(!GetDigitsTree(event)) return 0;
- }
-#endif
UShort_t dig;
Int_t time,pad,sector,row;
tempPt->fDigitData[localcount].fCharge=dig;
tempPt->fDigitData[localcount].fPad=pad;
tempPt->fDigitData[localcount].fTime=time;
-#ifdef do_mc
tempPt->fDigitData[localcount].fTrackID[0] = (fDigits->GetTrackIDFast(time,pad,0)-2);
tempPt->fDigitData[localcount].fTrackID[1] = (fDigits->GetTrackIDFast(time,pad,1)-2);
tempPt->fDigitData[localcount].fTrackID[2] = (fDigits->GetTrackIDFast(time,pad,2)-2);
tempPt->fDigitData[localcount].fTrackID[1] += ((event&0x3ff)<<22);
tempPt->fDigitData[localcount].fTrackID[2] += ((event&0x3ff)<<22);
}
-#endif
localcount++;
}
}
Bool_t AliHLTTPCFileHandler::GetDigitsTree(Int_t event)
{
//Connects to the TPC digit tree in the AliROOT file.
-#ifdef use_newio
AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader");
if(!tpcLoader){
LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::GetDigitsTree","File")
fInAli->GetEvent(event);
tpcLoader->LoadDigits();
fDigitsTree = tpcLoader->TreeD();
-#else
- fInAli->cd();
- Char_t dname[100];
- sprintf(dname,"TreeD_%s_%d",AliHLTTPCTransform::GetParamName(),event);
- fDigitsTree = (TTree*)fInAli->Get(dname);
-#endif
if(!fDigitsTree)
{
LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::GetDigitsTree","Digits Tree")
else return kTRUE;
}
-void AliHLTTPCFileHandler::AliDigits2RootFile(AliHLTTPCDigitRowData *rowPt,Char_t *new_digitsfile)
+void AliHLTTPCFileHandler::AliDigits2RootFile(AliHLTTPCDigitRowData *rowPt,Char_t *newDigitsfile)
{
//Write the data stored in rowPt, into a new AliROOT file.
//The data is stored in the AliROOT format
return;
}
-#ifdef use_newio
//Get the original digitstree:
AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader");
if(!tpcLoader){
tpcLoader->LoadDigits();
TTree *t=tpcLoader->TreeD();
- AliTPCDigitsArray *old_array = new AliTPCDigitsArray();
- old_array->Setup(fParam);
- old_array->SetClass("AliSimDigits");
+ AliTPCDigitsArray *oldArray = new AliTPCDigitsArray();
+ oldArray->Setup(fParam);
+ oldArray->SetClass("AliSimDigits");
- Bool_t ok = old_array->ConnectTree(t);
+ Bool_t ok = oldArray->ConnectTree(t);
if(!ok)
{
LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliDigits2RootFile","File")
return;
}
- tpcLoader->SetDigitsFileName(new_digitsfile);
+ tpcLoader->SetDigitsFileName(newDigitsfile);
tpcLoader->MakeDigitsContainer();
//setup a new one, or connect it to the existing one:
arr->SetClass("AliSimDigits");
arr->Setup(fParam);
arr->MakeTree(tpcLoader->TreeD());
-#else
-
- //Get the original digitstree:
- Char_t dname[100];
- sprintf(dname,"TreeD_%s_0",AliHLTTPCTransform::GetParamName());
-
- fInAli->cd();
- AliTPCDigitsArray *old_array = new AliTPCDigitsArray();
- old_array->Setup(fParam);
- old_array->SetClass("AliSimDigits");
-
- Bool_t ok = old_array->ConnectTree(dname);
- if(!ok)
- {
- LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliDigits2RootFile","File")
- <<"No digits tree object." <<ENDLOG;
- return;
- }
-
- Bool_t create=kFALSE;
- TFile *digFile;
-
- if(gSystem->AccessPathName(new_digitsfile))
- {
- LOG(AliHLTTPCLog::kInformational,"AliHLTTPCFileHandler::AliDigits2RootFile","File")
- <<"Creating new file "<<new_digitsfile<<ENDLOG;
- create = kTRUE;
- digFile = TFile::Open(new_digitsfile,"RECREATE");
- fParam->Write(fParam->GetTitle());
- }
- else
- {
- create = kFALSE;
- digFile = TFile::Open(new_digitsfile,"UPDATE");
-
- }
- if(!digFile->IsOpen())
- {
- LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliDigits2RootFile","Rootfile")
- <<"Error opening rootfile "<<new_digitsfile<<ENDLOG;
- return;
- }
-
- digFile->cd();
-
- //setup a new one, or connect it to the existing one:
- AliTPCDigitsArray *arr = new AliTPCDigitsArray();
- arr->SetClass("AliSimDigits");
- arr->Setup(fParam);
- if(create)
- arr->MakeTree();
- else
- {
- Bool_t ok = arr->ConnectTree(dname);
- if(!ok)
- {
- LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliDigits2RootFile","Rootfile")
- <<"No digits tree object in existing file"<<ENDLOG;
- return;
- }
- }
-#endif
Int_t digcounter=0,trackID[3];
Int_t sector,row;
AliHLTTPCTransform::Slice2Sector(fSlice,i,sector,row);
- AliSimDigits *old_dig = (AliSimDigits*)old_array->LoadRow(sector,row);
+ AliSimDigits *oldDig = (AliSimDigits*)oldArray->LoadRow(sector,row);
AliSimDigits * dig = (AliSimDigits*)arr->CreateRow(sector,row);
- old_dig->ExpandBuffer();
- old_dig->ExpandTrackBuffer();
+ oldDig->ExpandBuffer();
+ oldDig->ExpandTrackBuffer();
dig->ExpandBuffer();
dig->ExpandTrackBuffer();
- if(!old_dig)
+ if(!oldDig)
LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliDigits2RootFile","Data")
<<"No padrow " << sector << " " << row <<ENDLOG;
//Tricks to get and set the correct track id's.
for(Int_t t=0; t<3; t++)
{
- Int_t label = old_dig->GetTrackIDFast(time,pad,t);
+ Int_t label = oldDig->GetTrackIDFast(time,pad,t);
if(label > 1)
trackID[t] = label - 2;
else if(label==0)
UpdateRowPointer(rowPt);
arr->StoreRow(sector,row);
arr->ClearRow(sector,row);
- old_array->ClearRow(sector,row);
+ oldArray->ClearRow(sector,row);
}
char treeName[100];
sprintf(treeName,"TreeD_%s_0",fParam->GetTitle());
-#ifdef use_newio
arr->GetTree()->SetName(treeName);
arr->GetTree()->AutoSave();
tpcLoader->WriteDigits("OVERWRITE");
-#else
- digFile->cd();
- arr->GetTree()->SetName(treeName);
- arr->GetTree()->AutoSave();
- digFile->Close();
-#endif
delete arr;
- delete old_array;
+ delete oldArray;
}
///////////////////////////////////////// Point IO
<<"No Input avalible: no object fInAli"<<ENDLOG;
return 0;
}
-#ifndef use_newio
- if(!fInAli->IsOpen()){
- LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliPoints2Memory","File")
- <<"No Input avalible: TFile not opend"<<ENDLOG;
- return 0;
- }
-#endif
TDirectory *savedir = gDirectory;
-#ifdef use_newio
AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader");
if(!tpcLoader){
LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliPoints2Memory","File")
carray.Setup(fParam);
carray.SetClusterType("AliTPCcluster");
Bool_t clusterok = carray.ConnectTree(tpcLoader->TreeR());
-#else
- fInAli->cd();
-
- Char_t cname[100];
- sprintf(cname,"TreeC_TPC_%d",eventn);
- AliTPCClustersArray carray;
- carray.Setup(fParam);
- carray.SetClusterType("AliTPCcluster");
- Bool_t clusterok = carray.ConnectTree(cname);
-#endif
if(!clusterok) return 0;
Int_t row = rows[i];
Int_t sector = sects[i];
AliHLTTPCTransform::Sector2Slice(lslice,lrow,sector,row);
- Int_t entries_in_row = clusterrow[i]->GetArray()->GetEntriesFast();
- for(Int_t j = 0;j<entries_in_row;j++){
+ Int_t entriesInRow = clusterrow[i]->GetArray()->GetEntriesFast();
+ for(Int_t j = 0;j<entriesInRow;j++){
AliTPCcluster *c = (AliTPCcluster*)(*clusterrow[i])[j];
data[n].fZ = c->GetZ();
data[n].fY = c->GetY();