]>
Commit | Line | Data |
---|---|---|
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 | |
19 | // | |
20 | // Class AliMpDDLStore | |
21 | // -------------------- | |
22 | // The top container class for DDLs, det elements and bus patched | |
23 | // It provides acces to DDL, det element and bus patches objects | |
24 | // via various characteristics. | |
25 | // Authors: Ivana Hrivnacova, IPN Orsay | |
26 | // Christian Finck, SUBATECH Nantes | |
61c370dd | 27 | |
f0c62051 | 28 | #include "AliMpDDLStore.h" |
61c370dd | 29 | #include "AliMpConstants.h" |
f0c62051 | 30 | #include "AliMpDEStore.h" |
31 | #include "AliMpDDL.h" | |
32 | #include "AliMpFiles.h" | |
33 | #include "AliMpHelper.h" | |
34 | #include "AliMpDEManager.h" | |
35 | #include "AliMpDetElement.h" | |
36 | #include "AliMpBusPatch.h" | |
61c370dd | 37 | #include "AliMpTriggerCrate.h" |
38 | #include "AliMpLocalBoard.h" | |
42d368d0 | 39 | #include "AliMpSegmentation.h" |
40 | #include "AliMpVSegmentation.h" | |
354e70ca | 41 | #include "AliMpStringObjMap.h" |
f0c62051 | 42 | #include "AliLog.h" |
43 | ||
44 | #include <Riostream.h> | |
42d368d0 | 45 | #include <TList.h> |
61c370dd | 46 | #include <TObjArray.h> |
47 | #include <TString.h> | |
48 | #include <TObjString.h> | |
5f377a9a | 49 | #include <TClass.h> |
f0c62051 | 50 | |
51 | /// \cond CLASSIMP | |
52 | ClassImp(AliMpDDLStore) | |
53 | /// \endcond | |
54 | ||
55 | AliMpDDLStore* AliMpDDLStore::fgInstance = 0; | |
56 | const Int_t AliMpDDLStore::fgkNofDDLs = 20; | |
61c370dd | 57 | const Int_t AliMpDDLStore::fgkNofTriggerDDLs = 2; |
f0c62051 | 58 | |
59 | // | |
60 | // static methods | |
61 | // | |
62 | ||
63 | //______________________________________________________________________________ | |
5f377a9a | 64 | AliMpDDLStore* AliMpDDLStore::Instance(Bool_t warn) |
f0c62051 | 65 | { |
66 | /// Create the DDL store if it does not yet exist | |
67 | /// and return its instance | |
68 | ||
5f377a9a | 69 | if ( ! fgInstance && warn ) { |
70 | AliWarningClass("DDL Store has not beenloaded"); | |
71 | } | |
72 | ||
73 | return fgInstance; | |
74 | } | |
75 | ||
76 | //______________________________________________________________________________ | |
77 | AliMpDDLStore* AliMpDDLStore::ReadData(Bool_t warn) | |
78 | { | |
79 | /// Load the DDL store rom ASCII data files | |
80 | /// and return its instance | |
81 | ||
82 | if ( fgInstance ) { | |
83 | if ( warn ) | |
84 | AliWarningClass("DDL Store has been already loaded"); | |
85 | return fgInstance; | |
86 | } | |
87 | ||
88 | AliInfoClass("Reading DDL Store from ASCII files."); | |
89 | ||
90 | fgInstance = new AliMpDDLStore(); | |
f0c62051 | 91 | return fgInstance; |
92 | } | |
93 | ||
94 | // | |
95 | // ctors, dtor | |
96 | // | |
97 | ||
98 | //______________________________________________________________________________ | |
99 | AliMpDDLStore::AliMpDDLStore() | |
100 | : TObject(), | |
61c370dd | 101 | fDDLs(fgkNofDDLs+fgkNofTriggerDDLs), // FIXEME |
f0c62051 | 102 | fDetElements(AliMpDEStore::Instance()), |
42d368d0 | 103 | fBusPatches(true), |
61c370dd | 104 | fTriggerCrates(true), |
105 | fLocalBoards(true), | |
0f30c458 | 106 | fManuList12(), |
107 | fManuBridge2() | |
f0c62051 | 108 | { |
109 | /// Standard constructor | |
110 | ||
111 | AliDebug(1,""); | |
112 | fDDLs.SetOwner(true); | |
113 | fBusPatches.SetOwner(true); | |
114 | fBusPatches.SetSize(900); | |
115 | ||
61c370dd | 116 | fTriggerCrates.SetOwner(true); |
117 | fTriggerCrates.SetSize(16); | |
118 | ||
119 | fLocalBoards.SetOwner(true); | |
120 | fLocalBoards.SetSize(242); // included non-identied board | |
121 | ||
f0c62051 | 122 | // Create all detection elements |
123 | ReadDDLs(); | |
61c370dd | 124 | ReadTriggerDDLs(); |
42d368d0 | 125 | SetManus(); |
dbc1e34c | 126 | SetPatchModules(); |
0f30c458 | 127 | SetBusPatchLength(); |
f0c62051 | 128 | } |
129 | ||
130 | //______________________________________________________________________________ | |
131 | AliMpDDLStore::AliMpDDLStore(TRootIOCtor* /*ioCtor*/) | |
132 | : TObject(), | |
133 | fDDLs(), | |
134 | fDetElements(0), | |
94306d67 | 135 | fBusPatches(), |
136 | fTriggerCrates(true), | |
137 | fLocalBoards(true) | |
f0c62051 | 138 | { |
139 | /// Constructor for IO | |
140 | ||
141 | AliDebug(1,""); | |
142 | ||
143 | fgInstance = this; | |
144 | } | |
145 | ||
146 | ||
147 | //______________________________________________________________________________ | |
148 | AliMpDDLStore::~AliMpDDLStore() | |
149 | { | |
150 | /// Destructor | |
151 | ||
152 | AliDebug(1,""); | |
153 | ||
154 | delete fDetElements; | |
155 | ||
156 | // DDL objects are deleted with fDDLs | |
157 | // Bus patches objects are deleted with fBusPatches | |
158 | ||
159 | fgInstance = 0; | |
160 | } | |
161 | ||
162 | // | |
163 | // private methods | |
164 | // | |
165 | ||
42d368d0 | 166 | //______________________________________________________________________________ |
167 | Int_t AliMpDDLStore::GetManuListIndex(Int_t detElemId) const | |
168 | { | |
169 | /// Return the index of the manu list for given detElemId | |
170 | ||
171 | return AliMpDEManager::GetChamberId(detElemId)*4 + (detElemId % 100); | |
172 | } | |
173 | ||
174 | ||
175 | //______________________________________________________________________________ | |
176 | Int_t AliMpDDLStore::GetBusPatchIndex(Int_t detElemId, Int_t manuId) const | |
177 | { | |
178 | /// Calculate the index of the buspatch from manuId | |
179 | ||
180 | Int_t pos = 0; | |
181 | AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId); | |
182 | static Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane) - 1; | |
183 | ||
184 | if( stationType == AliMp::kStation345) { | |
185 | pos = (manuId & manuMask)/100; | |
186 | } else { | |
187 | Int_t idx = GetManuListIndex(detElemId); | |
188 | ||
189 | // using array defined from DetElemIdToBusPatch.dat file | |
190 | for (pos = fManuList12[idx].GetSize()-1; pos >= 0; --pos) | |
191 | if ( manuId >= fManuList12[idx].At(pos)) break; | |
192 | } | |
193 | ||
194 | return pos; | |
195 | } | |
196 | ||
197 | ||
f0c62051 | 198 | //______________________________________________________________________________ |
199 | Bool_t AliMpDDLStore::ReadDDLs() | |
200 | { | |
201 | /// Read ddl <-> bus patch file | |
202 | ||
42d368d0 | 203 | |
f0c62051 | 204 | TString infile = AliMpFiles::BusPatchFilePath(); |
205 | ||
206 | ifstream in(infile, ios::in); | |
207 | if (!in) { | |
208 | AliErrorStream() << "Data file " << infile << " not found."; | |
209 | return false; | |
210 | } | |
211 | ||
42d368d0 | 212 | char line[255]; |
f0c62051 | 213 | |
42d368d0 | 214 | while ( in.getline(line,255) ) { |
f0c62051 | 215 | |
216 | if ( line[0] == '#' ) continue; | |
217 | ||
218 | TString tmp(AliMpHelper::Normalize(line)); | |
219 | ||
0f30c458 | 220 | TObjArray* stringList = tmp.Tokenize(TString(" ")); |
f0c62051 | 221 | |
0f30c458 | 222 | TString sDE = ((TObjString*)stringList->At(0))->GetString(); |
223 | Int_t idDE = atoi(sDE.Data()); | |
f0c62051 | 224 | |
0f30c458 | 225 | if ( ! AliMpDEManager::IsValidDetElemId(idDE, false) ) { |
226 | AliErrorStream() << "DetElemId "<< idDE << " not valid." << endl; | |
227 | return false; | |
228 | } | |
f0c62051 | 229 | |
0f30c458 | 230 | TString busPatch = ((TObjString*)stringList->At(1))->GetString(); |
f0c62051 | 231 | |
f0c62051 | 232 | |
0f30c458 | 233 | TString sDDL = ((TObjString*)stringList->At(2))->GetString(); |
234 | Int_t iDDL = atoi(sDDL.Data()); | |
f0c62051 | 235 | |
0f30c458 | 236 | if ( iDDL < 0 || iDDL >= fgkNofDDLs ) { |
237 | AliErrorStream() << "DDL id "<< iDDL << " outside limits." << endl; | |
238 | return false; | |
42d368d0 | 239 | } |
0f30c458 | 240 | |
f0c62051 | 241 | AliDebugStream(3) |
42d368d0 | 242 | << "idDE " << idDE << " buspatch " << busPatch.Data() << " iDDL " << iDDL |
243 | << endl; | |
244 | ||
0f30c458 | 245 | // reading 1st manu Id for each bus patch (station 1 & 2) |
246 | if(AliMpDEManager::GetStationType(idDE) != AliMp::kStation345) { | |
247 | ||
248 | TString sManu = ((TObjString*)stringList->At(3))->GetString(); | |
249 | AliMpHelper::DecodeName(sManu,',',fManuList12[GetManuListIndex(idDE)]); | |
250 | ||
251 | if(AliMpDEManager::GetStationType(idDE) == AliMp::kStation2) { | |
252 | TString sManuBridge = ((TObjString*)stringList->At(4))->GetString(); | |
253 | AliMpHelper::DecodeName(sManuBridge,',',fManuBridge2[GetManuListIndex(idDE)]); | |
254 | } | |
f0c62051 | 255 | |
0f30c458 | 256 | } |
257 | ||
258 | delete stringList; | |
f0c62051 | 259 | |
260 | AliMpDDL* ddl = GetDDL(iDDL, false); | |
261 | if ( !ddl) { | |
262 | ddl = new AliMpDDL(iDDL); | |
263 | fDDLs.AddAt(ddl, iDDL); | |
264 | } | |
265 | ddl->AddDE(idDE); | |
266 | ||
f0c62051 | 267 | TArrayI busPatchList; |
268 | // decoding range of buspatch | |
269 | AliMpHelper::DecodeName(busPatch,';',busPatchList); | |
270 | ||
271 | // Update DE | |
272 | AliMpDetElement* de = AliMpDEManager::GetDetElement(idDE); | |
273 | de->SetDdlId(iDDL); | |
274 | // filling buspatch -> idDE | |
275 | for (Int_t i = 0; i < busPatchList.GetSize(); i++) { | |
276 | fBusPatches.Add(busPatchList[i], | |
277 | new AliMpBusPatch(busPatchList[i], idDE, iDDL)); | |
278 | de->AddBusPatch(busPatchList[i]); | |
279 | } | |
280 | } | |
281 | ||
282 | // Fill bus patch Ids array in DDLs now | |
283 | for ( Int_t i=0; i<fDDLs.GetEntriesFast(); i++ ) { | |
284 | AliMpDDL* ddl = (AliMpDDL*) fDDLs.At(i); | |
285 | ddl->FillBusPatchIds(); | |
286 | } | |
287 | ||
288 | in.close(); | |
289 | return true; | |
290 | } | |
61c370dd | 291 | |
292 | //______________________________________________________________________________ | |
293 | Bool_t AliMpDDLStore::ReadTriggerDDLs() | |
294 | { | |
295 | /// create trigger DDL object ddl<->Crate<->local board | |
296 | ||
354e70ca | 297 | AliMpStringObjMap inputXfromMap; |
298 | AliMpStringObjMap inputXtoMap; | |
299 | AliMpStringObjMap inputYfromMap; | |
300 | AliMpStringObjMap inputYtoMap; | |
301 | ||
61c370dd | 302 | Int_t nonNotified = 0; |
303 | ||
304 | Int_t iDDL = -1; | |
305 | ||
306 | TString infile = AliMpFiles::LocalTriggerBoardMapping(); | |
307 | ||
308 | ifstream in(infile, ios::in); | |
309 | ||
310 | if (!in) { | |
311 | AliError(Form("Local Trigger Board Mapping File %s not found", infile.Data())); | |
312 | return kFALSE; | |
313 | } | |
314 | ||
315 | AliMpLocalBoard* board = 0x0; | |
316 | AliMpTriggerCrate* crate = 0x0; | |
317 | ||
318 | TString localNumber; | |
319 | Int_t localNumberId = 0; | |
320 | TArrayI list; | |
321 | ||
322 | char line[255]; | |
323 | while (in.getline(line, 255)) | |
324 | { | |
325 | ||
326 | // files contains lines with some blank caracters ??? | |
327 | if (line[0] == ' ' && strlen(line) < 12) continue; | |
328 | ||
329 | TString tmp(AliMpHelper::Normalize(line)); | |
330 | if (tmp.IsNull()) continue; // Ignore empty lines | |
331 | ||
332 | if (tmp.Contains("Board")) | |
333 | { | |
334 | // extract id, name, slot & crate name | |
335 | TObjArray* stringList = tmp.Tokenize(TString(" ")); | |
336 | ||
337 | TString localNumber = ((TObjString*)stringList->At(1))->GetString(); | |
338 | ||
339 | if (localNumber.CompareTo("nn") != 0) // Notified cards | |
340 | localNumberId = localNumber.Atoi(); | |
341 | else | |
342 | localNumberId = AliMpConstants::NofLocalBoards() + (++nonNotified); | |
343 | ||
344 | TString localName = ((TObjString*)stringList->At(4))->GetString(); | |
345 | TString slotName = ((TObjString*)stringList->At(10))->GetString(); | |
346 | ||
347 | AliDebug(3, Form("%d %s %d\n", localNumberId, localName.Data(), slotName.Atoi())); | |
348 | ||
349 | board = new AliMpLocalBoard(localNumberId, localName.Data(), slotName.Atoi()); | |
350 | ||
351 | // not notified board | |
352 | if (localNumber.CompareTo("nn") == 0) | |
353 | board->SetNotified(false); | |
354 | ||
355 | // compose name with number and side (Right or Left) | |
356 | TString crateNumber = ((TObjString*)stringList->At(6))->GetString(); | |
357 | TString crateSide = ((TObjString*)stringList->At(7))->GetString(); | |
358 | TString crateName = crateNumber + crateSide; | |
359 | ||
360 | // set crate name | |
361 | board->SetCrate(crateName); | |
362 | ||
363 | // determine ddl number vs crate side | |
364 | if (crateName.Contains("R")) | |
365 | iDDL = fgkNofDDLs; // starts where tracker ends | |
366 | else | |
367 | iDDL = fgkNofDDLs + 1; | |
368 | ||
369 | AliMpDDL* ddl = GetDDL(iDDL, false); | |
370 | if ( !ddl) { | |
371 | ddl = new AliMpDDL(iDDL); | |
372 | fDDLs.AddAt(ddl, iDDL); | |
373 | } | |
374 | ||
375 | Int_t crateId; | |
376 | if (crateNumber.CompareTo("2-3") != 0) | |
377 | crateId = crateNumber.Atoi(); | |
378 | else | |
379 | crateId = 23; | |
380 | ||
381 | // add trigger crate number for given ddl if not present | |
382 | if ( !ddl->HasTriggerCrateId(crateId) ) | |
383 | ddl->AddTriggerCrate(crateId); | |
384 | ||
385 | // if crate not existing then creating | |
386 | if (!GetTriggerCrate(crateName, false)) { | |
387 | crate = new AliMpTriggerCrate(crateName.Data(), iDDL); | |
388 | fTriggerCrates.Add(crateName.Data(), crate); | |
389 | } | |
390 | ||
391 | // create list of local board in this crate | |
392 | crate->AddLocalBoard(localNumberId); | |
393 | ||
394 | delete stringList; | |
395 | } | |
396 | ||
397 | if (tmp.Contains("DetElemId")) | |
398 | { | |
399 | list.Reset(); | |
400 | AliMpDDL* ddl = GetDDL(iDDL, true); | |
401 | ||
402 | // add DE for local board and DDL | |
403 | TString detElem = &tmp[tmp.First(" ")+1]; | |
404 | AliMpHelper::DecodeName(detElem,' ',list); | |
405 | for (Int_t i = 0; i < list.GetSize(); ++i) { | |
406 | board->AddDE(list[i]); | |
407 | if(!ddl->HasDEId(list[i])) | |
408 | ddl->AddDE(list[i]); | |
409 | } | |
410 | } | |
411 | ||
354e70ca | 412 | // map the different copies between cards in X and Y inputs |
413 | // when copying Xinput, Yinput are copied as well | |
414 | if (tmp.Contains("X3input1")) | |
415 | { | |
416 | TObjArray* stringList = tmp.Tokenize(TString(" ")); | |
417 | ||
418 | TString copyX = ((TObjString*)stringList->At(3))->GetString(); | |
419 | TString input = ((TObjString*)stringList->At(2))->GetString();; | |
420 | ||
421 | if (copyX.Contains("(1)")) { | |
422 | inputXfromMap.Add(input, board); | |
423 | inputYfromMap.Add(input, board); | |
424 | ||
425 | } | |
426 | if (copyX.Contains("(2)")) { | |
427 | inputXtoMap.Add(input, board); | |
428 | inputYtoMap.Add(input, board); | |
429 | } | |
430 | delete stringList; | |
431 | } | |
432 | ||
433 | if (tmp.Contains("Y1input1")) | |
434 | { | |
435 | TObjArray* stringList = tmp.Tokenize(TString(" ")); | |
436 | ||
437 | TString copyY = ((TObjString*)stringList->At(3))->GetString(); | |
438 | TString input = ((TObjString*)stringList->At(2))->GetString();; | |
439 | ||
440 | if (copyY.Contains("(1)")) | |
441 | inputYfromMap.Add(input, board); | |
442 | if (copyY.Contains("(2)")) | |
443 | inputYtoMap.Add(input, board); | |
444 | delete stringList; | |
445 | } | |
446 | ||
447 | ||
61c370dd | 448 | if (tmp.Contains("transv")) |
449 | { | |
450 | // set transverse connector | |
451 | Int_t blankPos = tmp.Last(' '); | |
452 | ||
453 | TString transv(tmp(blankPos+1, tmp.Length()-blankPos)); | |
454 | transv.ToUpper(); | |
455 | if (transv.CompareTo("NONE") == 0) | |
456 | board->SetTC(false); | |
457 | } | |
458 | ||
459 | if (tmp.Contains("Switch")) | |
460 | { | |
461 | list.Reset(); | |
462 | in.getline(line, 255);// skip one line | |
463 | ||
464 | in.getline(line, 255); | |
465 | TString tmp(AliMpHelper::Normalize(line)); | |
466 | ||
467 | // decode switches | |
468 | AliMpHelper::DecodeName(tmp,' ',list); | |
469 | ||
470 | // store switches | |
471 | AliMpArrayI switches; | |
472 | ||
473 | for (Int_t i = 0; i < list.GetSize(); ++i) | |
474 | board->AddSwitch(list[i]); | |
475 | ||
476 | // add local board into map | |
477 | fLocalBoards.Add(board->GetId(), board); | |
478 | ||
479 | } | |
480 | } | |
354e70ca | 481 | |
482 | // set copy card number to where the X-Y inputs are copied and | |
483 | // from where the X-Y inputs come. | |
484 | // deleting the first item (TString) done by AliMpStringObjMap itself | |
485 | // keep AliMpLocalBoard object undelete | |
486 | ||
487 | TString value; | |
488 | ||
489 | for (inputXfromMap.First(); !inputXfromMap.IsDone(); inputXfromMap.Next()) { | |
490 | ||
491 | value = inputXfromMap.CurrentKey(); | |
492 | AliMpLocalBoard* boardFrom = (AliMpLocalBoard*)inputXfromMap.CurrentItem(); | |
493 | AliMpLocalBoard* boardTo = (AliMpLocalBoard*)inputXtoMap.Get(value); | |
494 | boardFrom->SetInputXto(boardTo->GetId()); | |
495 | boardTo->SetInputXfrom(boardFrom->GetId()); | |
496 | AliDebug(3, Form("copy xInputs from local id %d_%s_%d to %d_%s_%d\n", | |
497 | boardTo->GetInputXfrom(), boardFrom->GetCrate().Data(), boardFrom->GetSlot(), | |
498 | boardFrom->GetInputXto(), boardTo->GetCrate().Data(), boardTo->GetSlot())); | |
499 | } | |
500 | ||
501 | for (inputYfromMap.First(); !inputYfromMap.IsDone(); inputYfromMap.Next()) { | |
502 | ||
503 | value = inputYfromMap.CurrentKey(); | |
504 | AliMpLocalBoard* boardFrom = (AliMpLocalBoard*)inputYfromMap.CurrentItem(); | |
505 | AliMpLocalBoard* boardTo = (AliMpLocalBoard*)inputYtoMap.Get(value); | |
506 | boardFrom->SetInputYto(boardTo->GetId()); | |
507 | boardTo->SetInputYfrom(boardFrom->GetId()); | |
508 | AliDebug(3, Form("copy yInputs from local id %d_%s_%d to %d_%s_%d\n", | |
509 | boardTo->GetInputYfrom(), boardFrom->GetCrate().Data(), boardFrom->GetSlot(), | |
510 | boardFrom->GetInputYto(), boardTo->GetCrate().Data(), boardTo->GetSlot())); | |
511 | } | |
61c370dd | 512 | |
513 | return kTRUE; | |
514 | } | |
515 | ||
42d368d0 | 516 | //______________________________________________________________________________ |
517 | Bool_t AliMpDDLStore::SetManus() | |
518 | { | |
519 | /// Set manus for each bus patch | |
520 | ||
521 | Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane) - 1; | |
522 | ||
523 | // loop over DDL | |
524 | for (Int_t iDDL = 0; iDDL < fgkNofDDLs; ++iDDL) { | |
525 | ||
526 | AliDebug(3, Form("DDL # %d\n", iDDL)); | |
527 | ||
528 | AliMpDDL* ddl = GetDDL(iDDL); | |
529 | ||
530 | // loop over DE in the given DDL | |
531 | for (Int_t detElemIdx = 0; detElemIdx < ddl->GetNofDEs(); ++detElemIdx) { | |
532 | ||
533 | Int_t detElemId = ddl->GetDEId(detElemIdx); | |
534 | ||
535 | AliMpDetElement* detElement = GetDetElement(detElemId); | |
536 | ||
537 | AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId); | |
538 | ||
539 | ||
540 | // list of manu per DE on both cathode | |
541 | TList manuList; | |
542 | for ( Int_t cath = 0; cath < 2 ; ++cath ) { | |
543 | const AliMpVSegmentation* seg | |
544 | = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(cath)); | |
545 | ||
546 | AliMp::PlaneType planeType = detElement->GetPlaneType(AliMp::GetCathodType(cath)); | |
547 | ||
548 | TArrayI manus; | |
549 | seg->GetAllElectronicCardIDs(manus); | |
550 | ||
551 | // filling TList manu | |
552 | for ( Int_t im = 0; im < manus.GetSize(); ++im ) { | |
553 | ||
554 | AliMpIntPair* manu = 0x0; | |
555 | if( stationType == AliMp::kStation345) | |
556 | manu = new AliMpIntPair((manus[im] & manuMask), planeType, kTRUE); //remove offset for NB | |
557 | else | |
558 | manu = new AliMpIntPair(manus[im], planeType, kTRUE); //keep offset for NB | |
559 | ||
560 | manuList.Add(manu); | |
561 | } | |
562 | }// cathode | |
563 | ||
564 | manuList.Sort(); // sort regardless B or NB plane | |
565 | ||
566 | // filling manu to the corresponding buspatch | |
567 | for (Int_t iEntry = 0; iEntry < manuList.GetEntries(); ++iEntry) { | |
568 | ||
569 | AliMpIntPair* manuPtr = (AliMpIntPair*)manuList.At(iEntry); | |
570 | ||
571 | Int_t manuId = manuPtr->GetFirst(); | |
572 | Int_t pos = GetBusPatchIndex(detElemId, manuId); | |
573 | ||
574 | if (pos > detElement->GetNofBusPatches()) { | |
575 | AliError(Form("pos greater %d than size %d manuId %d detElemId %d \n", | |
576 | pos, detElement->GetNofBusPatches(), manuId, detElemId)); | |
577 | return false; | |
578 | } | |
579 | ||
580 | // get buspatch and fill manus | |
581 | Int_t busPatchId = detElement->GetBusPatchId(pos); | |
582 | AliMpBusPatch* busPatch = GetBusPatch(busPatchId); | |
583 | ||
584 | if( stationType == AliMp::kStation345) { | |
585 | ||
586 | if (manuPtr->GetSecond()) | |
587 | busPatch->AddManu(manuId+manuMask+1); // add offset again after sorted | |
588 | else | |
589 | busPatch->AddManu(manuId); | |
590 | ||
591 | } else { | |
592 | ||
593 | busPatch->AddManu(manuId); | |
594 | ||
595 | } | |
596 | } | |
597 | ||
598 | manuList.Delete(); | |
599 | ||
600 | if (AliDebugLevel() == 3) { | |
601 | ||
602 | // print out for checking | |
603 | for(Int_t pos = 0; pos < detElement->GetNofBusPatches(); ++pos) { | |
604 | Int_t busPatchId = detElement->GetBusPatchId(pos); | |
605 | AliMpBusPatch* busPatch = GetBusPatch(busPatchId); | |
606 | printf("BusPatch: %d\n", busPatch->GetId()); | |
607 | for (Int_t iEntry = 0; iEntry < busPatch->GetNofManus(); ++iEntry) | |
608 | printf("manu Id: %d\n", busPatch->GetManuId(iEntry)); | |
609 | } | |
610 | } | |
611 | ||
612 | } // detection element loop | |
613 | }// DDL loop | |
614 | ||
615 | return true; | |
616 | } | |
f0c62051 | 617 | |
dbc1e34c | 618 | //______________________________________________________________________________ |
619 | Bool_t AliMpDDLStore::SetPatchModules() | |
620 | { | |
621 | /// Compute the number of manu per PCB for each buspatch | |
622 | ||
0f30c458 | 623 | AliMpDEIterator it; |
624 | Bool_t result = true; | |
dbc1e34c | 625 | |
0f30c458 | 626 | for ( it.First(); !it.IsDone(); it.Next() ) { |
dbc1e34c | 627 | |
0f30c458 | 628 | AliMpDetElement* detElement = it.CurrentDE(); |
629 | ||
630 | for (Int_t i = 0; i < detElement->GetNofBusPatches(); ++i) { | |
631 | AliMpBusPatch* busPatch = GetBusPatch(detElement->GetBusPatchId(i)); | |
632 | Bool_t newResult = false; | |
633 | Int_t idDE = busPatch->GetDEId(); | |
634 | ||
635 | if (AliMpDEManager::GetStationType(idDE) == AliMp::kStation2 ) | |
636 | newResult = busPatch->SetNofManusPerModule(fManuBridge2[GetManuListIndex(idDE)].At(i)); | |
637 | else | |
638 | newResult = busPatch->SetNofManusPerModule(); | |
639 | } | |
640 | } | |
641 | ||
642 | return result; | |
643 | } | |
644 | ||
645 | //______________________________________________________________________________ | |
646 | Bool_t AliMpDDLStore::SetBusPatchLength() | |
647 | { | |
648 | /// read the buspatch length file and set buspatch length | |
649 | ||
650 | TString infile = AliMpFiles::BusPatchLengthFilePath(); | |
651 | ifstream in(infile, ios::in); | |
652 | if (!in) { | |
653 | AliErrorStream() << "Data file " << infile << " not found."; | |
654 | return false; | |
655 | } | |
656 | char line[255]; | |
657 | ||
658 | for (Int_t iDDL = 0; iDDL < fgkNofDDLs; ++iDDL ) { | |
659 | AliMpDDL* ddl = GetDDL(iDDL); | |
660 | ||
661 | for (Int_t iBusPatch = 0; iBusPatch < ddl->GetNofBusPatches(); ++iBusPatch) { | |
dbc1e34c | 662 | |
0f30c458 | 663 | do { |
664 | if (!in.getline(line,255)) { | |
665 | AliWarning(Form("Wrong size in bus patch length file; index %d DDL %d", | |
666 | iBusPatch, iDDL)); | |
667 | return false; | |
668 | } | |
669 | } while(line[0] == '#'); | |
670 | ||
671 | TString tmp(AliMpHelper::Normalize(line)); | |
672 | Float_t length = tmp.Atof(); | |
673 | ||
674 | Int_t busPatchId = ddl->GetBusPatchId(iBusPatch); | |
675 | AliMpBusPatch* busPatch = GetBusPatch(busPatchId); | |
676 | busPatch->SetCableLength(length); | |
677 | } | |
678 | } | |
679 | ||
680 | return true; | |
dbc1e34c | 681 | } |
682 | ||
0f30c458 | 683 | |
61c370dd | 684 | //________________________________________________________________ |
685 | Int_t AliMpDDLStore::GetLocalBoardId(TString name) const | |
686 | { | |
687 | /// return the first board with a given side and line | |
688 | ||
689 | TExMapIter i = fLocalBoards.GetIterator(); | |
690 | Long_t key, value; | |
691 | while ( i.Next(key, value) ) { | |
692 | AliMpLocalBoard* local = (AliMpLocalBoard*)value; | |
693 | ||
694 | TString tmp(&local->GetName()[4], 2); | |
695 | if (name.Contains(tmp)) | |
696 | if (name[0] == local->GetName()[0]) | |
697 | return local->GetId(); | |
698 | } | |
699 | ||
700 | return 0; | |
701 | ||
702 | } | |
dbc1e34c | 703 | |
f0c62051 | 704 | // |
705 | // public methods | |
706 | // | |
707 | ||
708 | ||
709 | //______________________________________________________________________________ | |
710 | AliMpDDL* AliMpDDLStore::GetDDL(Int_t ddlId, Bool_t warn) const | |
711 | { | |
712 | /// Return DDL for given ddlId | |
713 | ||
714 | AliMpDDL* ddl | |
715 | = (AliMpDDL*)fDDLs.At(ddlId); | |
716 | ||
717 | if ( ! ddl && warn ) { | |
718 | AliErrorStream() | |
719 | << "DDL with Id = " << ddlId << " not defined." << endl; | |
720 | } | |
721 | ||
722 | return ddl; | |
723 | } | |
724 | ||
725 | //______________________________________________________________________________ | |
726 | AliMpDetElement* AliMpDDLStore::GetDetElement(Int_t detElemId, Bool_t warn) const | |
727 | { | |
728 | /// Return detection element with given detElemId | |
729 | ||
730 | return fDetElements->GetDetElement(detElemId, warn); | |
731 | } | |
732 | ||
733 | //______________________________________________________________________________ | |
734 | AliMpBusPatch* AliMpDDLStore::GetBusPatch(Int_t busPatchId, Bool_t warn) const | |
735 | { | |
736 | /// Return bus patch with given Id | |
737 | ||
738 | AliMpBusPatch* busPatch | |
739 | = (AliMpBusPatch*) fBusPatches.GetValue(busPatchId); | |
740 | ||
741 | if ( ! busPatch && warn ) { | |
742 | AliErrorStream() | |
743 | << "Bus patch with Id = " << busPatchId << " not defined." << endl; | |
744 | } | |
745 | ||
746 | return busPatch; | |
747 | } | |
748 | ||
61c370dd | 749 | //______________________________________________________________________________ |
750 | AliMpLocalBoard* AliMpDDLStore::GetLocalBoard(Int_t localBoardId, Bool_t warn) const | |
751 | { | |
752 | /// Return bus patch with given Id | |
753 | ||
754 | AliMpLocalBoard* localBoard | |
755 | = (AliMpLocalBoard*) fLocalBoards.GetValue(localBoardId); | |
756 | ||
757 | if ( ! localBoard && warn ) { | |
758 | AliErrorStream() | |
759 | << "Local board with Id = " << localBoardId << " not defined." << endl; | |
760 | } | |
761 | ||
762 | return localBoard; | |
763 | } | |
764 | ||
765 | //______________________________________________________________________________ | |
766 | AliMpTriggerCrate* AliMpDDLStore::GetTriggerCrate(TString name, Bool_t warn) const | |
767 | { | |
768 | /// Return trigger crate with given name | |
769 | ||
770 | AliMpTriggerCrate* crate | |
771 | = (AliMpTriggerCrate*) fTriggerCrates.GetValue(name.Data()); | |
772 | ||
773 | if ( ! crate && warn ) { | |
774 | AliErrorStream() | |
775 | << "Trigger crate with name = " << name.Data() << " not defined." << endl; | |
776 | } | |
777 | ||
778 | return crate; | |
779 | } | |
780 | ||
781 | //______________________________________________________________________________ | |
782 | AliMpTriggerCrate* AliMpDDLStore::GetTriggerCrate(Int_t ddlId, Int_t index, Bool_t warn) const | |
783 | { | |
784 | /// Return trigger crate with given ddl and index crate | |
785 | ||
fbd38b34 | 786 | if (ddlId == 0 || ddlId == 1) |
787 | ddlId += fgkNofDDLs; | |
788 | ||
61c370dd | 789 | AliMpDDL* ddl = GetDDL(ddlId, warn); |
790 | if ( ! ddl ) return 0; | |
791 | ||
792 | if ( index >= ddl->GetNofTriggerCrates() ) { | |
793 | AliError(Form("crate id %d greater than array[%d]", index, ddl->GetNofTriggerCrates())); | |
794 | return 0; | |
795 | } | |
796 | ||
797 | Int_t crateId = ddl->GetTriggerCrateId(index); | |
798 | TString name = AliMpTriggerCrate::GenerateName(crateId, ddlId, fgkNofDDLs); | |
799 | ||
800 | return GetTriggerCrate(name, warn); | |
801 | } | |
802 | ||
f0c62051 | 803 | //______________________________________________________________________________ |
804 | Int_t AliMpDDLStore::GetDEfromBus(Int_t busPatchId) const | |
805 | { | |
806 | /// Return detection element Id for given busPatchId | |
807 | ||
808 | AliMpBusPatch* busPatch = GetBusPatch(busPatchId); | |
809 | ||
810 | if ( ! busPatch ) { | |
811 | AliErrorStream() | |
812 | << "Bus patch with Id = " << busPatchId << " not defined." << endl; | |
813 | return 0; | |
814 | } | |
815 | ||
816 | return busPatch->GetDEId(); | |
817 | } | |
818 | ||
61c370dd | 819 | //______________________________________________________________________________ |
820 | Int_t AliMpDDLStore::GetDEfromLocalBoard(Int_t localBoardId, Int_t chamberId) const | |
821 | { | |
822 | /// Return detElemId for local board Id and chamber id. | |
823 | ||
824 | AliMpLocalBoard* localBoard = GetLocalBoard(localBoardId); | |
825 | ||
826 | if ( ! localBoard ) { | |
827 | AliErrorStream() | |
828 | << "Loacl board with Id = " << localBoardId << " not defined." << endl; | |
829 | return 0; | |
830 | } | |
831 | ||
832 | return localBoard->GetDEIdByChamber(chamberId); | |
833 | } | |
834 | ||
f0c62051 | 835 | //______________________________________________________________________________ |
836 | Int_t AliMpDDLStore::GetDDLfromBus(Int_t busPatchId) const | |
837 | { | |
838 | /// Return DDL Id for given busPatchId | |
839 | ||
840 | AliMpBusPatch* busPatch = GetBusPatch(busPatchId); | |
841 | ||
842 | if ( ! busPatch ) { | |
843 | AliErrorStream() | |
844 | << "Bus patch with Id = " << busPatchId << " not defined." << endl; | |
845 | return 0; | |
846 | } | |
847 | ||
848 | return busPatch->GetDdlId(); | |
849 | } | |
850 | ||
42d368d0 | 851 | //______________________________________________________________________________ |
852 | Int_t AliMpDDLStore::GetBusPatchId(Int_t detElemId, Int_t manuId) const | |
853 | { | |
854 | /// Return bus patch for a given manuId | |
855 | ||
856 | AliMpDetElement* detElement = GetDetElement(detElemId); | |
857 | Int_t pos = GetBusPatchIndex(detElemId, manuId); | |
858 | ||
859 | if ( pos > detElement->GetNofBusPatches() ) { | |
860 | AliErrorStream() | |
861 | << "Pos = " << pos | |
862 | << " greater than the size = " << detElement->GetNofBusPatches() | |
863 | << " for detElemId = " << detElemId | |
864 | << " manuId = " << manuId << endl; | |
865 | return -1; | |
866 | } | |
867 | ||
868 | return detElement->GetBusPatchId(pos); | |
869 | } | |
870 | ||
f0c62051 | 871 | //______________________________________________________________________________ |
872 | AliMpIntPair AliMpDDLStore::GetDetElemIdManu(Int_t manuSerial) const | |
873 | { | |
874 | /// Return the detElemId and manuId for given serial manu number | |
875 | ||
876 | return fDetElements->GetDetElemIdManu(manuSerial); | |
877 | } | |
92faf71f | 878 | |
879 | //______________________________________________________________________________ | |
880 | void AliMpDDLStore::PrintAllManu() const | |
881 | { | |
882 | /// Print all manu Ids and their serial numbers sorted by detection element | |
883 | /// and bus patch. \n | |
884 | /// As serial manu numbers are filled in a different way than manu Ids this | |
885 | /// printing allows to check that both ways are consistent | |
886 | ||
887 | // Loop over DE | |
888 | AliMpDEIterator it; | |
889 | for ( it.First(); ! it.IsDone(); it.Next() ) { | |
890 | AliMpDetElement* de = it.CurrentDE(); | |
891 | cout << "DE: " << de->GetId() << endl; | |
892 | ||
893 | // Loop over bus patches in this DE | |
894 | for ( Int_t i=0; i< de->GetNofBusPatches(); ++i ) { | |
895 | ||
896 | AliMpBusPatch* busPatch = GetBusPatch(de->GetBusPatchId(i)); | |
897 | cout << " busPatch: " << busPatch->GetId() << endl; | |
898 | ||
899 | cout << " Manu : "; | |
900 | for ( Int_t j=0; j<busPatch->GetNofManus(); ++j ) { | |
901 | cout << std::setw(6) << busPatch->GetManuId(j) << " "; | |
902 | } | |
903 | cout << endl; | |
904 | ||
905 | cout << " Manu serial: "; | |
906 | for ( Int_t k=0; k<busPatch->GetNofManus(); ++k ) { | |
907 | cout << std::setw(6) << de->GetManuSerialFromId(busPatch->GetManuId(k)) << " "; | |
908 | } | |
909 | cout << endl; | |
910 | } | |
911 | } | |
912 | } | |
913 | ||
61c370dd | 914 | //________________________________________________________________ |
915 | Int_t AliMpDDLStore::GetNextDEfromLocalBoard(Int_t localBoardId, Int_t chamberId ) const | |
916 | { | |
917 | /// return the next detection element in line | |
918 | ||
919 | AliMpLocalBoard* localBoard = GetLocalBoard(localBoardId); | |
920 | ||
921 | TString name(localBoard->GetName()); | |
922 | ||
923 | Int_t line = localBoard->GetPosition().GetFirst(); | |
924 | ++line; | |
925 | ||
926 | name.Replace(4,1,Form("%d", line)); | |
927 | ||
928 | Int_t nextLocalId; | |
929 | if ((nextLocalId = GetLocalBoardId(name))) | |
930 | return GetDEfromLocalBoard(nextLocalId, chamberId); | |
931 | else | |
932 | return 0; | |
933 | ||
934 | return 0; | |
935 | } | |
936 | ||
937 | //________________________________________________________________ | |
938 | Int_t AliMpDDLStore::GetPreviousDEfromLocalBoard(Int_t localBoardId, Int_t chamberId) const | |
939 | { | |
940 | /// return the previous detection element in line | |
941 | ||
942 | AliMpLocalBoard* localBoard = GetLocalBoard(localBoardId); | |
943 | ||
944 | TString name(localBoard->GetName()); | |
945 | ||
946 | Int_t line = localBoard->GetPosition().GetFirst(); | |
947 | --line; | |
948 | ||
949 | name.Replace(4,1,Form("%d", line)); | |
950 | ||
951 | Int_t prevLocalId; | |
952 | if ((prevLocalId = GetLocalBoardId(name))) | |
953 | return GetDEfromLocalBoard(prevLocalId, chamberId); | |
954 | else | |
955 | return 0; | |
956 | ||
957 | } | |
92faf71f | 958 |