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 //_________________________________________________________________________
21 //*-- Author : D.Peressounko (RRC KI & SUBATECH)
22 //////////////////////////////////////////////////////////////////////////////
25 // --- ROOT system ---
30 // --- Standard library ---
33 // --- AliRoot header files ---
34 #include "AliPHOSConTableDB.h"
35 #include "AliPHOSCalibrManager.h"
36 #include "AliPHOSCalibrationData.h"
37 ClassImp(AliPHOSCalibrManager)
40 AliPHOSCalibrManager * AliPHOSCalibrManager::fgCaMa = 0 ;
41 //____________________________________________________________________________
42 AliPHOSCalibrManager::AliPHOSCalibrManager():TNamed()
46 Fatal("Default constructor","Should not use") ;
48 //____________________________________________________________________________
49 AliPHOSCalibrManager::AliPHOSCalibrManager(const char* filename ):
50 TNamed("AliPHOSCalibrManager",filename){
51 fFileName = filename ;
54 //____________________________________________________________________________
55 AliPHOSCalibrManager::~AliPHOSCalibrManager()
57 TFile * f = gROOT->GetFile(fFileName) ;
64 //____________________________________________________________________________
65 AliPHOSCalibrManager * AliPHOSCalibrManager::GetInstance(void)
69 //____________________________________________________________________________
70 AliPHOSCalibrManager * AliPHOSCalibrManager::GetInstance(const char* filename )
73 fgCaMa = new AliPHOSCalibrManager(filename) ;
75 if(strcmp(filename,fgCaMa->fFileName.Data())){
76 //Close previous file, construct new Manager
78 fgCaMa = new AliPHOSCalibrManager(filename) ;
83 //____________________________________________________________________________
84 void AliPHOSCalibrManager::ReadFromASCII(AliPHOSCalibrationData &data,const char * filename){
85 //reads calibration parameters from ascii file
88 Error("ReadCalibrationParameters", "Specify Connections Table Database first") ;
91 ifstream file(filename) ;
92 for(Int_t i = 1; i<=64; i++){
95 data.SetData(fctdb->Raw2AbsId(i),static_cast<Float_t>(inp));
99 //____________________________________________________________________________
100 void AliPHOSCalibrManager::ReadFromRoot(AliPHOSCalibrationData & data,Int_t run){
101 //reads calibration parameters from root file
104 TString searchname(data.GetCategory()) ;
106 searchname+=data.GetVersion() ;
108 TFile * file = gROOT->GetFile(fFileName) ;
109 if(!file || !file->IsOpen())
110 file = TFile::Open(fFileName) ;
112 Error("ReadFromRoot","Can not open file %s\n",fFileName.Data() ) ;
115 TList * list = file->GetListOfKeys() ;
118 while((key=((TKey*)next()))){
119 TString kname(key->GetName()) ;
120 if(kname.BeginsWith(searchname)){
121 TString sbegin = kname(searchname.Sizeof()-1,
122 kname.Last('_')-searchname.Sizeof()+1) ;
123 TString send = kname(kname.Last('_')+1,kname.Sizeof()) ;
125 if(sscanf(sbegin.Data(),"%d",&begin) &&
126 sscanf(send.Data(),"%d",&end)){
127 if(begin<=run && end >=run){
128 data=(*dynamic_cast<AliPHOSCalibrationData*>(file->Get(key->GetName()) ));
134 Error("ReadFromRoot","Can not find key %s for run %d in file %s \n",searchname.Data(),run,fFileName.Data()) ;
136 //____________________________________________________________________________
137 void AliPHOSCalibrManager::WriteData(AliPHOSCalibrationData * data){
138 TFile * file = gROOT->GetFile(fFileName) ;
139 if(!file || !file->IsOpen()){
140 file = TFile::Open(fFileName,"UPDATE") ;
142 Error("WriteData","Can not open file %s\n",fFileName.Data() ) ;
147 TString kname(data->GetCategory()) ;
149 kname+=data->GetVersion() ;
152 data->GetValidityRange(begin,end) ;
156 data->Write(kname,TObject::kOverwrite) ;
159 //____________________________________________________________________________
160 AliPHOSCalibrManager& AliPHOSCalibrManager::operator=(AliPHOSCalibrManager const & cdb)
163 fFileName = cdb.fFileName;