]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSTableSSD.cxx
Adding histos to model fragment prod. from data
[u/mrichter/AliRoot.git] / ITS / AliITSTableSSD.cxx
1 /**************************************************************************
2  * Copyright(c) 2002-2003, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 #include <Riostream.h>
17 #include "AliITSTableSSD.h"
18
19 ClassImp(AliITSTableSSD)
20 ////////////////////////////////////////////////////////////////////////
21 // Version: 0                                                         //
22 // Origin: Massimo Masera                                             //
23 // March 2002                                                         //
24 //                                                                    //
25 // AliITSTableSSD is used by AliITSsimulationSSD class to fill the AliITSpList
26 // object starting from the map with energy depositions
27 ////////////////////////////////////////////////////////////////////////
28 //----------------------------------------------------------------------
29 AliITSTableSSD::AliITSTableSSD() : TObject(),
30 fDim(0),
31 fArray(0){
32   // Default Constructor
33   for(Int_t i=0;i<2;i++){
34     fCurrUse[i]=0;
35     fCurrFil[i]=0;
36   }
37 }
38 //----------------------------------------------------------------------
39 AliITSTableSSD::AliITSTableSSD(const AliITSTableSSD & source):TObject(source),
40 fDim(source.fDim),
41 fArray(source.fArray){
42   // Copy constructor
43
44     if(this == &source) return;
45     fArray = new Int_t [fDim];
46     fCurrUse[0]=(source.fCurrUse)[0];
47     fCurrUse[1]=(source.fCurrUse)[1];
48     fCurrFil[0]=(source.fCurrFil)[0];
49     fCurrFil[1]=(source.fCurrFil)[1];
50     for(Int_t i=0;i<fDim;i++)fArray[i]=(source.fArray)[i];
51 }
52 //----------------------------------------------------------------------
53 AliITSTableSSD& AliITSTableSSD::operator=(const AliITSTableSSD & source){
54   // = opporator constructor
55
56     if(this == &source) return *this;
57     fDim=source.fDim;
58     if(fArray)delete [] fArray;
59     fArray = new Int_t [fDim];
60     fCurrUse[0]=(source.fCurrUse)[0];
61     fCurrUse[1]=(source.fCurrUse)[1];
62     fCurrFil[0]=(source.fCurrFil)[0];
63     fCurrFil[1]=(source.fCurrFil)[1];
64     for(Int_t i=0;i<fDim;i++)fArray[i]=(source.fArray)[i];
65     return *this;
66 }
67 //----------------------------------------------------------------------
68 AliITSTableSSD::AliITSTableSSD(Int_t noelem) : TObject(),
69 fDim(0),
70 fArray(0){
71   // Standard constructor
72   fDim=noelem*2;
73   fArray = new Int_t [fDim];
74   Clear();
75 }
76 //----------------------------------------------------------------------
77 AliITSTableSSD::~AliITSTableSSD(){
78   // Destructor
79   delete [] fArray;
80   fArray=0;
81 }
82 //----------------------------------------------------------------------
83 void AliITSTableSSD::Add(Int_t side,Int_t strip){
84   // Add an element to the table
85   if(strip>=fDim/2){
86     cerr<<" Error in AliITSTableSSD::Add. "<<strip<<" is out of range\n";
87     return;
88   }
89   if((side!=0) && (side!=1)){
90     cerr<<" Error in AliITSTableSSD::Add. side="<<side<<endl;
91     cerr<<" side must be 0 or 1\n";
92     return;
93   }
94   if(fCurrFil[side]>(fDim/2-1)){
95     cerr<<" Error in AliITSTableSSD::Add. Trying to fill an element out of range\n";
96     cerr<<" Element="<<fCurrFil[side]<<" while max limit is "<<(fDim/2-1)<<endl;
97     fCurrFil[side]++;
98     return;
99   }
100   // P side = 0 and N side =1
101   Int_t index=(fDim/2)*side+fCurrFil[side];
102   Int_t * ptr= &fArray[(fDim/2)*side];
103   if(SearchValue(ptr,strip,fCurrFil[side])>=0)return;
104   fArray[index]=strip;
105   fCurrFil[side]++;
106 }
107 //----------------------------------------------------------------------
108 void AliITSTableSSD::Clear(){
109   //clear arrays
110   fCurrUse[0]= 0;
111   fCurrUse[1] = 0;
112   fCurrFil[0]= 0;
113   fCurrFil[1] = 0;
114   for(Int_t i=0;i<fDim;i++)fArray[i]=-1;
115 }
116 //----------------------------------------------------------------------
117 void AliITSTableSSD::DumpTable(){
118   // Dumps the contents of the table
119   cout<<"==============================================================\n";
120   cout<<" AliITSTableSSD::DumpTable \n";
121   cout<<" Dimension of the table "<<fDim<<" ("<<fDim/2<<" per side)\n";
122   cout<<" Current element to be filled for P side "<<fCurrFil[0]<<endl;
123   cout<<" Current element to be filled for N side "<<fCurrFil[1]<<endl;
124   cout<<" Current element in use for P side "<<fCurrUse[0]<<endl;
125   cout<<" Current element in use for N side "<<fCurrUse[1]<<endl;
126   cout<<"\n Elements for P side: \n";
127   for(Int_t i=0; i<fCurrFil[0];i++){
128     printf("%6d ",fArray[i]);
129     if(i%6==0 && i>0)printf("\n");
130   }
131   printf("\n");
132   cout<<"\n Elements for N side: \n";
133   for(Int_t i=0; i<fCurrFil[1];i++){
134     printf("%6d ",fArray[fDim/2+i]);
135     if(i%6==0 && i>0)printf("\n");
136   }
137   printf("\n");
138 }
139
140 //----------------------------------------------------------------------
141 Int_t AliITSTableSSD::Use(Int_t side){
142   // uses the current element. This means that the current element is returned
143   // and its content is replaced by -1. Hence each element can be used only 
144   // once.
145   Int_t elem=-1;
146   if((side!=0) && (side!=1)){
147     cerr<<" Error in AliITSTableSSD::Use. side="<<side<<endl;
148     cerr<<" side must be 0 or 1\n";
149     return elem;
150   }
151   if(fCurrUse[side]>(fDim/2-1)){
152     cerr<<" Error in AliITSTableSSD::Use. Trying to use an element out of range\n";
153     cerr<<" Element="<<fCurrUse[side]<<" while max limit is "<<(fDim/2-1)<<endl;
154     fCurrUse[side]++;
155     return elem;
156   }
157   Int_t index=(fDim/2)*side+fCurrUse[side];
158   elem=fArray[index];
159   fArray[index]=-1;
160   fCurrUse[side]++;
161   return elem;
162 }