1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONPedestalSubprocessor.h"
20 #include "AliCDBMetaData.h"
22 #include "AliMUON2DMap.h"
23 #include "AliMUON2DStoreValidator.h"
24 #include "AliMUONCalibParamNF.h"
25 #include "AliMUONPreprocessor.h"
26 #include "AliMUONTrackerIO.h"
27 #include "AliMpConstants.h"
28 #include "AliMpDDLStore.h"
29 #include "TObjString.h"
30 #include <Riostream.h>
32 #include <TObjString.h>
36 //-----------------------------------------------------------------------------
37 /// \class AliMUONPedestalSubprocessor
39 /// Implementation of AliMUONVSubprocessor class to deal with MUON TRK pedestals.
41 /// Pedestals are read in from an ascii file, with the format : \n
42 ///---------------------------------------------------------------------------\n
43 /// BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA \n
44 ///---------------------------------------------------------------------------\n
46 /// \author L. Aphecetche
47 //-----------------------------------------------------------------------------
50 ClassImp(AliMUONPedestalSubprocessor)
53 //_____________________________________________________________________________
54 AliMUONPedestalSubprocessor::AliMUONPedestalSubprocessor(AliMUONPreprocessor* master)
55 : AliMUONVSubprocessor(master,
57 "Upload MUON Tracker pedestals to OCDB"),
60 fConfigChanged(kFALSE)
65 //_____________________________________________________________________________
66 AliMUONPedestalSubprocessor::~AliMUONPedestalSubprocessor()
73 //_____________________________________________________________________________
75 AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
77 /// When starting a new run, reads in the pedestals ASCII files.
79 const Int_t kSystem = AliMUONPreprocessor::kDAQ;
80 const char* kId = "PEDESTALS";
83 fPedestals = new AliMUON2DMap(kTRUE);
86 fConfig = new AliMUON2DMap(kTRUE);
88 Master()->Log(Form("Reading pedestal files for Run %d startTime %ld endTime %ld",
89 run,startTime,endTime));
91 TList* sources = Master()->GetFileSources(kSystem,kId);
97 while ( ( o = static_cast<TObjString*>(next()) ) )
99 TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
100 Int_t ok = ReadPedestalFile(fileName.Data());
112 Master()->Log("Failed to read any pedestals");
120 const char* kIdConf = "CONFIG";
122 sources = Master()->GetFileSources(kSystem,kIdConf);
123 TIter nextConf(sources);
127 fConfigChanged = kFALSE;
129 while ( ( o = static_cast<TObjString*>(nextConf()) ) )
131 TString fileName(Master()->GetFile(kSystem,kIdConf,o->GetName()));
132 Int_t ok = ReadConfigFile(fileName.Data());
142 if ( npedFiles != nconfFiles )
144 Master()->Log(Form("ERROR : Number of config files (%d) different from number of pedestal files (%d)",nconfFiles,npedFiles));
155 //_____________________________________________________________________________
157 AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/)
159 /// Store the pedestals into the CDB
161 if (!fPedestals || !fConfig)
163 // this is the only reason to fail for the moment : getting no pedestal or no config
168 AliMUON2DStoreValidator validator;
170 Master()->Log("Validating");
172 TObjArray* chambers = validator.Validate(*fPedestals,fConfig);
176 // we hereby report what's missing, but this is not a reason to fail ;-)
177 // the only reason to fail would be if we got no pedestal at all
179 lines.SetOwner(kTRUE);
181 validator.Report(lines,*chambers);
186 while ( ( line = static_cast<TObjString*>(next()) ) )
188 Master()->Log(line->String().Data());
192 Master()->Log("Storing pedestals...");
193 if ( fConfigChanged )
195 Master()->Log("...and configuration, as it has changed");
198 AliCDBMetaData metaData;
199 metaData.SetBeamPeriod(0);
200 metaData.SetResponsible("MUON TRK");
201 TString comment("Computed by AliMUONPedestalSubprocessor $Id$");
202 comment.ReplaceAll("$","");
203 metaData.SetComment(comment.Data());
205 Bool_t validToInfinity = kTRUE;
206 Bool_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, validToInfinity);
207 if ( fConfigChanged )
209 result = result && Master()->Store("Calib", "Config", fConfig, &metaData, 0, validToInfinity);
211 return ( result != kTRUE ); // return 0 if everything is ok.
214 //_____________________________________________________________________________
216 AliMUONPedestalSubprocessor::ReadPedestalFile(const char* filename)
218 /// Read the pedestals from an ASCII file. \n
219 /// Format of that file is one line per channel : \n
220 ///-------------------------------------------------------------------------\n
221 /// BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA \n
222 ///-------------------------------------------------------------------------\n
224 /// Return kFALSE if reading was not successfull. \n
227 TString sFilename(gSystem->ExpandPathName(filename));
229 Master()->Log(Form("Reading %s",sFilename.Data()));
231 Int_t n = AliMUONTrackerIO::ReadPedestals(sFilename.Data(),*fPedestals);
236 Master()->Log(Form("Could not open %s",sFilename.Data()));
243 //_____________________________________________________________________________
245 AliMUONPedestalSubprocessor::ReadConfigFile(const char* filename)
247 /// Read the configuration from an ASCII file.
248 /// Format of that file is one line per manu :
249 /// BUS_PATCH MANU_ADDR
250 /// And the first line contains "unchanged" if the configuration is the same
252 /// Return kFALSE if reading was not successfull.
255 TString sFilename(gSystem->ExpandPathName(filename));
257 Master()->Log(Form("Reading %s",sFilename.Data()));
259 Int_t n = AliMUONTrackerIO::ReadConfig(sFilename.Data(),*fConfig,fConfigChanged);
264 Master()->Log(Form("Could not open %s",sFilename.Data()));
272 //_____________________________________________________________________________
274 AliMUONPedestalSubprocessor::Print(Option_t* opt) const
277 if (fPedestals) fPedestals->Print("",opt);
278 if (fConfig) fConfig->Print("",opt);