]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONTrackerIO.cxx
Fixing compiler warnings
[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"
7eafe398 34#include "AliMUONCalibParamND.h"
81028269 35#include "AliMUONCalibParamNF.h"
36#include "AliMUONVStore.h"
37#include "AliMpConstants.h"
38#include "AliMpDDLStore.h"
7eafe398 39#include "AliMpDetElement.h"
81028269 40#include <Riostream.h>
41#include <TClass.h>
42#include <TObjString.h>
43#include <TSystem.h>
44#include <sstream>
45
46//_____________________________________________________________________________
47AliMUONTrackerIO::AliMUONTrackerIO()
48{
49 /// ctor
50}
51
52//_____________________________________________________________________________
53AliMUONTrackerIO::~AliMUONTrackerIO()
54{
55 /// dtor
56}
57
7eafe398 58//_____________________________________________________________________________
59Int_t
60AliMUONTrackerIO::ReadOccupancy(const char* filename,AliMUONVStore& occupancyMap)
61{
62 /// Read occupancy file created by online DA
63 /// and append values to the occupancyMap store.
64 /// Expected format of the file is :
65 /// busPatchId manuId sumofn nevt
66
67 TString sFilename(gSystem->ExpandPathName(filename));
68
69 std::ifstream in(sFilename.Data());
70 if (!in.good())
71 {
72 return kCannotOpenFile;
73 }
74
75 TString datastring;
76 ostringstream stream;
77 char line[1024];
78 while ( in.getline(line,1024) )
79 stream << line << "\n";
80 datastring = TString(stream.str().c_str());
81
82 in.close();
83
84 return DecodeOccupancy(datastring,occupancyMap);
85
86}
87
88//_____________________________________________________________________________
89Int_t
90AliMUONTrackerIO::DecodeOccupancy(TString data, AliMUONVStore& occupancyMap)
91{
92 /// Decode occupancy string created append values to the occupancyMap store.
93 /// Expected format of the file is :
94 /// busPatchId manuId sumofn nevt
95
96 if ( ! AliMpDDLStore::Instance(kFALSE) )
97 {
98 AliErrorClass("Mapping not loaded. Cannot work");
99 return 0;
100 }
101
102 char line[1024];
103 istringstream in(data.Data());
104
105 Int_t n(0);
106
107 while ( in.getline(line,1024) )
108 {
109 AliDebugClass(3,Form("line=%s",line));
110 if ( line[0] == '/' && line[1] == '/' ) continue;
111 std::istringstream sin(line);
112
113 Int_t busPatchId, manuId;
114 Int_t numberOfEvents;
115 Double_t sumn;
116
117 sin >> busPatchId >> manuId >> sumn >> numberOfEvents;
118
119 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
120
121 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
122
123 Int_t numberOfChannelsInManu = -1;
124
125 if (de) numberOfChannelsInManu = de->NofChannelsInManu(manuId);
126
127 if ( numberOfChannelsInManu <= 0 )
128 {
129 AliErrorClass(Form("BP %5d DE %5d MANU %5d nchannels=%d",busPatchId,detElemId,manuId,numberOfChannelsInManu));
130 continue;
131 }
132
133 AliMUONVCalibParam* occupancy =
134 static_cast<AliMUONVCalibParam*>(occupancyMap.FindObject(detElemId,manuId));
135 if (occupancy)
136 {
137 AliErrorClass(Form("DE %5d MANU %5d is already there ?!",detElemId,manuId));
138 continue;
139 }
140
141 occupancy = new AliMUONCalibParamND(5,1,detElemId,manuId,0);
142
143 occupancyMap.Add(occupancy);
144
145 occupancy->SetValueAsDouble(0,0,sumn);
146 occupancy->SetValueAsDouble(0,1,sumn); // with only 0 and 1s, sumw = sumw2 = sumn
147 occupancy->SetValueAsDouble(0,2,sumn);
148 occupancy->SetValueAsInt(0,3,numberOfChannelsInManu);
149 occupancy->SetValueAsInt(0,4,numberOfEvents);
150 ++n;
151 }
152
153 return n;
154}
155
81028269 156//_____________________________________________________________________________
157Int_t
158AliMUONTrackerIO::ReadPedestals(const char* filename, AliMUONVStore& pedStore)
159{
160 /// Read pedestal file (produced by the MUONTRKda.exe program for instance)
161 /// and append the read values into the given VStore
cba13f7c 162 /// To be used when the input is a file (for instance when reading data
163 /// from the OCDB).
81028269 164
165 TString sFilename(gSystem->ExpandPathName(filename));
166
167 std::ifstream in(sFilename.Data());
168 if (!in.good())
169 {
170 return kCannotOpenFile;
171 }
172
cba13f7c 173 TString datastring;
06a51226 174 ostringstream stream;
175 char line[1024];
176 while ( in.getline(line,1024) )
177 stream << line << "\n";
178 datastring = TString(stream.str().c_str());
179
cba13f7c 180 in.close();
181
182 return DecodePedestals(datastring,pedStore);
183
184}
185
186//_____________________________________________________________________________
187Int_t
188AliMUONTrackerIO::DecodePedestals(TString data, AliMUONVStore& pedStore)
189{
190 /// Read pedestal Data (produced by the MUONTRKda.exe program for instance)
191 /// and append the read values into the given VStore
192 /// To be used when the input is a TString (for instance when getting data
193 /// from AMORE DB).
194
81028269 195 char line[1024];
196 Int_t busPatchID, manuID, manuChannel;
197 Float_t pedMean, pedSigma;
198 Int_t n(0);
cba13f7c 199 istringstream in(data.Data());
81028269 200
201 while ( in.getline(line,1024) )
202 {
203 AliDebugClass(3,Form("line=%s",line));
204 if ( line[0] == '/' && line[1] == '/' ) continue;
205 std::istringstream sin(line);
206 sin >> busPatchID >> manuID >> manuChannel >> pedMean >> pedSigma;
207 Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
208 AliDebugClass(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d MEAN %7.2f SIGMA %7.2f",
209 busPatchID,detElemID,manuID,manuChannel,pedMean,pedSigma));
cba13f7c 210
81028269 211 AliMUONVCalibParam* ped =
212 static_cast<AliMUONVCalibParam*>(pedStore.FindObject(detElemID,manuID));
81028269 213 if (!ped)
214 {
215 ped = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),
216 detElemID,manuID,
217 AliMUONVCalibParam::InvalidFloatValue());
218 pedStore.Add(ped);
219 }
220 ped->SetValueAsFloat(manuChannel,0,pedMean);
221 ped->SetValueAsFloat(manuChannel,1,pedSigma);
222 ++n;
223 }
81028269 224
225 return n;
226}
227
228//_____________________________________________________________________________
229Int_t
230AliMUONTrackerIO::ReadGains(const char* filename, AliMUONVStore& gainStore,
231 TString& comment)
232{
233 /// Read gain file (produced by the MUONTRKda.exe program for instance)
234 /// and append the read values into the given VStore
cba13f7c 235 /// To be used when the input is a file (for instance when reading data
236 /// from the OCDB).
81028269 237
238 comment = "";
239
240 TString sFilename(gSystem->ExpandPathName(filename));
241
242 std::ifstream in(sFilename.Data());
243 if (!in.good())
244 {
245 return kCannotOpenFile;
246 }
247
cba13f7c 248 TString datastring;
249 ostringstream stream;
250 char line[1024];
251 while ( in.getline(line,1024) )
252 stream << line << "\n";
253 datastring = TString(stream.str().c_str());
254
255 in.close();
256
257 return DecodeGains(datastring,gainStore,comment);
258
259}
260
261//_____________________________________________________________________________
262Int_t
263AliMUONTrackerIO::DecodeGains(TString data, AliMUONVStore& gainStore,
264 TString& comment)
265{
266 /// Read gain file (produced by the MUONTRKda.exe program for instance)
267 /// and append the read values into the given VStore
268 /// To be used when the input is a TString (for instance when getting data
269 /// from AMORE DB).
270
81028269 271 char line[1024];
cba13f7c 272 istringstream in(data.Data());
81028269 273 Int_t busPatchID, manuID, manuChannel;
274 Float_t a0, a1;
275 Int_t thres;
276 UInt_t qual;
277 const Int_t kSaturation(3000); // FIXME: how to get this number ?
278 Int_t n(0);
279 Int_t runNumber(-1);
280 Int_t* runs(0x0);
281 Int_t* dac(0x0);
282 Int_t nDAC(0);
283 Int_t iDAC(0);
284
285 while ( in.getline(line,1024) )
286 {
287 if ( strlen(line) < 10 ) continue;
288 if ( line[0] == '/' && line[1] == '/' )
289 {
290 TString sline(line);
291 if ( sline.Contains("DUMMY") )
292 {
293 AliDebugClass(1,"Got a dummy file here");
294 return kDummyFile;
295 }
296 if ( sline.Contains("* Run") )
297 {
298 TObjArray* a = sline.Tokenize(":");
299 if ( a->GetLast() >= 1 )
300 {
301 TString s = static_cast<TObjString*>(a->At(1))->String();
302 runNumber = s.Atoi();
303 AliDebugClass(1,Form("runNumber is %d",runNumber));
304 }
305 }
306 if ( sline.Contains("DAC values") )
307 {
308 nDAC = TString(sline(2,sline.Length()-2)).Atoi();
309 AliDebugClass(1,Form("# of DAC values = %d",nDAC));
310 if ( nDAC > 0 )
311 {
312 if ( nDAC < 100 )
313 {
314 runs = new Int_t[nDAC];
315 dac = new Int_t[nDAC];
316 // skip two lines
317 in.getline(line,1024);
318 in.getline(line,1024);
319 // then get run and dac values
320 for ( Int_t i = 0; i < nDAC; ++i )
321 {
322 in.getline(line,1024);
323 Int_t a,b;
324 sscanf(line,"// %d %d",&a,&b);
325 runs[iDAC] = a;
326 dac[iDAC] = b;
327 AliDebugClass(1,Form("RUN %d is DAC %d",runs[iDAC],dac[iDAC]));
328 ++iDAC;
329 }
330 }
331 else
332 {
333 AliErrorClass(Form("Something went wrong, as I get too big nDAC = %d",nDAC));
334 nDAC = 0;
335 return kFormatError;
336 }
337 }
338 }
339 continue;
340 }
341
342 sscanf(line,"%d %d %d %f %f %d %x",&busPatchID,&manuID,&manuChannel,
343 &a0,&a1,&thres,&qual);
344 AliDebugClass(3,Form("line=%s",line));
345 Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
346 AliDebugClass(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d A0 %7.2f "
347 "A1 %e THRES %5d QUAL %x",
348 busPatchID,detElemID,manuID,manuChannel,a0,a1,thres,qual));
349 if ( qual == 0 ) continue;
350
351 AliMUONVCalibParam* gain =
352 static_cast<AliMUONVCalibParam*>(gainStore.FindObject(detElemID,manuID));
353
cba13f7c 354 if (!gain)
81028269 355 {
356 gain = new AliMUONCalibParamNF(5,AliMpConstants::ManuNofChannels(),detElemID,manuID,0);
357 gainStore.Add(gain);
358 }
359 gain->SetValueAsFloat(manuChannel,0,a0);
360 gain->SetValueAsFloat(manuChannel,1,a1);
361 gain->SetValueAsInt(manuChannel,2,thres);
362 gain->SetValueAsInt(manuChannel,3,qual);
363 gain->SetValueAsInt(manuChannel,4,kSaturation);
364 ++n;
365 }
cba13f7c 366
81028269 367 comment = "";
368
369 if ( runNumber > 0 )
370 {
371 comment = Form("RUN %d",runNumber);
372 }
373
374 for ( Int_t i = 0; i < nDAC; ++i )
375 {
376 comment += Form(";(RUN %d = DAC %d)",runs[i],dac[i]);
377 }
378
379 delete[] runs;
380 delete[] dac;
381
382 return n;
383}
384
385//_____________________________________________________________________________
386Int_t
387AliMUONTrackerIO::ReadCapacitances(const char* file, AliMUONVStore& capaStore)
388{
389 /// Read capacitance file
390 /// and append the read values into the given VStore
391
392 ifstream in(gSystem->ExpandPathName(file));
393 if (in.bad()) return kCannotOpenFile;
394
395 Int_t ngenerated(0);
396
397 char line[1024];
398 Int_t serialNumber(-1);
399 AliMUONVCalibParam* param(0x0);
400
401 while ( in.getline(line,1024,'\n') )
402 {
403 if ( isdigit(line[0]) )
404 {
405 serialNumber = atoi(line);
406 param = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
407 if (param)
408 {
409 AliErrorClass(Form("serialNumber %d appears several times !",serialNumber));
630711ed 410 continue;
81028269 411 }
412 param = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
413 Bool_t ok = capaStore.Add(param);
414 if (!ok)
415 {
416 AliErrorClass(Form("Could not set serialNumber=%d",serialNumber));
417 continue;
418 }
419 continue;
420 }
421 Int_t channel;
422 Float_t capaValue;
423 Float_t injectionGain;
424 sscanf(line,"%d %f %f",&channel,&capaValue,&injectionGain);
425 AliDebugClass(1,Form("SerialNumber %10d Channel %3d Capa %f injectionGain %f",
426 serialNumber,channel,capaValue,injectionGain));
427 param->SetValueAsFloat(channel,0,capaValue);
428 param->SetValueAsFloat(channel,1,injectionGain);
429 ++ngenerated;
430 }
431
432 in.close();
433
434 return ngenerated;
435}