]>
Commit | Line | Data |
---|---|---|
505bc496 | 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 "AliMUON2DMap.h" | |
19 | #include "AliMUONCalibParamNF.h" | |
20 | #include "AliMUONConstants.h" | |
21 | #include "AliMUONObjectPair.h" | |
22 | #include "AliMUONGainSubprocessor.h" | |
23 | #include "AliMUONPreprocessor.h" | |
24 | #include "AliMUONVDataIterator.h" | |
25 | #include "AliMpDDLStore.h" | |
26 | #include "AliMUON2DStoreValidator.h" | |
27 | ||
28 | #include "AliCDBMetaData.h" | |
29 | #include "AliLog.h" | |
30 | ||
31 | #include <TObjString.h> | |
32 | #include <Riostream.h> | |
33 | #include <TList.h> | |
34 | #include <TObjString.h> | |
35 | #include <TSystem.h> | |
36 | ||
37 | #include <sstream> | |
38 | ||
39 | /// | |
40 | /// \class AliMUONGainSubprocessor | |
41 | /// | |
42 | /// Implementation of AliMUONVSubprocessor class to deal with MUON TRK Gains. | |
43 | /// | |
44 | /// Gains are read in from an ascii file, with the format : \n | |
45 | ///---------------------------------------------------------------------------\n | |
46 | ///BUS_PATCH MANU CHANNEL Ped. a0 a1 a2 xlim P(chi2) P(chi2)_2 \n | |
47 | ///---------------------------------------------------------------------------\n | |
48 | /// | |
49 | /// \author L. Aphecetche | |
50 | /// | |
51 | ||
52 | /// \cond CLASSIMP | |
53 | ClassImp(AliMUONGainSubprocessor) | |
54 | /// \endcond | |
55 | ||
56 | //_____________________________________________________________________________ | |
57 | AliMUONGainSubprocessor::AliMUONGainSubprocessor(AliMUONPreprocessor* master) | |
58 | : AliMUONVSubprocessor(master, | |
59 | "Gains", | |
60 | "Upload MUON Tracker Gains to OCDB"), | |
61 | fGains(0x0) | |
62 | { | |
63 | /// default ctor | |
64 | } | |
65 | ||
66 | //_____________________________________________________________________________ | |
67 | AliMUONGainSubprocessor::~AliMUONGainSubprocessor() | |
68 | { | |
69 | /// dtor | |
70 | delete fGains; | |
71 | } | |
72 | ||
73 | //_____________________________________________________________________________ | |
74 | void | |
75 | AliMUONGainSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime) | |
76 | { | |
77 | /// When starting a new run, reads in the Gains ASCII files. | |
78 | ||
79 | const Int_t kSystem = AliMUONPreprocessor::kDAQ; | |
80 | const char* kId = "GAINS"; | |
81 | ||
82 | delete fGains; | |
83 | fGains = new AliMUON2DMap(kTRUE); | |
84 | ||
85 | Master()->Log(Form("Reading Gain files for Run %d startTime %ld endTime %ld", | |
86 | run,startTime,endTime)); | |
87 | ||
88 | TList* sources = Master()->GetFileSources(kSystem,kId); | |
89 | TIter next(sources); | |
90 | TObjString* o(0x0); | |
91 | Int_t n(0); | |
92 | ||
93 | while ( ( o = static_cast<TObjString*>(next()) ) ) | |
94 | { | |
95 | TString fileName(Master()->GetFile(kSystem,kId,o->GetName())); | |
96 | Int_t ok = ReadFile(fileName.Data()); | |
97 | if (!ok) | |
98 | { | |
99 | Master()->Log(Form("Could not read file %s",fileName.Data())); | |
100 | } | |
101 | else | |
102 | { | |
103 | n += ok; | |
104 | } | |
105 | } | |
106 | ||
107 | if (!n) | |
108 | { | |
109 | Master()->Log("Failed to read any Gains"); | |
110 | delete fGains; | |
111 | fGains = 0; | |
112 | } | |
113 | delete sources; | |
114 | } | |
115 | ||
116 | //_____________________________________________________________________________ | |
117 | UInt_t | |
118 | AliMUONGainSubprocessor::Process(TMap* /*dcsAliasMap*/) | |
119 | { | |
120 | /// Store the Gains into the CDB | |
121 | ||
122 | if (!fGains) | |
123 | { | |
124 | // this is the only reason to fail for the moment : getting no Gain | |
125 | // at all. | |
126 | return 0; | |
127 | } | |
128 | ||
129 | AliMUON2DStoreValidator validator; | |
130 | ||
131 | Master()->Log("Validating"); | |
132 | ||
133 | TObjArray* chambers = validator.Validate(*fGains); | |
134 | ||
135 | if (chambers) | |
136 | { | |
137 | // we hereby report what's missing, but this is not a reason to fail ;-) | |
138 | // the only reason to fail would be if we got no Gain at all | |
139 | TList lines; | |
140 | lines.SetOwner(kTRUE); | |
141 | ||
142 | validator.Report(lines,*chambers); | |
143 | ||
144 | TIter next(&lines); | |
145 | TObjString* line; | |
146 | ||
147 | while ( ( line = static_cast<TObjString*>(next()) ) ) | |
148 | { | |
149 | Master()->Log(line->String().Data()); | |
150 | } | |
151 | } | |
152 | ||
153 | Master()->Log("Storing Gains"); | |
154 | ||
155 | AliCDBMetaData metaData; | |
156 | metaData.SetBeamPeriod(0); | |
157 | metaData.SetResponsible("MUON TRK"); | |
158 | metaData.SetComment("Computed by AliMUONGainSubprocessor $Id$"); | |
159 | ||
160 | Bool_t validToInfinity = kTRUE; | |
161 | UInt_t result = Master()->Store("Calib", "Gains", fGains, &metaData, 0, validToInfinity); | |
162 | ||
163 | return result; | |
164 | } | |
165 | ||
166 | //_____________________________________________________________________________ | |
167 | Int_t | |
168 | AliMUONGainSubprocessor::ReadFile(const char* filename) | |
169 | { | |
170 | /// Read the Gains from an ASCII file. \n | |
171 | /// Format of that file is one line per channel : \n | |
172 | ///-------------------------------------------------------------------------\n | |
173 | ///BUS_PATCH MANU CHANNEL Ped. a0 a1 a2 xlim P(chi2) P(chi2)_2 \n | |
174 | ///-------------------------------------------------------------------------\n | |
175 | /// \n | |
176 | /// Return kFALSE if reading was not successfull. \n | |
177 | /// | |
178 | ||
179 | TString sFilename(gSystem->ExpandPathName(filename)); | |
180 | ||
181 | Master()->Log(Form("Reading %s",sFilename.Data())); | |
182 | ||
183 | std::ifstream in(sFilename.Data()); | |
184 | if (!in.good()) | |
185 | { | |
186 | return 0; | |
187 | } | |
188 | char line[256]; | |
189 | Int_t busPatchID, manuID, manuChannel; | |
190 | Float_t ped; | |
191 | Float_t a0, a1, a2; | |
192 | Float_t xlim; | |
193 | Float_t chi2, chi22; | |
194 | ||
195 | static const Int_t kNchannels(64); | |
196 | static Bool_t replace(kFALSE); | |
197 | Int_t n(0); | |
198 | ||
199 | while ( in.getline(line,256) ) | |
200 | { | |
201 | if ( strlen(line) < 10 ) continue; | |
202 | if ( line[0] == '/' && line[1] == '/' ) continue; | |
203 | std::istringstream sin(line); | |
204 | AliDebug(3,Form("line=%s",line)); | |
205 | sin >> busPatchID >> manuID >> manuChannel >> ped >> a0 >> a1 >> a2 >> xlim >> chi2 >> chi22; | |
206 | Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID); | |
207 | AliDebug(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d PED %7.2f A0 %7.2f A1 %7.2f A2 %7.2f" | |
208 | " XLIM %7.2f CHI2 %7.2f CHI22 %7.2f", | |
209 | busPatchID,detElemID,manuID,manuChannel,ped,a0,a1,a2,xlim,chi2,chi22)); | |
210 | if ( a0==a1 && a1==a2 && a0==-2) continue; | |
211 | ||
212 | AliMUONVCalibParam* gain = | |
213 | static_cast<AliMUONVCalibParam*>(fGains->Get(detElemID,manuID)); | |
214 | ||
215 | if (!gain) | |
216 | { | |
217 | gain = new AliMUONCalibParamNF(6,kNchannels,0);//AliMUONVCalibParam::InvalidFloatValue()); | |
218 | fGains->Set(detElemID,manuID,gain,replace); | |
219 | } | |
220 | gain->SetValueAsFloat(manuChannel,0,a0); | |
221 | gain->SetValueAsFloat(manuChannel,1,a1); | |
222 | gain->SetValueAsFloat(manuChannel,2,a2); | |
223 | gain->SetValueAsFloat(manuChannel,3,xlim); | |
224 | gain->SetValueAsFloat(manuChannel,4,chi2); | |
225 | gain->SetValueAsFloat(manuChannel,5,chi22); | |
226 | ++n; | |
227 | } | |
228 | in.close(); | |
229 | return n; | |
230 | } | |
231 | ||
232 | ||
233 | //_____________________________________________________________________________ | |
234 | void | |
235 | AliMUONGainSubprocessor::Print(Option_t* opt) const | |
236 | { | |
237 | /// ouput to screen | |
238 | AliMUONVDataIterator* it = fGains->Iterator(); | |
239 | AliMUONObjectPair* p; | |
240 | ||
241 | while ( ( p = static_cast<AliMUONObjectPair*>(it->Next() ) ) ) | |
242 | { | |
243 | AliMUONVCalibParam* value = static_cast<AliMUONVCalibParam*>(p->Value()); | |
244 | value->Print(opt); | |
245 | } | |
246 | } |