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