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"
23 #include "AliMUON2DMap.h"
24 #include "AliMUON2DStoreValidator.h"
25 #include "AliMUONCalibParamNF.h"
26 #include "AliMUONPreprocessor.h"
27 #include "AliMUONTrackerIO.h"
28 #include "AliMpConstants.h"
29 #include "AliMpDDLStore.h"
30 #include "TObjString.h"
31 #include <Riostream.h>
33 #include <TObjString.h>
37 //-----------------------------------------------------------------------------
38 /// \class AliMUONPedestalSubprocessor
40 /// Implementation of AliMUONVSubprocessor class to deal with MUON TRK pedestals.
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
47 /// \author L. Aphecetche
48 //-----------------------------------------------------------------------------
51 ClassImp(AliMUONPedestalSubprocessor)
54 //_____________________________________________________________________________
55 AliMUONPedestalSubprocessor::AliMUONPedestalSubprocessor(AliMUONPreprocessor* master)
56 : AliMUONVSubprocessor(master,
58 "Upload MUON Tracker pedestals to OCDB"),
61 fConfigChanged(kFALSE)
66 //_____________________________________________________________________________
67 AliMUONPedestalSubprocessor::~AliMUONPedestalSubprocessor()
74 //_____________________________________________________________________________
76 AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
78 /// When starting a new run, reads in the pedestals ASCII files.
80 const Int_t kSystem = AliMUONPreprocessor::kDAQ;
81 const char* kId = "PEDESTALS";
84 fPedestals = new AliMUON2DMap(kTRUE);
87 fConfig = new AliMUON2DMap(kTRUE);
89 Master()->Log(Form("Reading pedestal files for Run %d startTime %ld endTime %ld",
90 run,startTime,endTime));
92 TList* sources = Master()->GetFileSources(kSystem,kId);
98 while ( ( o = static_cast<TObjString*>(next()) ) )
100 TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
101 Int_t ok = ReadPedestalFile(fileName.Data());
113 Master()->Log("Failed to read any pedestals");
121 const char* kIdConf = "CONFIG";
123 sources = Master()->GetFileSources(kSystem,kIdConf);
124 TIter nextConf(sources);
128 fConfigChanged = kFALSE;
130 while ( ( o = static_cast<TObjString*>(nextConf()) ) )
132 TString fileName(Master()->GetFile(kSystem,kIdConf,o->GetName()));
133 Int_t ok = ReadConfigFile(fileName.Data());
143 if ( npedFiles != nconfFiles )
145 Master()->Log(Form("ERROR : Number of config files (%d) different from number of pedestal files (%d)",nconfFiles,npedFiles));
153 if ( nconfFiles > 0 && nconfFiles < AliDAQ::NumberOfLdcs("MUONTRK") )
155 // force a writing of the configuration for any incomplete configuration
156 fConfigChanged = kTRUE;
162 //_____________________________________________________________________________
164 AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/)
166 /// Store the pedestals into the CDB
168 if (!fPedestals || !fConfig)
170 // this is the only reason to fail for the moment : getting no pedestal or no config
175 AliMUON2DStoreValidator validator;
177 Master()->Log("Validating");
179 TObjArray* chambers = validator.Validate(*fPedestals,fConfig);
183 // we hereby report what's missing, but this is not a reason to fail ;-)
184 // the only reason to fail would be if we got no pedestal at all
186 lines.SetOwner(kTRUE);
188 validator.Report(lines,*chambers);
193 while ( ( line = static_cast<TObjString*>(next()) ) )
195 Master()->Log(line->String().Data());
199 Master()->Log("Storing pedestals...");
200 if ( fConfigChanged )
202 Master()->Log("...and configuration, as it has changed");
205 AliCDBMetaData metaData;
206 metaData.SetBeamPeriod(0);
207 metaData.SetResponsible("MUON TRK");
208 TString comment("Computed by AliMUONPedestalSubprocessor $Id$");
209 comment.ReplaceAll("$","");
210 metaData.SetComment(comment.Data());
212 Bool_t validToInfinity = kTRUE;
213 Bool_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, validToInfinity);
214 if ( fConfigChanged )
216 result = result && Master()->Store("Calib", "Config", fConfig, &metaData, 0, validToInfinity);
218 return ( result != kTRUE ); // return 0 if everything is ok.
221 //_____________________________________________________________________________
223 AliMUONPedestalSubprocessor::ReadPedestalFile(const char* filename)
225 /// Read the pedestals from an ASCII file. \n
226 /// Format of that file is one line per channel : \n
227 ///-------------------------------------------------------------------------\n
228 /// BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA \n
229 ///-------------------------------------------------------------------------\n
231 /// Return kFALSE if reading was not successfull. \n
234 TString sFilename(gSystem->ExpandPathName(filename));
236 Master()->Log(Form("Reading %s",sFilename.Data()));
238 Int_t n = AliMUONTrackerIO::ReadPedestals(sFilename.Data(),*fPedestals);
243 Master()->Log(Form("Could not open %s",sFilename.Data()));
250 //_____________________________________________________________________________
252 AliMUONPedestalSubprocessor::ReadConfigFile(const char* filename)
254 /// Read the configuration from an ASCII file.
255 /// Format of that file is one line per manu :
256 /// BUS_PATCH MANU_ADDR
257 /// And the first line contains "unchanged" if the configuration is the same
259 /// Return kFALSE if reading was not successfull.
262 TString sFilename(gSystem->ExpandPathName(filename));
264 Master()->Log(Form("Reading %s",sFilename.Data()));
266 Int_t n = AliMUONTrackerIO::ReadConfig(sFilename.Data(),*fConfig,fConfigChanged);
271 Master()->Log(Form("Could not open %s",sFilename.Data()));
279 //_____________________________________________________________________________
281 AliMUONPedestalSubprocessor::Print(Option_t* opt) const
284 if (fPedestals) fPedestals->Print("",opt);
285 if (fConfig) fConfig->Print("",opt);