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