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