]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONTrackerIO.cxx
Add missing target/projectile information
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackerIO.cxx
CommitLineData
81028269 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
b09247a2 18#include <cstdlib>
81028269 19#include "AliMUONTrackerIO.h"
20
21/// \class AliMUONTrackerIO
22///
23/// Reader class for ASCII calibration files for MUON tracker :
24/// converts those ASCII files into AliMUONVStore (suitable to e.g. feed
25/// the OCDB).
26///
27/// \author Laurent Aphecetche, Subatech
28
29/// \cond CLASSIMP
30ClassImp(AliMUONTrackerIO)
31/// \endcond
32
33#include "AliLog.h"
34#include "AliMUONCalibParamNF.h"
35#include "AliMUONVStore.h"
36#include "AliMpConstants.h"
37#include "AliMpDDLStore.h"
38#include <Riostream.h>
39#include <TClass.h>
40#include <TObjString.h>
41#include <TSystem.h>
42#include <sstream>
43
44//_____________________________________________________________________________
45AliMUONTrackerIO::AliMUONTrackerIO()
46{
47 /// ctor
48}
49
50//_____________________________________________________________________________
51AliMUONTrackerIO::~AliMUONTrackerIO()
52{
53 /// dtor
54}
55
56//_____________________________________________________________________________
57Int_t
58AliMUONTrackerIO::ReadPedestals(const char* filename, AliMUONVStore& pedStore)
59{
60 /// Read pedestal file (produced by the MUONTRKda.exe program for instance)
61 /// and append the read values into the given VStore
cba13f7c 62 /// To be used when the input is a file (for instance when reading data
63 /// from the OCDB).
81028269 64
65 TString sFilename(gSystem->ExpandPathName(filename));
66
67 std::ifstream in(sFilename.Data());
68 if (!in.good())
69 {
70 return kCannotOpenFile;
71 }
72
cba13f7c 73 TString datastring;
06a51226 74 ostringstream stream;
75 char line[1024];
76 while ( in.getline(line,1024) )
77 stream << line << "\n";
78 datastring = TString(stream.str().c_str());
79
cba13f7c 80 in.close();
81
82 return DecodePedestals(datastring,pedStore);
83
84}
85
86//_____________________________________________________________________________
87Int_t
88AliMUONTrackerIO::DecodePedestals(TString data, AliMUONVStore& pedStore)
89{
90 /// Read pedestal Data (produced by the MUONTRKda.exe program for instance)
91 /// and append the read values into the given VStore
92 /// To be used when the input is a TString (for instance when getting data
93 /// from AMORE DB).
94
81028269 95 char line[1024];
96 Int_t busPatchID, manuID, manuChannel;
97 Float_t pedMean, pedSigma;
98 Int_t n(0);
cba13f7c 99 istringstream in(data.Data());
81028269 100
101 while ( in.getline(line,1024) )
102 {
103 AliDebugClass(3,Form("line=%s",line));
104 if ( line[0] == '/' && line[1] == '/' ) continue;
105 std::istringstream sin(line);
106 sin >> busPatchID >> manuID >> manuChannel >> pedMean >> pedSigma;
107 Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
108 AliDebugClass(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d MEAN %7.2f SIGMA %7.2f",
109 busPatchID,detElemID,manuID,manuChannel,pedMean,pedSigma));
cba13f7c 110
81028269 111 AliMUONVCalibParam* ped =
112 static_cast<AliMUONVCalibParam*>(pedStore.FindObject(detElemID,manuID));
81028269 113 if (!ped)
114 {
115 ped = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),
116 detElemID,manuID,
117 AliMUONVCalibParam::InvalidFloatValue());
118 pedStore.Add(ped);
119 }
120 ped->SetValueAsFloat(manuChannel,0,pedMean);
121 ped->SetValueAsFloat(manuChannel,1,pedSigma);
122 ++n;
123 }
81028269 124
125 return n;
126}
127
128//_____________________________________________________________________________
129Int_t
130AliMUONTrackerIO::ReadGains(const char* filename, AliMUONVStore& gainStore,
131 TString& comment)
132{
133 /// Read gain file (produced by the MUONTRKda.exe program for instance)
134 /// and append the read values into the given VStore
cba13f7c 135 /// To be used when the input is a file (for instance when reading data
136 /// from the OCDB).
81028269 137
138 comment = "";
139
140 TString sFilename(gSystem->ExpandPathName(filename));
141
142 std::ifstream in(sFilename.Data());
143 if (!in.good())
144 {
145 return kCannotOpenFile;
146 }
147
cba13f7c 148 TString datastring;
149 ostringstream stream;
150 char line[1024];
151 while ( in.getline(line,1024) )
152 stream << line << "\n";
153 datastring = TString(stream.str().c_str());
154
155 in.close();
156
157 return DecodeGains(datastring,gainStore,comment);
158
159}
160
161//_____________________________________________________________________________
162Int_t
163AliMUONTrackerIO::DecodeGains(TString data, AliMUONVStore& gainStore,
164 TString& comment)
165{
166 /// Read gain file (produced by the MUONTRKda.exe program for instance)
167 /// and append the read values into the given VStore
168 /// To be used when the input is a TString (for instance when getting data
169 /// from AMORE DB).
170
81028269 171 char line[1024];
cba13f7c 172 istringstream in(data.Data());
81028269 173 Int_t busPatchID, manuID, manuChannel;
174 Float_t a0, a1;
175 Int_t thres;
176 UInt_t qual;
177 const Int_t kSaturation(3000); // FIXME: how to get this number ?
178 Int_t n(0);
179 Int_t runNumber(-1);
180 Int_t* runs(0x0);
181 Int_t* dac(0x0);
182 Int_t nDAC(0);
183 Int_t iDAC(0);
184
185 while ( in.getline(line,1024) )
186 {
187 if ( strlen(line) < 10 ) continue;
188 if ( line[0] == '/' && line[1] == '/' )
189 {
190 TString sline(line);
191 if ( sline.Contains("DUMMY") )
192 {
193 AliDebugClass(1,"Got a dummy file here");
194 return kDummyFile;
195 }
196 if ( sline.Contains("* Run") )
197 {
198 TObjArray* a = sline.Tokenize(":");
199 if ( a->GetLast() >= 1 )
200 {
201 TString s = static_cast<TObjString*>(a->At(1))->String();
202 runNumber = s.Atoi();
203 AliDebugClass(1,Form("runNumber is %d",runNumber));
204 }
205 }
206 if ( sline.Contains("DAC values") )
207 {
208 nDAC = TString(sline(2,sline.Length()-2)).Atoi();
209 AliDebugClass(1,Form("# of DAC values = %d",nDAC));
210 if ( nDAC > 0 )
211 {
212 if ( nDAC < 100 )
213 {
214 runs = new Int_t[nDAC];
215 dac = new Int_t[nDAC];
216 // skip two lines
217 in.getline(line,1024);
218 in.getline(line,1024);
219 // then get run and dac values
220 for ( Int_t i = 0; i < nDAC; ++i )
221 {
222 in.getline(line,1024);
223 Int_t a,b;
224 sscanf(line,"// %d %d",&a,&b);
225 runs[iDAC] = a;
226 dac[iDAC] = b;
227 AliDebugClass(1,Form("RUN %d is DAC %d",runs[iDAC],dac[iDAC]));
228 ++iDAC;
229 }
230 }
231 else
232 {
233 AliErrorClass(Form("Something went wrong, as I get too big nDAC = %d",nDAC));
234 nDAC = 0;
235 return kFormatError;
236 }
237 }
238 }
239 continue;
240 }
241
242 sscanf(line,"%d %d %d %f %f %d %x",&busPatchID,&manuID,&manuChannel,
243 &a0,&a1,&thres,&qual);
244 AliDebugClass(3,Form("line=%s",line));
245 Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
246 AliDebugClass(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d A0 %7.2f "
247 "A1 %e THRES %5d QUAL %x",
248 busPatchID,detElemID,manuID,manuChannel,a0,a1,thres,qual));
249 if ( qual == 0 ) continue;
250
251 AliMUONVCalibParam* gain =
252 static_cast<AliMUONVCalibParam*>(gainStore.FindObject(detElemID,manuID));
253
cba13f7c 254 if (!gain)
81028269 255 {
256 gain = new AliMUONCalibParamNF(5,AliMpConstants::ManuNofChannels(),detElemID,manuID,0);
257 gainStore.Add(gain);
258 }
259 gain->SetValueAsFloat(manuChannel,0,a0);
260 gain->SetValueAsFloat(manuChannel,1,a1);
261 gain->SetValueAsInt(manuChannel,2,thres);
262 gain->SetValueAsInt(manuChannel,3,qual);
263 gain->SetValueAsInt(manuChannel,4,kSaturation);
264 ++n;
265 }
cba13f7c 266
81028269 267 comment = "";
268
269 if ( runNumber > 0 )
270 {
271 comment = Form("RUN %d",runNumber);
272 }
273
274 for ( Int_t i = 0; i < nDAC; ++i )
275 {
276 comment += Form(";(RUN %d = DAC %d)",runs[i],dac[i]);
277 }
278
279 delete[] runs;
280 delete[] dac;
281
282 return n;
283}
284
285//_____________________________________________________________________________
286Int_t
287AliMUONTrackerIO::ReadCapacitances(const char* file, AliMUONVStore& capaStore)
288{
289 /// Read capacitance file
290 /// and append the read values into the given VStore
291
292 ifstream in(gSystem->ExpandPathName(file));
293 if (in.bad()) return kCannotOpenFile;
294
295 Int_t ngenerated(0);
296
297 char line[1024];
298 Int_t serialNumber(-1);
299 AliMUONVCalibParam* param(0x0);
300
301 while ( in.getline(line,1024,'\n') )
302 {
303 if ( isdigit(line[0]) )
304 {
305 serialNumber = atoi(line);
306 param = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
307 if (param)
308 {
309 AliErrorClass(Form("serialNumber %d appears several times !",serialNumber));
630711ed 310 continue;
81028269 311 }
312 param = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
313 Bool_t ok = capaStore.Add(param);
314 if (!ok)
315 {
316 AliErrorClass(Form("Could not set serialNumber=%d",serialNumber));
317 continue;
318 }
319 continue;
320 }
321 Int_t channel;
322 Float_t capaValue;
323 Float_t injectionGain;
324 sscanf(line,"%d %f %f",&channel,&capaValue,&injectionGain);
325 AliDebugClass(1,Form("SerialNumber %10d Channel %3d Capa %f injectionGain %f",
326 serialNumber,channel,capaValue,injectionGain));
327 param->SetValueAsFloat(channel,0,capaValue);
328 param->SetValueAsFloat(channel,1,injectionGain);
329 ++ngenerated;
330 }
331
332 in.close();
333
334 return ngenerated;
335}