#include "AliCDBMetaData.h"
#include "AliLog.h"
#include "AliMUON1DArray.h"
+#include "AliMUONGlobalCrateConfig.h"
+#include "AliMUONRegionalTriggerConfig.h"
#include "AliMUONCalibParamNI.h"
#include "AliMUONPreprocessor.h"
#include "AliMUONTriggerIO.h"
: AliMUONVSubprocessor(master,
"Triggers",
"Upload MUON Trigger masks and LUT to OCDB"),
-fRegionalMasks(0x0),
+fRegionalConfig(0x0),
fLocalMasks(0x0),
-fGlobalMasks(0x0),
+fGlobalConfig(0x0),
fLUT(0x0)
{
/// default ctor
AliMUONTriggerSubprocessor::~AliMUONTriggerSubprocessor()
{
/// dtor
- delete fRegionalMasks;
+ delete fRegionalConfig;
delete fLocalMasks;
- delete fGlobalMasks;
+ delete fGlobalConfig;
delete fLUT;
}
{
/// When starting a new run, reads in the trigger online files.
+ // First thing to do (after cleanup, that is), is to check whether the DA
+ // was alive or not. If it was, it should have put the "MtgCurrent.dat" file
+ // on the FXS.
+ //
+
+ Bool_t da(kTRUE);
+
+ TString exportedFiles(gSystem->ExpandPathName(GetFileName("EXPORTED").Data()));
+
+ if ( exportedFiles == "" )
+ {
+ Master()->Log("exported files not specified !");
+ da = kFALSE;
+ }
+
+ if ( gSystem->AccessPathName(exportedFiles.Data(),kFileExists) ) // mind the strange return value convention of that method !
+ {
+ Master()->Log(Form("%s is not there !",exportedFiles.Data()));
+ da = kFALSE;
+ }
+
+ if (!da)
+ {
+ Master()->Log("FATAL ERROR : DA does not seem to have been run !!!");
+ Master()->Invalidate();
+ return;
+ }
+
+ // OK. We have an exportedFiles.dat file at hand.
+ // Read it to know what other files should be there.
+
+ Bool_t regionalFile(kFALSE);
+ Bool_t globalFile(kFALSE);
+ Bool_t localFile(kFALSE);
+ Bool_t lutFile(kFALSE);
+
+ WhichFilesToRead(GetFileName("EXPORTED").Data(),
+ globalFile,regionalFile,localFile,lutFile);
+
+ delete fRegionalConfig; fRegionalConfig = 0x0;
+ delete fLocalMasks; fLocalMasks = 0x0;
+ delete fGlobalConfig; fGlobalConfig = 0x0;
+ delete fLUT; fLUT = 0x0;
+
Master()->Log(Form("Reading trigger masks for Run %d startTime %ld endTime %ld",
run,startTime,endTime));
- delete fRegionalMasks;
- delete fLocalMasks;
- delete fGlobalMasks;
+ Int_t check =
+ TestFile("REGIONAL",regionalFile) +
+ TestFile("LOCAL",localFile) +
+ TestFile("GLOBAL",globalFile) +
+ TestFile("LUT",lutFile);
+
+ if ( check )
+ {
+ Master()->Log("Could not read some input file(s). Aborting");
+ Master()->Invalidate();
+ return;
+ }
- fRegionalMasks = new AliMUON1DArray(16);
- fLocalMasks = new AliMUON1DArray(AliMpConstants::NofLocalBoards()+1);
- fGlobalMasks = 0x0; // new AliMUONCalibParamNI(1,16,1,0,0);
+ if ( regionalFile ) fRegionalConfig = new AliMUONRegionalTriggerConfig();
+ if ( localFile ) fLocalMasks = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
+ if ( globalFile ) fGlobalConfig = new AliMUONGlobalCrateConfig();
AliMUONTriggerIO tio;
- tio.ReadMasks(GetFileName("LOCAL").Data(),
- GetFileName("REGIONAL").Data(),
- GetFileName("GLOBAL").Data(),
- fLocalMasks,fRegionalMasks,fGlobalMasks);
+ Bool_t ok = tio.ReadConfig(GetFileName("LOCAL").Data(),
+ GetFileName("REGIONAL").Data(),
+ GetFileName("GLOBAL").Data(),
+ fLocalMasks,fRegionalConfig,fGlobalConfig);
+
+ if (!ok)
+ {
+ Master()->Log("ERROR : ReadConfig failed");
+ delete fLocalMasks;
+ delete fRegionalConfig;
+ delete fGlobalConfig;
+ fLocalMasks = 0x0;
+ fRegionalConfig = 0x0;
+ fGlobalConfig = 0x0;
+ }
- delete fLUT;
- fLUT = 0x0; // new AliMUONTriggerLut;
+ if ( lutFile )
+ {
+ fLUT = new AliMUONTriggerLut;
-// Master()->Log(Form("Reading trigger LUT for Run %d startTime %ld endTime %ld",
-// run,startTime,endTime));
-// tio.ReadLut(lutFile,fLUT);
+ Master()->Log(Form("Reading trigger LUT for Run %d startTime %ld endTime %ld",
+ run,startTime,endTime));
+
+ ok = tio.ReadLUT(GetFileName("LUT").Data(),*fLUT);
+
+ if (!ok)
+ {
+ Master()->Log("ERROR : ReadLUT failed");
+ delete fLUT;
+ fLUT = 0x0;
+ }
+ }
}
//_____________________________________________________________________________
{
/// Store the trigger masks into the CDB
- if ( !fGlobalMasks && !fRegionalMasks && !fLocalMasks && !fLUT )
+ if ( !fGlobalConfig && !fRegionalConfig && !fLocalMasks && !fLUT )
{
// nothing to do
return 0;
}
- Master()->Log(Form("N global = %d N regional = %d N local %d",
- (fGlobalMasks ? 1 : 0 ),
- (fRegionalMasks ? fRegionalMasks->GetSize() : 0 ),
- (fLocalMasks ? fLocalMasks->GetSize() : 0 )));
+ Master()->Log(Form("N global = %d N regional = %d N local %d N lut %d",
+ (fGlobalConfig ? 1 : 0 ),
+ (fRegionalConfig ? fRegionalConfig->GetNofTriggerCrates() : 0 ),
+ (fLocalMasks ? fLocalMasks->GetSize() : 0 ),
+ (fLUT ? 1 : 0)));
AliCDBMetaData metaData;
metaData.SetBeamPeriod(0);
Bool_t result3(kTRUE);
Bool_t result4(kTRUE);
- if ( fGlobalMasks )
+ if ( fGlobalConfig )
{
- result1 = Master()->Store("Calib", "GlobalTriggerBoardMasks", fGlobalMasks,
+ result1 = Master()->Store("Calib", "GlobalTriggerCrateConfig", fGlobalConfig,
&metaData, 0, validToInfinity);
}
- if ( fRegionalMasks && fRegionalMasks->GetSize() > 0 )
+ if ( fRegionalConfig && fRegionalConfig->GetNofTriggerCrates() > 0 )
{
- result2 = Master()->Store("Calib", "RegionalTriggerBoardMasks", fRegionalMasks,
+ result2 = Master()->Store("Calib", "RegionalTriggerConfig", fRegionalConfig,
&metaData, 0, validToInfinity);
}
&metaData, 0, validToInfinity);
}
- return ( result1 != kTRUE && result2 != kTRUE && result3 != kTRUE && result4 != kTRUE ); // return 0 if everything is ok.
+ return ( result1 != kTRUE || result2 != kTRUE || result3 != kTRUE || result4 != kTRUE ); // return 0 if everything is ok.
}
+
+//_____________________________________________________________________________
+Int_t
+AliMUONTriggerSubprocessor::TestFile(const char* baseName, Bool_t shouldBeThere) const
+{
+ /// Check if required file can be accessed
+ if (!shouldBeThere) return 0; // all is ok
+
+ TString fileName(gSystem->ExpandPathName(GetFileName(baseName).Data()));
+
+ if ( gSystem->AccessPathName(fileName.Data(),kFileExists) )
+ {
+ // mind the strange return value convention of that method !
+ Master()->Log(Form("File %s does not exist",fileName.Data()));
+ return 1; // this is an error
+ }
+ return 0; // all is ok.
+}
+
+//_____________________________________________________________________________
+void
+AliMUONTriggerSubprocessor::WhichFilesToRead(const char* exportedFiles,
+ Bool_t& globalFile,
+ Bool_t& regionalFile,
+ Bool_t& localFile,
+ Bool_t& lutFile) const
+{
+ /// From the exportedFiles file, determine which other files will need
+ /// to be read in
+ ifstream in(gSystem->ExpandPathName(exportedFiles));
+
+ globalFile = kFALSE;
+ regionalFile = kFALSE;
+ localFile = kFALSE;
+ lutFile = kFALSE;
+
+ char line[1024];
+
+ while ( in.getline(line,1024,'\n') )
+ {
+ TString sline(line);
+ sline.ToUpper();
+
+ if ( sline.Contains("REGIONAL") ) regionalFile = kTRUE;
+ if ( sline.Contains("LUT") ) lutFile = kTRUE;
+ if ( sline.Contains("LOCAL") && sline.Contains("MASK") ) localFile = kTRUE;
+ if ( sline.Contains("GLOBAL") ) globalFile = kTRUE;
+ }
+
+ if ( regionalFile || localFile || globalFile || lutFile )
+ {
+ Master()->Log(Form("Will have to read the following file types:"));
+ if ( globalFile) Master()->Log("GLOBAL");
+ if ( regionalFile ) Master()->Log("REGIONAL");
+ if ( localFile) Master()->Log("LOCAL");
+ if ( lutFile ) Master()->Log("LUT");
+ }
+}
+