AliRoot Core  3abf5b4 (3abf5b4)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMUONTriggerSubprocessor.cxx
Go to the documentation of this file.
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 
19 
20 #include "AliCDBMetaData.h"
21 #include "AliLog.h"
22 #include "AliMUON1DArray.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 
43 
44 using std::ifstream;
48 
49 //_____________________________________________________________________________
51 : AliMUONVSubprocessor(master,
52  "Triggers",
53  "Upload MUON Trigger masks and LUT to OCDB"),
54 fRegionalConfig(0x0),
55 fLocalMasks(0x0),
56 fGlobalConfig(0x0),
57 fLUT(0x0),
58 fTrigScalers(0x0),
59 fRegionalConfigToOCDB(kFALSE),
60 fLocalMasksToOCDB(kFALSE),
61 fGlobalConfigToOCDB(kFALSE),
62 fLUTToOCDB(kFALSE),
63 fTrigScalersToOCDB(kFALSE)
64 {
66 }
67 
68 //_____________________________________________________________________________
70 {
72  delete fRegionalConfig;
73  delete fLocalMasks;
74  delete fGlobalConfig;
75  delete fLUT;
76  delete [] fTrigScalers;
77 }
78 
79 //_____________________________________________________________________________
80 TString
82 {
84 
85  const Int_t kSystem = AliMUONPreprocessor::kDAQ;
86 
87  TList* sources = Master()->GetFileSources(kSystem,fid);
88  if ( sources && sources->GetSize() == 1 )
89  {
90  return Master()->GetFile(kSystem,fid,static_cast<TObjString*>(sources->First())->GetName());
91  }
92  return "";
93 }
94 
95 //_____________________________________________________________________________
96 Bool_t
97 AliMUONTriggerSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
98 {
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  TString exportedFiles(gSystem->ExpandPathName(GetFileName("EXPORTED").Data()));
109 
110  if ( exportedFiles == "" )
111  {
112  Master()->Log("exported files not specified !");
113  da = kFALSE;
114  }
115 
116  if ( gSystem->AccessPathName(exportedFiles.Data(),kFileExists) ) // mind the strange return value convention of that method !
117  {
118  Master()->Log(Form("%s is not there !",exportedFiles.Data()));
119  da = kFALSE;
120  }
121 
122  if (!da)
123  {
124  Master()->Log("FATAL ERROR : DA does not seem to have been run !!!");
125  Master()->Invalidate();
126  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  Bool_t regionalFile(kFALSE);
133  Bool_t globalFile(kFALSE);
134  Bool_t localFile(kFALSE);
135  Bool_t lutFile(kFALSE);
136  Bool_t trigScalFile(kFALSE);
137 
138  WhichFilesToRead(GetFileName("EXPORTED").Data(),
139  globalFile,regionalFile,localFile,lutFile,trigScalFile);
140 
141  if ((globalFile+regionalFile+localFile+lutFile+trigScalFile) == 0) {
142  Master()->Log("No file(s) to be processed for this run. Exiting.");
143  return kTRUE;
144  }
145 
146  delete fRegionalConfig; fRegionalConfig = 0x0;
147  delete fLocalMasks; fLocalMasks = 0x0;
148  delete fGlobalConfig; fGlobalConfig = 0x0;
149  delete fLUT; fLUT = 0x0;
150  delete fTrigScalers; fTrigScalers = 0x0;
151 
152  Master()->Log(Form("Reading trigger masks for Run %d startTime %u endTime %u",
153  run,startTime,endTime));
154 
155  Int_t check =
156  TestFile("REGIONAL",regionalFile) +
157  TestFile("LOCAL",localFile) +
158  TestFile("GLOBAL",globalFile) +
159  TestFile("LUT",lutFile) +
160  TestFile("TRIGSCAL",trigScalFile);
161 
162  if ( check )
163  {
164  Master()->Log("Could not read some input file(s). Exiting");
165  Master()->Invalidate();
166  return kFALSE;
167  }
168 
169  if ( regionalFile ) globalFile = kTRUE;
170 
171  if ( regionalFile ) fRegionalConfig = new AliMUONRegionalTriggerConfig();
173  if ( globalFile ) fGlobalConfig = new AliMUONGlobalCrateConfig();
174 
175  AliMUONTriggerIO tio;
176 
177  Bool_t ok = tio.ReadConfig(localFile ? GetFileName("LOCAL").Data() : "",
178  regionalFile ? GetFileName("REGIONAL").Data() : "",
179  globalFile ? GetFileName("GLOBAL").Data() : "",
181 
182  if (!ok)
183  {
184  Master()->Log("ERROR : ReadConfig failed");
185  delete fLocalMasks;
186  delete fRegionalConfig;
187  delete fGlobalConfig;
188  fLocalMasks = 0x0;
189  fRegionalConfig = 0x0;
190  fGlobalConfig = 0x0;
191  }
192 
193  if ( lutFile )
194  {
195  fLUT = new AliMUONTriggerLut;
196 
197  Master()->Log(Form("Reading trigger LUT for Run %d startTime %u endTime %u",
198  run,startTime,endTime));
199 
200  ok = tio.ReadLUT(GetFileName("LUT").Data(),*fLUT);
201 
202  if (!ok)
203  {
204  Master()->Log("ERROR : ReadLUT failed");
205  delete fLUT;
206  fLUT = 0x0;
207  }
208  }
209 
210  if ( trigScalFile ) {
211  fTrigScalers = new TClonesArray("AliMUONTriggerScalers",10);
212  ok = tio.ReadTrigScalers(GetFileName("TRIGSCAL").Data(),*fTrigScalers);
213  if (!ok)
214  {
215  Master()->Log("ERROR : ReadTrigScalers failed");
216  delete fTrigScalers;
217  fTrigScalers = 0x0;
218  }
219  }
220 
221  return kTRUE;
222 
223 }
224 
225 //_____________________________________________________________________________
226 UInt_t
228 {
230 
231  if ( !fGlobalConfig && !fRegionalConfig && !fLocalMasks && !fLUT )
232  {
233  // nothing to do
234  return 0;
235  }
236 
237  Master()->Log(Form("N global = %d N regional = %d N local %d N lut %d",
238  (fGlobalConfig ? 1 : 0 ),
240  (fLocalMasks ? fLocalMasks->GetSize() : 0 ),
241  (fLUT ? 1 : 0)));
242 
243  AliCDBMetaData metaData;
244  metaData.SetBeamPeriod(0);
245  metaData.SetResponsible("MUON TRG");
246  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 
257  {
258  result1 = Master()->Store("Calib", "GlobalTriggerCrateConfig", fGlobalConfig,
259  &metaData, 0, validToInfinity);
260  }
261 
263  {
264  result2 = Master()->Store("Calib", "RegionalTriggerConfig", fRegionalConfig,
265  &metaData, 0, validToInfinity);
266  }
267 
268  if ( fLocalMasks && fLocalMasks->GetSize() > 0 && fLocalMasksToOCDB )
269  {
270  result3 = Master()->Store("Calib", "LocalTriggerBoardMasks", fLocalMasks,
271  &metaData, 0, validToInfinity);
272  }
273 
274  if ( fLUT && fLUTToOCDB )
275  {
276  result4 = Master()->Store("Calib", "TriggerLut", fLUT,
277  &metaData, 0, validToInfinity);
278  }
279 
281  {
282  result5 = Master()->Store("Calib","TriggerScalers", fTrigScalers,
283  &metaData, 0, kFALSE);
284  }
285 
286  return ( result1 != kTRUE || result2 != kTRUE || result3 != kTRUE || result4 != kTRUE || result5 != kTRUE); // return 0 if everything is ok.
287 }
288 
289 //_____________________________________________________________________________
290 Int_t
291 AliMUONTriggerSubprocessor::TestFile(const char* baseName, Bool_t shouldBeThere) const
292 {
294  if (!shouldBeThere) return 0; // all is ok
295 
296  TString fileName(gSystem->ExpandPathName(GetFileName(baseName).Data()));
297 
298  if ( gSystem->AccessPathName(fileName.Data(),kFileExists) )
299  {
300  // mind the strange return value convention of that method !
301  Master()->Log(Form("File %s does not exist",fileName.Data()));
302  return 1; // this is an error
303  }
304  return 0; // all is ok.
305 }
306 
307 //_____________________________________________________________________________
308 void
310  Bool_t& globalFile,
311  Bool_t& regionalFile,
312  Bool_t& localFile,
313  Bool_t& lutFile,
314  Bool_t& trigScalFile)
315 {
318  ifstream in(gSystem->ExpandPathName(exportedFiles));
319 
320  globalFile = kFALSE;
321  regionalFile = kFALSE;
322  localFile = kFALSE;
323  lutFile = kFALSE;
324  trigScalFile = kFALSE;
325 
326  char line[1024];
327  TObjArray *oa;
328  TObjString *os;
329 
330  while ( in.getline(line,1024,'\n') )
331  {
332  TString sline(line);
333  sline.ToUpper();
334 
335  if ( sline.Contains("REGIONAL") ) {
336  regionalFile = kTRUE;
337  oa = sline.Tokenize(" ");
338  if (oa->GetLast() >= 1) {
339  // new format, use the integer flag after the file name
340  os = (TObjString*)oa->At(1);
341  fRegionalConfigToOCDB |= (os->GetString()).Atoi();
342  } else {
343  // old format, transfer anyway
345  }
346  }
347  if ( sline.Contains("LUT") ) {
348  lutFile = kTRUE;
349  oa = sline.Tokenize(" ");
350  if (oa->GetLast() >= 1) {
351  // new format, use the integer flag after the file name
352  os = (TObjString*)oa->At(1);
353  fLUTToOCDB |= (os->GetString()).Atoi();
354  } else {
355  // old format, transfer anyway
356  fLUTToOCDB |= 1;
357  }
358  }
359  if ( sline.Contains("LOCAL") && sline.Contains("MASK") ) {
360  localFile = kTRUE;
361  oa = sline.Tokenize(" ");
362  if (oa->GetLast() >= 1) {
363  // new format, use the integer flag after the file name
364  os = (TObjString*)oa->At(1);
365  fLocalMasksToOCDB |= (os->GetString()).Atoi();
366  } else {
367  // old format, transfer anyway
368  fLocalMasksToOCDB |= 1;
369  }
370  }
371  if ( sline.Contains("GLOBAL") ) {
372  globalFile = kTRUE;
373  oa = sline.Tokenize(" ");
374  if (oa->GetLast() >= 1) {
375  // new format, use the integer flag after the file name
376  os = (TObjString*)oa->At(1);
377  fGlobalConfigToOCDB |= (os->GetString()).Atoi();
378  } else {
379  // old format, transfer anyway
380  fGlobalConfigToOCDB |= 1;
381  }
382  }
383  if ( sline.Contains("TRIGSCAL") ) {
384  trigScalFile = kTRUE;
385  oa = sline.Tokenize(" ");
386  if (oa->GetLast() >= 1) {
387  // new format, use the integer flag after the file name
388  os = (TObjString*)oa->At(1);
389  fTrigScalersToOCDB |= (os->GetString()).Atoi();
390  } else {
391  // old format, transfer anyway
392  fTrigScalersToOCDB |= 1;
393  }
394  }
395 
396  }
397 
398  if ( regionalFile || localFile || globalFile || lutFile || trigScalFile)
399  {
400  Master()->Log(Form("Will have to read the following file types:"));
401  if ( globalFile) Master()->Log(Form("GLOBAL (%d)",fGlobalConfigToOCDB));
402  if ( regionalFile ) Master()->Log(Form("REGIONAL (%d)",fRegionalConfigToOCDB));
403  if ( localFile) Master()->Log(Form("LOCAL (%d)",fLocalMasksToOCDB));
404  if ( lutFile ) Master()->Log(Form("LUT (%d)",fLUTToOCDB));
405  if ( trigScalFile ) Master()->Log(Form("TRIGSCAL (%d)",fTrigScalersToOCDB));
406  }
407 }
408 
Bool_t ReadLUT(const char *lutFileToRead, AliMUONTriggerLut &lut)
AliMUONVStore * fLocalMasks
! local masks
The class defines the configuration of global crate.
TString GetFileName(const char *fid) const
AliMUONPreprocessor * Master() const
Return the pointer to our master.
#define TObjArray
virtual Int_t GetSize() const =0
The number of objects stored.
Bool_t fRegionalConfigToOCDB
! to store in the OCDB
Bool_t fGlobalConfigToOCDB
! to store in the OCDB
AliMUONRegionalTriggerConfig * fRegionalConfig
! regional config
void WhichFilesToRead(const char *exportedFiles, Bool_t &globalFile, Bool_t &regionalFile, Bool_t &localFile, Bool_t &lutFile, Bool_t &trigScalFile)
Bool_t fTrigScalersToOCDB
! to store in the OCDB
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
Bool_t ReadTrigScalers(const char *scfile, TClonesArray &scalers) const
Handles read/write of masks and LUT to/from online files.
Base class for a shuttle sub-task for MUON (either TRK or TRG)
TTimeStamp startTime(2009, 8, 7, 0, 0, 0)
AliMUONGlobalCrateConfig * fGlobalConfig
! global config
Implementation of AliMUONVSubprocessor for MUON TRK masks.
const char * GetFile(Int_t system, const char *id, const char *source)
Publish AliPreprocessor::GetFile function.
Bool_t Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
Int_t TestFile(const char *baseName, Bool_t shouldBeThere) const
void Log(const char *message)
Publish AliPreprocessor::Log function.
static Int_t TotalNofLocalBoards()
Return total number of trigger local boards.
Implementation of AliMUONVStore.
Bool_t fLUTToOCDB
! to store in the OCDB
UInt_t Process(TMap *dcsAliasMap)
Process this sub-task.
TList * GetFileSources(Int_t system, const char *id)
Publish AliPreprocessor::GetFileSources function.
Bool_t fLocalMasksToOCDB
! to store in the OCDB
TClonesArray * fTrigScalers
! trigger scalers
Bool_t Store(const char *pathLevel2, const char *pathLevel3, TObject *object, AliCDBMetaData *metaData, Int_t validityStart=0, Bool_t validityInfinite=kFALSE)
Publish AliPreprocessor::Store function.
AliMUONTriggerLut * fLUT
! look-up table(s)
Shuttle preprocessor for MUON subsystems (TRK and TRG)
void Invalidate()
Mark as invalid.
MUON trigger look up table class.
Bool_t ReadConfig(const char *localFile, const char *regionalFile, const char *globalFile, AliMUONVStore *localMasks, AliMUONRegionalTriggerConfig *regionalConfig, AliMUONGlobalCrateConfig *globalConfig)
The class defines the properties of regional trigger crate.