]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPedestalSubprocessor.cxx
Make usage of mask=0 possible
[u/mrichter/AliRoot.git] / MUON / AliMUONPedestalSubprocessor.cxx
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 "AliMUONPedestalSubprocessor.h"
19
20 #include "AliCDBMetaData.h"
21 #include "AliLog.h"
22 #include "AliMUON2DMap.h"
23 #include "AliMUON2DStoreValidator.h"
24 #include "AliMUONCalibParamNF.h"
25 #include "AliMUONPreprocessor.h"
26 #include "AliMUONTrackerIO.h"
27 #include "AliMpConstants.h"
28 #include "AliMpDDLStore.h"
29 #include "TObjString.h"
30 #include <Riostream.h>
31 #include <TList.h>
32 #include <TObjString.h>
33 #include <TSystem.h>
34 #include <sstream>
35
36 //-----------------------------------------------------------------------------
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
47 //-----------------------------------------------------------------------------
48
49 /// \cond CLASSIMP
50 ClassImp(AliMUONPedestalSubprocessor)
51 /// \endcond
52
53 //_____________________________________________________________________________
54 AliMUONPedestalSubprocessor::AliMUONPedestalSubprocessor(AliMUONPreprocessor* master)
55 : AliMUONVSubprocessor(master,
56                        "Pedestals",
57                        "Upload MUON Tracker pedestals to OCDB"),
58 fPedestals(0x0),
59 fConfig(0x0),
60 fConfigChanged(kFALSE)
61 {
62   /// default ctor
63 }
64
65 //_____________________________________________________________________________
66 AliMUONPedestalSubprocessor::~AliMUONPedestalSubprocessor()
67 {
68   /// dtor
69   delete fPedestals;
70   delete fConfig;
71 }
72
73 //_____________________________________________________________________________
74 Bool_t 
75 AliMUONPedestalSubprocessor::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   
85   delete fConfig;
86   fConfig = new AliMUON2DMap(kTRUE);
87   
88   Master()->Log(Form("Reading pedestal files for Run %d startTime %ld endTime %ld",
89                      run,startTime,endTime));
90   
91   TList* sources = Master()->GetFileSources(kSystem,kId);
92   TIter next(sources);
93   TObjString* o(0x0);
94   Int_t n(0);
95   Int_t npedFiles(0);
96   
97   while ( ( o = static_cast<TObjString*>(next()) ) )
98   {
99     TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
100     Int_t ok = ReadPedestalFile(fileName.Data());
101     if (ok>0)
102     {
103       n += ok;
104       ++npedFiles;
105     }
106   }
107
108   delete sources;
109   
110   if (!n)
111   {
112     Master()->Log("Failed to read any pedestals");
113     delete fPedestals;
114     fPedestals = 0;
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     }
138   }
139   
140   delete sources;
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;
153 }
154
155 //_____________________________________________________________________________
156 UInt_t 
157 AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/)
158 {
159   /// Store the pedestals into the CDB
160   
161   if (!fPedestals || !fConfig) 
162   {
163     // this is the only reason to fail for the moment : getting no pedestal or no config
164     // at all.
165     return 1;
166   }
167     
168   AliMUON2DStoreValidator validator;
169
170   Master()->Log("Validating");
171
172   TObjArray* chambers = validator.Validate(*fPedestals,fConfig);
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   
192   Master()->Log("Storing pedestals...");
193   if ( fConfigChanged ) 
194   {
195     Master()->Log("...and configuration, as it has changed");
196   }
197   
198   AliCDBMetaData metaData;
199         metaData.SetBeamPeriod(0);
200         metaData.SetResponsible("MUON TRK");
201   TString comment("Computed by AliMUONPedestalSubprocessor $Id$");
202   comment.ReplaceAll("$","");
203         metaData.SetComment(comment.Data());
204   
205   Bool_t validToInfinity = kTRUE;
206         Bool_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, validToInfinity);
207   if ( fConfigChanged ) 
208   {
209     result = result && Master()->Store("Calib", "Config", fConfig, &metaData, 0, validToInfinity);
210   }
211   return ( result != kTRUE ); // return 0 if everything is ok.  
212 }
213
214 //_____________________________________________________________________________
215 Int_t
216 AliMUONPedestalSubprocessor::ReadPedestalFile(const char* filename)
217 {
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   ///
226   
227   TString sFilename(gSystem->ExpandPathName(filename));
228   
229   Master()->Log(Form("Reading %s",sFilename.Data()));
230   
231   Int_t n = AliMUONTrackerIO::ReadPedestals(sFilename.Data(),*fPedestals);
232   
233   switch (n)
234   {
235     case -1:
236       Master()->Log(Form("Could not open %s",sFilename.Data()));
237       break;
238   }
239   
240   return n;
241 }
242
243 //_____________________________________________________________________________
244 Int_t
245 AliMUONPedestalSubprocessor::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
271
272 //_____________________________________________________________________________
273 void
274 AliMUONPedestalSubprocessor::Print(Option_t* opt) const
275 {
276   /// ouput to screen
277   if (fPedestals) fPedestals->Print("",opt);
278   if (fConfig) fConfig->Print("",opt);
279 }
280