Line data Source code
1 : /**************************************************************************
2 : * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 : * *
4 : * Author: The ALICE Off-line Project. *
5 : * Contributors are mentioned in the code where appropriate. *
6 : * *
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 : **************************************************************************/
15 :
16 : // $Id$
17 :
18 : #include "AliMUONTriggerSubprocessor.h"
19 :
20 : #include "AliCDBMetaData.h"
21 : #include "AliLog.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>
31 : #include <TList.h>
32 : #include <TObjString.h>
33 : #include <TSystem.h>
34 : #include <TClonesArray.h>
35 :
36 : /// \class AliMUONTriggerSubprocessor
37 : ///
38 : /// Implementation of AliMUONVSubprocessor for MUON trigger system
39 : ///
40 : /// Reads masks and LUT online files to feed the OCDB
41 : ///
42 : /// \author L. Aphecetche
43 :
44 : using std::ifstream;
45 : /// \cond CLASSIMP
46 12 : ClassImp(AliMUONTriggerSubprocessor)
47 : /// \endcond
48 :
49 : //_____________________________________________________________________________
50 : AliMUONTriggerSubprocessor::AliMUONTriggerSubprocessor(AliMUONPreprocessor* master)
51 0 : : AliMUONVSubprocessor(master,
52 : "Triggers",
53 : "Upload MUON Trigger masks and LUT to OCDB"),
54 0 : fRegionalConfig(0x0),
55 0 : fLocalMasks(0x0),
56 0 : fGlobalConfig(0x0),
57 0 : fLUT(0x0),
58 0 : fTrigScalers(0x0),
59 0 : fRegionalConfigToOCDB(kFALSE),
60 0 : fLocalMasksToOCDB(kFALSE),
61 0 : fGlobalConfigToOCDB(kFALSE),
62 0 : fLUTToOCDB(kFALSE),
63 0 : fTrigScalersToOCDB(kFALSE)
64 0 : {
65 : /// default ctor
66 0 : }
67 :
68 : //_____________________________________________________________________________
69 : AliMUONTriggerSubprocessor::~AliMUONTriggerSubprocessor()
70 0 : {
71 : /// dtor
72 0 : delete fRegionalConfig;
73 0 : delete fLocalMasks;
74 0 : delete fGlobalConfig;
75 0 : delete fLUT;
76 0 : delete [] fTrigScalers;
77 0 : }
78 :
79 : //_____________________________________________________________________________
80 : TString
81 : AliMUONTriggerSubprocessor::GetFileName(const char* fid) const
82 : {
83 : /// Get filename for a given id
84 :
85 : const Int_t kSystem = AliMUONPreprocessor::kDAQ;
86 :
87 0 : TList* sources = Master()->GetFileSources(kSystem,fid);
88 0 : if ( sources && sources->GetSize() == 1 )
89 : {
90 0 : return Master()->GetFile(kSystem,fid,static_cast<TObjString*>(sources->First())->GetName());
91 : }
92 0 : return "";
93 0 : }
94 :
95 : //_____________________________________________________________________________
96 : Bool_t
97 : AliMUONTriggerSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
98 : {
99 : /// When starting a new run, reads in the trigger online files.
100 :
101 : // First thing to do (after cleanup, that is), is to check whether the DA
102 : // was alive or not. If it was, it should have put the "MtgCurrent.dat" file
103 : // on the FXS.
104 : //
105 :
106 : Bool_t da(kTRUE);
107 :
108 0 : TString exportedFiles(gSystem->ExpandPathName(GetFileName("EXPORTED").Data()));
109 :
110 0 : if ( exportedFiles == "" )
111 : {
112 0 : Master()->Log("exported files not specified !");
113 : da = kFALSE;
114 0 : }
115 :
116 0 : if ( gSystem->AccessPathName(exportedFiles.Data(),kFileExists) ) // mind the strange return value convention of that method !
117 : {
118 0 : Master()->Log(Form("%s is not there !",exportedFiles.Data()));
119 : da = kFALSE;
120 0 : }
121 :
122 0 : if (!da)
123 : {
124 0 : Master()->Log("FATAL ERROR : DA does not seem to have been run !!!");
125 0 : Master()->Invalidate();
126 0 : return kFALSE;
127 : }
128 :
129 : // OK. We have an exportedFiles.dat file at hand.
130 : // Read it to know what other files should be there.
131 :
132 0 : Bool_t regionalFile(kFALSE);
133 0 : Bool_t globalFile(kFALSE);
134 0 : Bool_t localFile(kFALSE);
135 0 : Bool_t lutFile(kFALSE);
136 0 : Bool_t trigScalFile(kFALSE);
137 :
138 0 : WhichFilesToRead(GetFileName("EXPORTED").Data(),
139 : globalFile,regionalFile,localFile,lutFile,trigScalFile);
140 :
141 0 : if ((globalFile+regionalFile+localFile+lutFile+trigScalFile) == 0) {
142 0 : Master()->Log("No file(s) to be processed for this run. Exiting.");
143 0 : return kTRUE;
144 : }
145 :
146 0 : delete fRegionalConfig; fRegionalConfig = 0x0;
147 0 : delete fLocalMasks; fLocalMasks = 0x0;
148 0 : delete fGlobalConfig; fGlobalConfig = 0x0;
149 0 : delete fLUT; fLUT = 0x0;
150 0 : delete fTrigScalers; fTrigScalers = 0x0;
151 :
152 0 : Master()->Log(Form("Reading trigger masks for Run %d startTime %u endTime %u",
153 : run,startTime,endTime));
154 :
155 : Int_t check =
156 0 : TestFile("REGIONAL",regionalFile) +
157 0 : TestFile("LOCAL",localFile) +
158 0 : TestFile("GLOBAL",globalFile) +
159 0 : TestFile("LUT",lutFile) +
160 0 : TestFile("TRIGSCAL",trigScalFile);
161 :
162 0 : if ( check )
163 : {
164 0 : Master()->Log("Could not read some input file(s). Exiting");
165 0 : Master()->Invalidate();
166 0 : return kFALSE;
167 : }
168 :
169 0 : if ( regionalFile ) globalFile = kTRUE;
170 :
171 0 : if ( regionalFile ) fRegionalConfig = new AliMUONRegionalTriggerConfig();
172 0 : if ( localFile ) fLocalMasks = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
173 0 : if ( globalFile ) fGlobalConfig = new AliMUONGlobalCrateConfig();
174 :
175 0 : AliMUONTriggerIO tio;
176 :
177 0 : Bool_t ok = tio.ReadConfig(localFile ? GetFileName("LOCAL").Data() : "",
178 0 : regionalFile ? GetFileName("REGIONAL").Data() : "",
179 0 : globalFile ? GetFileName("GLOBAL").Data() : "",
180 0 : fLocalMasks,fRegionalConfig,fGlobalConfig);
181 :
182 0 : if (!ok)
183 : {
184 0 : Master()->Log("ERROR : ReadConfig failed");
185 0 : delete fLocalMasks;
186 0 : delete fRegionalConfig;
187 0 : delete fGlobalConfig;
188 0 : fLocalMasks = 0x0;
189 0 : fRegionalConfig = 0x0;
190 0 : fGlobalConfig = 0x0;
191 0 : }
192 :
193 0 : if ( lutFile )
194 : {
195 0 : fLUT = new AliMUONTriggerLut;
196 :
197 0 : Master()->Log(Form("Reading trigger LUT for Run %d startTime %u endTime %u",
198 : run,startTime,endTime));
199 :
200 0 : ok = tio.ReadLUT(GetFileName("LUT").Data(),*fLUT);
201 :
202 0 : if (!ok)
203 : {
204 0 : Master()->Log("ERROR : ReadLUT failed");
205 0 : delete fLUT;
206 0 : fLUT = 0x0;
207 0 : }
208 : }
209 :
210 0 : if ( trigScalFile ) {
211 0 : fTrigScalers = new TClonesArray("AliMUONTriggerScalers",10);
212 0 : ok = tio.ReadTrigScalers(GetFileName("TRIGSCAL").Data(),*fTrigScalers);
213 0 : if (!ok)
214 : {
215 0 : Master()->Log("ERROR : ReadTrigScalers failed");
216 0 : delete fTrigScalers;
217 0 : fTrigScalers = 0x0;
218 0 : }
219 : }
220 :
221 : return kTRUE;
222 :
223 0 : }
224 :
225 : //_____________________________________________________________________________
226 : UInt_t
227 : AliMUONTriggerSubprocessor::Process(TMap* /*dcsAliasMap*/)
228 : {
229 : /// Store the trigger masks into the CDB
230 :
231 0 : if ( !fGlobalConfig && !fRegionalConfig && !fLocalMasks && !fLUT )
232 : {
233 : // nothing to do
234 0 : return 0;
235 : }
236 :
237 0 : Master()->Log(Form("N global = %d N regional = %d N local %d N lut %d",
238 0 : (fGlobalConfig ? 1 : 0 ),
239 0 : (fRegionalConfig ? fRegionalConfig->GetNofTriggerCrates() : 0 ),
240 0 : (fLocalMasks ? fLocalMasks->GetSize() : 0 ),
241 0 : (fLUT ? 1 : 0)));
242 :
243 0 : AliCDBMetaData metaData;
244 0 : metaData.SetBeamPeriod(0);
245 0 : metaData.SetResponsible("MUON TRG");
246 0 : metaData.SetComment("Computed by AliMUONTriggerSubprocessor $Id$");
247 :
248 : Bool_t validToInfinity = kTRUE;
249 :
250 : Bool_t result1(kTRUE);
251 : Bool_t result2(kTRUE);
252 : Bool_t result3(kTRUE);
253 : Bool_t result4(kTRUE);
254 : Bool_t result5(kTRUE);
255 :
256 0 : if ( fGlobalConfig && fGlobalConfigToOCDB )
257 : {
258 0 : result1 = Master()->Store("Calib", "GlobalTriggerCrateConfig", fGlobalConfig,
259 : &metaData, 0, validToInfinity);
260 0 : }
261 :
262 0 : if ( fRegionalConfig && fRegionalConfig->GetNofTriggerCrates() > 0 && fRegionalConfigToOCDB )
263 : {
264 0 : result2 = Master()->Store("Calib", "RegionalTriggerConfig", fRegionalConfig,
265 : &metaData, 0, validToInfinity);
266 0 : }
267 :
268 0 : if ( fLocalMasks && fLocalMasks->GetSize() > 0 && fLocalMasksToOCDB )
269 : {
270 0 : result3 = Master()->Store("Calib", "LocalTriggerBoardMasks", fLocalMasks,
271 : &metaData, 0, validToInfinity);
272 0 : }
273 :
274 0 : if ( fLUT && fLUTToOCDB )
275 : {
276 0 : result4 = Master()->Store("Calib", "TriggerLut", fLUT,
277 : &metaData, 0, validToInfinity);
278 0 : }
279 :
280 0 : if ( fTrigScalers && fTrigScalersToOCDB )
281 : {
282 0 : result5 = Master()->Store("Calib","TriggerScalers", fTrigScalers,
283 : &metaData, 0, kFALSE);
284 0 : }
285 :
286 0 : return ( result1 != kTRUE || result2 != kTRUE || result3 != kTRUE || result4 != kTRUE || result5 != kTRUE); // return 0 if everything is ok.
287 0 : }
288 :
289 : //_____________________________________________________________________________
290 : Int_t
291 : AliMUONTriggerSubprocessor::TestFile(const char* baseName, Bool_t shouldBeThere) const
292 : {
293 : /// Check if required file can be accessed
294 0 : if (!shouldBeThere) return 0; // all is ok
295 :
296 0 : TString fileName(gSystem->ExpandPathName(GetFileName(baseName).Data()));
297 :
298 0 : if ( gSystem->AccessPathName(fileName.Data(),kFileExists) )
299 : {
300 : // mind the strange return value convention of that method !
301 0 : Master()->Log(Form("File %s does not exist",fileName.Data()));
302 0 : return 1; // this is an error
303 : }
304 0 : return 0; // all is ok.
305 0 : }
306 :
307 : //_____________________________________________________________________________
308 : void
309 : AliMUONTriggerSubprocessor::WhichFilesToRead(const char* exportedFiles,
310 : Bool_t& globalFile,
311 : Bool_t& regionalFile,
312 : Bool_t& localFile,
313 : Bool_t& lutFile,
314 : Bool_t& trigScalFile)
315 : {
316 : /// From the exportedFiles file, determine which other files will need
317 : /// to be read in
318 0 : ifstream in(gSystem->ExpandPathName(exportedFiles));
319 :
320 0 : globalFile = kFALSE;
321 0 : regionalFile = kFALSE;
322 0 : localFile = kFALSE;
323 0 : lutFile = kFALSE;
324 0 : trigScalFile = kFALSE;
325 :
326 0 : char line[1024];
327 : TObjArray *oa;
328 : TObjString *os;
329 :
330 0 : while ( in.getline(line,1024,'\n') )
331 : {
332 0 : TString sline(line);
333 0 : sline.ToUpper();
334 :
335 0 : if ( sline.Contains("REGIONAL") ) {
336 0 : regionalFile = kTRUE;
337 0 : oa = sline.Tokenize(" ");
338 0 : if (oa->GetLast() >= 1) {
339 : // new format, use the integer flag after the file name
340 0 : os = (TObjString*)oa->At(1);
341 0 : fRegionalConfigToOCDB |= (os->GetString()).Atoi();
342 0 : } else {
343 : // old format, transfer anyway
344 0 : fRegionalConfigToOCDB |= 1;
345 : }
346 : }
347 0 : if ( sline.Contains("LUT") ) {
348 0 : lutFile = kTRUE;
349 0 : oa = sline.Tokenize(" ");
350 0 : if (oa->GetLast() >= 1) {
351 : // new format, use the integer flag after the file name
352 0 : os = (TObjString*)oa->At(1);
353 0 : fLUTToOCDB |= (os->GetString()).Atoi();
354 0 : } else {
355 : // old format, transfer anyway
356 0 : fLUTToOCDB |= 1;
357 : }
358 : }
359 0 : if ( sline.Contains("LOCAL") && sline.Contains("MASK") ) {
360 0 : localFile = kTRUE;
361 0 : oa = sline.Tokenize(" ");
362 0 : if (oa->GetLast() >= 1) {
363 : // new format, use the integer flag after the file name
364 0 : os = (TObjString*)oa->At(1);
365 0 : fLocalMasksToOCDB |= (os->GetString()).Atoi();
366 0 : } else {
367 : // old format, transfer anyway
368 0 : fLocalMasksToOCDB |= 1;
369 : }
370 : }
371 0 : if ( sline.Contains("GLOBAL") ) {
372 0 : globalFile = kTRUE;
373 0 : oa = sline.Tokenize(" ");
374 0 : if (oa->GetLast() >= 1) {
375 : // new format, use the integer flag after the file name
376 0 : os = (TObjString*)oa->At(1);
377 0 : fGlobalConfigToOCDB |= (os->GetString()).Atoi();
378 0 : } else {
379 : // old format, transfer anyway
380 0 : fGlobalConfigToOCDB |= 1;
381 : }
382 : }
383 0 : if ( sline.Contains("TRIGSCAL") ) {
384 0 : trigScalFile = kTRUE;
385 0 : oa = sline.Tokenize(" ");
386 0 : if (oa->GetLast() >= 1) {
387 : // new format, use the integer flag after the file name
388 0 : os = (TObjString*)oa->At(1);
389 0 : fTrigScalersToOCDB |= (os->GetString()).Atoi();
390 0 : } else {
391 : // old format, transfer anyway
392 0 : fTrigScalersToOCDB |= 1;
393 : }
394 : }
395 :
396 0 : }
397 :
398 0 : if ( regionalFile || localFile || globalFile || lutFile || trigScalFile)
399 : {
400 0 : Master()->Log(Form("Will have to read the following file types:"));
401 0 : if ( globalFile) Master()->Log(Form("GLOBAL (%d)",fGlobalConfigToOCDB));
402 0 : if ( regionalFile ) Master()->Log(Form("REGIONAL (%d)",fRegionalConfigToOCDB));
403 0 : if ( localFile) Master()->Log(Form("LOCAL (%d)",fLocalMasksToOCDB));
404 0 : if ( lutFile ) Master()->Log(Form("LUT (%d)",fLUTToOCDB));
405 0 : if ( trigScalFile ) Master()->Log(Form("TRIGSCAL (%d)",fTrigScalersToOCDB));
406 : }
407 0 : }
408 :
|