1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //_________________________________________________________________________
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.)
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") ;
31 // m->Write(&mydata) ;
32 // AliPHOSCalibrationData myanotherdata("Gains","v2") ;
33 // m->ReadFromRoot(&myanotherdata) ;
35 //*-- Author : D.Peressounko (RRC KI & SUBATECH)
36 //////////////////////////////////////////////////////////////////////////////
39 // --- ROOT system ---
44 // --- Standard library ---
47 // --- AliRoot header files ---
49 #include "AliPHOSConTableDB.h"
50 #include "AliPHOSCalibrManager.h"
51 #include "AliPHOSCalibrationData.h"
52 ClassImp(AliPHOSCalibrManager)
55 AliPHOSCalibrManager * AliPHOSCalibrManager::fgCaMa = 0 ;
56 //____________________________________________________________________________
57 AliPHOSCalibrManager::AliPHOSCalibrManager() :
62 // default ctor: not to be used
63 AliFatal(Form("Should not be used")) ;
65 //____________________________________________________________________________
66 AliPHOSCalibrManager::AliPHOSCalibrManager(const char* filename,const char * kind ):
67 TNamed("AliPHOSCalibrManager",filename),
72 if(strcmp(kind,"root")==0){
80 //____________________________________________________________________________
81 AliPHOSCalibrManager::AliPHOSCalibrManager(const AliPHOSCalibrManager & manager) :
88 // requested by the Coding Convention
89 Fatal("cpy ctor", "not implemented") ;
92 //____________________________________________________________________________
93 AliPHOSCalibrManager::~AliPHOSCalibrManager()
97 TFile * f = gROOT->GetFile(fFileName) ;
102 //____________________________________________________________________________
103 AliPHOSCalibrManager * AliPHOSCalibrManager::GetInstance(void)
105 // gets the instance of the unique object
108 //____________________________________________________________________________
109 AliPHOSCalibrManager * AliPHOSCalibrManager::GetInstance(const char* filename,const char * kind)
111 // Opens source (now only root file) and
112 // returns the instance of the unique object
115 fgCaMa = new AliPHOSCalibrManager(filename,kind) ;
117 if(strcmp(filename,fgCaMa->fFileName.Data())){
118 //Close previous file, construct new Manager
120 fgCaMa = new AliPHOSCalibrManager(filename,kind) ;
125 //____________________________________________________________________________
126 void AliPHOSCalibrManager::GetParameters(AliPHOSCalibrationData &data){
131 ReadFromASCII(data) ;
134 //____________________________________________________________________________
135 void AliPHOSCalibrManager::ReadFromASCII(AliPHOSCalibrationData &data){
136 // We read pedestals and gains from *.dat file with following format:
137 // 0 0 0 0 37.09 1972. // next nmodrows*nmodcols*ncryrows*ncrycols lines
138 // 0 0 0 1 28.53 2072. // contains <RR CC r c ped peak>
139 // 0 0 0 2 30.93 1938. //
140 // where module is an array of 8*8 crystals and RR and CC are module raw and column position
143 AliError(Form("Specify Connections Table Database first")) ;
147 FILE * file = fopen(fFileName, "r");
149 Error("ReadFromASCII", "could not open file %s", fFileName.Data());
153 Bool_t isPed = kFALSE ;
154 if(strcmp(data.GetCategory(),"Pedestals")==0){
158 if(strcmp(data.GetCategory(),"Gains")){
159 Error("ReadFromASCII","Unknown data category: %s",data.GetCategory()) ;
164 Int_t modRaw,modCol,raw,col;
167 while(fscanf(file,"%d %d %d %d %f %f",&modRaw,&modCol,&raw,&col,&ped,&pik)==6){
168 //Calculate plain crystal position:
169 Int_t rawPosition = (modRaw*8+raw)*fctdb->GetNColumns()+modCol*8+col ;
170 Int_t absId = fctdb->Raw2AbsId(rawPosition);
172 data.SetData(absId,ped) ;
176 data.SetData(absId,1./pik);
178 data.SetData(absId,0.);
182 if(nread != fctdb->GetNColumns()*fctdb->GetNRaws()){
183 Error("ReadFromASCII","Read %d parameters instead of %d\n",nread,fctdb->GetNColumns()*fctdb->GetNRaws()) ;
188 //____________________________________________________________________________
189 void AliPHOSCalibrManager::ReadFromRoot(AliPHOSCalibrationData & data)
191 //reads calibration parameters from root file
194 TString searchname(data.GetCategory()) ;
196 searchname+=data.GetVersion() ;
197 TFile * file = gROOT->GetFile(fFileName) ;
198 if(!file || !file->IsOpen())
199 file = TFile::Open(fFileName) ;
201 AliError(Form("Can not open file %s\n",fFileName.Data() )) ;
205 AliPHOSCalibrationData * tmp = dynamic_cast<AliPHOSCalibrationData*>(file->Get(searchname) ) ;
207 Error("ReadFromRoot","there is no data %s in file %s",fFileName.Data(),fFileName.Data()) ;
212 // TList * list = file->GetListOfKeys() ;
213 // TIter next(list) ;
215 // while((key=((TKey*)next()))){
216 // TString kname(key->GetName()) ;
217 // if(kname.BeginsWith(searchname)){
218 // TString sbegin = kname(searchname.Sizeof()-1,
219 // kname.Last('_')-searchname.Sizeof()+1) ;
220 // TString send = kname(kname.Last('_')+1,kname.Sizeof()) ;
222 // if(sscanf(sbegin.Data(),"%d",&begin) &&
223 // sscanf(send.Data(),"%d",&end)){
224 // if(begin<=run && end >=run){
225 // data=(*dynamic_cast<AliPHOSCalibrationData*>(file->Get(key->GetName()) ));
231 // Error("ReadFromRoot","Can not find key %s for run %d in file %s \n",searchname.Data(),run,fFileName.Data()) ;
233 //____________________________________________________________________________
234 void AliPHOSCalibrManager::WriteData(AliPHOSCalibrationData &data)
237 TFile * file = gROOT->GetFile(fFileName) ;
238 if(!file || !file->IsOpen()){
239 file = TFile::Open(fFileName,"UPDATE") ;
241 AliError(Form("Can not open file %s\n",fFileName.Data() )) ;
246 TString kname(data.GetCategory()) ;
248 kname+=data.GetVersion() ;
251 // data->GetValidityRange(begin,end) ;
255 data.Write(kname,TObject::kOverwrite) ;
258 //____________________________________________________________________________
259 AliPHOSCalibrManager& AliPHOSCalibrManager::operator=(AliPHOSCalibrManager const & cdb)
261 //overloads = operator
262 fFileName = cdb.fFileName;