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 ---
48 #include "AliPHOSConTableDB.h"
49 #include "AliPHOSCalibrManager.h"
50 #include "AliPHOSCalibrationData.h"
51 ClassImp(AliPHOSCalibrManager)
54 AliPHOSCalibrManager * AliPHOSCalibrManager::fgCaMa = 0 ;
55 //____________________________________________________________________________
56 AliPHOSCalibrManager::AliPHOSCalibrManager():TNamed()
58 // default ctor: not to be used
61 Fatal("Default constructor","Should not use") ;
63 //____________________________________________________________________________
64 AliPHOSCalibrManager::AliPHOSCalibrManager(const char* filename ):
65 TNamed("AliPHOSCalibrManager",filename){
66 fFileName = filename ;
69 //____________________________________________________________________________
70 AliPHOSCalibrManager::~AliPHOSCalibrManager()
73 TFile * f = gROOT->GetFile(fFileName) ;
80 //____________________________________________________________________________
81 AliPHOSCalibrManager * AliPHOSCalibrManager::GetInstance(void)
83 // gets the instance of the unique object
86 //____________________________________________________________________________
87 AliPHOSCalibrManager * AliPHOSCalibrManager::GetInstance(const char* filename )
89 // Opens source (now only root file) and
90 // returns the instance of the unique object
93 fgCaMa = new AliPHOSCalibrManager(filename) ;
95 if(strcmp(filename,fgCaMa->fFileName.Data())){
96 //Close previous file, construct new Manager
98 fgCaMa = new AliPHOSCalibrManager(filename) ;
103 //____________________________________________________________________________
104 void AliPHOSCalibrManager::ReadFromASCII(AliPHOSCalibrationData &data,const char * filename)
106 //reads calibration parameters from ascii file
109 Error("ReadCalibrationParameters", "Specify Connections Table Database first") ;
112 ifstream file(filename) ;
113 for(Int_t i = 1; i<=64; i++){
116 data.SetData(fctdb->Raw2AbsId(i),static_cast<Float_t>(inp));
120 //____________________________________________________________________________
121 void AliPHOSCalibrManager::ReadFromRoot(AliPHOSCalibrationData & data,Int_t run)
123 //reads calibration parameters from root file
126 TString searchname(data.GetCategory()) ;
128 searchname+=data.GetVersion() ;
130 TFile * file = gROOT->GetFile(fFileName) ;
131 if(!file || !file->IsOpen())
132 file = TFile::Open(fFileName) ;
134 Error("ReadFromRoot","Can not open file %s\n",fFileName.Data() ) ;
137 TList * list = file->GetListOfKeys() ;
140 while((key=((TKey*)next()))){
141 TString kname(key->GetName()) ;
142 if(kname.BeginsWith(searchname)){
143 TString sbegin = kname(searchname.Sizeof()-1,
144 kname.Last('_')-searchname.Sizeof()+1) ;
145 TString send = kname(kname.Last('_')+1,kname.Sizeof()) ;
147 if(sscanf(sbegin.Data(),"%d",&begin) &&
148 sscanf(send.Data(),"%d",&end)){
149 if(begin<=run && end >=run){
150 data=(*dynamic_cast<AliPHOSCalibrationData*>(file->Get(key->GetName()) ));
156 Error("ReadFromRoot","Can not find key %s for run %d in file %s \n",searchname.Data(),run,fFileName.Data()) ;
158 //____________________________________________________________________________
159 void AliPHOSCalibrManager::WriteData(AliPHOSCalibrationData * data)
162 TFile * file = gROOT->GetFile(fFileName) ;
163 if(!file || !file->IsOpen()){
164 file = TFile::Open(fFileName,"UPDATE") ;
166 Error("WriteData","Can not open file %s\n",fFileName.Data() ) ;
171 TString kname(data->GetCategory()) ;
173 kname+=data->GetVersion() ;
176 data->GetValidityRange(begin,end) ;
180 data->Write(kname,TObject::kOverwrite) ;
183 //____________________________________________________________________________
184 AliPHOSCalibrManager& AliPHOSCalibrManager::operator=(AliPHOSCalibrManager const & cdb)
186 //overloads = operator
187 fFileName = cdb.fFileName;