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 "AliMUONCalibParamND.h"
35 #include "AliMUONCalibParamNF.h"
36 #include "AliMUONVStore.h"
37 #include "AliMpConstants.h"
38 #include "AliMpDDLStore.h"
39 #include "AliMpDetElement.h"
40 #include <Riostream.h>
42 #include <TObjString.h>
46 //_____________________________________________________________________________
47 AliMUONTrackerIO::AliMUONTrackerIO()
52 //_____________________________________________________________________________
53 AliMUONTrackerIO::~AliMUONTrackerIO()
58 //_____________________________________________________________________________
60 AliMUONTrackerIO::ReadOccupancy(const char* filename,AliMUONVStore& occupancyMap)
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
67 TString sFilename(gSystem->ExpandPathName(filename));
69 std::ifstream in(sFilename.Data());
72 return kCannotOpenFile;
78 while ( in.getline(line,1024) )
79 stream << line << "\n";
80 datastring = TString(stream.str().c_str());
84 return DecodeOccupancy(datastring,occupancyMap);
88 //_____________________________________________________________________________
90 AliMUONTrackerIO::DecodeOccupancy(TString data, AliMUONVStore& occupancyMap)
92 /// Decode occupancy string created append values to the occupancyMap store.
93 /// Expected format of the file is :
94 /// busPatchId manuId sumofn nevt
96 if ( ! AliMpDDLStore::Instance(kFALSE) )
98 AliErrorClass("Mapping not loaded. Cannot work");
103 istringstream in(data.Data());
107 while ( in.getline(line,1024) )
109 AliDebugClass(3,Form("line=%s",line));
110 if ( line[0] == '/' && line[1] == '/' ) continue;
111 std::istringstream sin(line);
113 Int_t busPatchId, manuId;
114 Int_t numberOfEvents;
117 sin >> busPatchId >> manuId >> sumn >> numberOfEvents;
119 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
121 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
123 Int_t numberOfChannelsInManu = -1;
125 if (de) numberOfChannelsInManu = de->NofChannelsInManu(manuId);
127 if ( numberOfChannelsInManu <= 0 )
129 AliErrorClass(Form("BP %5d DE %5d MANU %5d nchannels=%d",busPatchId,detElemId,manuId,numberOfChannelsInManu));
133 AliMUONVCalibParam* occupancy =
134 static_cast<AliMUONVCalibParam*>(occupancyMap.FindObject(detElemId,manuId));
137 AliErrorClass(Form("DE %5d MANU %5d is already there ?!",detElemId,manuId));
141 occupancy = new AliMUONCalibParamND(5,1,detElemId,manuId,0);
143 occupancyMap.Add(occupancy);
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);
156 //_____________________________________________________________________________
158 AliMUONTrackerIO::ReadPedestals(const char* filename, AliMUONVStore& pedStore)
160 /// Read pedestal file (produced by the MUONTRKda.exe program for instance)
161 /// and append the read values into the given VStore
162 /// To be used when the input is a file (for instance when reading data
165 TString sFilename(gSystem->ExpandPathName(filename));
167 std::ifstream in(sFilename.Data());
170 return kCannotOpenFile;
174 ostringstream stream;
176 while ( in.getline(line,1024) )
177 stream << line << "\n";
178 datastring = TString(stream.str().c_str());
182 return DecodePedestals(datastring,pedStore);
186 //_____________________________________________________________________________
188 AliMUONTrackerIO::DecodePedestals(TString data, AliMUONVStore& pedStore)
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
196 Int_t busPatchID, manuID, manuChannel;
197 Float_t pedMean, pedSigma;
199 istringstream in(data.Data());
201 while ( in.getline(line,1024) )
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));
211 AliMUONVCalibParam* ped =
212 static_cast<AliMUONVCalibParam*>(pedStore.FindObject(detElemID,manuID));
215 ped = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),
217 AliMUONVCalibParam::InvalidFloatValue());
220 ped->SetValueAsFloat(manuChannel,0,pedMean);
221 ped->SetValueAsFloat(manuChannel,1,pedSigma);
228 //_____________________________________________________________________________
230 AliMUONTrackerIO::ReadGains(const char* filename, AliMUONVStore& gainStore,
233 /// Read gain file (produced by the MUONTRKda.exe program for instance)
234 /// and append the read values into the given VStore
235 /// To be used when the input is a file (for instance when reading data
240 TString sFilename(gSystem->ExpandPathName(filename));
242 std::ifstream in(sFilename.Data());
245 return kCannotOpenFile;
249 ostringstream stream;
251 while ( in.getline(line,1024) )
252 stream << line << "\n";
253 datastring = TString(stream.str().c_str());
257 return DecodeGains(datastring,gainStore,comment);
261 //_____________________________________________________________________________
263 AliMUONTrackerIO::DecodeGains(TString data, AliMUONVStore& gainStore,
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
272 istringstream in(data.Data());
273 Int_t busPatchID, manuID, manuChannel;
277 const Int_t kSaturation(3000); // FIXME: how to get this number ?
285 while ( in.getline(line,1024) )
287 if ( strlen(line) < 10 ) continue;
288 if ( line[0] == '/' && line[1] == '/' )
291 if ( sline.Contains("DUMMY") )
293 AliDebugClass(1,"Got a dummy file here");
296 if ( sline.Contains("* Run") )
298 TObjArray* a = sline.Tokenize(":");
299 if ( a->GetLast() >= 1 )
301 TString s = static_cast<TObjString*>(a->At(1))->String();
302 runNumber = s.Atoi();
303 AliDebugClass(1,Form("runNumber is %d",runNumber));
306 if ( sline.Contains("DAC values") )
308 nDAC = TString(sline(2,sline.Length()-2)).Atoi();
309 AliDebugClass(1,Form("# of DAC values = %d",nDAC));
314 runs = new Int_t[nDAC];
315 dac = new Int_t[nDAC];
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 )
322 in.getline(line,1024);
324 sscanf(line,"// %d %d",&a,&b);
327 AliDebugClass(1,Form("RUN %d is DAC %d",runs[iDAC],dac[iDAC]));
333 AliErrorClass(Form("Something went wrong, as I get too big nDAC = %d",nDAC));
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;
351 AliMUONVCalibParam* gain =
352 static_cast<AliMUONVCalibParam*>(gainStore.FindObject(detElemID,manuID));
356 gain = new AliMUONCalibParamNF(5,AliMpConstants::ManuNofChannels(),detElemID,manuID,0);
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);
371 comment = Form("RUN %d",runNumber);
374 for ( Int_t i = 0; i < nDAC; ++i )
376 comment += Form(";(RUN %d = DAC %d)",runs[i],dac[i]);
385 //_____________________________________________________________________________
387 AliMUONTrackerIO::ReadCapacitances(const char* file, AliMUONVStore& capaStore)
389 /// Read capacitance file
390 /// and append the read values into the given VStore
392 ifstream in(gSystem->ExpandPathName(file));
393 if (in.bad()) return kCannotOpenFile;
398 Int_t serialNumber(-1);
399 AliMUONVCalibParam* param(0x0);
401 while ( in.getline(line,1024,'\n') )
403 if ( isdigit(line[0]) )
405 serialNumber = atoi(line);
406 param = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
409 AliErrorClass(Form("serialNumber %d appears several times !",serialNumber));
412 param = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
413 Bool_t ok = capaStore.Add(param);
416 AliErrorClass(Form("Could not set serialNumber=%d",serialNumber));
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);