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 **************************************************************************/
19 #include "AliMUONTrackerIO.h"
21 /// \class AliMUONTrackerIO
23 /// Reader class for ASCII calibration files for MUON tracker :
24 /// converts those ASCII files into AliMUONVStore (suitable to e.g. feed
27 /// \author Laurent Aphecetche, Subatech
30 ClassImp(AliMUONTrackerIO)
34 #include "AliMUONCalibParamNF.h"
35 #include "AliMUONVStore.h"
36 #include "AliMpConstants.h"
37 #include "AliMpDDLStore.h"
38 #include <Riostream.h>
40 #include <TObjString.h>
44 //_____________________________________________________________________________
45 AliMUONTrackerIO::AliMUONTrackerIO()
50 //_____________________________________________________________________________
51 AliMUONTrackerIO::~AliMUONTrackerIO()
56 //_____________________________________________________________________________
58 AliMUONTrackerIO::ReadPedestals(const char* filename, AliMUONVStore& pedStore)
60 /// Read pedestal file (produced by the MUONTRKda.exe program for instance)
61 /// and append the read values into the given VStore
62 /// To be used when the input is a file (for instance when reading data
65 TString sFilename(gSystem->ExpandPathName(filename));
67 std::ifstream in(sFilename.Data());
70 return kCannotOpenFile;
76 while ( in.getline(line,1024) )
77 stream << line << "\n";
78 datastring = TString(stream.str().c_str());
82 return DecodePedestals(datastring,pedStore);
86 //_____________________________________________________________________________
88 AliMUONTrackerIO::DecodePedestals(TString data, AliMUONVStore& pedStore)
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
96 Int_t busPatchID, manuID, manuChannel;
97 Float_t pedMean, pedSigma;
99 istringstream in(data.Data());
101 while ( in.getline(line,1024) )
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));
111 AliMUONVCalibParam* ped =
112 static_cast<AliMUONVCalibParam*>(pedStore.FindObject(detElemID,manuID));
115 ped = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),
117 AliMUONVCalibParam::InvalidFloatValue());
120 ped->SetValueAsFloat(manuChannel,0,pedMean);
121 ped->SetValueAsFloat(manuChannel,1,pedSigma);
128 //_____________________________________________________________________________
130 AliMUONTrackerIO::ReadGains(const char* filename, AliMUONVStore& gainStore,
133 /// Read gain file (produced by the MUONTRKda.exe program for instance)
134 /// and append the read values into the given VStore
135 /// To be used when the input is a file (for instance when reading data
140 TString sFilename(gSystem->ExpandPathName(filename));
142 std::ifstream in(sFilename.Data());
145 return kCannotOpenFile;
149 ostringstream stream;
151 while ( in.getline(line,1024) )
152 stream << line << "\n";
153 datastring = TString(stream.str().c_str());
157 return DecodeGains(datastring,gainStore,comment);
161 //_____________________________________________________________________________
163 AliMUONTrackerIO::DecodeGains(TString data, AliMUONVStore& gainStore,
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
172 istringstream in(data.Data());
173 Int_t busPatchID, manuID, manuChannel;
177 const Int_t kSaturation(3000); // FIXME: how to get this number ?
185 while ( in.getline(line,1024) )
187 if ( strlen(line) < 10 ) continue;
188 if ( line[0] == '/' && line[1] == '/' )
191 if ( sline.Contains("DUMMY") )
193 AliDebugClass(1,"Got a dummy file here");
196 if ( sline.Contains("* Run") )
198 TObjArray* a = sline.Tokenize(":");
199 if ( a->GetLast() >= 1 )
201 TString s = static_cast<TObjString*>(a->At(1))->String();
202 runNumber = s.Atoi();
203 AliDebugClass(1,Form("runNumber is %d",runNumber));
206 if ( sline.Contains("DAC values") )
208 nDAC = TString(sline(2,sline.Length()-2)).Atoi();
209 AliDebugClass(1,Form("# of DAC values = %d",nDAC));
214 runs = new Int_t[nDAC];
215 dac = new Int_t[nDAC];
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 )
222 in.getline(line,1024);
224 sscanf(line,"// %d %d",&a,&b);
227 AliDebugClass(1,Form("RUN %d is DAC %d",runs[iDAC],dac[iDAC]));
233 AliErrorClass(Form("Something went wrong, as I get too big nDAC = %d",nDAC));
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;
251 AliMUONVCalibParam* gain =
252 static_cast<AliMUONVCalibParam*>(gainStore.FindObject(detElemID,manuID));
256 gain = new AliMUONCalibParamNF(5,AliMpConstants::ManuNofChannels(),detElemID,manuID,0);
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);
271 comment = Form("RUN %d",runNumber);
274 for ( Int_t i = 0; i < nDAC; ++i )
276 comment += Form(";(RUN %d = DAC %d)",runs[i],dac[i]);
285 //_____________________________________________________________________________
287 AliMUONTrackerIO::ReadCapacitances(const char* file, AliMUONVStore& capaStore)
289 /// Read capacitance file
290 /// and append the read values into the given VStore
292 ifstream in(gSystem->ExpandPathName(file));
293 if (in.bad()) return kCannotOpenFile;
298 Int_t serialNumber(-1);
299 AliMUONVCalibParam* param(0x0);
301 while ( in.getline(line,1024,'\n') )
303 if ( isdigit(line[0]) )
305 serialNumber = atoi(line);
306 param = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
309 AliErrorClass(Form("serialNumber %d appears several times !",serialNumber));
312 param = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
313 Bool_t ok = capaStore.Add(param);
316 AliErrorClass(Form("Could not set serialNumber=%d",serialNumber));
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);