LCOV - code coverage report
Current view: top level - MUON/MUONmapping - AliMpDDLStore.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 315 418 75.4 %
Date: 2016-06-14 17:26:59 Functions: 33 38 86.8 %

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

Generated by: LCOV version 1.11