]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpDDLStore.cxx
New class which defines the properties of regional trigger crate;
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpDDLStore.cxx
CommitLineData
f0c62051 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 *
354e70ca 12 * about the suitability of this software for any purpose. It is *
f0c62051 13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16// $Id$
17// $MpId: AliMpDDLStore.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
18// Category: management
3d1463c8 19
20//-----------------------------------------------------------------------------
f0c62051 21// Class AliMpDDLStore
22// --------------------
23// The top container class for DDLs, det elements and bus patched
24// It provides acces to DDL, det element and bus patches objects
25// via various characteristics.
26// Authors: Ivana Hrivnacova, IPN Orsay
27// Christian Finck, SUBATECH Nantes
3d1463c8 28//-----------------------------------------------------------------------------
61c370dd 29
f0c62051 30#include "AliMpDDLStore.h"
61c370dd 31#include "AliMpConstants.h"
f0c62051 32#include "AliMpDEStore.h"
33#include "AliMpDDL.h"
34#include "AliMpFiles.h"
35#include "AliMpHelper.h"
36#include "AliMpDEManager.h"
37#include "AliMpDetElement.h"
38#include "AliMpBusPatch.h"
61c370dd 39#include "AliMpTriggerCrate.h"
40#include "AliMpLocalBoard.h"
42d368d0 41#include "AliMpSegmentation.h"
42#include "AliMpVSegmentation.h"
354e70ca 43#include "AliMpStringObjMap.h"
472027a9 44
f0c62051 45#include "AliLog.h"
46
472027a9 47
f0c62051 48#include <Riostream.h>
42d368d0 49#include <TList.h>
61c370dd 50#include <TObjArray.h>
51#include <TString.h>
52#include <TObjString.h>
5f377a9a 53#include <TClass.h>
f5820f28 54#include <TSystem.h>
f0c62051 55
56/// \cond CLASSIMP
57ClassImp(AliMpDDLStore)
58/// \endcond
59
60AliMpDDLStore* AliMpDDLStore::fgInstance = 0;
61const Int_t AliMpDDLStore::fgkNofDDLs = 20;
61c370dd 62const Int_t AliMpDDLStore::fgkNofTriggerDDLs = 2;
f0c62051 63
64//
65// static methods
66//
67
68//______________________________________________________________________________
40c8e44b 69AliMpDDLStore* AliMpDDLStore::Instance(Bool_t warn)
f0c62051 70{
40c8e44b 71 /// Create the DDL store if it does not yet exist
72 /// and return its instance
f0c62051 73
40c8e44b 74 if ( ! fgInstance && warn ) {
75 AliWarningClass("DDL Store has not been loaded");
76 }
77
78 return fgInstance;
79}
5f377a9a 80
81//______________________________________________________________________________
40c8e44b 82AliMpDDLStore* AliMpDDLStore::ReadData(Bool_t warn)
5f377a9a 83{
40c8e44b 84 /// Load the DDL store from ASCII data files
85 /// and return its instance
5f377a9a 86
40c8e44b 87 if ( fgInstance ) {
88 if ( warn )
89 AliWarningClass("DDL Store has been already loaded");
90 return fgInstance;
91 }
5f377a9a 92
40c8e44b 93 AliInfoClass("Reading DDL Store from ASCII files.");
94
95 fgInstance = new AliMpDDLStore();
96 return fgInstance;
97}
f0c62051 98
99//
100// ctors, dtor
101//
102
103//______________________________________________________________________________
104AliMpDDLStore::AliMpDDLStore()
40c8e44b 105 : TObject(),
106 fDDLs(fgkNofDDLs+fgkNofTriggerDDLs), // FIXEME
107 fBusPatches(true),
108 fTriggerCrates(true),
109 fLocalBoards(true),
110 fManuList12(),
111 fManuBridge2(),
112 fGlobalCrate(new AliMpGlobalCrate())
113{
114 /// Standard constructor
115
116 AliDebug(1,"");
117 fDDLs.SetOwner(true);
118 fBusPatches.SetOwner(true);
119 fBusPatches.SetSize(900);
120
121 fTriggerCrates.SetOwner(true);
122 fTriggerCrates.SetSize(16);
123
124 fLocalBoards.SetOwner(true);
125 fLocalBoards.SetSize(242); // included non-identied board
126
472027a9 127
40c8e44b 128 // Load segmentation & DE store data
129 if ( ! AliMpSegmentation::Instance(false) )
130 AliMpSegmentation::ReadData(true);
131
132 // Create all detection elements
133 ReadDDLs();
134 ReadTriggerDDLs();
135 SetManus();
136 SetPatchModules();
137 SetBusPatchLength();
f0c62051 138}
139
140//______________________________________________________________________________
141AliMpDDLStore::AliMpDDLStore(TRootIOCtor* /*ioCtor*/)
40c8e44b 142 : TObject(),
143 fDDLs(),
144 fBusPatches(),
145 fTriggerCrates(true),
146 fLocalBoards(true),
147 fGlobalCrate()
148{
149 /// Constructor for IO
f0c62051 150
40c8e44b 151 AliDebug(1,"");
f0c62051 152
40c8e44b 153 fgInstance = this;
f0c62051 154}
155
156
157//______________________________________________________________________________
40c8e44b 158AliMpDDLStore::~AliMpDDLStore()
f0c62051 159{
40c8e44b 160 /// Destructor
f0c62051 161
40c8e44b 162 AliDebug(1,"");
f0c62051 163
40c8e44b 164 // DDL objects are deleted with fDDLs
165 // Bus patches objects are deleted with fBusPatches
166
167 fgInstance = 0;
168 delete fGlobalCrate;
f0c62051 169}
170
171//
172// private methods
173//
174
42d368d0 175//______________________________________________________________________________
40c8e44b 176Int_t AliMpDDLStore::GetManuListIndex(Int_t detElemId) const
42d368d0 177{
40c8e44b 178 /// Return the index of the manu list for given detElemId
179
180 return AliMpDEManager::GetChamberId(detElemId)*4 + (detElemId % 100);
181}
42d368d0 182
42d368d0 183
184//______________________________________________________________________________
40c8e44b 185Int_t AliMpDDLStore::GetBusPatchIndex(Int_t detElemId, Int_t manuId) const
42d368d0 186{
40c8e44b 187 /// Calculate the index of the buspatch from manuId
42d368d0 188
189 Int_t pos = 0;
190 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
191 static Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane) - 1;
192
193 if( stationType == AliMp::kStation345) {
40c8e44b 194 pos = (manuId & manuMask)/100;
42d368d0 195 } else {
40c8e44b 196 Int_t idx = GetManuListIndex(detElemId);
42d368d0 197
40c8e44b 198 // using array defined from DetElemIdToBusPatch.dat file
199 for (pos = fManuList12[idx].GetSize()-1; pos >= 0; --pos)
200 if ( manuId >= fManuList12[idx].At(pos))
201 break;
42d368d0 202 }
203
204 return pos;
205}
206
f0c62051 207//______________________________________________________________________________
40c8e44b 208Bool_t AliMpDDLStore::ReadGlobalTrigger(AliMpGlobalCrate& crate, const Char_t* globalName)
f0c62051 209{
40c8e44b 210 /// Fill trigger global crate object from ascii file
211 /// put the method static to be used by other class w/o initializing object
212
213 TString infile;
214
215 if (globalName == 0)
216 infile = AliMpFiles::GlobalTriggerBoardMapping();
217 else
218 infile = globalName;
42d368d0 219
f5820f28 220 infile = gSystem->ExpandPathName(infile.Data());
221
40c8e44b 222 ifstream in(infile, ios::in);
f0c62051 223
40c8e44b 224 if (!in) {
f5820f28 225 AliErrorClass(Form("Local Trigger Board Mapping File %s not found", infile.Data()));
226 return kFALSE;
40c8e44b 227 }
f0c62051 228
40c8e44b 229 TArrayI list;
f0c62051 230
40c8e44b 231 char line[255];
232 in.getline(line, 255);
233 TString tmp(AliMpHelper::Normalize(line));
234
235 if (!tmp.Contains(crate.GetName()))
f5820f28 236 {
237 AliErrorClass("Wrong Global Crate File");
238 }
239
40c8e44b 240 in.getline(line, 255);
241 tmp = AliMpHelper::Normalize(line);
242
243 if (tmp.Contains(crate.GetJtagName())) {
244 // vme addr
245 in.getline(line, 255);
246 TString tmp(AliMpHelper::Normalize(line));
247 ULong_t addr;
248 sscanf(tmp.Data(), "%lx", &addr);
249 crate.SetJtagVmeAddr(addr);
250 //AliDebug(1, Form("Jtag Vme Address: 0x%x", addr));
251
252 // clk div, rx phase, read delay
253 in.getline(line, 255);
254 tmp = AliMpHelper::Normalize(line);
255 TArrayI list;
256 AliMpHelper::DecodeName(line, ' ', list);
257 crate.SetJtagClockDiv(list[0]);
258 crate.SetJtagRxPhase(list[1]);
259 crate.SetJtagRdDelay(list[2]);
260 //AliDebug(1, Form("Jtag Clock Div: %d, Rx Phase: %d, Read Delay %d", list[0], list[1], list[2]));
261
262 // enable
263 in.getline(line, 255);
264 tmp = AliMpHelper::Normalize(line);
265 AliMpHelper::DecodeName(line, ' ', list);
266 UChar_t enable = 0;
267 for (Int_t i = 0; i < crate.GetJtagNofLines(); ++i)
268 enable |= (list[i] << i);
269 crate.SetEnableJtag(enable);
270 //AliDebug(1, Form("Jtag Enable: 0x%x", enable));
271
272 for (Int_t i = 0; i < crate.GetJtagNofLines(); ++i) {
273 in.getline(line, 255);
274 for (Int_t j = 0; j < crate.GetJtagNofLines(); ++j) {
275 in.getline(line, 255);
276 tmp = AliMpHelper::Normalize(line);
277 crate.SetJtagCrateName(i*crate.GetJtagNofLines() + j, tmp);
278 //AliDebug(1, Form("Jtag Crate Name: %s", tmp.Data()));
279 }
280 }
281 }
f0c62051 282
40c8e44b 283 in.getline(line, 255);
284 tmp = AliMpHelper::Normalize(line);
285 if (tmp.Contains(crate.GetFirstDarcName())) {
286 // vme addr
287 in.getline(line, 255);
288 TString tmp(AliMpHelper::Normalize(line));
289 ULong_t addr;
290 sscanf(tmp.Data(), "%lx", &addr);
291 crate.SetFirstDarcVmeAddr(addr);
292 //AliDebug(1, Form("First Darc Vme Address: 0x%x", addr));
293
294 // type
295 in.getline(line, 255);
296 tmp = AliMpHelper::Normalize(line);
297 crate.SetFirstDarcType(tmp.Atoi());
298 //AliDebug(1, Form("First Darc Type: %d", tmp.Atoi()));
299
300 // enable
301 in.getline(line, 255);
302 UInt_t item;
303 tmp = AliMpHelper::Normalize(line);
304 sscanf(tmp.Data(), "%x", &item);
305 crate.SetFirstDarcDisable(item);
306 //AliDebug(1, Form("First Darc Enable: 0x%x", item));
307
308 // L0
309 in.getline(line, 255);
310 tmp = AliMpHelper::Normalize(line);
311 sscanf(tmp.Data(), "%x", &item);
312 crate.SetFirstDarcL0Delay(item);
313 //AliDebug(1, Form("First Darc L0 Delay: 0x%x", item));
314
315 // L1
316 in.getline(line, 255);
317 tmp = AliMpHelper::Normalize(line);
318 sscanf(tmp.Data(), "%x", &item);
319 crate.SetFirstDarcL1TimeOut(item);
320 //AliDebug(1, Form("First Darc L1 Time Out: 0x%x", item));
321 }
f0c62051 322
40c8e44b 323 in.getline(line, 255);
324 tmp = AliMpHelper::Normalize(line);
325 if (tmp.Contains(crate.GetSecondDarcName())) {
326 // vme addr
327 in.getline(line, 255);
328 TString tmp(AliMpHelper::Normalize(line));
329 ULong_t addr;
330 sscanf(tmp.Data(), "%lx", &addr);
331 crate.SetSecondDarcVmeAddr(addr);
332 //AliDebug(1, Form("Second Darc Vme Address: 0x%x", addr));
333
334 // type
335 in.getline(line, 255);
336 tmp = AliMpHelper::Normalize(line);
337 crate.SetSecondDarcType(tmp.Atoi());
338 //AliDebug(1, Form("Second Darc Type: %d", tmp.Atoi()));
339
340 // enable
341 in.getline(line, 255);
342 UInt_t item;
343 tmp = AliMpHelper::Normalize(line);
344 sscanf(tmp.Data(), "%x", &item);
345 crate.SetSecondDarcDisable(item);
346 //AliDebug(1, Form("Second Darc Enable: 0x%x", item));
347
348 // L0
349 in.getline(line, 255);
350 tmp = AliMpHelper::Normalize(line);
351 sscanf(tmp.Data(), "%x", &item);
352 crate.SetSecondDarcL0Delay(item);
353 //AliDebug(1, Form("Second Darc L0 Delay: 0x%x", item));
354
355 // L1
356 in.getline(line, 255);
357 tmp = AliMpHelper::Normalize(line);
358 sscanf(tmp.Data(), "%x", &item);
359 crate.SetSecondDarcL1TimeOut(item);
360 //AliDebug(1, Form("Second Darc L1 Time Out: 0x%x", item));
361 }
f0c62051 362
40c8e44b 363 in.getline(line, 255);
364 tmp = AliMpHelper::Normalize(line);
365 if (tmp.Contains(crate.GetGlobalName())) {
366 in.getline(line, 255);
367 TString tmp(AliMpHelper::Normalize(line));
368 ULong_t addr;
369 sscanf(tmp.Data(), "%lx", &addr);
370 crate.SetGlobalVmeAddr(addr);
371 //AliDebug(1, Form("Global Vme Address: 0x%x", addr));
372
373 for (Int_t i = 0; i < crate.GetGlobalNofRegisters(); ++i) {
374 in.getline(line, 255);
375 TString tmp(AliMpHelper::Normalize(line));
376 UInt_t reg;
377 sscanf(tmp.Data(), "%x", &reg);
378 crate.SetGlobalRegister(i, reg);
379 //AliDebug(1, Form("Global Register %d: 0x%x", i, reg));
380 }
381 }
f0c62051 382
40c8e44b 383 in.getline(line, 255);
384 tmp = AliMpHelper::Normalize(line);
385 if (tmp.Contains(crate.GetFetName())) {
386 in.getline(line, 255);
387 TString tmp(AliMpHelper::Normalize(line));
388 ULong_t addr;
389 sscanf(tmp.Data(), "%lx", &addr);
390 crate.SetFetVmeAddr(addr);
391 //AliDebug(1, Form("Fet Vme Address: 0x%x", addr));
392
393 for (Int_t i = 0; i < crate.GetFetNofRegisters(); ++i) {
394 in.getline(line, 255);
395 TString tmp(AliMpHelper::Normalize(line));
396 UInt_t reg;
397 sscanf(tmp.Data(), "%x", &reg);
398 crate.SetFetRegister(i, reg);
399 //AliDebug(1, Form("Fet Register %d: 0x%x", i, reg));
400 }
401 }
f0c62051 402
40c8e44b 403 return kTRUE;
f0c62051 404}
61c370dd 405//______________________________________________________________________________
40c8e44b 406Bool_t AliMpDDLStore::ReadDDLs()
61c370dd 407{
40c8e44b 408 /// Read ddl <-> bus patch file
354e70ca 409
40c8e44b 410 TString infile = AliMpFiles::BusPatchFilePath();
61c370dd 411
61c370dd 412 ifstream in(infile, ios::in);
61c370dd 413 if (!in) {
40c8e44b 414 AliErrorStream() << "Data file " << infile << " not found.";
415 return false;
61c370dd 416 }
61c370dd 417
418 char line[255];
61c370dd 419
40c8e44b 420 while ( in.getline(line,255) ) {
61c370dd 421
40c8e44b 422 if ( line[0] == '#' )
423 continue;
61c370dd 424
40c8e44b 425 TString tmp(AliMpHelper::Normalize(line));
61c370dd 426
40c8e44b 427 TObjArray* stringList = tmp.Tokenize(TString(" "));
354e70ca 428
40c8e44b 429 TString sDE = ((TObjString*)stringList->At(0))->GetString();
430 Int_t idDE = atoi(sDE.Data());
354e70ca 431
40c8e44b 432 if ( ! AliMpDEManager::IsValidDetElemId(idDE, false) ) {
433 AliErrorStream() << "DetElemId "<< idDE << " not valid." << endl;
434 return false;
435 }
354e70ca 436
40c8e44b 437 TString busPatch = ((TObjString*)stringList->At(1))->GetString();
354e70ca 438
439
40c8e44b 440 TString sDDL = ((TObjString*)stringList->At(2))->GetString();
441 Int_t iDDL = atoi(sDDL.Data());
61c370dd 442
40c8e44b 443 if ( iDDL < 0 || iDDL >= fgkNofDDLs ) {
444 AliErrorStream() << "DDL id "<< iDDL << " outside limits." << endl;
445 return false;
446 }
61c370dd 447
40c8e44b 448 AliDebugStream(3)
449 << "idDE " << idDE << " buspatch " << busPatch.Data() << " iDDL " << iDDL
450 << endl;
61c370dd 451
40c8e44b 452 // reading 1st manu Id for each bus patch (station 1 & 2)
453 if(AliMpDEManager::GetStationType(idDE) != AliMp::kStation345) {
61c370dd 454
40c8e44b 455 TString sManu = ((TObjString*)stringList->At(3))->GetString();
456 AliMpHelper::DecodeName(sManu,',',fManuList12[GetManuListIndex(idDE)]);
61c370dd 457
40c8e44b 458 if(AliMpDEManager::GetStationType(idDE) == AliMp::kStation2) {
459 TString sManuBridge = ((TObjString*)stringList->At(4))->GetString();
460 AliMpHelper::DecodeName(sManuBridge,',',fManuBridge2[GetManuListIndex(idDE)]);
461 }
61c370dd 462
40c8e44b 463 }
61c370dd 464
40c8e44b 465 delete stringList;
61c370dd 466
40c8e44b 467 AliMpDDL* ddl = GetDDL(iDDL, false);
468 if ( !ddl) {
469 ddl = new AliMpDDL(iDDL);
470 fDDLs.AddAt(ddl, iDDL);
471 }
472 ddl->AddDE(idDE);
473
474 TArrayI busPatchList;
475 // decoding range of buspatch
476 AliMpHelper::DecodeName(busPatch,';',busPatchList);
477
478 // Update DE
479 AliMpDetElement* de = AliMpDEManager::GetDetElement(idDE);
480 de->SetDdlId(iDDL);
481 // filling buspatch -> idDE
482 for (Int_t i = 0; i < busPatchList.GetSize(); i++) {
483 fBusPatches.Add(busPatchList[i],
484 new AliMpBusPatch(busPatchList[i], idDE, iDDL));
485 de->AddBusPatch(busPatchList[i]);
486 }
487 }
488
489 // Fill bus patch Ids array in DDLs now
490 for ( Int_t i=0; i<fDDLs.GetEntriesFast(); i++ ) {
491 AliMpDDL* ddl = (AliMpDDL*) fDDLs.At(i);
492 ddl->FillBusPatchIds();
61c370dd 493 }
40c8e44b 494
495 in.close();
496 return true;
497}
498//______________________________________________________________________________
499Bool_t AliMpDDLStore::ReadTriggerDDLs()
500{
501 /// create trigger DDL object and Global crate object
502
503 if (!ReadGlobalTrigger(*fGlobalCrate)) return false;
472027a9 504 if (!ReadRegionalTrigger(fTriggerCrates, fLocalBoards, fDDLs)) return false;
40c8e44b 505
506 return true;
507}
508
509//______________________________________________________________________________
472027a9 510Bool_t AliMpDDLStore::ReadRegionalTrigger(AliMpExMap& triggerCrates, AliMpExMap& localBoards,
511 TObjArray& ddls, const Char_t* fileName, Bool_t warn)
40c8e44b 512{
513 /// create trigger DDL object ddl<->Crate<->local board
354e70ca 514
40c8e44b 515 Int_t iDDL = -1;
472027a9 516 TString infile;
517
518 if (fileName == 0)
519 infile = AliMpFiles::LocalTriggerBoardMapping();
520 else
521 infile = fileName;
522
f5820f28 523 infile = gSystem->ExpandPathName(infile.Data());
524
40c8e44b 525 ifstream in(infile, ios::in);
526
527 if (!in) {
f5820f28 528 AliErrorClass(Form("Local Trigger Board Mapping File %s not found", infile.Data()));
40c8e44b 529 return kFALSE;
354e70ca 530 }
531
40c8e44b 532 AliMpLocalBoard* board = 0x0;
533 AliMpTriggerCrate* crate = 0x0;
354e70ca 534
61c370dd 535
40c8e44b 536 Int_t localBoardId = 0;
537 TArrayI list;
538 UShort_t crateId, mask;
539 Int_t mode, coincidence;
540
541 char line[80];
542
543 while (!in.eof())
544 {
472027a9 545 in.getline(line,80);
546 if (!strlen(line)) break;
547 TString crateName(AliMpHelper::Normalize(line));
40c8e44b 548
472027a9 549 in.getline(line,80);
550 sscanf(line,"%hx",&crateId);
40c8e44b 551
472027a9 552 in.getline(line,80);
553 sscanf(line,"%d",&mode);
554
555 in.getline(line,80);
556 sscanf(line,"%d",&coincidence);
557
558 in.getline(line,80);
559 sscanf(line,"%hx",&mask);
560
561
562 // determine ddl number vs crate side
563 if (crateName.Contains("R"))
564 iDDL = fgkNofDDLs; // starts where tracker ends
565 else
566 iDDL = fgkNofDDLs + 1;
40c8e44b 567
472027a9 568 AliMpDDL* ddl = (AliMpDDL*)ddls.At(iDDL);
569 if ( !ddl) {
570 ddl = new AliMpDDL(iDDL);
571 ddls.AddAt(ddl, iDDL);
572 }
573
574 crate = (AliMpTriggerCrate*)triggerCrates.GetValue(crateName.Data());
575 if (!crate)
576 {
577 crate = new AliMpTriggerCrate(crateName.Data(), crateId, mask, mode, coincidence);
578 crate->SetDdlId(iDDL);
579 triggerCrates.Add(crateName.Data(), crate);
580 }
581
582
583 // add trigger crate number for given ddl if not present
584 if ( !ddl->HasTriggerCrateId(crateId) )
585 ddl->AddTriggerCrate(crateId);
586
587
588 Char_t localBoardName[20];
589 Int_t slot;
590 UInt_t switches;
591
592 for ( Int_t i = 0; i < AliMpConstants::LocalBoardNofChannels(); ++i )
593 {
594 if ( (mask >> i ) & 0x1 )
595 {
596 in.getline(line,80);
597 sscanf(line,"%02d %s %03d %03x",&slot,localBoardName,&localBoardId,&switches);
598 board = new AliMpLocalBoard(localBoardId, localBoardName, slot);
599 board->SetSwitch(switches);
600 board->SetCrate(crateName);
601
602 if (localBoardId > AliMpConstants::NofLocalBoards())
603 board->SetNotified(false); // copy cards
604
605 crate->AddLocalBoard(localBoardId);
606
607 list.Reset();
608 AliMpDDL* ddl = (AliMpDDL*)ddls.At(iDDL);
609 if (!ddl)
610 cout << "DDL with Id = " << iDDL << " not defined." << endl;
611
612 // add DE for local board and DDL
613 in.getline(line,80);
614 TString tmp(AliMpHelper::Normalize(line));
615 AliMpHelper::DecodeName(tmp,' ',list);
616
617 for (Int_t i = 0; i < list.GetSize(); ++i) {
618
619 if (list[i])
620 { // skip copy card
621 if (AliMpDEStore::Instance(warn))
622 {
623 AliMpDetElement* de = AliMpDEManager::GetDetElement(list[i]);
624 if (de->GetDdlId() == -1)
625 de->SetDdlId(iDDL);
626
627 if(!ddl->HasDEId(list[i]))
628 ddl->AddDE(list[i]);
629 }
630 }
631 board->AddDE(list[i]);
40c8e44b 632 }
472027a9 633
634 // set copy number and transverse connector
635 in.getline(line,80);
636 tmp = AliMpHelper::Normalize(line);
637 AliMpHelper::DecodeName(tmp,' ',list);
638
639 board->SetInputXfrom(list[0]);
640 board->SetInputXto(list[1]);
641
642 board->SetInputYfrom(list[2]);
643 board->SetInputYto(list[3]);
644
645 board->SetTC(list[4]);
646
647 // add local board into map
648 localBoards.Add(board->GetId(), board);
40c8e44b 649 }
40c8e44b 650 }
472027a9 651
40c8e44b 652 }
61c370dd 653 return kTRUE;
654}
655
42d368d0 656//______________________________________________________________________________
40c8e44b 657Bool_t AliMpDDLStore::SetManus() {
658 /// Set manus for each bus patch
42d368d0 659
660 Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane) - 1;
661
40c8e44b 662 // loop over DDL
42d368d0 663 for (Int_t iDDL = 0; iDDL < fgkNofDDLs; ++iDDL) {
664
40c8e44b 665 AliDebug(3, Form("DDL # %d\n", iDDL));
42d368d0 666
40c8e44b 667 AliMpDDL* ddl = GetDDL(iDDL);
42d368d0 668
40c8e44b 669 // loop over DE in the given DDL
670 for (Int_t detElemIdx = 0; detElemIdx < ddl->GetNofDEs(); ++detElemIdx) {
42d368d0 671
40c8e44b 672 Int_t detElemId = ddl->GetDEId(detElemIdx);
42d368d0 673
40c8e44b 674 AliMpDetElement* detElement = GetDetElement(detElemId);
42d368d0 675
40c8e44b 676 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
42d368d0 677
678
40c8e44b 679 // list of manu per DE on both cathode
680 TList manuList;
681 for ( Int_t cath = 0; cath < 2 ; ++cath ) {
682 const AliMpVSegmentation* seg
683 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(cath));
42d368d0 684
40c8e44b 685 AliMp::PlaneType planeType = detElement->GetPlaneType(AliMp::GetCathodType(cath));
42d368d0 686
40c8e44b 687 TArrayI manus;
688 seg->GetAllElectronicCardIDs(manus);
42d368d0 689
40c8e44b 690 // filling TList manu
691 for ( Int_t im = 0; im < manus.GetSize(); ++im ) {
42d368d0 692
40c8e44b 693 AliMpIntPair* manu = 0x0;
694 if( stationType == AliMp::kStation345)
695 manu = new AliMpIntPair((manus[im] & manuMask), planeType, kTRUE); //remove offset for NB
696 else
697 manu = new AliMpIntPair(manus[im], planeType, kTRUE); //keep offset for NB
42d368d0 698
40c8e44b 699 manuList.Add(manu);
42d368d0 700
40c8e44b 701 detElement->AddManu(manus[im]);
702 }
703 }// cathode
704
705 manuList.Sort(); // sort regardless B or NB plane
42d368d0 706
40c8e44b 707 // filling manu to the corresponding buspatch
708 for (Int_t iEntry = 0; iEntry < manuList.GetEntries(); ++iEntry) {
42d368d0 709
40c8e44b 710 AliMpIntPair* manuPtr = (AliMpIntPair*)manuList.At(iEntry);
42d368d0 711
40c8e44b 712 Int_t manuId = manuPtr->GetFirst();
713 Int_t pos = GetBusPatchIndex(detElemId, manuId);
42d368d0 714
40c8e44b 715 if (pos > detElement->GetNofBusPatches()) {
716 AliError(Form("pos greater %d than size %d manuId %d detElemId %d \n",
717 pos, detElement->GetNofBusPatches(), manuId, detElemId));
718 return false;
719 }
720
721 // get buspatch and fill manus
722 Int_t busPatchId = detElement->GetBusPatchId(pos);
723 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
724
725 if( stationType == AliMp::kStation345) {
726
727 if (manuPtr->GetSecond())
728 busPatch->AddManu(manuId+manuMask+1); // add offset again after sorted
729 else
730 busPatch->AddManu(manuId);
731
732 } else {
733
734 busPatch->AddManu(manuId);
735
736 }
737 }
738
739 manuList.Delete();
740
741 if (AliDebugLevel() == 3) {
742
743 // print out for checking
744 for(Int_t pos = 0; pos < detElement->GetNofBusPatches(); ++pos) {
745 Int_t busPatchId = detElement->GetBusPatchId(pos);
746 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
747 printf("BusPatch: %d\n", busPatch->GetId());
748 for (Int_t iEntry = 0; iEntry < busPatch->GetNofManus(); ++iEntry)
749 printf("manu Id: %d\n", busPatch->GetManuId(iEntry));
750 }
751 }
752
753 } // detection element loop
42d368d0 754 }// DDL loop
755
756 return true;
757}
f0c62051 758
dbc1e34c 759//______________________________________________________________________________
40c8e44b 760Bool_t AliMpDDLStore::SetPatchModules() {
761 /// Compute the number of manu per PCB for each buspatch
dbc1e34c 762
0f30c458 763 AliMpDEIterator it;
764 Bool_t result = true;
dbc1e34c 765
0f30c458 766 for ( it.First(); !it.IsDone(); it.Next() ) {
dbc1e34c 767
40c8e44b 768 AliMpDetElement* detElement = it.CurrentDE();
769
770 for (Int_t i = 0; i < detElement->GetNofBusPatches(); ++i) {
771 AliMpBusPatch* busPatch = GetBusPatch(detElement->GetBusPatchId(i));
772 Bool_t newResult = false;
773 Int_t idDE = busPatch->GetDEId();
774
775 if (AliMpDEManager::GetStationType(idDE) == AliMp::kStation2 )
776 newResult = busPatch->SetNofManusPerModule(fManuBridge2[GetManuListIndex(idDE)].At(i));
777 else
778 newResult = busPatch->SetNofManusPerModule();
779 }
0f30c458 780 }
781
782 return result;
783}
784
785//______________________________________________________________________________
40c8e44b 786Bool_t AliMpDDLStore::SetBusPatchLength() {
787 /// read the buspatch length file and set buspatch length
0f30c458 788
789 TString infile = AliMpFiles::BusPatchLengthFilePath();
790 ifstream in(infile, ios::in);
791 if (!in) {
40c8e44b 792 AliErrorStream() << "Data file " << infile << " not found.";
793 return false;
794 }
0f30c458 795 char line[255];
796
797 for (Int_t iDDL = 0; iDDL < fgkNofDDLs; ++iDDL ) {
40c8e44b 798 AliMpDDL* ddl = GetDDL(iDDL);
0f30c458 799
40c8e44b 800 for (Int_t iBusPatch = 0; iBusPatch < ddl->GetNofBusPatches(); ++iBusPatch) {
0f30c458 801
40c8e44b 802 do {
803 if (!in.getline(line,255)) {
804 AliWarning(Form("Wrong size in bus patch length file; index %d DDL %d",
805 iBusPatch, iDDL));
806 return false;
807 }
808 } while(line[0] == '#');
d9fc467c 809
40c8e44b 810 TString tmp(AliMpHelper::Normalize(line));
d9fc467c 811
40c8e44b 812 TObjArray* stringList = tmp.Tokenize(TString(" "));
d9fc467c 813
40c8e44b 814 TString sLocalBusId = ((TObjString*)stringList->At(0))->GetString();
815 Int_t localBusId = sLocalBusId.Atoi();
d9fc467c 816
40c8e44b 817 TString sLength = ((TObjString*)stringList->At(1))->GetString();
818 Float_t length = sLength.Atof();
0f30c458 819
40c8e44b 820 delete stringList;
821
822 if (localBusId != iBusPatch + 1)
823 AliWarning(Form("Wrong local buspatch id %d instead of %d", iBusPatch+1, localBusId));
824
825 Int_t busPatchId = ddl->GetBusPatchId(iBusPatch);
826 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
827 busPatch->SetCableLength(length);
828 }
0f30c458 829 }
830
831 return true;
dbc1e34c 832}
833
0f30c458 834
61c370dd 835//________________________________________________________________
40c8e44b 836Int_t AliMpDDLStore::GetLocalBoardId(TString name) const {
837 /// return the first board with a given side and line
61c370dd 838
40c8e44b 839 TExMapIter i = fLocalBoards.GetIterator();
61c370dd 840 Long_t key, value;
841 while ( i.Next(key, value) ) {
40c8e44b 842 AliMpLocalBoard* local = (AliMpLocalBoard*)value;
61c370dd 843
40c8e44b 844 TString tmp(&local->GetName()[4], 2);
845 if (name.Contains(tmp))
846 if (name[0] == local->GetName()[0])
847 return local->GetId();
61c370dd 848 }
849
850 return 0;
851
852}
dbc1e34c 853
f0c62051 854//
855// public methods
856//
857
858
859//______________________________________________________________________________
40c8e44b 860AliMpDDL* AliMpDDLStore::GetDDL(Int_t ddlId, Bool_t warn) const {
861 /// Return DDL for given ddlId
f0c62051 862
40c8e44b 863 AliMpDDL* ddl
f0c62051 864 = (AliMpDDL*)fDDLs.At(ddlId);
40c8e44b 865
866 if ( ! ddl && warn ) {
867 AliErrorStream()
f0c62051 868 << "DDL with Id = " << ddlId << " not defined." << endl;
40c8e44b 869 }
f0c62051 870
40c8e44b 871 return ddl;
872}
f0c62051 873
874//______________________________________________________________________________
40c8e44b 875AliMpDetElement* AliMpDDLStore::GetDetElement(Int_t detElemId, Bool_t warn) const {
876 /// Return detection element with given detElemId
f0c62051 877
40c8e44b 878 if ( ! AliMpDEStore::Instance() ) {
879 AliFatal("DE Store has not been loaded.");
880 return 0;
881 }
24f9bd97 882
40c8e44b 883 return AliMpDEStore::Instance()->GetDetElement(detElemId, warn);
884}
f0c62051 885
886//______________________________________________________________________________
40c8e44b 887AliMpBusPatch* AliMpDDLStore::GetBusPatch(Int_t busPatchId, Bool_t warn) const {
888 /// Return bus patch with given Id
f0c62051 889
40c8e44b 890 AliMpBusPatch* busPatch
f0c62051 891 = (AliMpBusPatch*) fBusPatches.GetValue(busPatchId);
40c8e44b 892
893 if ( ! busPatch && warn ) {
894 AliErrorStream()
f0c62051 895 << "Bus patch with Id = " << busPatchId << " not defined." << endl;
40c8e44b 896 }
f0c62051 897
40c8e44b 898 return busPatch;
899}
f0c62051 900
61c370dd 901//______________________________________________________________________________
40c8e44b 902AliMpLocalBoard* AliMpDDLStore::GetLocalBoard(Int_t localBoardId, Bool_t warn) const {
903 /// Return bus patch with given Id
61c370dd 904
40c8e44b 905 AliMpLocalBoard* localBoard
61c370dd 906 = (AliMpLocalBoard*) fLocalBoards.GetValue(localBoardId);
40c8e44b 907
908 if ( ! localBoard && warn ) {
909 AliErrorStream()
61c370dd 910 << "Local board with Id = " << localBoardId << " not defined." << endl;
40c8e44b 911 }
61c370dd 912
40c8e44b 913 return localBoard;
914}
61c370dd 915
916//______________________________________________________________________________
40c8e44b 917AliMpTriggerCrate* AliMpDDLStore::GetTriggerCrate(TString name, Bool_t warn) const {
918 /// Return trigger crate with given name
61c370dd 919
40c8e44b 920 AliMpTriggerCrate* crate
921 = (AliMpTriggerCrate*) fTriggerCrates.GetValue(name.Data());
922
923 if ( ! crate && warn ) {
924 AliErrorStream()
61c370dd 925 << "Trigger crate with name = " << name.Data() << " not defined." << endl;
40c8e44b 926 }
61c370dd 927
40c8e44b 928 return crate;
929}
61c370dd 930
931//______________________________________________________________________________
40c8e44b 932AliMpTriggerCrate* AliMpDDLStore::GetTriggerCrate(Int_t ddlId, Int_t index, Bool_t warn) const {
933 /// Return trigger crate with given ddl and index crate
61c370dd 934
40c8e44b 935 if (ddlId == 0 || ddlId == 1)
936 ddlId += fgkNofDDLs;
fbd38b34 937
40c8e44b 938 AliMpDDL* ddl = GetDDL(ddlId, warn);
939 if ( ! ddl )
940 return 0;
941
942 if ( index >= ddl->GetNofTriggerCrates() ) {
943 AliError(Form("crate id %d greater than array[%d]", index, ddl->GetNofTriggerCrates()));
944 return 0;
945 }
946
947 TString name = AliMpTriggerCrate::GenerateName(index, ddlId, fgkNofDDLs);
948
949 return GetTriggerCrate(name, warn);
950}
61c370dd 951
f0c62051 952//______________________________________________________________________________
40c8e44b 953Int_t AliMpDDLStore::GetDEfromBus(Int_t busPatchId) const {
954 /// Return detection element Id for given busPatchId
f0c62051 955
40c8e44b 956 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
957
958 if ( ! busPatch ) {
959 AliErrorStream()
f0c62051 960 << "Bus patch with Id = " << busPatchId << " not defined." << endl;
40c8e44b 961 return 0;
962 }
f0c62051 963
40c8e44b 964 return busPatch->GetDEId();
965}
f0c62051 966
61c370dd 967//______________________________________________________________________________
40c8e44b 968Int_t AliMpDDLStore::GetDEfromLocalBoard(Int_t localBoardId, Int_t chamberId) const {
969 /// Return detElemId for local board Id and chamber id.
61c370dd 970
40c8e44b 971 AliMpLocalBoard* localBoard = GetLocalBoard(localBoardId);
972
973 if ( ! localBoard ) {
974 AliErrorStream()
61c370dd 975 << "Loacl board with Id = " << localBoardId << " not defined." << endl;
40c8e44b 976 return 0;
977 }
61c370dd 978
40c8e44b 979 return localBoard->GetDEIdByChamber(chamberId);
61c370dd 980}
981
f0c62051 982//______________________________________________________________________________
40c8e44b 983Int_t AliMpDDLStore::GetDDLfromBus(Int_t busPatchId) const {
984 /// Return DDL Id for given busPatchId
f0c62051 985
40c8e44b 986 AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
987
988 if ( ! busPatch ) {
989 AliErrorStream()
f0c62051 990 << "Bus patch with Id = " << busPatchId << " not defined." << endl;
40c8e44b 991 return 0;
992 }
f0c62051 993
40c8e44b 994 return busPatch->GetDdlId();
995}
f0c62051 996
42d368d0 997//______________________________________________________________________________
40c8e44b 998Int_t AliMpDDLStore::GetBusPatchId(Int_t detElemId, Int_t manuId) const {
999 /// Return bus patch for a given manuId
1000
1001 AliMpDetElement* detElement = GetDetElement(detElemId);
1002 Int_t pos = GetBusPatchIndex(detElemId, manuId);
1003
1004 if ( pos > detElement->GetNofBusPatches() ) {
1005 AliErrorStream()
1006 << "Pos = " << pos
1007 << " greater than the size = " << detElement->GetNofBusPatches()
1008 << " for detElemId = " << detElemId
1009 << " manuId = " << manuId << endl;
1010 return -1;
1011 }
42d368d0 1012
40c8e44b 1013 return detElement->GetBusPatchId(pos);
1014}
42d368d0 1015
f0c62051 1016//______________________________________________________________________________
40c8e44b 1017AliMpIntPair AliMpDDLStore::GetDetElemIdManu(Int_t manuSerial) const {
1018 /// Return the detElemId and manuId for given serial manu number
f0c62051 1019
40c8e44b 1020 if ( ! AliMpDEStore::Instance() ) {
1021 AliFatal("DE Store has not been loaded.");
1022 return AliMpIntPair::Invalid();
1023 }
24f9bd97 1024
40c8e44b 1025 return AliMpDEStore::Instance()->GetDetElemIdManu(manuSerial);
1026}
92faf71f 1027
1028//______________________________________________________________________________
40c8e44b 1029void AliMpDDLStore::PrintAllManu() const {
1030 /// Print all manu Ids and their serial numbers sorted by detection element
1031 /// and bus patch. \n
1032 /// As serial manu numbers are filled in a different way than manu Ids this
1033 /// printing allows to check that both ways are consistent
1034
1035 // Loop over DE
1036 AliMpDEIterator it;
1037 for ( it.First(); ! it.IsDone(); it.Next() ) {
1038 AliMpDetElement* de = it.CurrentDE();
1039 cout << "DE: " << de->GetId() << endl;
1040
1041 // Loop over bus patches in this DE
1042 for ( Int_t i=0; i< de->GetNofBusPatches(); ++i ) {
1043
1044 AliMpBusPatch* busPatch = GetBusPatch(de->GetBusPatchId(i));
1045 cout << " busPatch: " << busPatch->GetId() << endl;
1046
1047 cout << " Manu : ";
1048 for ( Int_t j=0; j<busPatch->GetNofManus(); ++j ) {
1049 cout << std::setw(6) << busPatch->GetManuId(j) << " ";
1050 }
1051 cout << endl;
1052
1053 cout << " Manu serial: ";
1054 for ( Int_t k=0; k<busPatch->GetNofManus(); ++k ) {
1055 cout << std::setw(6) << de->GetManuSerialFromId(busPatch->GetManuId(k)) << " ";
1056 }
1057 cout << endl;
1058 }
1059 }
1060}
92faf71f 1061
61c370dd 1062//________________________________________________________________
40c8e44b 1063Int_t AliMpDDLStore::GetNextDEfromLocalBoard(Int_t localBoardId, Int_t chamberId ) const {
1064 /// return the next detection element in line
61c370dd 1065
1066 AliMpLocalBoard* localBoard = GetLocalBoard(localBoardId);
1067
1068 TString name(localBoard->GetName());
1069
1070 Int_t line = localBoard->GetPosition().GetFirst();
1071 ++line;
40c8e44b 1072
61c370dd 1073 name.Replace(4,1,Form("%d", line));
1074
40c8e44b 1075 Int_t nextLocalId;
61c370dd 1076 if ((nextLocalId = GetLocalBoardId(name)))
40c8e44b 1077 return GetDEfromLocalBoard(nextLocalId, chamberId);
61c370dd 1078 else
40c8e44b 1079 return 0;
61c370dd 1080
1081 return 0;
1082}
1083
1084//________________________________________________________________
40c8e44b 1085Int_t AliMpDDLStore::GetPreviousDEfromLocalBoard(Int_t localBoardId, Int_t chamberId) const {
1086 /// return the previous detection element in line
61c370dd 1087
1088 AliMpLocalBoard* localBoard = GetLocalBoard(localBoardId);
1089
1090 TString name(localBoard->GetName());
1091
1092 Int_t line = localBoard->GetPosition().GetFirst();
1093 --line;
40c8e44b 1094
61c370dd 1095 name.Replace(4,1,Form("%d", line));
1096
1097 Int_t prevLocalId;
1098 if ((prevLocalId = GetLocalBoardId(name)))
40c8e44b 1099 return GetDEfromLocalBoard(prevLocalId, chamberId);
61c370dd 1100 else
40c8e44b 1101 return 0;
61c370dd 1102
1103}