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