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),
68 //_____________________________________________________________________________
69 AliMUONPedestalSubprocessor::~AliMUONPedestalSubprocessor()
76 //_____________________________________________________________________________
78 AliMUONPedestalSubprocessor::HasConfigChanged(const AliMUONVStore& newConfig) const
80 /// Check whether the config changed.
81 /// Any error will return kTRUE to trig a config upload (safer way).
83 AliCDBEntry* entry = Master()->GetFromOCDB("Calib","Config");
86 AliError("Could not get MUON/Calib/Config entry for current run ! That's not OK !");
89 AliMUONVStore* oldConfig = dynamic_cast<AliMUONVStore*>(entry->GetObject());
92 AliError("Could not get MUON/Calib/Config object for current run (wrong type ?) ! That's not OK !");
96 if ( oldConfig->GetSize() != newConfig.GetSize() )
101 TIter next(oldConfig->CreateIterator());
102 AliMUONVCalibParam* old;
104 while ( ( old = static_cast<AliMUONVCalibParam*>(next()) ) )
106 Int_t detElemId = old->ID0();
107 Int_t manuId = old->ID1();
109 if ( ! newConfig.FindObject(detElemId,manuId) )
111 // not found in new. Configurations are different. Return right now.
116 // all tests OK. Configuration has not changed.
121 //_____________________________________________________________________________
123 AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
125 /// When starting a new run, reads in the pedestals ASCII files.
127 const Int_t kSystem = AliMUONPreprocessor::kDAQ;
128 const char* kId = "PEDESTALS";
131 fPedestals = new AliMUON2DMap(kTRUE);
134 fConfig = new AliMUON2DMap(kTRUE);
136 fTooFewEvents = kFALSE;
138 Master()->Log(Form("Reading pedestal files for Run %d startTime %u endTime %u",
139 run,startTime,endTime));
141 TList* sources = Master()->GetFileSources(kSystem,kId);
147 while ( ( o = static_cast<TObjString*>(next()) ) )
149 TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
150 Int_t ok = ReadPedestalFile(fileName.Data());
162 Master()->Log("Failed to read any pedestals");
169 // OK, we did not get our pedestals. Check if the ped run itself
170 // was bad, i.e. too few events
171 TString nevents(Master()->GetRunParameter("totalEvents"));
173 if ( nevents.Atoi() < 50 )
175 Master()->Log(Form("The run had only %d events, so the failure to read pedestals is normal",nevents.Atoi()));
176 // too few events, failure is normal, returns OK.
177 fTooFewEvents = kTRUE;
181 // no ped, but run looks clean, that's an error
185 const char* kIdConf = "CONFIG";
187 sources = Master()->GetFileSources(kSystem,kIdConf);
188 TIter nextConf(sources);
192 while ( ( o = static_cast<TObjString*>(nextConf()) ) )
194 TString fileName(Master()->GetFile(kSystem,kIdConf,o->GetName()));
195 Int_t ok = ReadConfigFile(fileName.Data());
205 if ( npedFiles != nconfFiles )
207 Master()->Log(Form("ERROR : Number of config files (%d) different from number of pedestal files (%d)",nconfFiles,npedFiles));
215 fConfigChanged = HasConfigChanged(*fConfig);
220 //_____________________________________________________________________________
222 AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/)
224 /// Store the pedestals into the CDB
226 if (!fPedestals || !fConfig)
230 // ped run was too short, no reason to complain about that, it's "normal"
231 // not to have pedestals in that case.
236 // this is the only reason to fail for the moment : getting no pedestal or no config
242 AliMUON2DStoreValidator validator;
244 Master()->Log("Validating");
246 TObjArray* chambers = validator.Validate(*fPedestals,fConfig);
250 // we hereby report what's missing, but this is not a reason to fail ;-)
251 // the only reason to fail would be if we got no pedestal at all
253 lines.SetOwner(kTRUE);
255 validator.Report(lines,*chambers);
260 while ( ( line = static_cast<TObjString*>(next()) ) )
262 Master()->Log(line->String().Data());
266 Master()->Log("Storing pedestals...");
267 if ( fConfigChanged )
269 Master()->Log("...and configuration, as it has changed");
272 AliCDBMetaData metaData;
273 metaData.SetBeamPeriod(0);
274 metaData.SetResponsible("MUON TRK");
275 TString comment("Computed by AliMUONPedestalSubprocessor $Id$");
276 comment.ReplaceAll("$","");
277 metaData.SetComment(comment.Data());
279 Bool_t validToInfinity = kTRUE;
280 Bool_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, validToInfinity);
281 if ( fConfigChanged )
283 result = result && Master()->Store("Calib", "Config", fConfig, &metaData, 0, validToInfinity);
285 return ( result != kTRUE ); // return 0 if everything is ok.
288 //_____________________________________________________________________________
290 AliMUONPedestalSubprocessor::ReadPedestalFile(const char* filename)
292 /// Read the pedestals from an ASCII file. \n
293 /// Format of that file is one line per channel : \n
294 ///-------------------------------------------------------------------------\n
295 /// BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA \n
296 ///-------------------------------------------------------------------------\n
298 /// Return kFALSE if reading was not successfull. \n
301 TString sFilename(gSystem->ExpandPathName(filename));
303 Master()->Log(Form("Reading %s",sFilename.Data()));
305 Int_t n = AliMUONTrackerIO::ReadPedestals(sFilename.Data(),*fPedestals);
310 Master()->Log(Form("Could not open %s",sFilename.Data()));
317 //_____________________________________________________________________________
319 AliMUONPedestalSubprocessor::ReadConfigFile(const char* filename)
321 /// Read the configuration from an ASCII file.
322 /// Format of that file is one line per manu :
323 /// BUS_PATCH MANU_ADDR
324 /// Return kFALSE if reading was not successfull.
327 TString sFilename(gSystem->ExpandPathName(filename));
329 Master()->Log(Form("Reading %s",sFilename.Data()));
331 Int_t n = AliMUONTrackerIO::ReadConfig(sFilename.Data(),*fConfig);
336 Master()->Log(Form("Could not open %s",sFilename.Data()));
344 //_____________________________________________________________________________
346 AliMUONPedestalSubprocessor::Print(Option_t* opt) const
349 if (fPedestals) fPedestals->Print("",opt);
350 if (fConfig) fConfig->Print("",opt);