#include "AliMultiplicity.h"
#include "AliRawDataErrorLog.h"
#include "AliLog.h"
-
+#include "AliESDACORDE.h"
ClassImp(AliESDEvent)
"CaloClusters",
"EMCALCells",
"PHOSCells",
- "AliRawDataErrorLogs"};
+ "AliRawDataErrorLogs",
+ "AliESDACORDE"};
+
//______________________________________________________________________________
AliESDEvent::AliESDEvent():
AliVEvent(),
fSPDMult(0),
fPHOSTrigger(0),
fEMCALTrigger(0),
+ fESDACORDE(0),
fTracks(0),
fMuonTracks(0),
fPmdTracks(0),
fESDOld(0),
fESDFriendOld(0),
fConnected(kFALSE),
+ fUseOwnList(kFALSE),
fEMCALClusters(0),
fFirstEMCALCluster(-1),
fPHOSClusters(0),
fSPDMult(new AliMultiplicity(*esd.fSPDMult)),
fPHOSTrigger(new AliESDCaloTrigger(*esd.fPHOSTrigger)),
fEMCALTrigger(new AliESDCaloTrigger(*esd.fEMCALTrigger)),
+ fESDACORDE(new AliESDACORDE(*esd.fESDACORDE)),
fTracks(new TClonesArray(*esd.fTracks)),
fMuonTracks(new TClonesArray(*esd.fMuonTracks)),
fPmdTracks(new TClonesArray(*esd.fPmdTracks)),
fESDOld(new AliESD(*esd.fESDOld)),
fESDFriendOld(new AliESDfriend(*esd.fESDFriendOld)),
fConnected(esd.fConnected),
+ fUseOwnList(esd.fUseOwnList),
fEMCALClusters(esd.fEMCALClusters),
fFirstEMCALCluster(esd.fFirstEMCALCluster),
fPHOSClusters(esd.fPHOSClusters),
AddObject(fEMCALCells);
AddObject(fPHOSCells);
AddObject(fErrorLogs);
+ AddObject(fESDACORDE);
GetStdContent();
if(&source == this) return *this;
AliVEvent::operator=(source);
- fESDRun = new AliESDRun(*source.fESDRun);
- fHeader = new AliESDHeader(*source.fHeader);
- fESDZDC = new AliESDZDC(*source.fESDZDC);
- fESDFMD = new AliESDFMD(*source.fESDFMD);
- fESDVZERO = new AliESDVZERO(*source.fESDVZERO);
- fESDTZERO = new AliESDTZERO(*source.fESDTZERO);
- fTPCVertex = new AliESDVertex(*source.fTPCVertex);
- fSPDVertex = new AliESDVertex(*source.fSPDVertex);
- fPrimaryVertex = new AliESDVertex(*source.fPrimaryVertex);
- fSPDMult = new AliMultiplicity(*source.fSPDMult);
- fPHOSTrigger = new AliESDCaloTrigger(*source.fPHOSTrigger);
- fEMCALTrigger = new AliESDCaloTrigger(*source.fEMCALTrigger);
- fTracks = new TClonesArray(*source.fTracks);
- fMuonTracks = new TClonesArray(*source.fMuonTracks);
- fPmdTracks = new TClonesArray(*source.fPmdTracks);
- fTrdTracks = new TClonesArray(*source.fTrdTracks);
- fV0s = new TClonesArray(*source.fV0s);
- fCascades = new TClonesArray(*source.fCascades);
- fKinks = new TClonesArray(*source.fKinks);
- fCaloClusters = new TClonesArray(*source.fCaloClusters);
- fEMCALCells = new AliESDCaloCells(*source.fEMCALCells);
- fPHOSCells = new AliESDCaloCells(*source.fPHOSCells);
- fErrorLogs = new TClonesArray(*source.fErrorLogs);
- fESDOld = new AliESD(*source.fESDOld);
- fESDFriendOld = new AliESDfriend(*source.fESDFriendOld);
- // CKB this way?? or
- // or AddObject( fESDZDC = new AliESDZDC(*source.fESDZDC));
-
- fESDObjects = new TList();
- AddObject(fESDRun);
- AddObject(fHeader);
- AddObject(fESDZDC);
- AddObject(fESDFMD);
- AddObject(fESDVZERO);
- AddObject(fESDTZERO);
- AddObject(fTPCVertex);
- AddObject(fSPDVertex);
- AddObject(fPrimaryVertex);
- AddObject(fSPDMult);
- AddObject(fPHOSTrigger);
- AddObject(fEMCALTrigger);
- AddObject(fTracks);
- AddObject(fMuonTracks);
- AddObject(fPmdTracks);
- AddObject(fTrdTracks);
- AddObject(fV0s);
- AddObject(fCascades);
- AddObject(fKinks);
- AddObject(fCaloClusters);
- AddObject(fEMCALCells);
- AddObject(fPHOSCells);
- AddObject(fErrorLogs);
+ // This assumes that the list is already created
+ // and that the virtual void Copy(Tobject&) function
+ // is correctly implemented in the derived class
+ // otherwise only TObject::Copy() will be used
+
+
+
+ if((fESDObjects->GetSize()==0)&&(source.fESDObjects->GetSize()>=kESDListN)){
+ // We cover the case that we do not yet have the
+ // standard content but the source has it
+ CreateStdContent();
+ }
+
+ TIter next(source.GetList());
+ TObject *its = 0;
+ TString name;
+ while ((its = next())) {
+ name.Form("%s", its->GetName());
+ TObject *mine = fESDObjects->FindObject(name.Data());
+ if(!mine){
+ TClass* pClass=TClass::GetClass(its->ClassName());
+ if (!pClass) {
+ AliWarning(Form("Can not find class description for entry %s (%s)\n",
+ its->ClassName(), name.Data()));
+ continue;
+ }
+
+ mine=(TObject*)pClass->New();
+ if(!mine){
+ // not in this: can be added to list
+ AliWarning(Form("%s:%d Could not find %s for copying \n",
+ (char*)__FILE__,__LINE__,name.Data()));
+ continue;
+ }
+ if(mine->InheritsFrom("TNamed")){
+ ((TNamed*)mine)->SetName(name);
+ }
+ else if(mine->InheritsFrom("TCollection")){
+ if(mine->InheritsFrom("TClonesArray"))
+ dynamic_cast<TClonesArray*>(mine)->SetClass(dynamic_cast<TClonesArray*>(its)->GetClass());
+ dynamic_cast<TCollection*>(mine)->SetName(name);
+ }
+ AliDebug(1, Form("adding object %s of type %s", mine->GetName(), mine->ClassName()));
+ AddObject(mine);
+ }
+
+ if(!its->InheritsFrom("TCollection")){
+ // simple objects
+ its->Copy(*mine);
+ }
+ else if(its->InheritsFrom("TClonesArray")){
+ // Create or expand the tclonesarray pointers
+ // so we can directly copy to the object
+ TClonesArray *its_tca = (TClonesArray*)its;
+ TClonesArray *mine_tca = (TClonesArray*)mine;
+
+ // this leaves the capacity of the TClonesArray the same
+ // except for a factor of 2 increase when size > capacity
+ // does not release any memory occupied by the tca
+ mine_tca->ExpandCreate(its_tca->GetEntriesFast());
+ for(int i = 0;i < its_tca->GetEntriesFast();++i){
+ // copy
+ TObject *mine_tca_obj = mine_tca->At(i);
+ TObject *its_tca_obj = its_tca->At(i);
+ // no need to delete first
+ // pointers within the class should be handled by Copy()...
+ // Can there be Empty slots?
+ its_tca_obj->Copy(*mine_tca_obj);
+ }
+ }
+ else{
+ AliWarning(Form("%s:%d cannot copy TCollection \n",
+ (char*)__FILE__,__LINE__));
+ }
+ }
fConnected = source.fConnected;
+ fUseOwnList = source.fUseOwnList;
fEMCALClusters = source.fEMCALClusters;
fFirstEMCALCluster = source.fFirstEMCALCluster;
fPHOSClusters = source.fPHOSClusters;
fFirstPHOSCluster = source.fFirstPHOSCluster;
-
return *this;
}
}
+void AliESDEvent::Copy(TObject &obj) const {
+
+ // interface to TOBject::Copy
+ // Copies the content of this into obj!
+ // bascially obj = *this
+
+ if(this==&obj)return;
+ AliESDEvent *robj = dynamic_cast<AliESDEvent*>(&obj);
+ if(!robj)return; // not an AliESEvent
+ *robj = *this;
+ return;
+}
+
//______________________________________________________________________________
void AliESDEvent::Reset()
{
-
+ // Handle the cases
+ // Std content + Non std content
+
// Reset the standard contents
ResetStdContent();
+
+ // reset for the old data without AliESDEvent...
if(fESDOld)fESDOld->Reset();
- // reset for the friends...
if(fESDFriendOld){
fESDFriendOld->~AliESDfriend();
new (fESDFriendOld) AliESDfriend();
}
- // for new data we have to fetch the Pointer from the list
- AliESDfriend *fr = (AliESDfriend*)FindListObject("AliESDfriend");
- if(fr){
- // delete the content
- fr->~AliESDfriend();
- // make a new valid ESDfriend at the same place
- new (fr) AliESDfriend();
+ //
+
+ if(fESDObjects->GetSize()>kESDListN){
+ // we have non std content
+ // this also covers esdfriends
+ for(int i = kESDListN;i < fESDObjects->GetSize();++i){
+ TObject *pObject = fESDObjects->At(i);
+ // TClonesArrays
+ if(pObject->InheritsFrom(TClonesArray::Class())){
+ ((TClonesArray*)pObject)->Delete();
+ }
+ else if(!pObject->InheritsFrom(TCollection::Class())){
+ ResetWithPlacementNew(pObject);
+ }
+ else{
+ AliWarning(Form("No reset for %s (%s)\n",
+ pObject->ClassName()));
+ }
+ }
}
- // call reset for user supplied data?
+}
+
+Bool_t AliESDEvent::ResetWithPlacementNew(TObject *pObject){
+ Long_t dtoronly = TObject::GetDtorOnly();
+ TClass *pClass = TClass::GetClass(pObject->ClassName());
+ TObject::SetDtorOnly(pObject);
+ delete pObject;
+ // Recreate with placement new
+ pClass->New(pObject);
+ // Restore the state.
+ TObject::SetDtorOnly((void*)dtoronly);
+ return kTRUE;
}
void AliESDEvent::ResetStdContent()
if(fESDRun) fESDRun->Reset();
if(fHeader) fHeader->Reset();
if(fESDZDC) fESDZDC->Reset();
- if(fESDFMD) fESDFMD->Clear(); // why clear.... need consistend names
+ if(fESDFMD) {
+ fESDFMD->Clear();
+ }
if(fESDVZERO){
// reset by callin d'to /c'tor keep the pointer
fESDVZERO->~AliESDVZERO();
new (fESDVZERO) AliESDVZERO();
}
+ if(fESDACORDE){
+ fESDACORDE->~AliESDACORDE();
+ new (fESDACORDE) AliESDACORDE();
+ }
if(fESDTZERO) fESDTZERO->Reset();
// CKB no clear/reset implemented
if(fTPCVertex){
Int_t used=0;
+ // Check if this track comes from the reconstructed primary vertices
+ if (fTPCVertex && fTPCVertex->GetStatus()) {
+ UShort_t *primIdx=fTPCVertex->GetIndices();
+ Int_t n=fTPCVertex->GetNIndices();
+ while (n--) {
+ Int_t idx=Int_t(primIdx[n]);
+ if (rm==idx) return kFALSE;
+ if (idx==last) used++;
+ }
+ }
+ if (fPrimaryVertex && fPrimaryVertex->GetStatus()) {
+ UShort_t *primIdx=fPrimaryVertex->GetIndices();
+ Int_t n=fPrimaryVertex->GetNIndices();
+ while (n--) {
+ Int_t idx=Int_t(primIdx[n]);
+ if (rm==idx) return kFALSE;
+ if (idx==last) used++;
+ }
+ }
+
// Check if this track comes from a reconstructed decay
Int_t nv0=GetNumberOfV0s();
for (Int_t n=0; n<nv0; n++) {
new (a[rm]) AliESDtrack(*t);
delete a.RemoveAt(last);
+
if (!used) return kTRUE;
+ // Remap the indices of the tracks used for the primary vertex reconstruction
+ if (fTPCVertex && fTPCVertex->GetStatus()) {
+ UShort_t *primIdx=fTPCVertex->GetIndices();
+ Int_t n=fTPCVertex->GetNIndices();
+ while (n--) {
+ Int_t idx=Int_t(primIdx[n]);
+ if (idx==last) {
+ primIdx[n]=Short_t(rm);
+ used--;
+ if (!used) return kTRUE;
+ }
+ }
+ }
+ if (fPrimaryVertex && fPrimaryVertex->GetStatus()) {
+ UShort_t *primIdx=fPrimaryVertex->GetIndices();
+ Int_t n=fPrimaryVertex->GetNIndices();
+ while (n--) {
+ Int_t idx=Int_t(primIdx[n]);
+ if (idx==last) {
+ primIdx[n]=Short_t(rm);
+ used--;
+ if (!used) return kTRUE;
+ }
+ }
+ }
+
// Remap the indices of the daughters of reconstructed decays
for (Int_t n=0; n<nv0; n++) {
AliESDv0 *v0=GetV0(n);
}
}
-void AliESDEvent::SetPrimaryVertex(const AliESDVertex *vertex)
+void AliESDEvent::SetPrimaryVertexTracks(const AliESDVertex *vertex)
{
- // Set the primary vertex
+ // Set the primary vertex reconstructed using he ESD tracks.
// use already allocated space
if(fPrimaryVertex){
*fPrimaryVertex = *vertex;
}
}
+const AliESDVertex * AliESDEvent::GetPrimaryVertex() const
+{
+ //
+ // Get the "best" available reconstructed primary vertex.
+ //
+ if(fPrimaryVertex){
+ if (fPrimaryVertex->GetStatus()) return fPrimaryVertex;
+ }
+ if(fSPDVertex){
+ if (fSPDVertex->GetStatus()) return fSPDVertex;
+ }
+ if(fTPCVertex) return fTPCVertex;
+
+ AliWarning("No primary vertex available. Returning the \"default\"...");
+ return fSPDVertex;
+}
+
void AliESDEvent::SetMultiplicity(const AliMultiplicity *mul)
{
// Set the SPD Multiplicity
*fESDVZERO = *obj;
}
+void AliESDEvent::SetACORDEData(AliESDACORDE * obj)
+{
+ if(fESDACORDE)
+ *fESDACORDE = *obj;
+}
+
+
void AliESDEvent::GetESDfriend(AliESDfriend *ev) const
{
//
t->ReleaseESDfriendTrack();// Not to have two copies of "friendTrack"
}
-}
+ AliESDfriend *fr = (AliESDfriend*)(const_cast<AliESDEvent*>(this)->FindListObject("AliESDfriend"));
+ if (fr) ev->SetVZEROfriend(fr->GetVZEROfriend());
+}
void AliESDEvent::AddObject(TObject* obj)
{
fEMCALCells = (AliESDCaloCells*)fESDObjects->FindObject(fgkESDListName[kEMCALCells]);
fPHOSCells = (AliESDCaloCells*)fESDObjects->FindObject(fgkESDListName[kPHOSCells]);
fErrorLogs = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kErrorLogs]);
+ fESDACORDE = (AliESDACORDE*)fESDObjects->FindObject(fgkESDListName[kESDACORDE]);
}
void AliESDEvent::SetStdNames(){
// Set the names of the standard contents
//
- if(fESDObjects->GetEntries()==kESDListN){
- for(int i = 0;i < fESDObjects->GetEntries();i++){
+ if(fESDObjects->GetEntries()>=kESDListN){
+ for(int i = 0;i < fESDObjects->GetEntries() && i<kESDListN;i++){
TObject *fObj = fESDObjects->At(i);
if(fObj->InheritsFrom("TNamed")){
((TNamed*)fObj)->SetName(fgkESDListName[i]);
}
}
else{
- printf("%s:%d SetStdNames() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
+ AliWarning("Std Entries missing");
}
}
+
+void AliESDEvent::CreateStdContent(Bool_t bUseThisList){
+ fUseOwnList = bUseThisList;
+ CreateStdContent();
+}
+
void AliESDEvent::CreateStdContent()
{
// create the standard AOD content and set pointers
AddObject(new AliESDCaloCells());
AddObject(new AliESDCaloCells());
AddObject(new TClonesArray("AliRawDataErrorLog",0));
+ AddObject(new AliESDACORDE());
// check the order of the indices against enum...
return clusters->GetEntriesFast();
}
-const void AliESDEvent::WriteToTree(TTree* tree) const {
+void AliESDEvent::WriteToTree(TTree* tree) const {
// Book the branches as in TTree::Branch(TCollection*)
// but add a "." at the end of top level branches which are
// not a TClonesArray
while ((obj = next())) {
branchname.Form("%s", obj->GetName());
+ if(branchname.CompareTo("AliESDfriend")==0)branchname = "ESDfriend.";
if ((kSplitlevel > 1) && !obj->InheritsFrom(TClonesArray::Class())) {
- branchname += ".";
+ if(!branchname.EndsWith("."))branchname += ".";
+ }
+ if (!tree->FindBranch(branchname)) {
+ tree->Bronch(branchname, obj->ClassName(), fESDObjects->GetObjectRef(obj),
+ kBufsize, kSplitlevel - 1);
}
- tree->Bronch(branchname, obj->ClassName(), fESDObjects->GetObjectRef(obj),
- kBufsize, kSplitlevel - 1);
}
-
}
-void AliESDEvent::ReadFromTree(TTree *tree){
+void AliESDEvent::ReadFromTree(TTree *tree, Option_t* /*opt*/){
//
// Connect the ESDEvent to a tree
//
if(!tree){
- Printf("%s %d AliESDEvent::ReadFromTree() Zero Pointer to Tree \n",(char*)__FILE__,__LINE__);
+ AliWarning("AliESDEvent::ReadFromTree() Zero Pointer to Tree \n");
return;
}
// load the TTree
char ** addressF = 0;
if(esdFB)addressF = (char **)(esdFB->GetAddress());
if (!address) {
- printf("%s %d AliESDEvent::ReadFromTree() Reading old Tree \n",(char*)__FILE__,__LINE__);
+ AliInfo("AliESDEvent::ReadFromTree() Reading old Tree");
tree->SetBranchAddress("ESD", &fESDOld);
if(esdFB){
tree->SetBranchAddress("ESDfriend.",&fESDFriendOld);
}
} else {
- printf("%s %d AliESDEvent::ReadFromTree() Reading old Tree \n",(char*)__FILE__,__LINE__);
- printf("%s %d Branch already connected. Using existing branch address. \n",(char*)__FILE__,__LINE__);
+ AliInfo("AliESDEvent::ReadFromTree() Reading old Tree");
+ AliInfo("Branch already connected. Using existing branch address.");
fESDOld = (AliESD*) (*address);
// addressF can still be 0, since branch needs to switched on
if(addressF)fESDFriendOld = (AliESDfriend*) (*addressF);
return;
}
- delete fESDOld;
- fESDOld = 0;
+
+ delete fESDOld;
+ fESDOld = 0;
// Try to find AliESDEvent
AliESDEvent *esdEvent = 0;
esdEvent = (AliESDEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliESDEvent");
fConnected = true;
return;
}
+
// Connect to tree
// prevent a memory leak when reading back the TList
- delete fESDObjects;
- fESDObjects = 0;
- // create a new TList from the UserInfo TList...
- // copy constructor does not work...
- fESDObjects = (TList*)(esdEvent->GetList()->Clone());
- fESDObjects->SetOwner(kFALSE);
+
+ if(!fUseOwnList){
+ delete fESDObjects;
+ fESDObjects = 0;
+ // create a new TList from the UserInfo TList...
+ // copy constructor does not work...
+ fESDObjects = (TList*)(esdEvent->GetList()->Clone());
+ fESDObjects->SetOwner(kFALSE);
+ }
+ else if ( fESDObjects->GetEntries()==0){
+ // at least create the std content if we want to read to our list
+ CreateStdContent();
+ }
+
+ // in principle
+ // we only need new things in the list if we do no already have it..
+ // TODO just add new entries
+
if(fESDObjects->GetEntries()<kESDListN){
- printf("%s %d AliESDEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n",
- (char*)__FILE__,__LINE__,fESDObjects->GetEntries(),kESDListN);
+ AliWarning(Form("AliESDEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n",
+ fESDObjects->GetEntries(),kESDListN));
}
// set the branch addresses
TIter next(fESDObjects);
tree->SetBranchAddress(Form("%s.",bname.Data()),fESDObjects->GetObjectRef(el));
}
else{
- printf("%s %d AliESDEvent::ReadFromTree() No Branch found with Name %s or %s. \n",
- (char*)__FILE__,__LINE__,bname.Data(),bname.Data());
+ AliWarning(Form("AliESDEvent::ReadFromTree() No Branch found with Name %s or %s.",bname.Data(),bname.Data()));
}
}
TNamed *el;
while((el=(TNamed*)next())){
TString bname(el->GetName());
- tree->SetBranchAddress(bname.Data(),fESDObjects->GetObjectRef(el));
+ TBranch *br = tree->GetBranch(bname.Data());
+ if(br){
+ tree->SetBranchAddress(bname.Data(),fESDObjects->GetObjectRef(el));
+ }
+ else{
+ br = tree->GetBranch(Form("%s.",bname.Data()));
+ if(br){
+ tree->SetBranchAddress(Form("%s.",bname.Data()),fESDObjects->GetObjectRef(el));
+ }
+ }
}
GetStdContent();
// when reading back we are not owner of the list
0,
fESDOld->GetZDCN2Energy(),
fESDOld->GetZDCP2Energy(),
- fESDOld->GetZDCParticipants());
+ fESDOld->GetZDCParticipants(),
+ 0);
// FMD
if(fESDOld->GetVertex())SetPrimaryVertexSPD(fESDOld->GetVertex());
- if(fESDOld->GetPrimaryVertex())SetPrimaryVertex(fESDOld->GetPrimaryVertex());
+ if(fESDOld->GetPrimaryVertex())SetPrimaryVertexTracks(fESDOld->GetPrimaryVertex());
if(fESDOld->GetMultiplicity())SetMultiplicity(fESDOld->GetMultiplicity());