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