Line data Source code
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 :
22 : /// \class AliMUONTrackerIO
23 : ///
24 : /// Reader class for ASCII calibration files for MUON tracker :
25 : /// converts those ASCII files into AliMUONVStore (suitable to e.g. feed
26 : /// the OCDB).
27 : ///
28 : /// \author Laurent Aphecetche, Subatech
29 :
30 : using std::ostringstream;
31 : using std::istringstream;
32 : using std::cout;
33 : using std::endl;
34 : /// \cond CLASSIMP
35 18 : ClassImp(AliMUONTrackerIO)
36 : /// \endcond
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 : //_____________________________________________________________________________
54 0 : AliMUONTrackerIO::AliMUONTrackerIO()
55 0 : {
56 : /// ctor
57 0 : }
58 :
59 : //_____________________________________________________________________________
60 : AliMUONTrackerIO::~AliMUONTrackerIO()
61 0 : {
62 : /// dtor
63 0 : }
64 :
65 : //_____________________________________________________________________________
66 : Int_t
67 : AliMUONTrackerIO::ReadOccupancy(const char* filename,AliMUONVStore& occupancyMap)
68 : {
69 : /// Read occupancy file created by online DA
70 : /// and append values to the occupancyMap store.
71 : /// Expected format of the file is :
72 : /// busPatchId manuId sumofn nevt
73 :
74 0 : TString sFilename(gSystem->ExpandPathName(filename));
75 :
76 0 : std::ifstream in(sFilename.Data());
77 0 : if (!in.good())
78 : {
79 0 : return kCannotOpenFile;
80 : }
81 :
82 0 : TString datastring;
83 0 : ostringstream stream;
84 0 : char line[1024];
85 0 : while ( in.getline(line,1024) )
86 0 : stream << line << "\n";
87 :
88 0 : in.close();
89 :
90 0 : return DecodeOccupancy(stream.str().c_str(),occupancyMap);
91 :
92 0 : }
93 :
94 : //_____________________________________________________________________________
95 : Int_t
96 : AliMUONTrackerIO::DecodeOccupancy(const char* data, AliMUONVStore& occupancyMap)
97 : {
98 : /// Decode occupancy string created append values to the occupancyMap store.
99 : /// Expected format of the file is :
100 : /// busPatchId manuId sumofn nevt
101 :
102 0 : if ( ! AliMpDDLStore::Instance(kFALSE) )
103 : {
104 0 : AliErrorClass("Mapping not loaded. Cannot work");
105 0 : return kNoMapping;
106 : }
107 :
108 0 : char line[1024];
109 0 : istringstream in(data);
110 :
111 : Int_t n(0);
112 :
113 0 : while ( in.getline(line,1024) )
114 : {
115 0 : AliDebugClass(3,Form("line=%s",line));
116 0 : if ( line[0] == '/' && line[1] == '/' ) continue;
117 0 : std::istringstream sin(line);
118 :
119 0 : Int_t busPatchId, manuId;
120 0 : Int_t numberOfEvents;
121 0 : Double_t sumn;
122 :
123 0 : sin >> busPatchId >> manuId >> sumn >> numberOfEvents;
124 :
125 0 : if ( busPatchId == -1 && manuId == -1 && sumn == 0 && numberOfEvents == 0 )
126 : {
127 : /// DA could not produce information (because run failed somehow).
128 : /// That's OK, but let the world know about it
129 0 : return kNoInfoFile;
130 : }
131 :
132 0 : Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
133 :
134 0 : AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
135 :
136 : Int_t numberOfChannelsInManu = -1;
137 :
138 0 : if (de) numberOfChannelsInManu = de->NofChannelsInManu(manuId);
139 :
140 0 : if ( numberOfChannelsInManu <= 0 )
141 : {
142 0 : AliErrorClass(Form("BP %5d DE %5d MANU %5d nchannels=%d",busPatchId,detElemId,manuId,numberOfChannelsInManu));
143 0 : continue;
144 : }
145 :
146 : AliMUONVCalibParam* occupancy =
147 0 : static_cast<AliMUONVCalibParam*>(occupancyMap.FindObject(detElemId,manuId));
148 0 : if (occupancy)
149 : {
150 0 : AliErrorClass(Form("DE %5d MANU %5d is already there ?!",detElemId,manuId));
151 0 : continue;
152 : }
153 :
154 0 : occupancy = new AliMUONCalibParamND(5,1,detElemId,manuId,0);
155 :
156 0 : occupancyMap.Add(occupancy);
157 :
158 0 : occupancy->SetValueAsDouble(0,0,sumn);
159 0 : occupancy->SetValueAsDouble(0,1,sumn); // with only 0 and 1s, sumw = sumw2 = sumn
160 0 : occupancy->SetValueAsDouble(0,2,sumn);
161 0 : occupancy->SetValueAsInt(0,3,numberOfChannelsInManu);
162 0 : occupancy->SetValueAsInt(0,4,numberOfEvents);
163 0 : ++n;
164 0 : }
165 :
166 0 : return n;
167 0 : }
168 :
169 : //_____________________________________________________________________________
170 : Int_t
171 : AliMUONTrackerIO::ReadPedestals(const char* filename, AliMUONVStore& pedStore)
172 : {
173 : /// Read pedestal file (produced by the MUONTRKda.exe program for instance)
174 : /// and append the read values into the given VStore
175 : /// To be used when the input is a file (for instance when reading data
176 : /// from the OCDB).
177 :
178 0 : TString sFilename(gSystem->ExpandPathName(filename));
179 :
180 0 : std::ifstream in(sFilename.Data());
181 0 : if (!in.good())
182 : {
183 0 : return kCannotOpenFile;
184 : }
185 :
186 0 : ostringstream stream;
187 0 : char line[1024];
188 0 : while ( in.getline(line,1024) )
189 0 : stream << line << "\n";
190 :
191 0 : in.close();
192 :
193 0 : return DecodePedestals(stream.str().c_str(),pedStore);
194 :
195 0 : }
196 :
197 : //_____________________________________________________________________________
198 : Int_t
199 : AliMUONTrackerIO::DecodePedestals(const char* data, AliMUONVStore& pedStore)
200 : {
201 : /// Read pedestal Data (produced by the MUONTRKda.exe program for instance)
202 : /// and append the read values into the given VStore
203 : /// To be used when the input is a TString (for instance when getting data
204 : /// from AMORE DB).
205 :
206 0 : char line[1024];
207 0 : Int_t busPatchID, manuID, manuChannel;
208 0 : Float_t pedMean, pedSigma;
209 : Int_t n(0);
210 0 : istringstream in(data);
211 :
212 0 : while ( in.getline(line,1024) )
213 : {
214 0 : AliDebugClass(3,Form("line=%s",line));
215 0 : if ( line[0] == '/' && line[1] == '/' ) continue;
216 0 : std::istringstream sin(line);
217 0 : sin >> busPatchID >> manuID >> manuChannel >> pedMean >> pedSigma;
218 0 : Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
219 :
220 0 : if ( !AliMpDEManager::IsValidDetElemId(detElemID) )
221 : {
222 0 : AliErrorClass(Form("Got an invalid DE = %d from busPatchId=%d manuId=%d",
223 : detElemID,busPatchID,manuID));
224 0 : continue;
225 : }
226 :
227 0 : 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 0 : static_cast<AliMUONVCalibParam*>(pedStore.FindObject(detElemID,manuID));
232 0 : if (!ped)
233 : {
234 0 : ped = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),
235 0 : detElemID,manuID,
236 0 : AliMUONVCalibParam::InvalidFloatValue());
237 0 : pedStore.Add(ped);
238 : }
239 0 : ped->SetValueAsFloat(manuChannel,0,pedMean);
240 0 : ped->SetValueAsFloat(manuChannel,1,pedSigma);
241 0 : ++n;
242 0 : }
243 :
244 : return n;
245 0 : }
246 :
247 : //_____________________________________________________________________________
248 : Int_t
249 : AliMUONTrackerIO::ReadConfig(const char* filename, AliMUONVStore& confStore)
250 : {
251 : /// Read config file (produced by the MUONTRKda.exe program for instance)
252 : /// and append the read values into the given VStore
253 : /// To be used when the input is a file (for instance when reading data
254 : /// from the OCDB).
255 :
256 0 : TString sFilename(gSystem->ExpandPathName(filename));
257 :
258 0 : std::ifstream in(sFilename.Data());
259 0 : if (!in.good())
260 : {
261 0 : return kCannotOpenFile;
262 : }
263 :
264 0 : ostringstream stream;
265 0 : char line[1024];
266 0 : while ( in.getline(line,1024) )
267 0 : stream << line << "\n";
268 :
269 0 : in.close();
270 :
271 0 : return DecodeConfig(stream.str().c_str(),confStore);
272 0 : }
273 :
274 : //_____________________________________________________________________________
275 : Int_t
276 : AliMUONTrackerIO::DecodeConfig(const char* data, AliMUONVStore& confStore)
277 : {
278 : /// Read config data (produced by the MUONTRKda.exe program for instance)
279 : /// and append the read values into the given VStore
280 : /// To be used when the input is a TString (for instance when getting data
281 : /// from AMORE DB).
282 :
283 0 : char line[1024];
284 0 : Int_t busPatchID, manuID;
285 : Int_t n(0);
286 0 : istringstream in(data);
287 :
288 0 : while ( in.getline(line,1024) )
289 : {
290 0 : AliDebugClass(3,Form("line=%s",line));
291 0 : if ( line[0] == '#' )
292 : {
293 : continue;
294 : }
295 0 : std::istringstream sin(line);
296 0 : sin >> busPatchID >> manuID;
297 :
298 0 : Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
299 :
300 0 : if ( !AliMpDEManager::IsValidDetElemId(detElemID) )
301 : {
302 0 : AliErrorClass(Form("Got an invalid DE = %d from busPatchId=%d manuId=%d",
303 : detElemID,busPatchID,manuID));
304 0 : continue;
305 : }
306 :
307 : AliMUONVCalibParam* conf =
308 0 : static_cast<AliMUONVCalibParam*>(confStore.FindObject(detElemID,manuID));
309 0 : if (!conf)
310 : {
311 0 : conf = new AliMUONCalibParamNF(1,1,detElemID,manuID,1);
312 0 : confStore.Add(conf);
313 : }
314 0 : ++n;
315 0 : }
316 :
317 : return n;
318 0 : }
319 :
320 : //_____________________________________________________________________________
321 : Int_t
322 : AliMUONTrackerIO::WriteConfig(ofstream& out, const AliMUONVStore& confStore)
323 : {
324 : /// Write the conf store as an ASCII file
325 : /// Note that we are converting (back) the detElemId into a busPatchId
326 : /// Return the number of lines written
327 :
328 0 : if ( !AliMpDDLStore::Instance() )
329 : {
330 0 : cout << "ERROR: mapping not loaded. Cannot work" << endl;
331 0 : return 0;
332 : }
333 :
334 0 : TIter next(confStore.CreateIterator());
335 : AliMUONVCalibParam* param;
336 : Int_t n(0);
337 :
338 0 : while ( (param=static_cast<AliMUONVCalibParam*>(next())) )
339 : {
340 0 : Int_t detElemId = param->ID0();
341 0 : Int_t manuId = param->ID1();
342 :
343 0 : Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
344 0 : ++n;
345 :
346 0 : out << busPatchId << " " << manuId << endl;
347 : }
348 : return n;
349 0 : }
350 :
|