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
44 ClassImp(AliMUONTriggerSubprocessor)
47 //_____________________________________________________________________________
48 AliMUONTriggerSubprocessor::AliMUONTriggerSubprocessor(AliMUONPreprocessor* master)
49 : AliMUONVSubprocessor(master,
51 "Upload MUON Trigger masks and LUT to OCDB"),
60 //_____________________________________________________________________________
61 AliMUONTriggerSubprocessor::~AliMUONTriggerSubprocessor()
64 delete fRegionalConfig;
70 //_____________________________________________________________________________
72 AliMUONTriggerSubprocessor::GetFileName(const char* fid) const
74 /// Get filename for a given id
76 const Int_t kSystem = AliMUONPreprocessor::kDAQ;
78 TList* sources = Master()->GetFileSources(kSystem,fid);
79 if ( sources && sources->GetSize() == 1 )
81 return Master()->GetFile(kSystem,fid,static_cast<TObjString*>(sources->First())->GetName());
86 //_____________________________________________________________________________
88 AliMUONTriggerSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
90 /// When starting a new run, reads in the trigger online files.
92 // First thing to do (after cleanup, that is), is to check whether the DA
93 // was alive or not. If it was, it should have put the "MtgCurrent.dat" file
99 TString exportedFiles(gSystem->ExpandPathName(GetFileName("EXPORTED").Data()));
101 if ( exportedFiles == "" )
103 Master()->Log("exported files not specified !");
107 if ( gSystem->AccessPathName(exportedFiles.Data(),kFileExists) ) // mind the strange return value convention of that method !
109 Master()->Log(Form("%s is not there !",exportedFiles.Data()));
115 Master()->Log("FATAL ERROR : DA does not seem to have been run !!!");
116 Master()->Invalidate();
120 // OK. We have an exportedFiles.dat file at hand.
121 // Read it to know what other files should be there.
123 Bool_t regionalFile(kFALSE);
124 Bool_t globalFile(kFALSE);
125 Bool_t localFile(kFALSE);
126 Bool_t lutFile(kFALSE);
128 WhichFilesToRead(GetFileName("EXPORTED").Data(),
129 globalFile,regionalFile,localFile,lutFile);
131 if ((globalFile+regionalFile+localFile+lutFile) == 0) {
132 Master()->Log("No file(s) to be processed for this run. Exiting.");
136 delete fRegionalConfig; fRegionalConfig = 0x0;
137 delete fLocalMasks; fLocalMasks = 0x0;
138 delete fGlobalConfig; fGlobalConfig = 0x0;
139 delete fLUT; fLUT = 0x0;
141 Master()->Log(Form("Reading trigger masks for Run %d startTime %ld endTime %ld",
142 run,startTime,endTime));
145 TestFile("REGIONAL",regionalFile) +
146 TestFile("LOCAL",localFile) +
147 TestFile("GLOBAL",globalFile) +
148 TestFile("LUT",lutFile);
152 Master()->Log("Could not read some input file(s). Aborting");
153 Master()->Invalidate();
157 if ( regionalFile ) fRegionalConfig = new AliMUONRegionalTriggerConfig();
158 if ( localFile ) fLocalMasks = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
159 if ( globalFile ) fGlobalConfig = new AliMUONGlobalCrateConfig();
161 AliMUONTriggerIO tio;
163 Bool_t ok = tio.ReadConfig(localFile ? GetFileName("LOCAL").Data() : "",
164 regionalFile ? GetFileName("REGIONAL").Data() : "",
165 globalFile ? GetFileName("GLOBAL").Data() : "",
166 fLocalMasks,fRegionalConfig,fGlobalConfig);
170 Master()->Log("ERROR : ReadConfig failed");
172 delete fRegionalConfig;
173 delete fGlobalConfig;
175 fRegionalConfig = 0x0;
181 fLUT = new AliMUONTriggerLut;
183 Master()->Log(Form("Reading trigger LUT for Run %d startTime %ld endTime %ld",
184 run,startTime,endTime));
186 ok = tio.ReadLUT(GetFileName("LUT").Data(),*fLUT);
190 Master()->Log("ERROR : ReadLUT failed");
197 //_____________________________________________________________________________
199 AliMUONTriggerSubprocessor::Process(TMap* /*dcsAliasMap*/)
201 /// Store the trigger masks into the CDB
203 if ( !fGlobalConfig && !fRegionalConfig && !fLocalMasks && !fLUT )
209 Master()->Log(Form("N global = %d N regional = %d N local %d N lut %d",
210 (fGlobalConfig ? 1 : 0 ),
211 (fRegionalConfig ? fRegionalConfig->GetNofTriggerCrates() : 0 ),
212 (fLocalMasks ? fLocalMasks->GetSize() : 0 ),
215 AliCDBMetaData metaData;
216 metaData.SetBeamPeriod(0);
217 metaData.SetResponsible("MUON TRG");
218 metaData.SetComment("Computed by AliMUONTriggerSubprocessor $Id$");
220 Bool_t validToInfinity = kTRUE;
222 Bool_t result1(kTRUE);
223 Bool_t result2(kTRUE);
224 Bool_t result3(kTRUE);
225 Bool_t result4(kTRUE);
229 result1 = Master()->Store("Calib", "GlobalTriggerCrateConfig", fGlobalConfig,
230 &metaData, 0, validToInfinity);
233 if ( fRegionalConfig && fRegionalConfig->GetNofTriggerCrates() > 0 )
235 result2 = Master()->Store("Calib", "RegionalTriggerConfig", fRegionalConfig,
236 &metaData, 0, validToInfinity);
239 if ( fLocalMasks && fLocalMasks->GetSize() > 0 )
241 result3 = Master()->Store("Calib", "LocalTriggerBoardMasks", fLocalMasks,
242 &metaData, 0, validToInfinity);
247 result4 = Master()->Store("Calib", "TriggerLut", fLUT,
248 &metaData, 0, validToInfinity);
251 return ( result1 != kTRUE || result2 != kTRUE || result3 != kTRUE || result4 != kTRUE ); // return 0 if everything is ok.
254 //_____________________________________________________________________________
256 AliMUONTriggerSubprocessor::TestFile(const char* baseName, Bool_t shouldBeThere) const
258 /// Check if required file can be accessed
259 if (!shouldBeThere) return 0; // all is ok
261 TString fileName(gSystem->ExpandPathName(GetFileName(baseName).Data()));
263 if ( gSystem->AccessPathName(fileName.Data(),kFileExists) )
265 // mind the strange return value convention of that method !
266 Master()->Log(Form("File %s does not exist",fileName.Data()));
267 return 1; // this is an error
269 return 0; // all is ok.
272 //_____________________________________________________________________________
274 AliMUONTriggerSubprocessor::WhichFilesToRead(const char* exportedFiles,
276 Bool_t& regionalFile,
278 Bool_t& lutFile) const
280 /// From the exportedFiles file, determine which other files will need
282 ifstream in(gSystem->ExpandPathName(exportedFiles));
285 regionalFile = kFALSE;
291 while ( in.getline(line,1024,'\n') )
296 if ( sline.Contains("REGIONAL") ) regionalFile = kTRUE;
297 if ( sline.Contains("LUT") ) lutFile = kTRUE;
298 if ( sline.Contains("LOCAL") && sline.Contains("MASK") ) localFile = kTRUE;
299 if ( sline.Contains("GLOBAL") ) globalFile = kTRUE;
302 if ( regionalFile || localFile || globalFile || lutFile )
304 Master()->Log(Form("Will have to read the following file types:"));
305 if ( globalFile) Master()->Log("GLOBAL");
306 if ( regionalFile ) Master()->Log("REGIONAL");
307 if ( localFile) Master()->Log("LOCAL");
308 if ( lutFile ) Master()->Log("LUT");