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;
74 datastring.ReadFile(in);
78 return DecodePedestals(datastring,pedStore);
82 //_____________________________________________________________________________
84 AliMUONTrackerIO::DecodePedestals(TString data, AliMUONVStore& pedStore)
86 /// Read pedestal Data (produced by the MUONTRKda.exe program for instance)
87 /// and append the read values into the given VStore
88 /// To be used when the input is a TString (for instance when getting data
92 Int_t busPatchID, manuID, manuChannel;
93 Float_t pedMean, pedSigma;
95 istringstream in(data.Data());
97 while ( in.getline(line,1024) )
99 AliDebugClass(3,Form("line=%s",line));
100 if ( line[0] == '/' && line[1] == '/' ) continue;
101 std::istringstream sin(line);
102 sin >> busPatchID >> manuID >> manuChannel >> pedMean >> pedSigma;
103 Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
104 AliDebugClass(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d MEAN %7.2f SIGMA %7.2f",
105 busPatchID,detElemID,manuID,manuChannel,pedMean,pedSigma));
107 AliMUONVCalibParam* ped =
108 static_cast<AliMUONVCalibParam*>(pedStore.FindObject(detElemID,manuID));
111 ped = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),
113 AliMUONVCalibParam::InvalidFloatValue());
116 ped->SetValueAsFloat(manuChannel,0,pedMean);
117 ped->SetValueAsFloat(manuChannel,1,pedSigma);
124 //_____________________________________________________________________________
126 AliMUONTrackerIO::ReadGains(const char* filename, AliMUONVStore& gainStore,
129 /// Read gain file (produced by the MUONTRKda.exe program for instance)
130 /// and append the read values into the given VStore
131 /// To be used when the input is a file (for instance when reading data
136 TString sFilename(gSystem->ExpandPathName(filename));
138 std::ifstream in(sFilename.Data());
141 return kCannotOpenFile;
145 ostringstream stream;
147 while ( in.getline(line,1024) )
148 stream << line << "\n";
149 datastring = TString(stream.str().c_str());
153 return DecodeGains(datastring,gainStore,comment);
157 //_____________________________________________________________________________
159 AliMUONTrackerIO::DecodeGains(TString data, AliMUONVStore& gainStore,
162 /// Read gain file (produced by the MUONTRKda.exe program for instance)
163 /// and append the read values into the given VStore
164 /// To be used when the input is a TString (for instance when getting data
168 istringstream in(data.Data());
169 Int_t busPatchID, manuID, manuChannel;
173 const Int_t kSaturation(3000); // FIXME: how to get this number ?
181 while ( in.getline(line,1024) )
183 if ( strlen(line) < 10 ) continue;
184 if ( line[0] == '/' && line[1] == '/' )
187 if ( sline.Contains("DUMMY") )
189 AliDebugClass(1,"Got a dummy file here");
192 if ( sline.Contains("* Run") )
194 TObjArray* a = sline.Tokenize(":");
195 if ( a->GetLast() >= 1 )
197 TString s = static_cast<TObjString*>(a->At(1))->String();
198 runNumber = s.Atoi();
199 AliDebugClass(1,Form("runNumber is %d",runNumber));
202 if ( sline.Contains("DAC values") )
204 nDAC = TString(sline(2,sline.Length()-2)).Atoi();
205 AliDebugClass(1,Form("# of DAC values = %d",nDAC));
210 runs = new Int_t[nDAC];
211 dac = new Int_t[nDAC];
213 in.getline(line,1024);
214 in.getline(line,1024);
215 // then get run and dac values
216 for ( Int_t i = 0; i < nDAC; ++i )
218 in.getline(line,1024);
220 sscanf(line,"// %d %d",&a,&b);
223 AliDebugClass(1,Form("RUN %d is DAC %d",runs[iDAC],dac[iDAC]));
229 AliErrorClass(Form("Something went wrong, as I get too big nDAC = %d",nDAC));
238 sscanf(line,"%d %d %d %f %f %d %x",&busPatchID,&manuID,&manuChannel,
239 &a0,&a1,&thres,&qual);
240 AliDebugClass(3,Form("line=%s",line));
241 Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
242 AliDebugClass(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d A0 %7.2f "
243 "A1 %e THRES %5d QUAL %x",
244 busPatchID,detElemID,manuID,manuChannel,a0,a1,thres,qual));
245 if ( qual == 0 ) continue;
247 AliMUONVCalibParam* gain =
248 static_cast<AliMUONVCalibParam*>(gainStore.FindObject(detElemID,manuID));
252 gain = new AliMUONCalibParamNF(5,AliMpConstants::ManuNofChannels(),detElemID,manuID,0);
255 gain->SetValueAsFloat(manuChannel,0,a0);
256 gain->SetValueAsFloat(manuChannel,1,a1);
257 gain->SetValueAsInt(manuChannel,2,thres);
258 gain->SetValueAsInt(manuChannel,3,qual);
259 gain->SetValueAsInt(manuChannel,4,kSaturation);
267 comment = Form("RUN %d",runNumber);
270 for ( Int_t i = 0; i < nDAC; ++i )
272 comment += Form(";(RUN %d = DAC %d)",runs[i],dac[i]);
281 //_____________________________________________________________________________
283 AliMUONTrackerIO::ReadCapacitances(const char* file, AliMUONVStore& capaStore)
285 /// Read capacitance file
286 /// and append the read values into the given VStore
288 ifstream in(gSystem->ExpandPathName(file));
289 if (in.bad()) return kCannotOpenFile;
294 Int_t serialNumber(-1);
295 AliMUONVCalibParam* param(0x0);
297 while ( in.getline(line,1024,'\n') )
299 if ( isdigit(line[0]) )
301 serialNumber = atoi(line);
302 param = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
305 AliErrorClass(Form("serialNumber %d appears several times !",serialNumber));
308 param = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
309 Bool_t ok = capaStore.Add(param);
312 AliErrorClass(Form("Could not set serialNumber=%d",serialNumber));
319 Float_t injectionGain;
320 sscanf(line,"%d %f %f",&channel,&capaValue,&injectionGain);
321 AliDebugClass(1,Form("SerialNumber %10d Channel %3d Capa %f injectionGain %f",
322 serialNumber,channel,capaValue,injectionGain));
323 param->SetValueAsFloat(channel,0,capaValue);
324 param->SetValueAsFloat(channel,1,injectionGain);