]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPedestalSubprocessor.cxx
Add/remove classes according to changes in MUON.
[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 "AliMUONCalibParam2F.h"
25 #include "Riostream.h"
26 #include "TObjString.h"
27 #include "TSystem.h"
28 #include <sstream>
29 #include "AliMUONVDataIterator.h"
30 #include "AliMUONConstants.h"
31 #include "AliMUONObjectPair.h"
32 #include "AliMpBusPatch.h"
33 #include "AliMUONPreprocessor.h"
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   AliInfo(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   while ( ( o = static_cast<TObjString*>(next()) ) )
88   {
89     TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
90     Bool_t ok = ReadFile(fileName.Data());
91     if (!ok)
92     {
93       AliError(Form("Could not read file %s",fileName.Data()));
94     }
95   }
96   delete sources;
97 }
98
99 //_____________________________________________________________________________
100 UInt_t 
101 AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/)
102 {
103   // Store the pedestals into the CDB
104   
105   if (!fPedestals) return 0;
106   
107   AliInfo("Validating pedestals");
108   AliMUON2DStoreValidator validator;
109   TObjArray* missing =
110     validator.Validate(*fPedestals,AliMUONCalibParam2F::InvalidFloatValue());  
111   
112   if (missing)  
113   {
114     validator.Report(*missing);
115 //    AliError("Will not write into CDB as some pieces are missing...");
116 //    return 0;
117   }
118   
119   AliInfo("Storing pedestals");
120   
121   AliCDBMetaData metaData;
122         metaData.SetBeamPeriod(0);
123         metaData.SetResponsible("MUON TRK");
124         metaData.SetComment("Computed by AliMUONPedestalSubprocessor $Id$");
125   
126         UInt_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, 0);
127   
128   return result;  
129 }
130
131 //_____________________________________________________________________________
132 Bool_t
133 AliMUONPedestalSubprocessor::ReadFile(const char* filename)
134 {
135   // Read the pedestals from an ASCII file.
136   // Format of that file is one line per channel :
137   //---------------------------------------------------------------------------
138   // BUS_PATCH MANU_ADDR CHANNEL      MEAN       SIGMA
139   //---------------------------------------------------------------------------
140   //
141   // Return kFALSE if reading was not successfull.
142   //
143   
144   AliInfo(Form("Reading %s",filename));
145   
146   std::ifstream in(gSystem->ExpandPathName(filename));
147   if (!in.good()) return kFALSE;
148   
149   char line[80];
150   Int_t busPatchID, manuID, manuChannel;
151   Float_t pedMean, pedSigma;
152   AliMpBusPatch busPatch;
153   busPatch.ReadBusPatchFile();
154   static const Int_t kNchannels(64);
155   static Bool_t replace(kFALSE);
156   
157   while ( in.getline(line,80) )
158   {
159     if ( line[0] == '/' && line[1] == '/' ) continue;
160     std::istringstream sin(line);
161     sin >> busPatchID >> manuID >> manuChannel >> pedMean >> pedSigma;
162     Int_t detElemID = busPatch.GetDEfromBus(busPatchID);
163     AliDebug(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d MEAN %7.2f SIGMA %7.2f",
164              busPatchID,detElemID,manuID,manuChannel,pedMean,pedSigma));
165     
166     AliMUONVCalibParam* ped = 
167       static_cast<AliMUONVCalibParam*>(fPedestals->Get(detElemID,manuID));
168     
169     if (!ped) 
170     {
171       ped = new AliMUONCalibParam2F(kNchannels,AliMUONCalibParam2F::InvalidFloatValue());  
172       fPedestals->Set(detElemID,manuID,ped,replace);
173     }
174     ped->SetValueAsFloat(manuChannel,0,pedMean);
175     ped->SetValueAsFloat(manuChannel,1,pedSigma);
176   }
177   in.close();
178   return kTRUE;
179 }
180
181
182 //_____________________________________________________________________________
183 void
184 AliMUONPedestalSubprocessor::Print(Option_t* opt) const
185 {
186   /// ouput to screen
187   AliMUONVDataIterator* it = fPedestals->Iterator();
188   AliMUONObjectPair* p;
189
190   while ( ( p = static_cast<AliMUONObjectPair*>(it->Next() ) ) )
191   {
192     AliMUONVCalibParam* value = static_cast<AliMUONVCalibParam*>(p->Value());
193     value->Print(opt);
194   }
195 }