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