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