]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPedestalSubprocessor.cxx
Build TGeo geometry also when running with Geant4
[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 <sstream>
19
20 #include <Riostream.h>
21 #include <TList.h>
22 #include <TObjString.h>
23 #include <TSystem.h>
24
25 #include "AliCDBMetaData.h"
26 #include "AliLog.h"
27 #include "AliMUON2DMap.h"
28 #include "AliMUON2DStoreValidator.h"
29 #include "AliMUONCalibParam2F.h"
30 #include "AliMUONConstants.h"
31 #include "AliMUONObjectPair.h"
32 #include "AliMUONPedestalSubprocessor.h"
33 #include "AliMUONPreprocessor.h"
34 #include "AliMUONVDataIterator.h"
35 #include "AliMpDDLStore.h"
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 {
61   // default ctor
62 }
63
64 //_____________________________________________________________________________
65 AliMUONPedestalSubprocessor::~AliMUONPedestalSubprocessor()
66 {
67   // dtor
68   delete fPedestals;
69 }
70
71 //_____________________________________________________________________________
72 void 
73 AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
74 {
75   /// When starting a new run, reads in the pedestals ASCII files.
76   
77   const Int_t kSystem = AliMUONPreprocessor::kDAQ;
78   const char* kId = "PEDESTALS";
79   
80   delete fPedestals;
81   fPedestals = new AliMUON2DMap(kTRUE);
82   
83   AliInfo(Form("Reading pedestal files for Run %d startTime %ld endTime %ld",
84                run,startTime,endTime));
85   
86   TList* sources = Master()->GetFileSources(kSystem,kId);
87   TIter next(sources);
88   TObjString* o(0x0);
89   while ( ( o = static_cast<TObjString*>(next()) ) )
90   {
91     TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
92     Bool_t ok = ReadFile(fileName.Data());
93     if (!ok)
94     {
95       AliError(Form("Could not read file %s",fileName.Data()));
96     }
97   }
98   delete sources;
99 }
100
101 //_____________________________________________________________________________
102 UInt_t 
103 AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/)
104 {
105   // Store the pedestals into the CDB
106   
107   if (!fPedestals) return 0;
108   
109   Master()->Log("Validating pedestals");
110   AliMUON2DStoreValidator validator;
111   TObjArray* missing =
112     validator.Validate(*fPedestals,AliMUONCalibParam2F::InvalidFloatValue());  
113   
114   if (missing)  
115   {
116     TList lines;
117     lines.SetOwner(kTRUE);
118     validator.Report(lines,*missing);
119     TIter next(&lines);
120     TObjString* l;
121     while ( ( l = static_cast<TObjString*>(next())) )
122     {
123       Master()->Log(l->GetName());
124     }
125     return 0;
126   }
127   
128   Master()->Log("Storing pedestals");
129   
130   AliCDBMetaData metaData;
131         metaData.SetBeamPeriod(0);
132         metaData.SetResponsible("MUON TRK");
133         metaData.SetComment("Computed by AliMUONPedestalSubprocessor $Id$");
134   
135   Bool_t validToInfinity = kTRUE;
136         UInt_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, validToInfinity);
137   
138   return result;  
139 }
140
141 //_____________________________________________________________________________
142 Bool_t
143 AliMUONPedestalSubprocessor::ReadFile(const char* filename)
144 {
145   // Read the pedestals from an ASCII file.
146   // Format of that file is one line per channel :
147   //---------------------------------------------------------------------------
148   // BUS_PATCH MANU_ADDR CHANNEL      MEAN       SIGMA
149   //---------------------------------------------------------------------------
150   //
151   // Return kFALSE if reading was not successfull.
152   //
153   
154   AliInfo(Form("Reading %s",filename));
155   
156   std::ifstream in(gSystem->ExpandPathName(filename));
157   if (!in.good()) return kFALSE;
158   
159   char line[80];
160   Int_t busPatchID, manuID, manuChannel;
161   Float_t pedMean, pedSigma;
162   static const Int_t kNchannels(64);
163   static Bool_t replace(kFALSE);
164   
165   while ( in.getline(line,80) )
166   {
167     if ( line[0] == '/' && line[1] == '/' ) continue;
168     std::istringstream sin(line);
169     sin >> busPatchID >> manuID >> manuChannel >> pedMean >> pedSigma;
170     Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
171     AliDebug(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d MEAN %7.2f SIGMA %7.2f",
172              busPatchID,detElemID,manuID,manuChannel,pedMean,pedSigma));
173     
174     AliMUONVCalibParam* ped = 
175       static_cast<AliMUONVCalibParam*>(fPedestals->Get(detElemID,manuID));
176     
177     if (!ped) 
178     {
179       ped = new AliMUONCalibParam2F(kNchannels,AliMUONCalibParam2F::InvalidFloatValue());  
180       fPedestals->Set(detElemID,manuID,ped,replace);
181     }
182     ped->SetValueAsFloat(manuChannel,0,pedMean);
183     ped->SetValueAsFloat(manuChannel,1,pedSigma);
184   }
185   in.close();
186   return kTRUE;
187 }
188
189
190 //_____________________________________________________________________________
191 void
192 AliMUONPedestalSubprocessor::Print(Option_t* opt) const
193 {
194   /// ouput to screen
195   AliMUONVDataIterator* it = fPedestals->Iterator();
196   AliMUONObjectPair* p;
197
198   while ( ( p = static_cast<AliMUONObjectPair*>(it->Next() ) ) )
199   {
200     AliMUONVCalibParam* value = static_cast<AliMUONVCalibParam*>(p->Value());
201     value->Print(opt);
202   }
203 }