AliRoot Core  edcc906 (edcc906)
AliMUONTrackerIO.cxx
Go to the documentation of this file.
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 <iostream>
20 #include "AliMUONTrackerIO.h"
21 
29 
30 using std::ostringstream;
31 using std::istringstream;
32 using std::cout;
33 using std::endl;
35 ClassImp(AliMUONTrackerIO)
37 
38 #include "AliDCSValue.h"
39 #include "AliLog.h"
40 #include "AliMUONCalibParamND.h"
41 #include "AliMUONCalibParamNF.h"
42 #include "AliMUONVStore.h"
43 #include "AliMpConstants.h"
44 #include "AliMpDDLStore.h"
45 #include "AliMpDEManager.h"
46 #include "AliMpDetElement.h"
47 #include <Riostream.h>
48 #include <TClass.h>
49 #include <TObjString.h>
50 #include <TSystem.h>
51 #include <sstream>
52 
53 //_____________________________________________________________________________
55 {
57 }
58 
59 //_____________________________________________________________________________
61 {
63 }
64 
65 //_____________________________________________________________________________
66 Int_t
67 AliMUONTrackerIO::ReadOccupancy(const char* filename,AliMUONVStore& occupancyMap)
68 {
73 
74  TString sFilename(gSystem->ExpandPathName(filename));
75 
76  std::ifstream in(sFilename.Data());
77  if (!in.good())
78  {
79  return kCannotOpenFile;
80  }
81 
82  TString datastring;
83  ostringstream stream;
84  char line[1024];
85  while ( in.getline(line,1024) )
86  stream << line << "\n";
87 
88  in.close();
89 
90  return DecodeOccupancy(stream.str().c_str(),occupancyMap);
91 
92 }
93 
94 //_____________________________________________________________________________
95 Int_t
96 AliMUONTrackerIO::DecodeOccupancy(const char* data, AliMUONVStore& occupancyMap)
97 {
101 
102  if ( ! AliMpDDLStore::Instance(kFALSE) )
103  {
104  AliErrorClass("Mapping not loaded. Cannot work");
105  return kNoMapping;
106  }
107 
108  char line[1024];
109  istringstream in(data);
110 
111  Int_t n(0);
112 
113  while ( in.getline(line,1024) )
114  {
115  AliDebugClass(3,Form("line=%s",line));
116  if ( line[0] == '/' && line[1] == '/' ) continue;
117  std::istringstream sin(line);
118 
119  Int_t busPatchId, manuId;
120  Int_t numberOfEvents;
121  Double_t sumn;
122 
123  sin >> busPatchId >> manuId >> sumn >> numberOfEvents;
124 
125  if ( busPatchId == -1 && manuId == -1 && sumn == 0 && numberOfEvents == 0 )
126  {
129  return kNoInfoFile;
130  }
131 
132  Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
133 
135 
136  Int_t numberOfChannelsInManu = -1;
137 
138  if (de) numberOfChannelsInManu = de->NofChannelsInManu(manuId);
139 
140  if ( numberOfChannelsInManu <= 0 )
141  {
142  AliErrorClass(Form("BP %5d DE %5d MANU %5d nchannels=%d",busPatchId,detElemId,manuId,numberOfChannelsInManu));
143  continue;
144  }
145 
146  AliMUONVCalibParam* occupancy =
147  static_cast<AliMUONVCalibParam*>(occupancyMap.FindObject(detElemId,manuId));
148  if (occupancy)
149  {
150  AliErrorClass(Form("DE %5d MANU %5d is already there ?!",detElemId,manuId));
151  continue;
152  }
153 
154  occupancy = new AliMUONCalibParamND(5,1,detElemId,manuId,0);
155 
156  occupancyMap.Add(occupancy);
157 
158  occupancy->SetValueAsDouble(0,0,sumn);
159  occupancy->SetValueAsDouble(0,1,sumn); // with only 0 and 1s, sumw = sumw2 = sumn
160  occupancy->SetValueAsDouble(0,2,sumn);
161  occupancy->SetValueAsInt(0,3,numberOfChannelsInManu);
162  occupancy->SetValueAsInt(0,4,numberOfEvents);
163  ++n;
164  }
165 
166  return n;
167 }
168 
169 //_____________________________________________________________________________
170 Int_t
171 AliMUONTrackerIO::ReadPedestals(const char* filename, AliMUONVStore& pedStore)
172 {
177 
178  TString sFilename(gSystem->ExpandPathName(filename));
179 
180  std::ifstream in(sFilename.Data());
181  if (!in.good())
182  {
183  return kCannotOpenFile;
184  }
185 
186  ostringstream stream;
187  char line[1024];
188  while ( in.getline(line,1024) )
189  stream << line << "\n";
190 
191  in.close();
192 
193  return DecodePedestals(stream.str().c_str(),pedStore);
194 
195 }
196 
197 //_____________________________________________________________________________
198 Int_t
200 {
205 
206  char line[1024];
207  Int_t busPatchID, manuID, manuChannel;
208  Float_t pedMean, pedSigma;
209  Int_t n(0);
210  istringstream in(data);
211 
212  while ( in.getline(line,1024) )
213  {
214  AliDebugClass(3,Form("line=%s",line));
215  if ( line[0] == '/' && line[1] == '/' ) continue;
216  std::istringstream sin(line);
217  sin >> busPatchID >> manuID >> manuChannel >> pedMean >> pedSigma;
218  Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
219 
220  if ( !AliMpDEManager::IsValidDetElemId(detElemID) )
221  {
222  AliErrorClass(Form("Got an invalid DE = %d from busPatchId=%d manuId=%d",
223  detElemID,busPatchID,manuID));
224  continue;
225  }
226 
227  AliDebugClass(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d MEAN %7.2f SIGMA %7.2f",
228  busPatchID,detElemID,manuID,manuChannel,pedMean,pedSigma));
229 
230  AliMUONVCalibParam* ped =
231  static_cast<AliMUONVCalibParam*>(pedStore.FindObject(detElemID,manuID));
232  if (!ped)
233  {
235  detElemID,manuID,
237  pedStore.Add(ped);
238  }
239  ped->SetValueAsFloat(manuChannel,0,pedMean);
240  ped->SetValueAsFloat(manuChannel,1,pedSigma);
241  ++n;
242  }
243 
244  return n;
245 }
246 
247 //_____________________________________________________________________________
248 Int_t
249 AliMUONTrackerIO::ReadConfig(const char* filename, AliMUONVStore& confStore)
250 {
255 
256  TString sFilename(gSystem->ExpandPathName(filename));
257 
258  std::ifstream in(sFilename.Data());
259  if (!in.good())
260  {
261  return kCannotOpenFile;
262  }
263 
264  ostringstream stream;
265  char line[1024];
266  while ( in.getline(line,1024) )
267  stream << line << "\n";
268 
269  in.close();
270 
271  return DecodeConfig(stream.str().c_str(),confStore);
272 }
273 
274 //_____________________________________________________________________________
275 Int_t
276 AliMUONTrackerIO::DecodeConfig(const char* data, AliMUONVStore& confStore)
277 {
282 
283  char line[1024];
284  Int_t busPatchID, manuID;
285  Int_t n(0);
286  istringstream in(data);
287 
288  while ( in.getline(line,1024) )
289  {
290  AliDebugClass(3,Form("line=%s",line));
291  if ( line[0] == '#' )
292  {
293  continue;
294  }
295  std::istringstream sin(line);
296  sin >> busPatchID >> manuID;
297 
298  Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
299 
300  if ( !AliMpDEManager::IsValidDetElemId(detElemID) )
301  {
302  AliErrorClass(Form("Got an invalid DE = %d from busPatchId=%d manuId=%d",
303  detElemID,busPatchID,manuID));
304  continue;
305  }
306 
307  AliMUONVCalibParam* conf =
308  static_cast<AliMUONVCalibParam*>(confStore.FindObject(detElemID,manuID));
309  if (!conf)
310  {
311  conf = new AliMUONCalibParamNF(1,1,detElemID,manuID,1);
312  confStore.Add(conf);
313  }
314  ++n;
315  }
316 
317  return n;
318 }
319 
320 //_____________________________________________________________________________
321 Int_t
322 AliMUONTrackerIO::WriteConfig(ofstream& out, const AliMUONVStore& confStore)
323 {
327 
328  if ( !AliMpDDLStore::Instance() )
329  {
330  cout << "ERROR: mapping not loaded. Cannot work" << endl;
331  return 0;
332  }
333 
334  TIter next(confStore.CreateIterator());
335  AliMUONVCalibParam* param;
336  Int_t n(0);
337 
338  while ( (param=static_cast<AliMUONVCalibParam*>(next())) )
339  {
340  Int_t detElemId = param->ID0();
341  Int_t manuId = param->ID1();
342 
343  Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
344  ++n;
345 
346  out << busPatchId << " " << manuId << endl;
347  }
348  return n;
349 }
350 
static Int_t ReadOccupancy(const char *filename, AliMUONVStore &occupancyMap)
virtual ~AliMUONTrackerIO()
virtual TIterator * CreateIterator() const =0
Return an iterator to loop over the whole store.
static Float_t InvalidFloatValue()
Return 1E38 as invalid float value.
static Int_t WriteConfig(ofstream &out, const AliMUONVStore &confStore)
Implementation of AliMUONVCalibParam for tuples of floats.
virtual void SetValueAsFloat(Int_t i, Int_t j, Float_t value)=0
Set one value, for channel i, dimension j. Consider value is a float.
Int_t GetDEfromBus(Int_t busPatchId) const
static Int_t DecodeConfig(const char *data, AliMUONVStore &confStore)
virtual void SetValueAsInt(Int_t i, Int_t j, Int_t value)=0
Set one value, for channel i, dimension j. Consider value is an integer.
AliMpDetElement * GetDetElement(Int_t detElemId, Bool_t warn=true) const
The class defines the electronics properties of detection element.
Converts ASCII calibration files (ped, config, occupancy) into AliMUONVStore object.
Container of calibration values for a given number of channels.
#define AliErrorClass(message)
Definition: AliLog.h:596
static AliMpDDLStore * Instance(Bool_t warn=true)
static Int_t ManuNofChannels()
Max number of channels per manu.
#define AliDebugClass(logLevel, message)
Definition: AliLog.h:313
Int_t GetBusPatchId(Int_t detElemId, Int_t manuId) const
static Int_t ReadPedestals(const char *filename, AliMUONVStore &pedStore)
Implementation of AliMUONVCalibParam for tuples of double.
Int_t NofChannelsInManu(Int_t manuId) const
virtual Bool_t Add(TObject *object)=0
Add an object to the store.
static Int_t DecodePedestals(const char *data, AliMUONVStore &pedStore)
static Int_t DecodeOccupancy(const char *data, AliMUONVStore &occupancyMap)
static Int_t ReadConfig(const char *filename, AliMUONVStore &confStore)
Base class for MUON data stores.
Definition: AliMUONVStore.h:22
static Bool_t IsValidDetElemId(Int_t detElemId, Bool_t warn=false)
virtual TObject * FindObject(const char *name) const
Find an object by name.
file is "empty", i.e. contains to information but that&#39;s normal
virtual void SetValueAsDouble(Int_t i, Int_t j, Double_t value)
file is not of the expected format