]>
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 | //_________________________________________________________________________ | |
19 | // Short description | |
20 | // | |
21 | //*-- Author : D.Peressounko (RRC KI & SUBATECH) | |
22 | ////////////////////////////////////////////////////////////////////////////// | |
23 | ||
24 | ||
25 | // --- ROOT system --- | |
26 | #include "TROOT.h" | |
27 | #include "TKey.h" | |
28 | #include "TFile.h" | |
29 | ||
30 | // --- Standard library --- | |
00953b03 | 31 | #include <fstream> |
f3bd42f5 | 32 | |
33 | // --- AliRoot header files --- | |
34 | #include "AliPHOSConTableDB.h" | |
35 | #include "AliPHOSCalibrManager.h" | |
36 | #include "AliPHOSCalibrationData.h" | |
37 | ClassImp(AliPHOSCalibrManager) | |
38 | ||
39 | ||
40 | AliPHOSCalibrManager * AliPHOSCalibrManager::fgCaMa = 0 ; | |
41 | //____________________________________________________________________________ | |
42 | AliPHOSCalibrManager::AliPHOSCalibrManager():TNamed() | |
43 | { | |
00953b03 | 44 | // default ctor: nott to be used |
f3bd42f5 | 45 | fctdb = 0 ; |
46 | fFileName="" ; | |
47 | Fatal("Default constructor","Should not use") ; | |
48 | } | |
49 | //____________________________________________________________________________ | |
50 | AliPHOSCalibrManager::AliPHOSCalibrManager(const char* filename ): | |
51 | TNamed("AliPHOSCalibrManager",filename){ | |
52 | fFileName = filename ; | |
53 | fctdb = 0 ; | |
54 | } | |
55 | //____________________________________________________________________________ | |
56 | AliPHOSCalibrManager::~AliPHOSCalibrManager() | |
57 | { | |
00953b03 | 58 | //dtor |
f3bd42f5 | 59 | TFile * f = gROOT->GetFile(fFileName) ; |
60 | if(f && f->IsOpen()) | |
61 | f->Close() ; | |
62 | if(fctdb) | |
63 | delete fctdb ; | |
64 | fctdb = 0 ; | |
65 | } | |
66 | //____________________________________________________________________________ | |
67 | AliPHOSCalibrManager * AliPHOSCalibrManager::GetInstance(void) | |
68 | { | |
00953b03 | 69 | // gets the instance of the unique object |
f3bd42f5 | 70 | return fgCaMa ; |
71 | } | |
72 | //____________________________________________________________________________ | |
73 | AliPHOSCalibrManager * AliPHOSCalibrManager::GetInstance(const char* filename ) | |
74 | { | |
00953b03 | 75 | // gets the instance of the unique object |
76 | ||
f3bd42f5 | 77 | if(!fgCaMa) |
78 | fgCaMa = new AliPHOSCalibrManager(filename) ; | |
79 | else{ | |
80 | if(strcmp(filename,fgCaMa->fFileName.Data())){ | |
81 | //Close previous file, construct new Manager | |
82 | delete fgCaMa ; | |
83 | fgCaMa = new AliPHOSCalibrManager(filename) ; | |
84 | } | |
85 | } | |
86 | return fgCaMa ; | |
87 | } | |
88 | //____________________________________________________________________________ | |
00953b03 | 89 | void AliPHOSCalibrManager::ReadFromASCII(AliPHOSCalibrationData &data,const char * filename) |
90 | { | |
f3bd42f5 | 91 | //reads calibration parameters from ascii file |
92 | ||
93 | if(!fctdb){ | |
94 | Error("ReadCalibrationParameters", "Specify Connections Table Database first") ; | |
95 | return ; | |
96 | } | |
97 | ifstream file(filename) ; | |
98 | for(Int_t i = 1; i<=64; i++){ | |
99 | Float_t inp ; | |
100 | file >> inp ; | |
101 | data.SetData(fctdb->Raw2AbsId(i),static_cast<Float_t>(inp)); | |
102 | } | |
103 | file.close(); | |
104 | } | |
105 | //____________________________________________________________________________ | |
00953b03 | 106 | void AliPHOSCalibrManager::ReadFromRoot(AliPHOSCalibrationData & data,Int_t run) |
107 | { | |
f3bd42f5 | 108 | //reads calibration parameters from root file |
109 | ||
110 | //construct name | |
111 | TString searchname(data.GetCategory()) ; | |
112 | searchname+='_' ; | |
113 | searchname+=data.GetVersion() ; | |
114 | searchname+='_' ; | |
115 | TFile * file = gROOT->GetFile(fFileName) ; | |
116 | if(!file || !file->IsOpen()) | |
117 | file = TFile::Open(fFileName) ; | |
118 | if(!file->IsOpen()){ | |
119 | Error("ReadFromRoot","Can not open file %s\n",fFileName.Data() ) ; | |
120 | return ; | |
121 | } | |
122 | TList * list = file->GetListOfKeys() ; | |
123 | TIter next(list) ; | |
124 | TKey * key ; | |
125 | while((key=((TKey*)next()))){ | |
126 | TString kname(key->GetName()) ; | |
127 | if(kname.BeginsWith(searchname)){ | |
128 | TString sbegin = kname(searchname.Sizeof()-1, | |
129 | kname.Last('_')-searchname.Sizeof()+1) ; | |
130 | TString send = kname(kname.Last('_')+1,kname.Sizeof()) ; | |
131 | Int_t begin,end ; | |
132 | if(sscanf(sbegin.Data(),"%d",&begin) && | |
133 | sscanf(send.Data(),"%d",&end)){ | |
134 | if(begin<=run && end >=run){ | |
135 | data=(*dynamic_cast<AliPHOSCalibrationData*>(file->Get(key->GetName()) )); | |
136 | return ; | |
137 | } | |
138 | } | |
139 | } | |
140 | } | |
141 | Error("ReadFromRoot","Can not find key %s for run %d in file %s \n",searchname.Data(),run,fFileName.Data()) ; | |
142 | } | |
143 | //____________________________________________________________________________ | |
00953b03 | 144 | void AliPHOSCalibrManager::WriteData(AliPHOSCalibrationData * data) |
145 | { | |
146 | //Writes data | |
f3bd42f5 | 147 | TFile * file = gROOT->GetFile(fFileName) ; |
148 | if(!file || !file->IsOpen()){ | |
149 | file = TFile::Open(fFileName,"UPDATE") ; | |
150 | if(!file->IsOpen()){ | |
151 | Error("WriteData","Can not open file %s\n",fFileName.Data() ) ; | |
152 | return ; | |
153 | } | |
154 | } | |
155 | file->cd() ; | |
156 | TString kname(data->GetCategory()) ; | |
157 | kname+='_'; | |
158 | kname+=data->GetVersion() ; | |
159 | kname+='_'; | |
160 | Int_t begin,end ; | |
161 | data->GetValidityRange(begin,end) ; | |
162 | kname+=begin ; | |
163 | kname+='_' ; | |
164 | kname+=end ; | |
165 | data->Write(kname,TObject::kOverwrite) ; | |
166 | ||
167 | } | |
168 | //____________________________________________________________________________ | |
169 | AliPHOSCalibrManager& AliPHOSCalibrManager::operator=(AliPHOSCalibrManager const & cdb) | |
170 | { | |
00953b03 | 171 | //overloads = operator |
f3bd42f5 | 172 | fFileName = cdb.fFileName; |
173 | return *this ; | |
174 | } |