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 "AliMUONTriggerSubprocessor.h"
20 #include "AliCDBMetaData.h"
22 #include "AliMUON1DArray.h"
23 #include "AliMUONGlobalCrateConfig.h"
24 #include "AliMUONRegionalTriggerConfig.h"
25 #include "AliMUONCalibParamNI.h"
26 #include "AliMUONPreprocessor.h"
27 #include "AliMUONTriggerIO.h"
28 #include "AliMUONTriggerLut.h"
29 #include "AliMpConstants.h"
30 #include <Riostream.h>
32 #include <TObjString.h>
35 /// \class AliMUONTriggerSubprocessor
37 /// Implementation of AliMUONVSubprocessor for MUON trigger system
39 /// Reads masks and LUT online files to feed the OCDB
41 /// \author L. Aphecetche
45 ClassImp(AliMUONTriggerSubprocessor)
48 //_____________________________________________________________________________
49 AliMUONTriggerSubprocessor::AliMUONTriggerSubprocessor(AliMUONPreprocessor* master)
50 : AliMUONVSubprocessor(master,
52 "Upload MUON Trigger masks and LUT to OCDB"),
61 //_____________________________________________________________________________
62 AliMUONTriggerSubprocessor::~AliMUONTriggerSubprocessor()
65 delete fRegionalConfig;
71 //_____________________________________________________________________________
73 AliMUONTriggerSubprocessor::GetFileName(const char* fid) const
75 /// Get filename for a given id
77 const Int_t kSystem = AliMUONPreprocessor::kDAQ;
79 TList* sources = Master()->GetFileSources(kSystem,fid);
80 if ( sources && sources->GetSize() == 1 )
82 return Master()->GetFile(kSystem,fid,static_cast<TObjString*>(sources->First())->GetName());
87 //_____________________________________________________________________________
89 AliMUONTriggerSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
91 /// When starting a new run, reads in the trigger online files.
93 // First thing to do (after cleanup, that is), is to check whether the DA
94 // was alive or not. If it was, it should have put the "MtgCurrent.dat" file
100 TString exportedFiles(gSystem->ExpandPathName(GetFileName("EXPORTED").Data()));
102 if ( exportedFiles == "" )
104 Master()->Log("exported files not specified !");
108 if ( gSystem->AccessPathName(exportedFiles.Data(),kFileExists) ) // mind the strange return value convention of that method !
110 Master()->Log(Form("%s is not there !",exportedFiles.Data()));
116 Master()->Log("FATAL ERROR : DA does not seem to have been run !!!");
117 Master()->Invalidate();
121 // OK. We have an exportedFiles.dat file at hand.
122 // Read it to know what other files should be there.
124 Bool_t regionalFile(kFALSE);
125 Bool_t globalFile(kFALSE);
126 Bool_t localFile(kFALSE);
127 Bool_t lutFile(kFALSE);
129 WhichFilesToRead(GetFileName("EXPORTED").Data(),
130 globalFile,regionalFile,localFile,lutFile);
132 if ((globalFile+regionalFile+localFile+lutFile) == 0) {
133 Master()->Log("No file(s) to be processed for this run. Exiting.");
137 delete fRegionalConfig; fRegionalConfig = 0x0;
138 delete fLocalMasks; fLocalMasks = 0x0;
139 delete fGlobalConfig; fGlobalConfig = 0x0;
140 delete fLUT; fLUT = 0x0;
142 Master()->Log(Form("Reading trigger masks for Run %d startTime %u endTime %u",
143 run,startTime,endTime));
146 TestFile("REGIONAL",regionalFile) +
147 TestFile("LOCAL",localFile) +
148 TestFile("GLOBAL",globalFile) +
149 TestFile("LUT",lutFile);
153 Master()->Log("Could not read some input file(s). Exiting");
154 Master()->Invalidate();
158 if ( regionalFile ) globalFile = kTRUE;
160 if ( regionalFile ) fRegionalConfig = new AliMUONRegionalTriggerConfig();
161 if ( localFile ) fLocalMasks = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
162 if ( globalFile ) fGlobalConfig = new AliMUONGlobalCrateConfig();
164 AliMUONTriggerIO tio;
166 Bool_t ok = tio.ReadConfig(localFile ? GetFileName("LOCAL").Data() : "",
167 regionalFile ? GetFileName("REGIONAL").Data() : "",
168 globalFile ? GetFileName("GLOBAL").Data() : "",
169 fLocalMasks,fRegionalConfig,fGlobalConfig);
173 Master()->Log("ERROR : ReadConfig failed");
175 delete fRegionalConfig;
176 delete fGlobalConfig;
178 fRegionalConfig = 0x0;
184 fLUT = new AliMUONTriggerLut;
186 Master()->Log(Form("Reading trigger LUT for Run %d startTime %u endTime %u",
187 run,startTime,endTime));
189 ok = tio.ReadLUT(GetFileName("LUT").Data(),*fLUT);
193 Master()->Log("ERROR : ReadLUT failed");
201 //_____________________________________________________________________________
203 AliMUONTriggerSubprocessor::Process(TMap* /*dcsAliasMap*/)
205 /// Store the trigger masks into the CDB
207 if ( !fGlobalConfig && !fRegionalConfig && !fLocalMasks && !fLUT )
213 Master()->Log(Form("N global = %d N regional = %d N local %d N lut %d",
214 (fGlobalConfig ? 1 : 0 ),
215 (fRegionalConfig ? fRegionalConfig->GetNofTriggerCrates() : 0 ),
216 (fLocalMasks ? fLocalMasks->GetSize() : 0 ),
219 AliCDBMetaData metaData;
220 metaData.SetBeamPeriod(0);
221 metaData.SetResponsible("MUON TRG");
222 metaData.SetComment("Computed by AliMUONTriggerSubprocessor $Id$");
224 Bool_t validToInfinity = kTRUE;
226 Bool_t result1(kTRUE);
227 Bool_t result2(kTRUE);
228 Bool_t result3(kTRUE);
229 Bool_t result4(kTRUE);
233 result1 = Master()->Store("Calib", "GlobalTriggerCrateConfig", fGlobalConfig,
234 &metaData, 0, validToInfinity);
237 if ( fRegionalConfig && fRegionalConfig->GetNofTriggerCrates() > 0 )
239 result2 = Master()->Store("Calib", "RegionalTriggerConfig", fRegionalConfig,
240 &metaData, 0, validToInfinity);
243 if ( fLocalMasks && fLocalMasks->GetSize() > 0 )
245 result3 = Master()->Store("Calib", "LocalTriggerBoardMasks", fLocalMasks,
246 &metaData, 0, validToInfinity);
251 result4 = Master()->Store("Calib", "TriggerLut", fLUT,
252 &metaData, 0, validToInfinity);
255 return ( result1 != kTRUE || result2 != kTRUE || result3 != kTRUE || result4 != kTRUE ); // return 0 if everything is ok.
258 //_____________________________________________________________________________
260 AliMUONTriggerSubprocessor::TestFile(const char* baseName, Bool_t shouldBeThere) const
262 /// Check if required file can be accessed
263 if (!shouldBeThere) return 0; // all is ok
265 TString fileName(gSystem->ExpandPathName(GetFileName(baseName).Data()));
267 if ( gSystem->AccessPathName(fileName.Data(),kFileExists) )
269 // mind the strange return value convention of that method !
270 Master()->Log(Form("File %s does not exist",fileName.Data()));
271 return 1; // this is an error
273 return 0; // all is ok.
276 //_____________________________________________________________________________
278 AliMUONTriggerSubprocessor::WhichFilesToRead(const char* exportedFiles,
280 Bool_t& regionalFile,
282 Bool_t& lutFile) const
284 /// From the exportedFiles file, determine which other files will need
286 ifstream in(gSystem->ExpandPathName(exportedFiles));
289 regionalFile = kFALSE;
295 while ( in.getline(line,1024,'\n') )
300 if ( sline.Contains("REGIONAL") ) regionalFile = kTRUE;
301 if ( sline.Contains("LUT") ) lutFile = kTRUE;
302 if ( sline.Contains("LOCAL") && sline.Contains("MASK") ) localFile = kTRUE;
303 if ( sline.Contains("GLOBAL") ) globalFile = kTRUE;
306 if ( regionalFile || localFile || globalFile || lutFile )
308 Master()->Log(Form("Will have to read the following file types:"));
309 if ( globalFile) Master()->Log("GLOBAL");
310 if ( regionalFile ) Master()->Log("REGIONAL");
311 if ( localFile) Master()->Log("LOCAL");
312 if ( lutFile ) Master()->Log("LUT");