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