]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPedestalSubprocessor.cxx
AliTPCRecoParam.h AliTPCRecoParam.cxx AliTPCtrack.cxx
[u/mrichter/AliRoot.git] / MUON / AliMUONPedestalSubprocessor.cxx
CommitLineData
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
8d8e920c 18#include "AliMUONPedestalSubprocessor.h"
ea199e33 19
20#include "AliCDBMetaData.h"
21#include "AliLog.h"
22#include "AliMUON2DMap.h"
8d8e920c 23#include "AliMUON2DStoreValidator.h"
a8f77ca0 24#include "AliMUONCalibParamNF.h"
ea199e33 25#include "AliMUONPreprocessor.h"
81028269 26#include "AliMUONTrackerIO.h"
8d8e920c 27#include "AliMpConstants.h"
7ca4655f 28#include "AliMpDDLStore.h"
a8f77ca0 29#include "TObjString.h"
8d8e920c 30#include <Riostream.h>
31#include <TList.h>
32#include <TObjString.h>
33#include <TSystem.h>
34#include <sstream>
ea199e33 35
3d1463c8 36//-----------------------------------------------------------------------------
ea199e33 37/// \class AliMUONPedestalSubprocessor
38///
39/// Implementation of AliMUONVSubprocessor class to deal with MUON TRK pedestals.
40///
41/// Pedestals are read in from an ascii file, with the format : \n
42///---------------------------------------------------------------------------\n
43/// BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA \n
44///---------------------------------------------------------------------------\n
45///
46/// \author L. Aphecetche
3d1463c8 47//-----------------------------------------------------------------------------
ea199e33 48
49/// \cond CLASSIMP
50ClassImp(AliMUONPedestalSubprocessor)
51/// \endcond
52
53//_____________________________________________________________________________
54AliMUONPedestalSubprocessor::AliMUONPedestalSubprocessor(AliMUONPreprocessor* master)
55: AliMUONVSubprocessor(master,
56 "Pedestals",
57 "Upload MUON Tracker pedestals to OCDB"),
6c870207 58fPedestals(0x0),
59fConfig(0x0),
60fConfigChanged(kFALSE)
ea199e33 61{
71a2d3aa 62 /// default ctor
ea199e33 63}
64
65//_____________________________________________________________________________
66AliMUONPedestalSubprocessor::~AliMUONPedestalSubprocessor()
67{
71a2d3aa 68 /// dtor
ea199e33 69 delete fPedestals;
6c870207 70 delete fConfig;
ea199e33 71}
72
73//_____________________________________________________________________________
6c870207 74Bool_t
ea199e33 75AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
76{
77 /// When starting a new run, reads in the pedestals ASCII files.
78
79 const Int_t kSystem = AliMUONPreprocessor::kDAQ;
80 const char* kId = "PEDESTALS";
81
82 delete fPedestals;
83 fPedestals = new AliMUON2DMap(kTRUE);
84
6c870207 85 delete fConfig;
86 fConfig = new AliMUON2DMap(kTRUE);
87
d2db856e 88 Master()->Log(Form("Reading pedestal files for Run %d startTime %ld endTime %ld",
89 run,startTime,endTime));
ea199e33 90
91 TList* sources = Master()->GetFileSources(kSystem,kId);
92 TIter next(sources);
93 TObjString* o(0x0);
703d8257 94 Int_t n(0);
6c870207 95 Int_t npedFiles(0);
703d8257 96
ea199e33 97 while ( ( o = static_cast<TObjString*>(next()) ) )
98 {
99 TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
6c870207 100 Int_t ok = ReadPedestalFile(fileName.Data());
81028269 101 if (ok>0)
703d8257 102 {
103 n += ok;
6c870207 104 ++npedFiles;
703d8257 105 }
106 }
6c870207 107
108 delete sources;
703d8257 109
110 if (!n)
111 {
112 Master()->Log("Failed to read any pedestals");
113 delete fPedestals;
114 fPedestals = 0;
6c870207 115 delete fConfig;
116 fConfig = 0;
117 return kFALSE;
118 }
119
120 const char* kIdConf = "CONFIG";
121
122 sources = Master()->GetFileSources(kSystem,kIdConf);
123 TIter nextConf(sources);
124 Int_t nconf(0);
125 Int_t nconfFiles(0);
126
127 fConfigChanged = kFALSE;
128
129 while ( ( o = static_cast<TObjString*>(nextConf()) ) )
130 {
131 TString fileName(Master()->GetFile(kSystem,kIdConf,o->GetName()));
132 Int_t ok = ReadConfigFile(fileName.Data());
133 if (ok>0)
134 {
135 nconf += ok;
136 ++nconfFiles;
137 }
ea199e33 138 }
6c870207 139
ea199e33 140 delete sources;
6c870207 141
142 if ( npedFiles != nconfFiles )
143 {
144 Master()->Log(Form("ERROR : Number of config files (%d) different from number of pedestal files (%d)",nconfFiles,npedFiles));
145 delete fPedestals;
146 fPedestals = 0;
147 delete fConfig;
148 fConfig = 0;
149 return kFALSE;
150 }
151
152 return kTRUE;
ea199e33 153}
154
155//_____________________________________________________________________________
156UInt_t
157AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/)
158{
71a2d3aa 159 /// Store the pedestals into the CDB
ea199e33 160
6c870207 161 if (!fPedestals || !fConfig)
a8f77ca0 162 {
6c870207 163 // this is the only reason to fail for the moment : getting no pedestal or no config
a8f77ca0 164 // at all.
d489129d 165 return 1;
a8f77ca0 166 }
703d8257 167
a8f77ca0 168 AliMUON2DStoreValidator validator;
169
170 Master()->Log("Validating");
171
6c870207 172 TObjArray* chambers = validator.Validate(*fPedestals,fConfig);
a8f77ca0 173
174 if (chambers)
175 {
176 // we hereby report what's missing, but this is not a reason to fail ;-)
177 // the only reason to fail would be if we got no pedestal at all
178 TList lines;
179 lines.SetOwner(kTRUE);
180
181 validator.Report(lines,*chambers);
182
183 TIter next(&lines);
184 TObjString* line;
185
186 while ( ( line = static_cast<TObjString*>(next()) ) )
187 {
188 Master()->Log(line->String().Data());
189 }
190 }
191
6c870207 192 Master()->Log("Storing pedestals...");
193 if ( fConfigChanged )
194 {
195 Master()->Log("...and configuration, as it has changed");
196 }
ea199e33 197
198 AliCDBMetaData metaData;
199 metaData.SetBeamPeriod(0);
200 metaData.SetResponsible("MUON TRK");
d3231306 201 TString comment("Computed by AliMUONPedestalSubprocessor $Id$");
202 comment.ReplaceAll("$","");
203 metaData.SetComment(comment.Data());
ea199e33 204
3b32651c 205 Bool_t validToInfinity = kTRUE;
d489129d 206 Bool_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, validToInfinity);
6c870207 207 if ( fConfigChanged )
208 {
209 result = result && Master()->Store("Calib", "Config", fConfig, &metaData, 0, validToInfinity);
210 }
d489129d 211 return ( result != kTRUE ); // return 0 if everything is ok.
ea199e33 212}
213
214//_____________________________________________________________________________
703d8257 215Int_t
6c870207 216AliMUONPedestalSubprocessor::ReadPedestalFile(const char* filename)
ea199e33 217{
71a2d3aa 218 /// Read the pedestals from an ASCII file. \n
219 /// Format of that file is one line per channel : \n
220 ///-------------------------------------------------------------------------\n
221 /// BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA \n
222 ///-------------------------------------------------------------------------\n
223 /// \n
224 /// Return kFALSE if reading was not successfull. \n
225 ///
ea199e33 226
d2db856e 227 TString sFilename(gSystem->ExpandPathName(filename));
ea199e33 228
d2db856e 229 Master()->Log(Form("Reading %s",sFilename.Data()));
ea199e33 230
81028269 231 Int_t n = AliMUONTrackerIO::ReadPedestals(sFilename.Data(),*fPedestals);
ea199e33 232
81028269 233 switch (n)
ea199e33 234 {
81028269 235 case -1:
236 Master()->Log(Form("Could not open %s",sFilename.Data()));
237 break;
ea199e33 238 }
2a7274d9 239
703d8257 240 return n;
ea199e33 241}
242
6c870207 243//_____________________________________________________________________________
244Int_t
245AliMUONPedestalSubprocessor::ReadConfigFile(const char* filename)
246{
247 /// Read the configuration from an ASCII file.
248 /// Format of that file is one line per manu :
249 /// BUS_PATCH MANU_ADDR
250 /// And the first line contains "unchanged" if the configuration is the same
251 /// as before.
252 /// Return kFALSE if reading was not successfull.
253 ///
254
255 TString sFilename(gSystem->ExpandPathName(filename));
256
257 Master()->Log(Form("Reading %s",sFilename.Data()));
258
259 Int_t n = AliMUONTrackerIO::ReadConfig(sFilename.Data(),*fConfig,fConfigChanged);
260
261 switch (n)
262 {
263 case -1:
264 Master()->Log(Form("Could not open %s",sFilename.Data()));
265 break;
266 }
267
268 return n;
269}
270
ea199e33 271
272//_____________________________________________________________________________
273void
274AliMUONPedestalSubprocessor::Print(Option_t* opt) const
275{
276 /// ouput to screen
8d8e920c 277 if (fPedestals) fPedestals->Print("",opt);
6c870207 278 if (fConfig) fConfig->Print("",opt);
ea199e33 279}
6c870207 280