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