]>
Commit | Line | Data |
---|---|---|
f3bd42f5 | 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 | //_________________________________________________________________________ | |
cd228525 | 19 | // Class provides interface between classes |
20 | // consuming/producing calibration data, | |
21 | // such as AliPHOSClusterizer and AliPHOSCalibrator | |
22 | // from one side and database (now just a root file, | |
23 | // later - AliEn etc.) | |
24 | // Use case: | |
25 | // First Manager should be configured so that is reads data | |
26 | // from a given source. e.g. from a root file: | |
27 | // AliPHOSCalibrManager * m = AliPHOSCalibrManager::GetInstance("MyCalibrationRootFile.root") ; | |
28 | // After that one can real/write data to this source: | |
29 | // AliPHOSCalibrationData mydata("Gains","v1") ; | |
30 | // ...... | |
31 | // m->Write(&mydata) ; | |
32 | // AliPHOSCalibrationData myanotherdata("Gains","v2") ; | |
33 | // m->ReadFromRoot(&myanotherdata) ; | |
f3bd42f5 | 34 | // |
35 | //*-- Author : D.Peressounko (RRC KI & SUBATECH) | |
36 | ////////////////////////////////////////////////////////////////////////////// | |
37 | ||
38 | ||
39 | // --- ROOT system --- | |
40 | #include "TROOT.h" | |
41 | #include "TKey.h" | |
42 | #include "TFile.h" | |
43 | ||
44 | // --- Standard library --- | |
00953b03 | 45 | #include <fstream> |
f3bd42f5 | 46 | |
47 | // --- AliRoot header files --- | |
48 | #include "AliPHOSConTableDB.h" | |
49 | #include "AliPHOSCalibrManager.h" | |
50 | #include "AliPHOSCalibrationData.h" | |
51 | ClassImp(AliPHOSCalibrManager) | |
52 | ||
e4778e0c | 53 | |
54 | AliPHOSCalibrManager * AliPHOSCalibrManager::fgCaMa = 0 ; | |
f3bd42f5 | 55 | //____________________________________________________________________________ |
56 | AliPHOSCalibrManager::AliPHOSCalibrManager():TNamed() | |
57 | { | |
cd228525 | 58 | // default ctor: not to be used |
e4778e0c | 59 | fInputKind = 0 ; |
60 | fFileName= "" ; | |
f3bd42f5 | 61 | fctdb = 0 ; |
f3bd42f5 | 62 | Fatal("Default constructor","Should not use") ; |
63 | } | |
64 | //____________________________________________________________________________ | |
e4778e0c | 65 | AliPHOSCalibrManager::AliPHOSCalibrManager(const char* filename,const char * kind ): |
f3bd42f5 | 66 | TNamed("AliPHOSCalibrManager",filename){ |
e4778e0c | 67 | if(strcmp(kind,"root")==0){ |
68 | fInputKind = 0 ; | |
69 | } | |
70 | else{ | |
71 | fInputKind = 1 ; | |
72 | } | |
73 | fFileName = filename; | |
f3bd42f5 | 74 | fctdb = 0 ; |
75 | } | |
76 | //____________________________________________________________________________ | |
e4778e0c | 77 | AliPHOSCalibrManager::~AliPHOSCalibrManager() |
f3bd42f5 | 78 | { |
00953b03 | 79 | //dtor |
e4778e0c | 80 | if(fInputKind==0){ |
81 | TFile * f = gROOT->GetFile(fFileName) ; | |
82 | if(f && f->IsOpen()) | |
83 | f->Close() ; | |
84 | } | |
f3bd42f5 | 85 | } |
86 | //____________________________________________________________________________ | |
87 | AliPHOSCalibrManager * AliPHOSCalibrManager::GetInstance(void) | |
88 | { | |
00953b03 | 89 | // gets the instance of the unique object |
e4778e0c | 90 | return fgCaMa ; |
f3bd42f5 | 91 | } |
92 | //____________________________________________________________________________ | |
e4778e0c | 93 | AliPHOSCalibrManager * AliPHOSCalibrManager::GetInstance(const char* filename,const char * kind) |
f3bd42f5 | 94 | { |
cd228525 | 95 | // Opens source (now only root file) and |
96 | // returns the instance of the unique object | |
e4778e0c | 97 | |
f3bd42f5 | 98 | if(!fgCaMa) |
e4778e0c | 99 | fgCaMa = new AliPHOSCalibrManager(filename,kind) ; |
f3bd42f5 | 100 | else{ |
e4778e0c | 101 | if(strcmp(filename,fgCaMa->fFileName.Data())){ |
102 | //Close previous file, construct new Manager | |
103 | delete fgCaMa ; | |
104 | fgCaMa = new AliPHOSCalibrManager(filename,kind) ; | |
105 | } | |
f3bd42f5 | 106 | } |
107 | return fgCaMa ; | |
108 | } | |
109 | //____________________________________________________________________________ | |
e4778e0c | 110 | void AliPHOSCalibrManager::GetParameters(AliPHOSCalibrationData &data){ |
111 | if(fInputKind == 0){ | |
112 | ReadFromRoot(data) ; | |
113 | } | |
114 | else{ | |
115 | ReadFromASCII(data) ; | |
116 | } | |
117 | } | |
118 | //____________________________________________________________________________ | |
119 | void AliPHOSCalibrManager::ReadFromASCII(AliPHOSCalibrationData &data){ | |
120 | // We read pedestals and gains from *.dat file with following format: | |
121 | // 0 0 0 0 37.09 1972. // next nmodrows*nmodcols*ncryrows*ncrycols lines | |
122 | // 0 0 0 1 28.53 2072. // contains <RR CC r c ped peak> | |
123 | // 0 0 0 2 30.93 1938. // | |
124 | // where module is an array of 8*8 crystals and RR and CC are module raw and column position | |
f3bd42f5 | 125 | |
126 | if(!fctdb){ | |
127 | Error("ReadCalibrationParameters", "Specify Connections Table Database first") ; | |
128 | return ; | |
129 | } | |
e4778e0c | 130 | |
131 | FILE * file = fopen(fFileName, "r"); | |
132 | if (!file) { | |
133 | Error("ReadFromASCII", "could not open file %s", fFileName.Data()); | |
134 | return; | |
135 | } | |
136 | ||
137 | Bool_t isPed = kFALSE ; | |
138 | if(strcmp(data.GetCategory(),"Pedestals")==0){ | |
139 | isPed = 1 ; | |
140 | } | |
141 | else{ | |
142 | if(strcmp(data.GetCategory(),"Gains")){ | |
143 | Error("ReadFromASCII","Unknown data category: %s",data.GetCategory()) ; | |
144 | return ; | |
145 | } | |
146 | } | |
147 | ||
148 | Int_t modRaw,modCol,raw,col; | |
149 | Float_t ped,pik; | |
150 | Int_t nread = 0 ; | |
151 | while(fscanf(file,"%d %d %d %d %f %f",&modRaw,&modCol,&raw,&col,&ped,&pik)==6){ | |
152 | //Calculate plain crystal position: | |
153 | Int_t rawPosition = (modRaw*8+raw)*fctdb->GetNColumns()+modCol*8+col ; | |
154 | Int_t absId = fctdb->Raw2AbsId(rawPosition); | |
155 | if(isPed){ | |
156 | data.SetData(absId,ped) ; | |
157 | } | |
158 | else{ | |
159 | if(pik!=0.) | |
160 | data.SetData(absId,1./pik); | |
161 | else | |
162 | data.SetData(absId,0.); | |
163 | } | |
164 | nread++ ; | |
165 | } | |
166 | if(nread != fctdb->GetNColumns()*fctdb->GetNRaws()){ | |
167 | Error("ReadFromASCII","Read %d parameters instead of %d\n",nread,fctdb->GetNColumns()*fctdb->GetNRaws()) ; | |
f3bd42f5 | 168 | } |
e4778e0c | 169 | fclose(file) ; |
170 | ||
f3bd42f5 | 171 | } |
172 | //____________________________________________________________________________ | |
e4778e0c | 173 | void AliPHOSCalibrManager::ReadFromRoot(AliPHOSCalibrationData & data) |
00953b03 | 174 | { |
f3bd42f5 | 175 | //reads calibration parameters from root file |
e4778e0c | 176 | |
f3bd42f5 | 177 | //construct name |
178 | TString searchname(data.GetCategory()) ; | |
179 | searchname+='_' ; | |
180 | searchname+=data.GetVersion() ; | |
f3bd42f5 | 181 | TFile * file = gROOT->GetFile(fFileName) ; |
182 | if(!file || !file->IsOpen()) | |
183 | file = TFile::Open(fFileName) ; | |
184 | if(!file->IsOpen()){ | |
185 | Error("ReadFromRoot","Can not open file %s\n",fFileName.Data() ) ; | |
186 | return ; | |
187 | } | |
e4778e0c | 188 | AliPHOSCalibrationData * tmp = dynamic_cast<AliPHOSCalibrationData*>(file->Get(searchname) ) ; |
189 | if(!tmp) | |
190 | Error("ReadFromRoot","there is no data %s in file %s",fFileName.Data(),fFileName.Data()) ; | |
191 | else | |
192 | data=(*tmp); | |
193 | ||
194 | ||
195 | // TList * list = file->GetListOfKeys() ; | |
196 | // TIter next(list) ; | |
197 | // TKey * key ; | |
198 | // while((key=((TKey*)next()))){ | |
199 | // TString kname(key->GetName()) ; | |
200 | // if(kname.BeginsWith(searchname)){ | |
201 | // TString sbegin = kname(searchname.Sizeof()-1, | |
202 | // kname.Last('_')-searchname.Sizeof()+1) ; | |
203 | // TString send = kname(kname.Last('_')+1,kname.Sizeof()) ; | |
204 | // Int_t begin,end ; | |
205 | // if(sscanf(sbegin.Data(),"%d",&begin) && | |
206 | // sscanf(send.Data(),"%d",&end)){ | |
207 | // if(begin<=run && end >=run){ | |
208 | // data=(*dynamic_cast<AliPHOSCalibrationData*>(file->Get(key->GetName()) )); | |
209 | // return ; | |
210 | // } | |
211 | // } | |
212 | // } | |
213 | // } | |
214 | // Error("ReadFromRoot","Can not find key %s for run %d in file %s \n",searchname.Data(),run,fFileName.Data()) ; | |
f3bd42f5 | 215 | } |
216 | //____________________________________________________________________________ | |
e4778e0c | 217 | void AliPHOSCalibrManager::WriteData(AliPHOSCalibrationData &data) |
00953b03 | 218 | { |
219 | //Writes data | |
f3bd42f5 | 220 | TFile * file = gROOT->GetFile(fFileName) ; |
221 | if(!file || !file->IsOpen()){ | |
222 | file = TFile::Open(fFileName,"UPDATE") ; | |
223 | if(!file->IsOpen()){ | |
224 | Error("WriteData","Can not open file %s\n",fFileName.Data() ) ; | |
225 | return ; | |
226 | } | |
227 | } | |
228 | file->cd() ; | |
e4778e0c | 229 | TString kname(data.GetCategory()) ; |
f3bd42f5 | 230 | kname+='_'; |
e4778e0c | 231 | kname+=data.GetVersion() ; |
232 | // kname+='_'; | |
233 | // Int_t begin,end ; | |
234 | // data->GetValidityRange(begin,end) ; | |
235 | // kname+=begin ; | |
236 | // kname+='_' ; | |
237 | // kname+=end ; | |
238 | data.Write(kname,TObject::kOverwrite) ; | |
f3bd42f5 | 239 | |
240 | } | |
241 | //____________________________________________________________________________ | |
242 | AliPHOSCalibrManager& AliPHOSCalibrManager::operator=(AliPHOSCalibrManager const & cdb) | |
243 | { | |
00953b03 | 244 | //overloads = operator |
f3bd42f5 | 245 | fFileName = cdb.fFileName; |
246 | return *this ; | |
247 | } |