]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPedestalSubprocessor.cxx
correction of trivial typo preventing compilation
[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 {
60   /// default ctor
61 }
62
63 //_____________________________________________________________________________
64 AliMUONPedestalSubprocessor::~AliMUONPedestalSubprocessor()
65 {
66   /// dtor
67   delete fPedestals;
68 }
69
70 //_____________________________________________________________________________
71 void 
72 AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
73 {
74   /// When starting a new run, reads in the pedestals ASCII files.
75   
76   const Int_t kSystem = AliMUONPreprocessor::kDAQ;
77   const char* kId = "PEDESTALS";
78   
79   delete fPedestals;
80   fPedestals = new AliMUON2DMap(kTRUE);
81   
82   Master()->Log(Form("Reading pedestal 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>0)
95     {
96       n += ok;
97     }
98   }
99   
100   if (!n)
101   {
102     Master()->Log("Failed to read any pedestals");
103     delete fPedestals;
104     fPedestals = 0;
105   }
106   delete sources;
107 }
108
109 //_____________________________________________________________________________
110 UInt_t 
111 AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/)
112 {
113   /// Store the pedestals into the CDB
114   
115   if (!fPedestals) 
116   {
117     // this is the only reason to fail for the moment : getting no pedestal
118     // at all.
119     return 1;
120   }
121     
122   AliMUON2DStoreValidator validator;
123
124   Master()->Log("Validating");
125
126   TObjArray* chambers = validator.Validate(*fPedestals);
127   
128   if (chambers)
129   {
130     // we hereby report what's missing, but this is not a reason to fail ;-)
131     // the only reason to fail would be if we got no pedestal at all
132     TList lines;
133     lines.SetOwner(kTRUE);
134   
135     validator.Report(lines,*chambers);
136   
137     TIter next(&lines);
138     TObjString* line;
139   
140     while ( ( line = static_cast<TObjString*>(next()) ) )
141     {
142       Master()->Log(line->String().Data());
143     }
144   }
145   
146   Master()->Log("Storing pedestals");
147   
148   AliCDBMetaData metaData;
149         metaData.SetBeamPeriod(0);
150         metaData.SetResponsible("MUON TRK");
151         metaData.SetComment("Computed by AliMUONPedestalSubprocessor $Id$");
152   
153   Bool_t validToInfinity = kTRUE;
154         Bool_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, validToInfinity);
155   
156   return ( result != kTRUE ); // return 0 if everything is ok.  
157 }
158
159 //_____________________________________________________________________________
160 Int_t
161 AliMUONPedestalSubprocessor::ReadFile(const char* filename)
162 {
163   /// Read the pedestals from an ASCII file.                                  \n
164   /// Format of that file is one line per channel :                           \n
165   ///-------------------------------------------------------------------------\n
166   /// BUS_PATCH MANU_ADDR CHANNEL      MEAN       SIGMA                       \n
167   ///-------------------------------------------------------------------------\n
168   ///                                                                         \n
169   /// Return kFALSE if reading was not successfull.                           \n
170   ///
171   
172   TString sFilename(gSystem->ExpandPathName(filename));
173   
174   Master()->Log(Form("Reading %s",sFilename.Data()));
175   
176   Int_t n = AliMUONTrackerIO::ReadPedestals(sFilename.Data(),*fPedestals);
177   
178   switch (n)
179   {
180     case -1:
181       Master()->Log(Form("Could not open %s",sFilename.Data()));
182       break;
183   }
184   
185   return n;
186 }
187
188
189 //_____________________________________________________________________________
190 void
191 AliMUONPedestalSubprocessor::Print(Option_t* opt) const
192 {
193   /// ouput to screen
194   if (fPedestals) fPedestals->Print("",opt);
195 }