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