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