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