typo fixed
[u/mrichter/AliRoot.git] / T0 / AliT0CalibData.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 // class for T0 calibration                       TM--AM_6-02-2006         //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include "AliT0CalibData.h"
25 #include "AliT0LookUpValue.h"
26 #include "AliT0LookUpKey.h"
27 #include "AliLog.h"
28
29 #include <Riostream.h>
30
31 //#include <string>
32
33 using std::ifstream;
34 ClassImp(AliT0CalibData)
35
36 //________________________________________________________________
37   AliT0CalibData::AliT0CalibData():   TNamed(),
38                                       fLookup(0),
39                                       fNumberOfTRMs(0)
40
41 {
42   //
43 }
44
45 //________________________________________________________________
46 AliT0CalibData::AliT0CalibData(const char* name):TNamed(),
47                                       fLookup(0),
48                                       fNumberOfTRMs(0)
49 {
50   TString namst = "Calib_";
51   namst += name;
52   SetName(namst.Data());
53   SetTitle(namst.Data());
54
55 }
56
57 //________________________________________________________________
58 AliT0CalibData::AliT0CalibData(const AliT0CalibData& calibda) :
59   TNamed(calibda),              
60   fLookup(0),
61   fNumberOfTRMs(0)
62
63 {
64 // copy constructor
65   SetName(calibda.GetName());
66   SetTitle(calibda.GetName());
67
68
69 }
70
71 //________________________________________________________________
72 AliT0CalibData &AliT0CalibData::operator =(const AliT0CalibData& calibda)
73 {
74 // assignment operator
75   SetName(calibda.GetName());
76   SetTitle(calibda.GetName());
77  
78   return *this;
79 }
80
81 //________________________________________________________________
82 AliT0CalibData::~AliT0CalibData()
83 {
84   //
85 }
86 //________________________________________________________________
87 void  AliT0CalibData::PrintLookup(Option_t*, Int_t iTRM, Int_t iTDC, Int_t iChannel) const
88 {
89   // print lookup table
90
91   AliT0LookUpKey* lookkey; //= new AliT0LookUpKey();
92   AliT0LookUpValue*  lookvalue= new AliT0LookUpValue();
93   printf("Number Of TRMs in setup %i\n",GetNumberOfTRMs());
94
95   iTRM=0; iTDC=0; Int_t chain=0; iChannel=0;
96
97   for (Int_t ik=0; ik<105; ik++){
98     lookvalue->SetTRM(iTRM);
99     lookvalue->SetTDC(iTDC);
100     lookvalue->SetChain(chain);
101     lookvalue->SetChannel(iChannel);
102     
103     if (iChannel<6) iChannel +=2;
104     else {iChannel = 0; iTDC++;}
105     if(ik==57) { iTDC=0; iChannel=0; iTRM=1;}
106    
107   printf(" AliT0CalibData::PrintLookup ::start GetValue %i %i %i %i\n",iTRM, iTDC,chain, iChannel);
108     lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
109     //    TString name= lookkey->GetChannelName();
110     // cout<<name.Data()<<endl;
111     if (lookkey)
112       {
113         TString name= lookkey->GetChannelName();
114         /*      cout<<" lookup KEY!!! "<<name.Data()<<" "<<lookkey->GetKey()<<" VALUE "<<lookvalue->GetTRM()<<" "
115             <<lookvalue->GetTDC()<<" "
116             << lookvalue->GetChain()<<" "
117             <<lookvalue->GetChannel()<<endl;*/
118       }
119   }
120   
121 }
122 //________________________________________________________________
123
124 void AliT0CalibData::ReadAsciiLookup(const Char_t *filename)
125 {
126   // read lookup table from ascii file
127
128   Int_t key, trm, tdc, chain, channel;
129
130   if(filename == 0){
131     AliError(Form("Please, specify file with database")) ;
132     return ;
133   }
134
135
136   ifstream lookup;
137   lookup.open(filename);
138   if(!lookup)
139     {
140      AliError(Form("!!!!!!!!!!!!!!No look up table in CDB!" ));
141  
142     }
143   Char_t varname[11];
144   Int_t ntrms;
145   if(lookup)
146     {
147       lookup>>ntrms;
148       //      fNumberOfTRMs=ntrms;
149       SetNumberOfTRMs(ntrms);
150        while(!lookup.eof())
151         {
152           AliT0LookUpKey * lookkey= new AliT0LookUpKey();
153           AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
154           
155           lookup>>varname>>key>>trm>>chain>>tdc>>channel;
156           lookvalue->SetTRM(trm);
157           lookvalue->SetTDC(tdc);
158           lookvalue->SetChain(chain);
159           lookvalue->SetChannel(channel);
160           lookkey->SetKey(key);
161           lookkey->SetChannelName(varname);
162           
163           fLookup.Add((TObject*)lookvalue,(TObject*)lookkey);
164           
165         }
166       
167       lookup.close();
168       
169     }
170 }
171 //________________________________________________________________
172
173 Int_t AliT0CalibData::GetChannel(Int_t trm,  Int_t tdc, Int_t chain, Int_t channel)
174 {
175   // read number of channel according physical addres 
176
177
178   AliT0LookUpKey * lookkey;//= new AliT0LookUpKey();
179   AliT0LookUpValue * lookvalue= new AliT0LookUpValue(trm,tdc,chain,channel);
180
181   lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
182
183   return lookkey->GetKey();
184
185 }
186