]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTrackerIO.cxx
In AliMUONTrackerIO:
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackerIO.cxx
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
18 #include <cstdlib>
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
30 ClassImp(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 //_____________________________________________________________________________
45 AliMUONTrackerIO::AliMUONTrackerIO()
46 {
47   /// ctor
48 }
49
50 //_____________________________________________________________________________
51 AliMUONTrackerIO::~AliMUONTrackerIO()
52 {
53   /// dtor
54 }
55
56 //_____________________________________________________________________________
57 Int_t 
58 AliMUONTrackerIO::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
62   /// To be used when the input is a file (for instance when reading data 
63   /// from the OCDB).
64   
65   TString sFilename(gSystem->ExpandPathName(filename));
66   
67   std::ifstream in(sFilename.Data());
68   if (!in.good()) 
69   {
70     return kCannotOpenFile;
71   }
72   
73   TString datastring;
74   datastring.ReadFile(in);
75     
76   in.close();
77
78   return DecodePedestals(datastring,pedStore);
79   
80 }
81
82 //_____________________________________________________________________________
83 Int_t 
84 AliMUONTrackerIO::DecodePedestals(TString data, AliMUONVStore& pedStore)
85 {
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 
89   /// from AMORE DB).
90   
91   char line[1024];
92   Int_t busPatchID, manuID, manuChannel;
93   Float_t pedMean, pedSigma;
94   Int_t n(0);
95   istringstream in(data.Data());
96   
97   while ( in.getline(line,1024) )
98   {
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));
106                     
107     AliMUONVCalibParam* ped = 
108       static_cast<AliMUONVCalibParam*>(pedStore.FindObject(detElemID,manuID));
109     if (!ped) 
110     {
111       ped = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),
112                                     detElemID,manuID,
113                                     AliMUONVCalibParam::InvalidFloatValue());  
114       pedStore.Add(ped);
115     }
116     ped->SetValueAsFloat(manuChannel,0,pedMean);
117     ped->SetValueAsFloat(manuChannel,1,pedSigma);
118     ++n;
119   }
120
121   return n;
122 }
123
124 //_____________________________________________________________________________
125 Int_t 
126 AliMUONTrackerIO::ReadGains(const char* filename, AliMUONVStore& gainStore,
127                             TString& comment)
128 {
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 
132   /// from the OCDB).
133   
134   comment = "";
135   
136   TString sFilename(gSystem->ExpandPathName(filename));
137   
138   std::ifstream in(sFilename.Data());
139   if (!in.good()) 
140   {
141     return kCannotOpenFile;
142   }
143   
144   TString datastring;
145   ostringstream stream;
146   char line[1024];
147   while ( in.getline(line,1024) )
148         stream << line << "\n";
149   datastring = TString(stream.str().c_str());
150   
151   in.close();
152   
153   return DecodeGains(datastring,gainStore,comment);
154
155 }
156
157 //_____________________________________________________________________________
158 Int_t 
159 AliMUONTrackerIO::DecodeGains(TString data, AliMUONVStore& gainStore,
160                             TString& comment)
161 {
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 
165   /// from AMORE DB).
166   
167   char line[1024];
168   istringstream in(data.Data());
169   Int_t busPatchID, manuID, manuChannel;
170   Float_t a0, a1;
171   Int_t thres;
172   UInt_t qual;
173   const Int_t kSaturation(3000); // FIXME: how to get this number ?
174   Int_t n(0);
175   Int_t runNumber(-1);
176   Int_t* runs(0x0);
177   Int_t* dac(0x0);
178   Int_t nDAC(0);
179   Int_t iDAC(0);
180   
181   while ( in.getline(line,1024) )
182   {
183     if ( strlen(line) < 10 ) continue;
184     if ( line[0] == '/' && line[1] == '/' ) 
185     {
186       TString sline(line);
187       if ( sline.Contains("DUMMY") )
188       {
189         AliDebugClass(1,"Got a dummy file here");
190         return kDummyFile;
191       }
192       if ( sline.Contains("* Run") )
193       {
194         TObjArray* a = sline.Tokenize(":");
195         if ( a->GetLast() >= 1 ) 
196         {
197           TString s = static_cast<TObjString*>(a->At(1))->String();
198           runNumber = s.Atoi();
199           AliDebugClass(1,Form("runNumber is %d",runNumber));
200         }            
201       }
202       if ( sline.Contains("DAC values") )
203       {
204         nDAC = TString(sline(2,sline.Length()-2)).Atoi();
205         AliDebugClass(1,Form("# of DAC values = %d",nDAC));
206         if ( nDAC > 0 )
207         {
208           if ( nDAC < 100 ) 
209           {
210             runs = new Int_t[nDAC];
211             dac = new Int_t[nDAC];
212             // skip two lines
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 ) 
217             {
218               in.getline(line,1024);
219               Int_t a,b;
220               sscanf(line,"// %d %d",&a,&b);
221               runs[iDAC] = a;
222               dac[iDAC] = b;
223               AliDebugClass(1,Form("RUN %d is DAC %d",runs[iDAC],dac[iDAC]));
224               ++iDAC;
225             }
226           }
227           else
228           {
229             AliErrorClass(Form("Something went wrong, as I get too big nDAC = %d",nDAC));
230             nDAC = 0;
231             return kFormatError;
232           }
233         }
234       }
235       continue;
236     }
237     
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;
246     
247     AliMUONVCalibParam* gain = 
248       static_cast<AliMUONVCalibParam*>(gainStore.FindObject(detElemID,manuID));
249     
250    if (!gain) 
251     {
252       gain = new AliMUONCalibParamNF(5,AliMpConstants::ManuNofChannels(),detElemID,manuID,0);
253       gainStore.Add(gain);
254     }
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);
260     ++n;
261   }
262
263   comment = "";
264   
265   if ( runNumber > 0 )
266   {
267     comment = Form("RUN %d",runNumber);
268   }
269   
270   for ( Int_t i = 0; i < nDAC; ++i )
271   {
272     comment += Form(";(RUN %d = DAC %d)",runs[i],dac[i]);
273   }
274   
275   delete[] runs;
276   delete[] dac;
277   
278   return n;
279 }
280
281 //_____________________________________________________________________________
282 Int_t
283 AliMUONTrackerIO::ReadCapacitances(const char* file, AliMUONVStore& capaStore)
284 {
285   /// Read capacitance file
286   /// and append the read values into the given VStore
287   
288   ifstream in(gSystem->ExpandPathName(file));
289   if (in.bad()) return kCannotOpenFile;
290   
291   Int_t ngenerated(0);
292   
293   char line[1024];
294   Int_t serialNumber(-1);
295   AliMUONVCalibParam* param(0x0);
296   
297   while ( in.getline(line,1024,'\n') )
298   {
299     if ( isdigit(line[0]) ) 
300     {
301       serialNumber = atoi(line);
302       param = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
303       if (param)
304       {
305         AliErrorClass(Form("serialNumber %d appears several times !",serialNumber));
306         continue;
307       }
308       param = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
309       Bool_t ok = capaStore.Add(param);
310       if (!ok)
311       {
312         AliErrorClass(Form("Could not set serialNumber=%d",serialNumber));
313         continue;
314       }      
315       continue;
316     }
317     Int_t channel;
318     Float_t capaValue;
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);
325     ++ngenerated;
326   }
327   
328   in.close();
329   
330   return ngenerated;
331 }