]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONTriggerCrateStore.cxx
In AliMUONAlignment: Coverity fixes
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerCrateStore.cxx
CommitLineData
30dd09e2 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 "AliMUONTriggerCrateStore.h"
630711ed 19#include "AliMpExMapIterator.h"
30dd09e2 20#include "AliMUONTriggerCrate.h"
21#include "AliMUONLocalTriggerBoard.h"
22#include "AliMUONRegionalTriggerBoard.h"
92c23b09 23#include "AliMUONRegionalTriggerConfig.h"
24#include "AliMUONGlobalCrateConfig.h"
25#include "AliMUONTriggerCrateConfig.h"
26#include "AliMUONCalibrationData.h"
27#include "AliMUONTriggerLut.h"
ac809573 28
29#include "AliMpTriggerCrate.h"
30#include "AliMpLocalBoard.h"
31#include "AliMpDDLStore.h"
30dd09e2 32#include "AliMpExMap.h"
30dd09e2 33#include "AliLog.h"
ac809573 34
35#include <TString.h>
36#include <TSystem.h>
37#include <Riostream.h>
30dd09e2 38
b785c4bd 39#include <cstdio>
40
3d1463c8 41//-----------------------------------------------------------------------------
30dd09e2 42/// \class AliMUONTriggerCrateStore
43///
44/// A container of trigger crate objects that offers iteration
45/// over both the crates themselves and the local boards they contain
46///
47/// \author Laurent Aphecetche
3d1463c8 48//-----------------------------------------------------------------------------
30dd09e2 49
5398f946 50/// \cond CLASSIMP
30dd09e2 51ClassImp(AliMUONTriggerCrateStore)
5398f946 52/// \endcond
30dd09e2 53
54//_____________________________________________________________________________
55AliMUONTriggerCrateStore::AliMUONTriggerCrateStore()
56: TObject(),
57fCrates(0x0),
630711ed 58fLocalBoards(0x0)
30dd09e2 59{
5398f946 60/// Default constructor
30dd09e2 61}
62
63//_____________________________________________________________________________
64AliMUONTriggerCrateStore::~AliMUONTriggerCrateStore()
65{
5398f946 66/// Destructor
30dd09e2 67 delete fCrates;
68 delete fLocalBoards;
69}
70
71//_____________________________________________________________________________
72void
73AliMUONTriggerCrateStore::AddCrate(const char *name)
74{
75 /// create and add a crate to our map
76 if (!fCrates)
77 {
78 AliError("Object not properly initialized");
79 return;
80 }
81
82 AliDebug(1,Form("Adding crate %s",name));
83 TObject* there = fCrates->GetValue(name);
84 if (there)
85 {
86 AliError(Form("Cannot add crate %s because it's already there !",name));
87 }
88 else
89 {
90 fCrates->Add(name,new AliMUONTriggerCrate(name,17));
91 }
92}
93
94//_____________________________________________________________________________
95AliMUONLocalTriggerBoard*
96AliMUONTriggerCrateStore::LocalBoard(Int_t boardNumber) const
97{
98 /// return a board by number
99
100 if ( !fLocalBoards )
101 {
102 AliError("Object not properly initialized");
103 return 0x0;
104 }
105
106 return static_cast<AliMUONLocalTriggerBoard*>(fLocalBoards->GetValue(boardNumber));
107}
108
630711ed 109//_____________________________________________________________________________
110TIterator*
111AliMUONTriggerCrateStore::CreateCrateIterator() const
112{
113 /// Create iterator over crates
114
115 return fCrates ? fCrates->CreateIterator() : 0x0;
116}
117
118//_____________________________________________________________________________
119TIterator*
120AliMUONTriggerCrateStore::CreateLocalBoardIterator() const
121{
122 /// Create iterator over local boards
123
124 return fLocalBoards ? fLocalBoards->CreateIterator() : 0x0;
125}
126
30dd09e2 127//_____________________________________________________________________________
128AliMUONTriggerCrate*
129AliMUONTriggerCrateStore::Crate(const char *name) const
130{
131 /// return a crate by name
132 if ( !fCrates )
133 {
134 AliError("Object not properly initialized");
135 return 0x0;
136 }
137 return static_cast<AliMUONTriggerCrate*>(fCrates->GetValue(name));
138}
139
ac809573 140// to be removed once AliMUONDigitMaker is linked with new mapping
aa6ecf89 141//_____________________________________________________________________________
142AliMUONTriggerCrate*
143AliMUONTriggerCrateStore::Crate(Int_t ddl, Int_t reg) const
144{
145 /// return a crate by name
146 if ( !fCrates )
147 {
148 AliError("Object not properly initialized");
149 return 0x0;
150 }
151 TString name = GetCrateName(ddl, reg);
152 return static_cast<AliMUONTriggerCrate*>(fCrates->GetValue(name.Data()));
153}
ac809573 154//____________________________________________________________________
aa6ecf89 155TString AliMUONTriggerCrateStore::GetCrateName(Int_t ddl, Int_t reg) const
156{
71a2d3aa 157 /// set crate name from DDL & reg number
aa6ecf89 158
159 Char_t name[10];
160 switch(reg) {
161 case 0:
162 case 1:
b785c4bd 163 snprintf(name,10,"%d", reg+1);
aa6ecf89 164 break;
165 case 2:
166 strcpy(name, "2-3");
167 break;
168 case 3:
169 case 4:
170 case 5:
171 case 6:
172 case 7:
b785c4bd 173 snprintf(name,10,"%d", reg);
aa6ecf89 174 break;
175 }
176
177 // crate Right for first DDL
178 if (ddl == 0)
b785c4bd 179 strncat(name, "R", 1);
aa6ecf89 180 else
b785c4bd 181 strncat(name, "L", 1);
aa6ecf89 182
183 return TString(name);
184}
30dd09e2 185//_____________________________________________________________________________
186Int_t
187AliMUONTriggerCrateStore::NumberOfCrates() const
188{
189 /// Number of crates we're holding
190 if ( fCrates ) return fCrates->GetSize();
191 return 0;
192}
193
194//_____________________________________________________________________________
195Int_t
196AliMUONTriggerCrateStore::NumberOfLocalBoards() const
197{
198 /// Number of local boards we're holding
199 if ( fLocalBoards ) return fLocalBoards->GetSize();
200 return 0;
201}
202
203//_____________________________________________________________________________
204void
92c23b09 205AliMUONTriggerCrateStore::ReadFromFile(AliMUONCalibrationData* calibData)
30dd09e2 206{
92c23b09 207 /// create crate and local board objects from mapping & calib (Ch.F)
630711ed 208 fCrates = new AliMpExMap;
6e241007 209 fCrates->SetOwner(kTRUE);
630711ed 210 fLocalBoards = new AliMpExMap;
6e241007 211 fLocalBoards->SetOwner(kFALSE);
30dd09e2 212
92c23b09 213
214 AliMUONTriggerLut* lut = calibData->TriggerLut();
ac809573 215
92c23b09 216 if (!lut)
217 AliWarning("No valid trigger LUT in CDB");
218
219 AliMUONRegionalTriggerConfig* regionalConfig = calibData->RegionalTriggerConfig();
fc2293be 220 if (!regionalConfig) {
221 AliError("No valid regional trigger configuration in CDB");
222 return;
223 }
92c23b09 224
630711ed 225 TIter next(AliMpDDLStore::Instance()->GetRegionalTrigger()->CreateCrateIterator());
226 AliMpTriggerCrate* crateMapping;
92c23b09 227
630711ed 228 while ( ( crateMapping = static_cast<AliMpTriggerCrate*>(next()) ) )
5a92f8e6 229 {
92c23b09 230
ac809573 231 TString crateName = crateMapping->GetName();
232 AliMUONTriggerCrate *crate = Crate(crateName.Data());
92c23b09 233
234 AliMUONTriggerCrateConfig* crateConfig = regionalConfig->FindTriggerCrate(crateName);
ac809573 235
236 if (!crate)
30dd09e2 237 {
ac809573 238 AddCrate(crateName.Data());
239 crate = Crate(crateName.Data());
240 AliDebug(3, Form("crate name %s\n", crateName.Data()));
241 AliMUONRegionalTriggerBoard *rboard = new AliMUONRegionalTriggerBoard();
242 crate->AddBoard(rboard, 0);
243 }
244
245 for(Int_t iLocal = 0; iLocal < crateMapping->GetNofLocalBoards(); ++iLocal) {
92c23b09 246
ac809573 247 Int_t localBoardId = crateMapping->GetLocalBoardId(iLocal);
248 if (!localBoardId) continue; //empty slot, should not happen
249
250 AliMpLocalBoard* localBoardMapping = AliMpDDLStore::Instance()->GetLocalBoard(localBoardId);
251 AliDebug(3, Form("local name %s id %d\n", localBoardMapping->GetName(), localBoardId));
92c23b09 252
ac809573 253 Int_t slot = localBoardMapping->GetSlot();
92c23b09 254 AliMUONLocalTriggerBoard *board = new AliMUONLocalTriggerBoard(localBoardMapping);
255 board->SetCoinc44(crateConfig->GetCoinc());
256 board->SetLUT(lut);
ac809573 257
92c23b09 258
ac809573 259 if (localBoardMapping->IsNotified()) {
260 fLocalBoards->Add(localBoardId, board);
5a92f8e6 261 }
92c23b09 262
ac809573 263 crate->AddBoard(board, slot);
92c23b09 264
ac809573 265 } // iLocal
266 } // while
30dd09e2 267}
92c23b09 268