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"
21 #include "AliCDBEntry.h"
24 #include "AliMUON2DMap.h"
25 #include "AliMUON2DStoreValidator.h"
26 #include "AliMUONCalibParamNF.h"
27 #include "AliMUONPreprocessor.h"
28 #include "AliMUONTrackerIO.h"
29 #include "AliMpConstants.h"
30 #include "AliMpDDLStore.h"
31 #include "TObjString.h"
32 #include <Riostream.h>
34 #include <TObjString.h>
38 //-----------------------------------------------------------------------------
39 /// \class AliMUONPedestalSubprocessor
41 /// Implementation of AliMUONVSubprocessor class to deal with MUON TRK pedestals.
43 /// Pedestals are read in from an ascii file, with the format : \n
44 ///---------------------------------------------------------------------------\n
45 /// BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA \n
46 ///---------------------------------------------------------------------------\n
48 /// \author L. Aphecetche
49 //-----------------------------------------------------------------------------
52 ClassImp(AliMUONPedestalSubprocessor)
55 //_____________________________________________________________________________
56 AliMUONPedestalSubprocessor::AliMUONPedestalSubprocessor(AliMUONPreprocessor* master)
57 : AliMUONVSubprocessor(master,
59 "Upload MUON Tracker pedestals to OCDB"),
62 fConfigChanged(kFALSE)
67 //_____________________________________________________________________________
68 AliMUONPedestalSubprocessor::~AliMUONPedestalSubprocessor()
75 //_____________________________________________________________________________
77 AliMUONPedestalSubprocessor::HasConfigChanged(const AliMUONVStore& newConfig) const
79 /// Check whether the config changed.
80 /// Any error will return kTRUE to trig a config upload (safer way).
82 AliCDBEntry* entry = Master()->GetFromOCDB("Calib","Config");
85 AliError("Could not get MUON/Calib/Config entry for current run ! That's not OK !");
88 AliMUONVStore* oldConfig = dynamic_cast<AliMUONVStore*>(entry->GetObject());
91 AliError("Could not get MUON/Calib/Config object for current run (wrong type ?) ! That's not OK !");
95 if ( oldConfig->GetSize() != newConfig.GetSize() )
100 TIter next(oldConfig->CreateIterator());
101 AliMUONVCalibParam* old;
103 while ( ( old = static_cast<AliMUONVCalibParam*>(next()) ) )
105 Int_t detElemId = old->ID0();
106 Int_t manuId = old->ID1();
108 if ( ! newConfig.FindObject(detElemId,manuId) )
110 // not found in new. Configurations are different. Return right now.
115 // all tests OK. Configuration has not changed.
120 //_____________________________________________________________________________
122 AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
124 /// When starting a new run, reads in the pedestals ASCII files.
126 const Int_t kSystem = AliMUONPreprocessor::kDAQ;
127 const char* kId = "PEDESTALS";
130 fPedestals = new AliMUON2DMap(kTRUE);
133 fConfig = new AliMUON2DMap(kTRUE);
135 Master()->Log(Form("Reading pedestal files for Run %d startTime %ld endTime %ld",
136 run,startTime,endTime));
138 TList* sources = Master()->GetFileSources(kSystem,kId);
144 while ( ( o = static_cast<TObjString*>(next()) ) )
146 TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
147 Int_t ok = ReadPedestalFile(fileName.Data());
159 Master()->Log("Failed to read any pedestals");
166 // OK, we did not get our pedestals. Check if the ped run itself
167 // was bad, i.e. too few events
168 TString nevents(Master()->GetRunParameter("totalEvents"));
170 if ( nevents.Atoi() < 50 )
172 Master()->Log(Form("The run had only %d events, so the failure to read pedestals is normal",nevents.Atoi()));
173 // too few events, failure is normal, returns OK.
177 // no ped, but run looks clean, that's an error
181 const char* kIdConf = "CONFIG";
183 sources = Master()->GetFileSources(kSystem,kIdConf);
184 TIter nextConf(sources);
188 while ( ( o = static_cast<TObjString*>(nextConf()) ) )
190 TString fileName(Master()->GetFile(kSystem,kIdConf,o->GetName()));
191 Int_t ok = ReadConfigFile(fileName.Data());
201 if ( npedFiles != nconfFiles )
203 Master()->Log(Form("ERROR : Number of config files (%d) different from number of pedestal files (%d)",nconfFiles,npedFiles));
211 fConfigChanged = HasConfigChanged(*fConfig);
216 //_____________________________________________________________________________
218 AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/)
220 /// Store the pedestals into the CDB
222 if (!fPedestals || !fConfig)
224 // this is the only reason to fail for the moment : getting no pedestal or no config
229 AliMUON2DStoreValidator validator;
231 Master()->Log("Validating");
233 TObjArray* chambers = validator.Validate(*fPedestals,fConfig);
237 // we hereby report what's missing, but this is not a reason to fail ;-)
238 // the only reason to fail would be if we got no pedestal at all
240 lines.SetOwner(kTRUE);
242 validator.Report(lines,*chambers);
247 while ( ( line = static_cast<TObjString*>(next()) ) )
249 Master()->Log(line->String().Data());
253 Master()->Log("Storing pedestals...");
254 if ( fConfigChanged )
256 Master()->Log("...and configuration, as it has changed");
259 AliCDBMetaData metaData;
260 metaData.SetBeamPeriod(0);
261 metaData.SetResponsible("MUON TRK");
262 TString comment("Computed by AliMUONPedestalSubprocessor $Id$");
263 comment.ReplaceAll("$","");
264 metaData.SetComment(comment.Data());
266 Bool_t validToInfinity = kTRUE;
267 Bool_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, validToInfinity);
268 if ( fConfigChanged )
270 result = result && Master()->Store("Calib", "Config", fConfig, &metaData, 0, validToInfinity);
272 return ( result != kTRUE ); // return 0 if everything is ok.
275 //_____________________________________________________________________________
277 AliMUONPedestalSubprocessor::ReadPedestalFile(const char* filename)
279 /// Read the pedestals from an ASCII file. \n
280 /// Format of that file is one line per channel : \n
281 ///-------------------------------------------------------------------------\n
282 /// BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA \n
283 ///-------------------------------------------------------------------------\n
285 /// Return kFALSE if reading was not successfull. \n
288 TString sFilename(gSystem->ExpandPathName(filename));
290 Master()->Log(Form("Reading %s",sFilename.Data()));
292 Int_t n = AliMUONTrackerIO::ReadPedestals(sFilename.Data(),*fPedestals);
297 Master()->Log(Form("Could not open %s",sFilename.Data()));
304 //_____________________________________________________________________________
306 AliMUONPedestalSubprocessor::ReadConfigFile(const char* filename)
308 /// Read the configuration from an ASCII file.
309 /// Format of that file is one line per manu :
310 /// BUS_PATCH MANU_ADDR
311 /// Return kFALSE if reading was not successfull.
314 TString sFilename(gSystem->ExpandPathName(filename));
316 Master()->Log(Form("Reading %s",sFilename.Data()));
318 Int_t n = AliMUONTrackerIO::ReadConfig(sFilename.Data(),*fConfig);
323 Master()->Log(Form("Could not open %s",sFilename.Data()));
331 //_____________________________________________________________________________
333 AliMUONPedestalSubprocessor::Print(Option_t* opt) const
336 if (fPedestals) fPedestals->Print("",opt);
337 if (fConfig) fConfig->Print("",opt);