]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSpList.cxx
fixed the tainted variables
[u/mrichter/AliRoot.git] / ITS / AliITSpList.cxx
index 260c2230bf449628ae3abbc3e66a9c78be82f78e..c9e85eea895b9e3b44ecf0a3a8da3604902c45be 100644 (file)
  **************************************************************************/
 /* $Id$ */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <iostream.h>
-#include <iomanip.h>
-#include <TObjArray.h>
-#include <TRandom.h>
-#include <TMath.h>
+//***********************************************************************
+//
+// It consist of a TClonesArray of 
+// AliITSpListItem objects
+// This array can be accessed via 2 indexed
+// it is used at digitization level by 
+// all the 3 ITS subdetectors
+//
+// ***********************************************************************
 
 #include "AliITSpList.h"
+#include "AliITSpListItem.h"
+
 
 //______________________________________________________________________
 
-ClassImp(AliITSpList);
+ClassImp(AliITSpList)
 //______________________________________________________________________
-AliITSpList::AliITSpList(){
+AliITSpList::AliITSpList():
+fNi(0),
+fNj(0),
+fa(0),
+fEntries(0){
     // Default constructor
+    // Inputs:
+    //    none.
+    // Outputs:
+    //    none.
+    // Return:
+    //    A zeroed/empty AliITSpList class.
 
-    fNi = 0;
-    fNj = 0;
-    fa  = 0;
 }
 //______________________________________________________________________
-AliITSpList::AliITSpList(Int_t imax,Int_t jmax){
+AliITSpList::AliITSpList(Int_t imax,Int_t jmax):
+fNi(imax),
+fNj(jmax),
+fa(new AliITSpListItem[imax*jmax]),
+fEntries(0){
     // Standard constructor
+    // Inputs:
+    //    none.
+    // Outputs:
+    //    none.
+    // Return:
+    //    A setup AliITSpList class.
 
-    fNi = imax;
-    fNj = jmax;
-    fa  = new TObjArray(fNi*fNj); // elements are zeroed by 
-                                  // TObjArray creator
 }
 //______________________________________________________________________
 AliITSpList::~AliITSpList(){
     // Default destructor
 
-    for(Int_t i=0;i<GetMaxIndex();i++) if(fa->At(i)!=0){
-       delete fa->At(i);
-       fa->AddAt(0,i); // zero content
-    } // end for i && if
-    fNi = 0;
-    fNj = 0;
-    delete fa;
-    fa  = 0;
+  delete [] fa;
+  fNi = 0;
+  fNj = 0;
+  fEntries = 0;
 }
+
 //______________________________________________________________________
 void AliITSpList::ClearMap(){
-    // Delete all AliITSpListItems and zero TObjArray.
-
-    for(Int_t i=0;i<GetMaxIndex();i++) if(fa->At(i)!=0){
-       delete fa->At(i);
-       fa->AddAt(0,i); // zero content
-    } // end for i && if
+    // Delete all AliITSpListItems and zero TClonesArray.
+    // Inputs:
+    //    none.
+    // Outputs:
+    //    none.
+    // Return:
+    //    A zeroed AliITSpList class.
+  for(Int_t i=0; i<fEntries; i++)(fa[i]).MarkUnused();
+  fEntries = 0;
 }
 //______________________________________________________________________
 void AliITSpList::DeleteHit(Int_t i,Int_t j){
-    // Delete a particular AliITSpListItems and zero TObjArray.
+    // Delete a particular AliITSpListItems.
+    // Inputs:
+    //    Int_t i   Row number
+    //    Int_t j   Columns number
+    // Outputs:
+    //    none.
+    // Return:
+    //    none.
     Int_t k = GetIndex(i,j);
-
-    if(fa->At(k)!=0){
-       delete fa->At(k);
-       fa->AddAt(0,k); // zero content
-    } // end for i && if
+    if((fa[k]).IsUsed())(fa[k]).MarkUnused();
+    if(k==fEntries-1) fEntries--;
 }
 //______________________________________________________________________
 AliITSpList& AliITSpList::operator=(const AliITSpList &source){
     // = operator
+    // Inputs:
+    //    const AliITSpList &source    A AliITSpList object.
+    // Outputs:
+    //    none.
+    // Return:
+    //    A copied AliITSpList object.
 
-    if(this == &source) return *this;
-
-    if(this->fa!=0){ // if this->fa exists delete it first.
-       for(Int_t i=0;i<GetMaxIndex();i++) if(fa->At(i)!=0){
-           delete fa->At(i);
-           fa->AddAt(0,i); // zero content
-       } // end for i && if
-       delete this->fa;
-    } // end if this->fa!=0
-    this->fNi = source.fNi;
-    this->fNj = source.fNj;
-    this->fa = new TObjArray(*(source.fa));
-
-    return *this;
+  this->~AliITSpList();
+  new(this) AliITSpList(source);
+  return *this;
 }
 //______________________________________________________________________
-AliITSpList::AliITSpList(AliITSpList &source){
-    // Copy operator
-
-    *this = source;
+AliITSpList::AliITSpList(const AliITSpList &source) : AliITSMap(source),
+fNi(source.fNi),
+fNj(source.fNj),
+fa(new AliITSpListItem[fNi*fNj]),
+fEntries(source.fEntries){
+    // Copy constructor
+  for(Int_t i=0; i<fEntries; i++)(fa[i]).Build(source.fa[i]);
+}
+//______________________________________________________________________
+void AliITSpList::AddItemTo(Int_t fileIndex, AliITSpListItem *pl) {
+    // Adds the contents of pl to the list with track number off set given by
+    // fileIndex.
+    // Creates the AliITSpListItem if needed.
+    // Inputs:
+    //    Int_t fileIndex      track number offset value
+    //    AliITSpListItem *pl  an AliITSpListItem to be added to this class.
+    // Outputs:
+    //    none.
+    // Return:
+    //    none.
+    Int_t index = pl->GetIndex();
+    AliITSpListItem &lit = fa[index];
+    if(!lit.IsUsed())lit.Build(-2,-1,pl->GetModule(),index,0.);
+    lit.AddTo(fileIndex,pl);
+    if(index>=fEntries) fEntries = index +1;
 }
 //______________________________________________________________________
 void AliITSpList::AddSignal(Int_t i,Int_t j,Int_t trk,Int_t ht,Int_t mod,
-                      Double_t signal){
-    // Adds a Signal value to the TObjArray at i,j. Creates the AliITSpListItem
+                       Double_t signal){
+    // Adds a Signal value to the TClonesArray at i,j. 
+    // Creates the AliITSpListItem
     // if needed.
-
-    if(GetpListItem(i,j)==0){ // most create AliITSpListItem
-       fa->AddAt(new AliITSpListItem(trk,ht,mod,GetIndex(i,j),signal),
-                 GetIndex(i,j));
-    }else{ // AliITSpListItem exists, just add signal to it.
-       GetpListItem(i,j)->AddSignal(trk,ht,mod,GetIndex(i,j),signal);
-    } // end if
+    // Inputs:
+    //    Int_t i         Row number for this signal
+    //    Int_t j         Column number for this signal
+    //    Int_t trk       Track number creating this signal
+    //    Int_t ht        Hit number creating this signal
+    //    Int_t mod       The module where this signal is in
+    //    Double_t signal The signal (ionization)
+    // Outputs:
+    //    none.
+    // Return:
+    //    none.
+    Int_t index = GetIndex(i,j);
+    if (index<0) return;
+    AliITSpListItem &lit = fa[index];
+    if(!lit.IsUsed()){
+      lit.Build(trk,ht,mod,index,signal);
+    }
+    else {
+      lit.AddSignal(trk,ht,mod,index,signal);
+    }
+    if(index>=fEntries) fEntries = index +1;
 }
 //______________________________________________________________________
 void AliITSpList::AddNoise(Int_t i,Int_t j,Int_t mod,Double_t noise){
-    // Adds a noise value to the TObjArray at i,j. Creates the AliITSpListItem
+    // Adds a noise value to the TClonesArray at i,j. 
+    // Creates the AliITSpListItem
     // if needed.
-
-    if(GetpListItem(i,j)==0){ // most create AliITSpListItem
-       fa->AddAt(new AliITSpListItem(mod,GetIndex(i,j),noise),
-                 GetIndex(i,j));
-    }else{ // AliITSpListItem exists, just add signal to it.
-       GetpListItem(i,j)->AddNoise(mod,GetIndex(i,j),noise);
-    } // end if
-}
-//______________________________________________________________________
-
-ClassImp(AliITSpListItem)
-//______________________________________________________________________
-AliITSpListItem::AliITSpListItem(){
-    // Default constructor
-
-    fmodule = -1;
-    findex  = -1;
-    for(Int_t i=0;i<this->fkSize;i++){
-       this->fTrack[i]  = -2;
-       this->fHits[i]   = -2;
-       this->fSignal[i] = 0.0;
-    } // end if i
-    fTsignal = 0.0;
-    fNoise   = 0.0;
-}
-//______________________________________________________________________
-AliITSpListItem::AliITSpListItem(Int_t module,Int_t index,Double_t noise){
-    // Standard noise constructor
-
-    this->fmodule    = module;
-    this->findex     = index;
-    for(Int_t i=0;i<this->fkSize;i++){
-       this->fTrack[i]  = -2;
-       this->fSignal[i] = 0.0;
-       this->fHits[i]   = 0;
-    } // end if i
-    this->fTsignal = 0.0;
-    this->fNoise   = noise;
-}
-//______________________________________________________________________
-AliITSpListItem::AliITSpListItem(Int_t track,Int_t hit,Int_t module,
-                              Int_t index,Double_t signal){
-    // Standard signal constructor
-
-    this->fmodule    = module;
-    this->findex     = index;
-    this->fTrack[0]  = track;
-    this->fHits[0]   = hit;
-    this->fSignal[0] = signal;
-    for(Int_t i=1;i<this->fkSize;i++){
-       this->fTrack[i]  = -2;
-       this->fSignal[i] = 0.0;
-       this->fHits[i]   = 0;
-    } // end if i
-    this->fTsignal = signal;
-    this->fNoise   = 0.0;
-}
-//______________________________________________________________________
-AliITSpListItem::~AliITSpListItem(){
-    // Denstructor
-
-    this->fmodule = 0;
-    this->findex  =0;
-    for(Int_t i=0;i<=this->GetNsignals();i++){
-       this->fTrack[i]  = 0;
-       this->fSignal[i] = 0.0;
-       this->fHits[i]   = 0;
-    } // end if i
-    this->fTsignal = 0.0;
-    this->fNoise   =0.0;
-}
-//______________________________________________________________________
-AliITSpListItem& AliITSpListItem::operator=(const AliITSpListItem &source){
-    // = operator
-
-    if(this == &source) return *this;
-
-    this->fmodule = source.fmodule;
-    this->findex  = source.findex;
-    for(Int_t i=0;i<this->fkSize;i++){
-       this->fTrack[i]  = source.fTrack[i];
-       this->fSignal[i] = source.fSignal[i];
-       this->fHits[i]   = source.fHits[i];
-    } // end if i
-    this->fTsignal = source.fTsignal;
-    this->fNoise   = source.fNoise;
-
-    return *this;
-}
-//______________________________________________________________________
-AliITSpListItem::AliITSpListItem(AliITSpListItem &source){
-    // Copy operator
-
-    *this = source;
-}
-//______________________________________________________________________
-void AliITSpListItem::AddSignal(Int_t track,Int_t hit,Int_t module,
-                              Int_t index,Double_t signal){
-    // Adds this track number and sinal to the pList and orders them
-    Int_t    i,j,trk,hts;
-    Double_t sig;
-    Bool_t   flg=kFALSE;
-
-    if(findex!=index || fmodule!=module) 
-       Warning("AddSignal","index=%d != findex=%d or module=%d != fmodule=%d",
-           index,findex,module,fmodule);
-    fTsignal += signal; // Keep track of sum signal.
-    if(signal<=fSignal[fkSize-1]) return; // smaller than smallest
-    for(i=0;i<fkSize;i++)if(track==fTrack[i] && hit ==fHits[i]){
-       fSignal[i] += signal;
-       flg = kTRUE;
-    } // end for i & if.
-    if(flg){ // the arrays are already sorted with the possible exception
-             // of one element
-      j=0;
-      for(i=0;i<fkSize-1;i++){
-        if(fSignal[i]<fSignal[i+1]){
-          j=i+1;
-          break;
-        }
-      }
-      /* debug printouts
-      if(j>0){
-        cout<<"AliITSpListItem::AddSignal - before sorting - signal="<<signal<<" mod="<<module<<endl;
-        for(i=0;i<fkSize-1;i++)cout<<fSignal[i]<<" ";
-        cout<<fSignal[fkSize-1]<<endl;
-      }
-      */
-      for(i=j;i>0;i--){
-        if(fSignal[i]>fSignal[i-1]){
-          trk = fTrack[i-1];
-          hts = fHits[i-1];
-          sig = fSignal[i-1];
-          fTrack[i-1]=fTrack[i];
-          fHits[i-1]=fHits[i];
-          fSignal[i-1]=fSignal[i];
-          fTrack[i]=trk;
-          fHits[i]=hts;
-          fSignal[i]=sig;
-        }
-      }
-      /*  debug printouts
-      if(j>0){
-        cout<<"AliITSpListItem::AddSignal - after sorting\n";
-        for(i=0;i<fkSize-1;i++)cout<<fSignal[i]<<" ";
-        cout<<fSignal[fkSize-1]<<endl;
-      }
-      */
-      return;
+    // Inputs:
+    //    Int_t i        Row number for this noise
+    //    Int_t j        Column number for this noise
+    //    Double_t noise The noise signal value.
+    // Outputs:
+    //    none.
+    // Return:
+    //    none.
+    Int_t index = GetIndex(i,j);
+    if (index<0) return;
+    AliITSpListItem &lit = fa[index];
+    if(!lit.IsUsed()){
+      lit.Build(mod,index,noise);
     }
-
-    // new entry add it in order.
-    // if this signal is <= smallest then don't add it.
-    if(signal <= fSignal[fkSize-1]) return;
-    for(i=fkSize-2;i>=0;i--){
-       if(signal > fSignal[i]){
-           fSignal[i+1] = fSignal[i];
-           fTrack[i+1]  = fTrack[i];
-           fHits[i+1]   = fHits[i];
-       }else{
-      fSignal[i+1] = signal;    // changed m.m.
-      fTrack[i+1]  = track;     // changed m.m. 
-      fHits[i+1]   = hit;       // changed m.m.
-           return; // put it in the right place, now exit.
-       } //  end if
-    } // end if; end for i
-    // Still haven't found the right place. Must be at top of list.
-    fSignal[0] = signal;
-    fTrack[0]  = track;
-    fHits[0]   = hit;
-    return;
-}
-//______________________________________________________________________
-void AliITSpListItem::AddNoise(Int_t module,Int_t index,Double_t noise){
-    // Addes noise to this existing list.
-
-    if(findex!=index || fmodule!=module) 
-       Warning("AddSignal","index=%d != findex=%d or module=%d != fmodule=%d",
-           index,findex,module,fmodule);
-    fNoise += noise; // Keep track of sum signal.
-}
-//______________________________________________________________________
-void AliITSpListItem::AddTo(Int_t fileIndex,AliITSpListItem *pl){
-    // Adds the contents of pl to this with track number off set given by
-    // fileIndex.
-    Int_t i,trk;
-    Double_t sig=0.0;
-
-    for(i=0;i<pl->GetNsignals()&&i<this->GetNsignals();i++){
-       trk = pl->GetTrack(i);
-       trk = pl->ShiftIndex(fileIndex,trk);
-       this->AddSignal(trk,pl->GetHit(i),pl->GetModule(),pl->GetIndex(),pl->GetSignal(i));
-       sig += pl->GetSignal(i);
-    } // end for i
-    this->fNoise   += pl->fNoise;
+    else {
+      lit.AddNoise(mod,index,noise);
+    } 
+    if(index>=fEntries) fEntries = index +1;
+}
+//______________________________________________________________________
+void AliITSpList::GetCell(Int_t index,Int_t &i,Int_t &j) const {
+  // returns the i,j index numbers from the linearized index computed
+  // with GetIndex
+  if(index<0 || index>=fNi*fNj){
+    Warning("GetCell","Index out of range 0<=index=%d<%d",
+           index,fNi*fNj);
+    i=-1;j=-1;
     return;
-}
-//______________________________________________________________________
-Int_t AliITSpListItem::ShiftIndex(Int_t in,Int_t trk){
-    // Shift an index number to occupy the upper four bits.
-    Int_t si = sizeof(Int_t) * 8;
-    UInt_t uin,utrk; // use UInt_t to avoid interger overflow-> goes negitive.
-
-    uin = in;
-    utrk = trk;
-    for(Int_t i=0;i<si-4;i++) uin *= 2;
-    uin += utrk;
-    in = uin;
-    return in;
-}
-//______________________________________________________________________
-void AliITSpListItem::Print(ostream *os){
-    //Standard output format for this class
-    Int_t i;
-
-    *os << fmodule <<","<<findex<<",";
-    *os << fkSize <<",";
-    for(i=0;i<fkSize;i++) *os << fTrack[i] <<",";
-    for(i=0;i<fkSize;i++) *os << fHits[i] <<",";
-    for(i=0;i<fkSize;i++) *os << fSignal[i] <<",";
-    *os << fTsignal <<","<< fNoise;
-}
-//______________________________________________________________________
-void AliITSpListItem::Read(istream *is){
-    // Standard output streaming function.
-    Int_t i,iss;
-
-    *is >> fmodule >> findex;
-    *is >> iss; // read in fkSize
-    for(i=0;i<fkSize&&i<iss;i++) *is >> fTrack[i];
-    for(i=0;i<fkSize&&i<iss;i++) *is >> fHits[i];
-    for(i=0;i<fkSize&&i<iss;i++) *is >> fSignal[i];
-    *is >> fTsignal >> fNoise;
-}
-//______________________________________________________________________
-ostream &operator<<(ostream &os,AliITSpListItem &source){
-    // Standard output streaming function.
-
-    source.Print(&os);
-    return os;
-}
-//______________________________________________________________________
-istream &operator>>(istream &os,AliITSpListItem &source){
-    // Standard output streaming function.
-
-    source.Read(&os);
-    return os;
+  } // end if
+  i = index/fNj;
+  j = index - fNj*i;
+  return;
 }