]>
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 | |
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 | |
b09247a2 | 30 | #include <cstdlib> |
f0c62051 | 31 | #include "AliMpDDLStore.h" |
61c370dd | 32 | #include "AliMpConstants.h" |
f0c62051 | 33 | #include "AliMpDEStore.h" |
34 | #include "AliMpDDL.h" | |
35 | #include "AliMpFiles.h" | |
36 | #include "AliMpHelper.h" | |
37 | #include "AliMpDEManager.h" | |
38 | #include "AliMpDetElement.h" | |
39 | #include "AliMpBusPatch.h" | |
61c370dd | 40 | #include "AliMpTriggerCrate.h" |
41 | #include "AliMpLocalBoard.h" | |
42d368d0 | 42 | #include "AliMpSegmentation.h" |
43 | #include "AliMpVSegmentation.h" | |
354e70ca | 44 | #include "AliMpStringObjMap.h" |
472027a9 | 45 | |
f0c62051 | 46 | #include "AliLog.h" |
47 | ||
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> |
f0c62051 | 54 | |
55 | /// \cond CLASSIMP | |
56 | ClassImp(AliMpDDLStore) | |
57 | /// \endcond | |
58 | ||
59 | AliMpDDLStore* AliMpDDLStore::fgInstance = 0; | |
60 | const Int_t AliMpDDLStore::fgkNofDDLs = 20; | |
61c370dd | 61 | const Int_t AliMpDDLStore::fgkNofTriggerDDLs = 2; |
ae649dcb | 62 | const TString AliMpDDLStore::fgkRevertKeyword = "REVERT"; |
63 | const TString AliMpDDLStore::fgkExplicitKeyword = "EXPLICIT"; | |
f0c62051 | 64 | |
65 | // | |
66 | // static methods | |
67 | // | |
68 | ||
69 | //______________________________________________________________________________ | |
40c8e44b | 70 | AliMpDDLStore* AliMpDDLStore::Instance(Bool_t warn) |
f0c62051 | 71 | { |
40c8e44b | 72 | /// Create the DDL store if it does not yet exist |
73 | /// and return its instance | |
f0c62051 | 74 | |
40c8e44b | 75 | if ( ! fgInstance && warn ) { |
76 | AliWarningClass("DDL Store has not been loaded"); | |
77 | } | |
78 | ||
79 | return fgInstance; | |
80 | } | |
5f377a9a | 81 | |
82 | //______________________________________________________________________________ | |
40c8e44b | 83 | AliMpDDLStore* AliMpDDLStore::ReadData(Bool_t warn) |
5f377a9a | 84 | { |
40c8e44b | 85 | /// Load the DDL store from ASCII data files |
86 | /// and return its instance | |
5f377a9a | 87 | |
40c8e44b | 88 | if ( fgInstance ) { |
89 | if ( warn ) | |
90 | AliWarningClass("DDL Store has been already loaded"); | |
91 | return fgInstance; | |
92 | } | |
5f377a9a | 93 | |
40c8e44b | 94 | AliInfoClass("Reading DDL Store from ASCII files."); |
95 | ||
96 | fgInstance = new AliMpDDLStore(); | |
97 | return fgInstance; | |
98 | } | |
f0c62051 | 99 | |
100 | // | |
101 | // ctors, dtor | |
102 | // | |
103 | ||
104 | //______________________________________________________________________________ | |
105 | AliMpDDLStore::AliMpDDLStore() | |
40c8e44b | 106 | : TObject(), |
107 | fDDLs(fgkNofDDLs+fgkNofTriggerDDLs), // FIXEME | |
108 | fBusPatches(true), | |
40c8e44b | 109 | fManuList12(), |
110 | fManuBridge2(), | |
efb566fd | 111 | fRegionalTrigger() |
40c8e44b | 112 | { |
113 | /// Standard constructor | |
114 | ||
115 | AliDebug(1,""); | |
116 | fDDLs.SetOwner(true); | |
117 | fBusPatches.SetOwner(true); | |
118 | fBusPatches.SetSize(900); | |
119 | ||
40c8e44b | 120 | // Load segmentation & DE store data |
121 | if ( ! AliMpSegmentation::Instance(false) ) | |
122 | AliMpSegmentation::ReadData(true); | |
123 | ||
124 | // Create all detection elements | |
125 | ReadDDLs(); | |
efb566fd | 126 | ReadTrigger(); |
127 | SetTriggerDDLs(); | |
40c8e44b | 128 | SetManus(); |
ae649dcb | 129 | ReadBusPatchSpecial(); |
40c8e44b | 130 | SetPatchModules(); |
131 | SetBusPatchLength(); | |
f0c62051 | 132 | } |
133 | ||
134 | //______________________________________________________________________________ | |
efb566fd | 135 | AliMpDDLStore::AliMpDDLStore(TRootIOCtor* ioCtor) |
40c8e44b | 136 | : TObject(), |
137 | fDDLs(), | |
138 | fBusPatches(), | |
efb566fd | 139 | fRegionalTrigger(ioCtor) |
40c8e44b | 140 | { |
efb566fd | 141 | /// Constructor for I0 |
f0c62051 | 142 | |
40c8e44b | 143 | AliDebug(1,""); |
f0c62051 | 144 | |
40c8e44b | 145 | fgInstance = this; |
f0c62051 | 146 | } |
147 | ||
148 | ||
149 | //______________________________________________________________________________ | |
40c8e44b | 150 | AliMpDDLStore::~AliMpDDLStore() |
f0c62051 | 151 | { |
40c8e44b | 152 | /// Destructor |
f0c62051 | 153 | |
40c8e44b | 154 | AliDebug(1,""); |
f0c62051 | 155 | |
40c8e44b | 156 | // DDL objects are deleted with fDDLs |
157 | // Bus patches objects are deleted with fBusPatches | |
158 | ||
159 | fgInstance = 0; | |
f0c62051 | 160 | } |
161 | ||
162 | // | |
163 | // private methods | |
164 | // | |
165 | ||
42d368d0 | 166 | //______________________________________________________________________________ |
40c8e44b | 167 | Int_t AliMpDDLStore::GetManuListIndex(Int_t detElemId) const |
42d368d0 | 168 | { |
40c8e44b | 169 | /// Return the index of the manu list for given detElemId |
170 | ||
171 | return AliMpDEManager::GetChamberId(detElemId)*4 + (detElemId % 100); | |
172 | } | |
42d368d0 | 173 | |
42d368d0 | 174 | |
175 | //______________________________________________________________________________ | |
40c8e44b | 176 | Int_t AliMpDDLStore::GetBusPatchIndex(Int_t detElemId, Int_t manuId) const |
42d368d0 | 177 | { |
40c8e44b | 178 | /// Calculate the index of the buspatch from manuId |
42d368d0 | 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) { | |
40c8e44b | 185 | pos = (manuId & manuMask)/100; |
42d368d0 | 186 | } else { |
40c8e44b | 187 | Int_t idx = GetManuListIndex(detElemId); |
42d368d0 | 188 | |
40c8e44b | 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)) | |
192 | break; | |
42d368d0 | 193 | } |
194 | ||
195 | return pos; | |
196 | } | |
197 | ||
61c370dd | 198 | //______________________________________________________________________________ |
40c8e44b | 199 | Bool_t AliMpDDLStore::ReadDDLs() |
61c370dd | 200 | { |
40c8e44b | 201 | /// Read ddl <-> bus patch file |
354e70ca | 202 | |
40c8e44b | 203 | TString infile = AliMpFiles::BusPatchFilePath(); |
61c370dd | 204 | |
61c370dd | 205 | ifstream in(infile, ios::in); |
61c370dd | 206 | if (!in) { |
40c8e44b | 207 | AliErrorStream() << "Data file " << infile << " not found."; |
208 | return false; | |
61c370dd | 209 | } |
61c370dd | 210 | |
211 | char line[255]; | |
61c370dd | 212 | |
40c8e44b | 213 | while ( in.getline(line,255) ) { |
61c370dd | 214 | |
40c8e44b | 215 | if ( line[0] == '#' ) |
216 | continue; | |
61c370dd | 217 | |
40c8e44b | 218 | TString tmp(AliMpHelper::Normalize(line)); |
61c370dd | 219 | |
40c8e44b | 220 | TObjArray* stringList = tmp.Tokenize(TString(" ")); |
354e70ca | 221 | |
40c8e44b | 222 | TString sDE = ((TObjString*)stringList->At(0))->GetString(); |
223 | Int_t idDE = atoi(sDE.Data()); | |
354e70ca | 224 | |
40c8e44b | 225 | if ( ! AliMpDEManager::IsValidDetElemId(idDE, false) ) { |
226 | AliErrorStream() << "DetElemId "<< idDE << " not valid." << endl; | |
227 | return false; | |
228 | } | |
354e70ca | 229 | |
40c8e44b | 230 | TString busPatch = ((TObjString*)stringList->At(1))->GetString(); |
354e70ca | 231 | |
232 | ||
40c8e44b | 233 | TString sDDL = ((TObjString*)stringList->At(2))->GetString(); |
234 | Int_t iDDL = atoi(sDDL.Data()); | |
61c370dd | 235 | |
40c8e44b | 236 | if ( iDDL < 0 || iDDL >= fgkNofDDLs ) { |
237 | AliErrorStream() << "DDL id "<< iDDL << " outside limits." << endl; | |
238 | return false; | |
239 | } | |
61c370dd | 240 | |
40c8e44b | 241 | AliDebugStream(3) |
242 | << "idDE " << idDE << " buspatch " << busPatch.Data() << " iDDL " << iDDL | |
243 | << endl; | |
61c370dd | 244 | |
40c8e44b | 245 | // reading 1st manu Id for each bus patch (station 1 & 2) |
246 | if(AliMpDEManager::GetStationType(idDE) != AliMp::kStation345) { | |
61c370dd | 247 | |
40c8e44b | 248 | TString sManu = ((TObjString*)stringList->At(3))->GetString(); |
249 | AliMpHelper::DecodeName(sManu,',',fManuList12[GetManuListIndex(idDE)]); | |
61c370dd | 250 | |
40c8e44b | 251 | if(AliMpDEManager::GetStationType(idDE) == AliMp::kStation2) { |
252 | TString sManuBridge = ((TObjString*)stringList->At(4))->GetString(); | |
253 | AliMpHelper::DecodeName(sManuBridge,',',fManuBridge2[GetManuListIndex(idDE)]); | |
254 | } | |
61c370dd | 255 | |
40c8e44b | 256 | } |
61c370dd | 257 | |
40c8e44b | 258 | delete stringList; |
61c370dd | 259 | |
40c8e44b | 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 | ||
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(); | |
61c370dd | 286 | } |
40c8e44b | 287 | |
288 | in.close(); | |
289 | return true; | |
290 | } | |
efb566fd | 291 | |
40c8e44b | 292 | //______________________________________________________________________________ |
efb566fd | 293 | Bool_t AliMpDDLStore::ReadTrigger() |
40c8e44b | 294 | { |
295 | /// create trigger DDL object and Global crate object | |
296 | ||
efb566fd | 297 | if ( ! fRegionalTrigger.ReadData() ) return false; |
298 | ||
40c8e44b | 299 | return true; |
300 | } | |
301 | ||
302 | //______________________________________________________________________________ | |
efb566fd | 303 | Bool_t AliMpDDLStore::SetTriggerDDLs() |
40c8e44b | 304 | { |
efb566fd | 305 | /// Create trigger DDLs and set DDL Ids in the regional trigger |
306 | ||
40c8e44b | 307 | |
efb566fd | 308 | Int_t iDDL = -1; |
354e70ca | 309 | |
efb566fd | 310 | for ( Int_t i=0; i<fRegionalTrigger.GetNofTriggerCrates(); ++i ) { |
311 | ||
312 | AliMpTriggerCrate* crate = fRegionalTrigger.GetTriggerCrateFast(i); | |
354e70ca | 313 | |
efb566fd | 314 | TString crateName = crate->GetName(); |
61c370dd | 315 | |
efb566fd | 316 | // determine ddl number vs crate side |
317 | if (crateName.Contains("R")) | |
318 | iDDL = fgkNofDDLs; // starts where tracker ends | |
319 | else | |
320 | iDDL = fgkNofDDLs + 1; | |
321 | ||
322 | // Create DDL if it does not yet exist and set it to the crate | |
323 | AliMpDDL* ddl = (AliMpDDL*)fDDLs.At(iDDL); | |
324 | if ( !ddl) { | |
efb566fd | 325 | ddl = new AliMpDDL(iDDL); |
326 | fDDLs.AddAt(ddl, iDDL); | |
327 | } | |
328 | crate->SetDdlId(iDDL); | |
40c8e44b | 329 | |
472027a9 | 330 | |
efb566fd | 331 | // Add trigger crate number for given ddl if not present |
332 | if ( !ddl->HasTriggerCrateId(crate->GetId()) ) | |
333 | ddl->AddTriggerCrate(crate->GetId()); | |
472027a9 | 334 | |
472027a9 | 335 | |
efb566fd | 336 | // Loop over local boards in this crate |
337 | ||
338 | for ( Int_t j=0; j<crate->GetNofLocalBoards(); ++j ) | |
339 | { | |
340 | Int_t localBoardId = crate->GetLocalBoardId(j); | |
341 | AliMpLocalBoard* localBoard | |
342 | = fRegionalTrigger.FindLocalBoard(localBoardId); | |
343 | if (!localBoard ) { | |
344 | AliFatalClass("Cannot find local board."); | |
345 | return kFALSE; | |
346 | } | |
347 | ||
348 | // Loop over DEs in this localBoard | |
349 | ||
350 | for ( Int_t k=0; k<localBoard->GetNofDEs(); ++k ) | |
351 | { | |
472027a9 | 352 | |
efb566fd | 353 | Int_t deId = localBoard->GetDEId(k); |
354 | AliMpDetElement* de = AliMpDEManager::GetDetElement(deId); | |
355 | ||
356 | if ( de->GetDdlId() == -1 ) de->SetDdlId(iDDL); | |
357 | ||
358 | if ( ! ddl->HasDEId(deId) ) ddl->AddDE(deId); | |
359 | } | |
40c8e44b | 360 | } |
efb566fd | 361 | } |
362 | return kTRUE; | |
61c370dd | 363 | } |
364 | ||
42d368d0 | 365 | //______________________________________________________________________________ |
40c8e44b | 366 | Bool_t AliMpDDLStore::SetManus() { |
367 | /// Set manus for each bus patch | |
42d368d0 | 368 | |
369 | Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane) - 1; | |
370 | ||
40c8e44b | 371 | // loop over DDL |
42d368d0 | 372 | for (Int_t iDDL = 0; iDDL < fgkNofDDLs; ++iDDL) { |
373 | ||
40c8e44b | 374 | AliDebug(3, Form("DDL # %d\n", iDDL)); |
42d368d0 | 375 | |
40c8e44b | 376 | AliMpDDL* ddl = GetDDL(iDDL); |
42d368d0 | 377 | |
40c8e44b | 378 | // loop over DE in the given DDL |
379 | for (Int_t detElemIdx = 0; detElemIdx < ddl->GetNofDEs(); ++detElemIdx) { | |
42d368d0 | 380 | |
40c8e44b | 381 | Int_t detElemId = ddl->GetDEId(detElemIdx); |
42d368d0 | 382 | |
40c8e44b | 383 | AliMpDetElement* detElement = GetDetElement(detElemId); |
42d368d0 | 384 | |
40c8e44b | 385 | AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId); |
42d368d0 | 386 | |
387 | ||
40c8e44b | 388 | // list of manu per DE on both cathode |
389 | TList manuList; | |
390 | for ( Int_t cath = 0; cath < 2 ; ++cath ) { | |
391 | const AliMpVSegmentation* seg | |
392 | = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(cath)); | |
42d368d0 | 393 | |
40c8e44b | 394 | AliMp::PlaneType planeType = detElement->GetPlaneType(AliMp::GetCathodType(cath)); |
42d368d0 | 395 | |
40c8e44b | 396 | TArrayI manus; |
397 | seg->GetAllElectronicCardIDs(manus); | |
42d368d0 | 398 | |
40c8e44b | 399 | // filling TList manu |
400 | for ( Int_t im = 0; im < manus.GetSize(); ++im ) { | |
42d368d0 | 401 | |
40c8e44b | 402 | AliMpIntPair* manu = 0x0; |
403 | if( stationType == AliMp::kStation345) | |
404 | manu = new AliMpIntPair((manus[im] & manuMask), planeType, kTRUE); //remove offset for NB | |
405 | else | |
406 | manu = new AliMpIntPair(manus[im], planeType, kTRUE); //keep offset for NB | |
42d368d0 | 407 | |
40c8e44b | 408 | manuList.Add(manu); |
42d368d0 | 409 | |
40c8e44b | 410 | detElement->AddManu(manus[im]); |
411 | } | |
412 | }// cathode | |
413 | ||
414 | manuList.Sort(); // sort regardless B or NB plane | |
42d368d0 | 415 | |
40c8e44b | 416 | // filling manu to the corresponding buspatch |
417 | for (Int_t iEntry = 0; iEntry < manuList.GetEntries(); ++iEntry) { | |
42d368d0 | 418 | |
40c8e44b | 419 | AliMpIntPair* manuPtr = (AliMpIntPair*)manuList.At(iEntry); |
42d368d0 | 420 | |
40c8e44b | 421 | Int_t manuId = manuPtr->GetFirst(); |
422 | Int_t pos = GetBusPatchIndex(detElemId, manuId); | |
42d368d0 | 423 | |
40c8e44b | 424 | if (pos > detElement->GetNofBusPatches()) { |
425 | AliError(Form("pos greater %d than size %d manuId %d detElemId %d \n", | |
426 | pos, detElement->GetNofBusPatches(), manuId, detElemId)); | |
427 | return false; | |
428 | } | |
429 | ||
430 | // get buspatch and fill manus | |
431 | Int_t busPatchId = detElement->GetBusPatchId(pos); | |
432 | AliMpBusPatch* busPatch = GetBusPatch(busPatchId); | |
433 | ||
434 | if( stationType == AliMp::kStation345) { | |
435 | ||
436 | if (manuPtr->GetSecond()) | |
437 | busPatch->AddManu(manuId+manuMask+1); // add offset again after sorted | |
438 | else | |
439 | busPatch->AddManu(manuId); | |
440 | ||
441 | } else { | |
442 | ||
443 | busPatch->AddManu(manuId); | |
444 | ||
445 | } | |
446 | } | |
447 | ||
448 | manuList.Delete(); | |
449 | ||
450 | if (AliDebugLevel() == 3) { | |
451 | ||
452 | // print out for checking | |
453 | for(Int_t pos = 0; pos < detElement->GetNofBusPatches(); ++pos) { | |
454 | Int_t busPatchId = detElement->GetBusPatchId(pos); | |
455 | AliMpBusPatch* busPatch = GetBusPatch(busPatchId); | |
456 | printf("BusPatch: %d\n", busPatch->GetId()); | |
457 | for (Int_t iEntry = 0; iEntry < busPatch->GetNofManus(); ++iEntry) | |
458 | printf("manu Id: %d\n", busPatch->GetManuId(iEntry)); | |
459 | } | |
460 | } | |
461 | ||
462 | } // detection element loop | |
42d368d0 | 463 | }// DDL loop |
464 | ||
465 | return true; | |
466 | } | |
f0c62051 | 467 | |
ae649dcb | 468 | //______________________________________________________________________________ |
469 | Bool_t AliMpDDLStore::ReadBusPatchSpecial() | |
470 | { | |
471 | /// Read file with bus patches with a special order of manus | |
472 | /// and reset the manus arrays filled via SetManu function | |
473 | ||
474 | TString infile = AliMpFiles::BusPatchSpecialFilePath(); | |
475 | ||
476 | ifstream in(infile, ios::in); | |
477 | if (!in) { | |
478 | AliErrorStream() << "Data file " << infile << " not found."; | |
479 | return false; | |
480 | } | |
481 | ||
482 | char line[255]; | |
483 | ||
484 | while ( in.getline(line,255) ) { | |
485 | ||
486 | if ( line[0] == '#' ) continue; | |
487 | ||
488 | TString tmp(AliMpHelper::Normalize(line)); | |
489 | TObjArray* stringList = tmp.Tokenize(TString(" ")); | |
490 | ||
491 | TString sKey = ((TObjString*)stringList->At(0))->GetString(); | |
492 | ||
493 | TString sDDL = ((TObjString*)stringList->At(1))->GetString(); | |
494 | TArrayI ddlList; | |
495 | AliMpHelper::DecodeName(sDDL,';',ddlList); | |
496 | ||
497 | TString sBusPatch = ((TObjString*)stringList->At(2))->GetString(); | |
498 | TArrayI busPatchList; | |
499 | AliMpHelper::DecodeName(sBusPatch,',',busPatchList); | |
500 | ||
501 | // Loop over DDL and Bus Patch | |
502 | for (Int_t iDDL = 0; iDDL < ddlList.GetSize(); ++iDDL ) { | |
503 | for (Int_t iBusPatch = 0; iBusPatch < busPatchList.GetSize(); ++iBusPatch) { | |
504 | // Global bus patch ID | |
505 | Int_t busPatchID | |
506 | = AliMpBusPatch::GetGlobalBusID( | |
507 | busPatchList.At(iBusPatch), ddlList.At(iDDL)); | |
508 | ||
509 | // Get this bus patch | |
510 | AliMpBusPatch* busPatch = GetBusPatch(busPatchID); | |
511 | if ( ! busPatch ) { | |
512 | AliErrorStream() << "Bus patch " << busPatchID << " does not exist." << endl; | |
513 | return kFALSE; | |
514 | } | |
515 | ||
516 | if ( sKey == fgkRevertKeyword ) { | |
517 | AliDebugStream(3) | |
518 | << "Reverting readout of bus patch " << busPatchID << endl; | |
519 | ||
520 | // Now revert the manus in this bus patch | |
521 | busPatch->RevertReadout(); | |
522 | } | |
523 | else if ( sKey == fgkExplicitKeyword ) { | |
524 | ||
525 | busPatch->ResetReadout(); | |
526 | ||
527 | TString sManus = ((TObjString*)stringList->At(3))->GetString(); | |
528 | TArrayI manuList; | |
529 | AliMpHelper::DecodeName(sManus,',',manuList); | |
530 | ||
531 | AliDebugStream(3) | |
532 | << "Reseting readout of bus patch " << busPatchID | |
533 | << " manus: " << sManus.Data() << endl; | |
534 | ||
535 | for (Int_t i = 0; i < manuList.GetSize(); i++) { | |
536 | busPatch->AddManu(manuList.At(i)); | |
537 | } | |
538 | } | |
539 | else { | |
540 | AliErrorStream() << "Unrecognized key." << endl; | |
541 | return kFALSE; | |
542 | } | |
543 | } | |
544 | } | |
545 | } | |
546 | ||
547 | return kTRUE; | |
548 | } | |
549 | ||
550 | ||
dbc1e34c | 551 | //______________________________________________________________________________ |
40c8e44b | 552 | Bool_t AliMpDDLStore::SetPatchModules() { |
553 | /// Compute the number of manu per PCB for each buspatch | |
dbc1e34c | 554 | |
0f30c458 | 555 | AliMpDEIterator it; |
556 | Bool_t result = true; | |
dbc1e34c | 557 | |
0f30c458 | 558 | for ( it.First(); !it.IsDone(); it.Next() ) { |
dbc1e34c | 559 | |
40c8e44b | 560 | AliMpDetElement* detElement = it.CurrentDE(); |
561 | ||
562 | for (Int_t i = 0; i < detElement->GetNofBusPatches(); ++i) { | |
563 | AliMpBusPatch* busPatch = GetBusPatch(detElement->GetBusPatchId(i)); | |
564 | Bool_t newResult = false; | |
565 | Int_t idDE = busPatch->GetDEId(); | |
566 | ||
567 | if (AliMpDEManager::GetStationType(idDE) == AliMp::kStation2 ) | |
568 | newResult = busPatch->SetNofManusPerModule(fManuBridge2[GetManuListIndex(idDE)].At(i)); | |
569 | else | |
570 | newResult = busPatch->SetNofManusPerModule(); | |
571 | } | |
0f30c458 | 572 | } |
573 | ||
574 | return result; | |
575 | } | |
576 | ||
577 | //______________________________________________________________________________ | |
40c8e44b | 578 | Bool_t AliMpDDLStore::SetBusPatchLength() { |
579 | /// read the buspatch length file and set buspatch length | |
0f30c458 | 580 | |
581 | TString infile = AliMpFiles::BusPatchLengthFilePath(); | |
582 | ifstream in(infile, ios::in); | |
583 | if (!in) { | |
40c8e44b | 584 | AliErrorStream() << "Data file " << infile << " not found."; |
585 | return false; | |
586 | } | |
0f30c458 | 587 | char line[255]; |
588 | ||
589 | for (Int_t iDDL = 0; iDDL < fgkNofDDLs; ++iDDL ) { | |
40c8e44b | 590 | AliMpDDL* ddl = GetDDL(iDDL); |
0f30c458 | 591 | |
40c8e44b | 592 | for (Int_t iBusPatch = 0; iBusPatch < ddl->GetNofBusPatches(); ++iBusPatch) { |
0f30c458 | 593 | |
40c8e44b | 594 | do { |
595 | if (!in.getline(line,255)) { | |
596 | AliWarning(Form("Wrong size in bus patch length file; index %d DDL %d", | |
597 | iBusPatch, iDDL)); | |
598 | return false; | |
599 | } | |
600 | } while(line[0] == '#'); | |
d9fc467c | 601 | |
40c8e44b | 602 | TString tmp(AliMpHelper::Normalize(line)); |
d9fc467c | 603 | |
40c8e44b | 604 | TObjArray* stringList = tmp.Tokenize(TString(" ")); |
d9fc467c | 605 | |
40c8e44b | 606 | TString sLocalBusId = ((TObjString*)stringList->At(0))->GetString(); |
607 | Int_t localBusId = sLocalBusId.Atoi(); | |
d9fc467c | 608 | |
40c8e44b | 609 | TString sLength = ((TObjString*)stringList->At(1))->GetString(); |
610 | Float_t length = sLength.Atof(); | |
0f30c458 | 611 | |
40c8e44b | 612 | delete stringList; |
613 | ||
614 | if (localBusId != iBusPatch + 1) | |
615 | AliWarning(Form("Wrong local buspatch id %d instead of %d", iBusPatch+1, localBusId)); | |
616 | ||
617 | Int_t busPatchId = ddl->GetBusPatchId(iBusPatch); | |
618 | AliMpBusPatch* busPatch = GetBusPatch(busPatchId); | |
619 | busPatch->SetCableLength(length); | |
620 | } | |
0f30c458 | 621 | } |
622 | ||
623 | return true; | |
dbc1e34c | 624 | } |
625 | ||
0f30c458 | 626 | |
61c370dd | 627 | //________________________________________________________________ |
40c8e44b | 628 | Int_t AliMpDDLStore::GetLocalBoardId(TString name) const { |
629 | /// return the first board with a given side and line | |
61c370dd | 630 | |
efb566fd | 631 | |
632 | TExMapIter i = fRegionalTrigger.GetLocalBoardItr(); | |
61c370dd | 633 | Long_t key, value; |
634 | while ( i.Next(key, value) ) { | |
40c8e44b | 635 | AliMpLocalBoard* local = (AliMpLocalBoard*)value; |
61c370dd | 636 | |
40c8e44b | 637 | TString tmp(&local->GetName()[4], 2); |
638 | if (name.Contains(tmp)) | |
639 | if (name[0] == local->GetName()[0]) | |
640 | return local->GetId(); | |
61c370dd | 641 | } |
642 | ||
643 | return 0; | |
644 | ||
645 | } | |
dbc1e34c | 646 | |
f0c62051 | 647 | // |
648 | // public methods | |
649 | // | |
650 | ||
651 | ||
652 | //______________________________________________________________________________ | |
40c8e44b | 653 | AliMpDDL* AliMpDDLStore::GetDDL(Int_t ddlId, Bool_t warn) const { |
654 | /// Return DDL for given ddlId | |
f0c62051 | 655 | |
40c8e44b | 656 | AliMpDDL* ddl |
f0c62051 | 657 | = (AliMpDDL*)fDDLs.At(ddlId); |
40c8e44b | 658 | |
659 | if ( ! ddl && warn ) { | |
660 | AliErrorStream() | |
f0c62051 | 661 | << "DDL with Id = " << ddlId << " not defined." << endl; |
40c8e44b | 662 | } |
f0c62051 | 663 | |
40c8e44b | 664 | return ddl; |
665 | } | |
f0c62051 | 666 | |
667 | //______________________________________________________________________________ | |
40c8e44b | 668 | AliMpDetElement* AliMpDDLStore::GetDetElement(Int_t detElemId, Bool_t warn) const { |
669 | /// Return detection element with given detElemId | |
f0c62051 | 670 | |
40c8e44b | 671 | if ( ! AliMpDEStore::Instance() ) { |
672 | AliFatal("DE Store has not been loaded."); | |
673 | return 0; | |
674 | } | |
24f9bd97 | 675 | |
40c8e44b | 676 | return AliMpDEStore::Instance()->GetDetElement(detElemId, warn); |
677 | } | |
f0c62051 | 678 | |
679 | //______________________________________________________________________________ | |
40c8e44b | 680 | AliMpBusPatch* AliMpDDLStore::GetBusPatch(Int_t busPatchId, Bool_t warn) const { |
681 | /// Return bus patch with given Id | |
f0c62051 | 682 | |
40c8e44b | 683 | AliMpBusPatch* busPatch |
f0c62051 | 684 | = (AliMpBusPatch*) fBusPatches.GetValue(busPatchId); |
40c8e44b | 685 | |
686 | if ( ! busPatch && warn ) { | |
687 | AliErrorStream() | |
f0c62051 | 688 | << "Bus patch with Id = " << busPatchId << " not defined." << endl; |
40c8e44b | 689 | } |
f0c62051 | 690 | |
40c8e44b | 691 | return busPatch; |
692 | } | |
f0c62051 | 693 | |
61c370dd | 694 | //______________________________________________________________________________ |
40c8e44b | 695 | AliMpLocalBoard* AliMpDDLStore::GetLocalBoard(Int_t localBoardId, Bool_t warn) const { |
696 | /// Return bus patch with given Id | |
61c370dd | 697 | |
efb566fd | 698 | return fRegionalTrigger.FindLocalBoard(localBoardId, warn); |
40c8e44b | 699 | } |
61c370dd | 700 | |
701 | //______________________________________________________________________________ | |
efb566fd | 702 | AliMpTriggerCrate* AliMpDDLStore::GetTriggerCrate(TString name, Bool_t warn) const { |
40c8e44b | 703 | /// Return trigger crate with given name |
61c370dd | 704 | |
efb566fd | 705 | return fRegionalTrigger.FindTriggerCrate(name, warn); |
40c8e44b | 706 | } |
61c370dd | 707 | |
708 | //______________________________________________________________________________ | |
efb566fd | 709 | AliMpTriggerCrate* AliMpDDLStore::GetTriggerCrate(Int_t ddlId, Int_t index, Bool_t warn) const { |
40c8e44b | 710 | /// Return trigger crate with given ddl and index crate |
61c370dd | 711 | |
40c8e44b | 712 | if (ddlId == 0 || ddlId == 1) |
713 | ddlId += fgkNofDDLs; | |
fbd38b34 | 714 | |
40c8e44b | 715 | AliMpDDL* ddl = GetDDL(ddlId, warn); |
716 | if ( ! ddl ) | |
717 | return 0; | |
718 | ||
719 | if ( index >= ddl->GetNofTriggerCrates() ) { | |
720 | AliError(Form("crate id %d greater than array[%d]", index, ddl->GetNofTriggerCrates())); | |
721 | return 0; | |
722 | } | |
723 | ||
724 | TString name = AliMpTriggerCrate::GenerateName(index, ddlId, fgkNofDDLs); | |
725 | ||
726 | return GetTriggerCrate(name, warn); | |
727 | } | |
61c370dd | 728 | |
f0c62051 | 729 | //______________________________________________________________________________ |
40c8e44b | 730 | Int_t AliMpDDLStore::GetDEfromBus(Int_t busPatchId) const { |
731 | /// Return detection element Id for given busPatchId | |
f0c62051 | 732 | |
40c8e44b | 733 | AliMpBusPatch* busPatch = GetBusPatch(busPatchId); |
734 | ||
735 | if ( ! busPatch ) { | |
736 | AliErrorStream() | |
f0c62051 | 737 | << "Bus patch with Id = " << busPatchId << " not defined." << endl; |
40c8e44b | 738 | return 0; |
739 | } | |
f0c62051 | 740 | |
40c8e44b | 741 | return busPatch->GetDEId(); |
742 | } | |
f0c62051 | 743 | |
61c370dd | 744 | //______________________________________________________________________________ |
40c8e44b | 745 | Int_t AliMpDDLStore::GetDEfromLocalBoard(Int_t localBoardId, Int_t chamberId) const { |
746 | /// Return detElemId for local board Id and chamber id. | |
61c370dd | 747 | |
40c8e44b | 748 | AliMpLocalBoard* localBoard = GetLocalBoard(localBoardId); |
749 | ||
750 | if ( ! localBoard ) { | |
751 | AliErrorStream() | |
61c370dd | 752 | << "Loacl board with Id = " << localBoardId << " not defined." << endl; |
40c8e44b | 753 | return 0; |
754 | } | |
61c370dd | 755 | |
40c8e44b | 756 | return localBoard->GetDEIdByChamber(chamberId); |
61c370dd | 757 | } |
758 | ||
f0c62051 | 759 | //______________________________________________________________________________ |
40c8e44b | 760 | Int_t AliMpDDLStore::GetDDLfromBus(Int_t busPatchId) const { |
761 | /// Return DDL Id for given busPatchId | |
f0c62051 | 762 | |
40c8e44b | 763 | AliMpBusPatch* busPatch = GetBusPatch(busPatchId); |
764 | ||
765 | if ( ! busPatch ) { | |
766 | AliErrorStream() | |
f0c62051 | 767 | << "Bus patch with Id = " << busPatchId << " not defined." << endl; |
40c8e44b | 768 | return 0; |
769 | } | |
f0c62051 | 770 | |
40c8e44b | 771 | return busPatch->GetDdlId(); |
772 | } | |
f0c62051 | 773 | |
42d368d0 | 774 | //______________________________________________________________________________ |
40c8e44b | 775 | Int_t AliMpDDLStore::GetBusPatchId(Int_t detElemId, Int_t manuId) const { |
776 | /// Return bus patch for a given manuId | |
777 | ||
778 | AliMpDetElement* detElement = GetDetElement(detElemId); | |
779 | Int_t pos = GetBusPatchIndex(detElemId, manuId); | |
780 | ||
781 | if ( pos > detElement->GetNofBusPatches() ) { | |
782 | AliErrorStream() | |
783 | << "Pos = " << pos | |
784 | << " greater than the size = " << detElement->GetNofBusPatches() | |
785 | << " for detElemId = " << detElemId | |
786 | << " manuId = " << manuId << endl; | |
787 | return -1; | |
788 | } | |
42d368d0 | 789 | |
40c8e44b | 790 | return detElement->GetBusPatchId(pos); |
791 | } | |
42d368d0 | 792 | |
f0c62051 | 793 | //______________________________________________________________________________ |
40c8e44b | 794 | AliMpIntPair AliMpDDLStore::GetDetElemIdManu(Int_t manuSerial) const { |
795 | /// Return the detElemId and manuId for given serial manu number | |
f0c62051 | 796 | |
40c8e44b | 797 | if ( ! AliMpDEStore::Instance() ) { |
798 | AliFatal("DE Store has not been loaded."); | |
799 | return AliMpIntPair::Invalid(); | |
800 | } | |
24f9bd97 | 801 | |
40c8e44b | 802 | return AliMpDEStore::Instance()->GetDetElemIdManu(manuSerial); |
803 | } | |
92faf71f | 804 | |
805 | //______________________________________________________________________________ | |
40c8e44b | 806 | void AliMpDDLStore::PrintAllManu() const { |
807 | /// Print all manu Ids and their serial numbers sorted by detection element | |
808 | /// and bus patch. \n | |
809 | /// As serial manu numbers are filled in a different way than manu Ids this | |
810 | /// printing allows to check that both ways are consistent | |
811 | ||
812 | // Loop over DE | |
813 | AliMpDEIterator it; | |
814 | for ( it.First(); ! it.IsDone(); it.Next() ) { | |
815 | AliMpDetElement* de = it.CurrentDE(); | |
816 | cout << "DE: " << de->GetId() << endl; | |
817 | ||
818 | // Loop over bus patches in this DE | |
819 | for ( Int_t i=0; i< de->GetNofBusPatches(); ++i ) { | |
820 | ||
821 | AliMpBusPatch* busPatch = GetBusPatch(de->GetBusPatchId(i)); | |
822 | cout << " busPatch: " << busPatch->GetId() << endl; | |
823 | ||
824 | cout << " Manu : "; | |
825 | for ( Int_t j=0; j<busPatch->GetNofManus(); ++j ) { | |
826 | cout << std::setw(6) << busPatch->GetManuId(j) << " "; | |
827 | } | |
828 | cout << endl; | |
829 | ||
830 | cout << " Manu serial: "; | |
831 | for ( Int_t k=0; k<busPatch->GetNofManus(); ++k ) { | |
832 | cout << std::setw(6) << de->GetManuSerialFromId(busPatch->GetManuId(k)) << " "; | |
833 | } | |
834 | cout << endl; | |
835 | } | |
836 | } | |
837 | } | |
92faf71f | 838 | |
efb566fd | 839 | //______________________________________________________________________________ |
40c8e44b | 840 | Int_t AliMpDDLStore::GetNextDEfromLocalBoard(Int_t localBoardId, Int_t chamberId ) const { |
841 | /// return the next detection element in line | |
61c370dd | 842 | |
843 | AliMpLocalBoard* localBoard = GetLocalBoard(localBoardId); | |
844 | ||
845 | TString name(localBoard->GetName()); | |
846 | ||
847 | Int_t line = localBoard->GetPosition().GetFirst(); | |
848 | ++line; | |
40c8e44b | 849 | |
61c370dd | 850 | name.Replace(4,1,Form("%d", line)); |
851 | ||
40c8e44b | 852 | Int_t nextLocalId; |
61c370dd | 853 | if ((nextLocalId = GetLocalBoardId(name))) |
40c8e44b | 854 | return GetDEfromLocalBoard(nextLocalId, chamberId); |
61c370dd | 855 | else |
40c8e44b | 856 | return 0; |
61c370dd | 857 | |
858 | return 0; | |
859 | } | |
860 | ||
efb566fd | 861 | //______________________________________________________________________________ |
40c8e44b | 862 | Int_t AliMpDDLStore::GetPreviousDEfromLocalBoard(Int_t localBoardId, Int_t chamberId) const { |
863 | /// return the previous detection element in line | |
61c370dd | 864 | |
865 | AliMpLocalBoard* localBoard = GetLocalBoard(localBoardId); | |
866 | ||
867 | TString name(localBoard->GetName()); | |
868 | ||
869 | Int_t line = localBoard->GetPosition().GetFirst(); | |
870 | --line; | |
40c8e44b | 871 | |
61c370dd | 872 | name.Replace(4,1,Form("%d", line)); |
873 | ||
874 | Int_t prevLocalId; | |
875 | if ((prevLocalId = GetLocalBoardId(name))) | |
40c8e44b | 876 | return GetDEfromLocalBoard(prevLocalId, chamberId); |
61c370dd | 877 | else |
40c8e44b | 878 | return 0; |
61c370dd | 879 | |
880 | } | |
efb566fd | 881 | |
882 | //______________________________________________________________________________ | |
883 | void AliMpDDLStore::SetRegionalTrigger(const AliMpRegionalTrigger& regionalTrigger) | |
884 | { | |
885 | /// Replace the existing regional trigger with the given one | |
886 | ||
887 | fRegionalTrigger = regionalTrigger; | |
888 | ||
92c23b09 | 889 | // Remove the existing trigger DDLsf |
efb566fd | 890 | fDDLs.RemoveAt(fgkNofDDLs+1); |
891 | fDDLs.RemoveAt(fgkNofDDLs); | |
892 | ||
893 | // Set new trigger DDLs from new regional trigger | |
894 | SetTriggerDDLs(); | |
895 | } |