]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerSubprocessor.cxx
Improved error handling
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerSubprocessor.cxx
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 "AliMUONCalibParamNI.h"
24 #include "AliMUONPreprocessor.h"
25 #include "AliMUONTriggerIO.h"
26 #include "AliMUONTriggerLut.h"
27 #include "AliMpConstants.h"
28 #include <Riostream.h>
29 #include <TList.h>
30 #include <TObjString.h>
31 #include <TSystem.h>
32
33 /// \class AliMUONTriggerSubprocessor
34 ///
35 /// Implementation of AliMUONVSubprocessor for MUON trigger system
36 ///
37 /// Reads masks and LUT online files to feed the OCDB
38 ///
39 /// \author L. Aphecetche
40
41 /// \cond CLASSIMP
42 ClassImp(AliMUONTriggerSubprocessor)
43 /// \endcond
44
45 //_____________________________________________________________________________
46 AliMUONTriggerSubprocessor::AliMUONTriggerSubprocessor(AliMUONPreprocessor* master)
47 : AliMUONVSubprocessor(master,
48                        "Triggers",
49                        "Upload MUON Trigger masks and LUT to OCDB"),
50 fRegionalMasks(0x0),
51 fLocalMasks(0x0),
52 fGlobalMasks(0x0),
53 fLUT(0x0)
54 {
55   /// default ctor
56 }
57
58 //_____________________________________________________________________________
59 AliMUONTriggerSubprocessor::~AliMUONTriggerSubprocessor()
60 {
61   /// dtor
62   delete fRegionalMasks;
63   delete fLocalMasks;
64   delete fGlobalMasks;
65   delete fLUT;
66 }
67
68 //_____________________________________________________________________________
69 TString
70 AliMUONTriggerSubprocessor::GetFileName(const char* fid) const
71 {
72   /// Get filename for a given id
73   
74   const Int_t kSystem = AliMUONPreprocessor::kDAQ;
75   
76   TList* sources = Master()->GetFileSources(kSystem,fid);
77   if ( sources && sources->GetSize() == 1 ) 
78   {
79     return Master()->GetFile(kSystem,fid,static_cast<TObjString*>(sources->First())->GetName());
80   }
81   return "";
82 }
83
84 //_____________________________________________________________________________
85 void 
86 AliMUONTriggerSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
87 {
88   /// When starting a new run, reads in the trigger online files.
89   
90   // First thing to do (after cleanup, that is), is to check whether the DA
91   // was alive or not. If it was, it should have put the "MtgCurrent.dat" file
92   // on the FXS. 
93   //
94   
95   Bool_t da(kTRUE);
96   
97   TString current(gSystem->ExpandPathName(GetFileName("CURRENT").Data()));
98   
99   if ( current == "" ) 
100   {
101     Master()->Log("CURRENT file not specified");
102     da = kFALSE;
103   }
104   
105   if ( gSystem->AccessPathName(current.Data(),kFileExists) ) // mind the strange return value convention of that method !
106   {
107     Master()->Log(Form("%s is not there !",current.Data()));
108     da = kFALSE;
109   }
110   
111   if (!da)
112   {
113     Master()->Log("FATAL ERROR : DA does not seem to have been run !!!");
114     Master()->Invalidate();
115     return;
116   }
117   
118   delete fRegionalMasks; fRegionalMasks = 0x0;
119   delete fLocalMasks; fLocalMasks = 0x0;
120   delete fGlobalMasks; fGlobalMasks = 0x0;
121   delete fLUT; fLUT = 0x0;
122   
123   Master()->Log(Form("Reading trigger masks for Run %d startTime %ld endTime %ld",
124                      run,startTime,endTime));
125     
126   fRegionalMasks = new AliMUON1DArray(16);
127   fLocalMasks = new AliMUON1DArray(AliMpConstants::NofLocalBoards()+1);
128   fGlobalMasks = 0x0; // new AliMUONCalibParamNI(1,16,1,0,0);
129
130   AliMUONTriggerIO tio;
131   
132   Bool_t ok = tio.ReadMasks(GetFileName("LOCAL").Data(),
133                             GetFileName("REGIONAL").Data(),
134                             GetFileName("GLOBAL").Data(),
135                             fLocalMasks,fRegionalMasks,fGlobalMasks);
136   
137   if (!ok)
138   {
139     Master()->Log("ERROR : ReadMasks failed");
140     delete fLocalMasks;
141     delete fRegionalMasks;
142     delete fGlobalMasks;
143     fLocalMasks = 0x0;
144     fRegionalMasks = 0x0;
145     fGlobalMasks = 0x0;
146   }
147
148   fLUT = new AliMUONTriggerLut;
149     
150   Master()->Log(Form("Reading trigger LUT for Run %d startTime %ld endTime %ld",
151                      run,startTime,endTime));
152   
153   ok = tio.ReadLUT(GetFileName("LUT").Data(),*fLUT);
154
155   if (!ok)
156   {
157     Master()->Log("ERROR : ReadLUT failed");
158     delete fLUT;
159     fLUT = 0x0;
160   }
161 }
162
163 //_____________________________________________________________________________
164 UInt_t 
165 AliMUONTriggerSubprocessor::Process(TMap* /*dcsAliasMap*/)
166 {
167   /// Store the trigger masks into the CDB
168   
169   if ( !fGlobalMasks && !fRegionalMasks && !fLocalMasks && !fLUT )
170   {
171     // nothing to do
172     return 0;
173   }
174   
175   Master()->Log(Form("N global = %d N regional = %d N local %d",                     
176                      (fGlobalMasks ? 1 : 0 ),
177                      (fRegionalMasks ? fRegionalMasks->GetSize() : 0 ),
178                      (fLocalMasks ? fLocalMasks->GetSize() : 0 )));
179   
180   AliCDBMetaData metaData;
181         metaData.SetBeamPeriod(0);
182         metaData.SetResponsible("MUON TRG");
183         metaData.SetComment("Computed by AliMUONTriggerSubprocessor $Id$");
184   
185   Bool_t validToInfinity = kTRUE;
186
187         Bool_t result1(kTRUE);
188   Bool_t result2(kTRUE);
189   Bool_t result3(kTRUE);
190   Bool_t result4(kTRUE);
191   
192   if ( fGlobalMasks ) 
193   {
194     result1 = Master()->Store("Calib", "GlobalTriggerBoardMasks", fGlobalMasks, 
195                               &metaData, 0, validToInfinity);
196   }
197   
198   if ( fRegionalMasks && fRegionalMasks->GetSize() > 0 )
199   {
200     result2 = Master()->Store("Calib", "RegionalTriggerBoardMasks", fRegionalMasks, 
201                               &metaData, 0, validToInfinity);
202   }
203   
204   if ( fLocalMasks && fLocalMasks->GetSize() > 0 ) 
205   {
206     result3 = Master()->Store("Calib", "LocalTriggerBoardMasks", fLocalMasks, 
207                               &metaData, 0, validToInfinity);
208   }
209
210   if ( fLUT )
211   {
212     result4 = Master()->Store("Calib", "TriggerLut", fLUT, 
213                               &metaData, 0, validToInfinity);
214   }
215   
216   return ( result1 != kTRUE && result2 != kTRUE && result3 != kTRUE && result4 != kTRUE ); // return 0 if everything is ok.  
217 }