LCOV - code coverage report
Current view: top level - MUON/MUONmapping - AliMpUID.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 134 0.7 %
Date: 2016-06-14 17:26:59 Functions: 1 27 3.7 %

          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             : 
      18             : #include "AliMpUID.h"
      19             : 
      20             : #include "AliLog.h"
      21             : #include "Riostream.h"
      22             : #include "TObjArray.h"
      23             : #include "TObjString.h"
      24             : #include "TSystem.h"
      25             : 
      26             : ///
      27             : /// station/chamber/de/bp/manu
      28             : ///
      29             : /// station/chamber/pcb/manu
      30             : 
      31             : using std::cout;
      32             : using std::endl;
      33          18 : ClassImp(AliMpUID)
      34             : 
      35             : namespace
      36             : {
      37             :   const char* nameTemplateMANU = "MANU %d";
      38             :   const char* nameTemplateDE = "DE %d";
      39             :   const char* nameTemplateBP = "BusPatch %d";
      40             :   const char* nameTemplateCHAMBER = "Chamber %d";
      41             :   const char* nameTemplateSTATION = "Station %d";
      42             :   const char* nameTemplatePCB = "PCB %d";
      43             :   
      44             :   const char* pathTemplateMANU = "Cathode%d/Station%d/Chamber%d/DE%04d/BUSPATCH%04d/MANU%04d";
      45             :   const char* pathTemplateBP = "Cathode%d/Station%d/Chamber%d/DE%04d/BUSPATCH%04d";
      46             :   const char* pathTemplateDE = "Cathode%d/Station%d/Chamber%d/DE%04d";
      47             :   const char* pathTemplateCHAMBER = "Cathode%d/Station%d/Chamber%d";
      48             :   const char* pathTemplateSTATION = "Cathode%d/Station%d";
      49             : 
      50             :   const char* pathTemplateMANUPCB = "Cathode%d/Station%d/Chamber%d/DE%04d/PCB%d/MANU%04d";
      51             :   const char* pathTemplatePCB = "Cathode%d/Station%d/Chamber%d/DE%04d/PCB%d";
      52             : }
      53             : 
      54             : //_____________________________________________________________________________
      55           0 : AliMpUID::AliMpUID()
      56             : : 
      57           0 : fCathodeId(-1),
      58           0 : fStationId(-1),
      59           0 : fChamberId(-1),
      60           0 : fDetElemId(-1),
      61           0 : fBusPatchId(-1),
      62           0 : fManuId(-1),
      63           0 : fPCBId(-1)
      64           0 : {
      65             :   /// empty ctor
      66           0 : }
      67             : 
      68             : //_____________________________________________________________________________
      69           0 : AliMpUID::AliMpUID(AliMp::CathodType cathodeType, Int_t station, Int_t chamber, Int_t de, Int_t bp, Int_t manu, Int_t pcb)
      70             : : 
      71           0 : fCathodeId(cathodeType),
      72           0 : fStationId(station),
      73           0 : fChamberId(chamber),
      74           0 : fDetElemId(de),
      75           0 : fBusPatchId(bp),
      76           0 : fManuId(manu),
      77           0 : fPCBId(pcb)
      78           0 : {
      79             :   /// default ctor
      80           0 : }
      81             : 
      82             : //_____________________________________________________________________________
      83           0 : AliMpUID::AliMpUID(AliMp::CathodType cathodeType, const AliMpUID& b)
      84             : : 
      85           0 : fCathodeId(cathodeType),
      86           0 : fStationId(b.StationId()),
      87           0 : fChamberId(b.ChamberId()),
      88           0 : fDetElemId(b.DetElemId()),
      89           0 : fBusPatchId(b.BusPatchId()),
      90           0 : fManuId(b.ManuId()),
      91           0 : fPCBId(b.PCBId())
      92           0 : {
      93             :   /// build the id from b, but using the given cathodeType
      94           0 : }
      95             : 
      96             : //_____________________________________________________________________________
      97           0 : AliMpUID::AliMpUID(AliMp::CathodType cathodeType, const char* pathname)
      98             : :
      99           0 : fCathodeId(cathodeType),
     100           0 : fStationId(-1),
     101           0 : fChamberId(-1),
     102           0 : fDetElemId(-1),
     103           0 : fBusPatchId(-1),
     104           0 : fManuId(-1),
     105           0 : fPCBId(-1)
     106           0 : {
     107             :   /// build id from path, but using the given cathodeType
     108             :   
     109           0 :   if ( CheckTemplate(pathname,pathTemplateMANUPCB,fPCBId) && fPCBId >= 0 ) return;
     110           0 :   if ( CheckTemplate(pathname,pathTemplatePCB,fPCBId) && fPCBId >= 0 ) return;
     111             :   
     112           0 :   if ( CheckTemplate(pathname,pathTemplateMANU,fBusPatchId) ) return;
     113           0 :   if ( CheckTemplate(pathname,pathTemplateBP,fBusPatchId) ) return;
     114           0 :   if ( CheckTemplate(pathname,pathTemplateDE,fBusPatchId) ) return;
     115           0 :   if ( CheckTemplate(pathname,pathTemplateCHAMBER,fBusPatchId) ) return;
     116           0 :   if ( CheckTemplate(pathname,pathTemplateSTATION,fBusPatchId) ) return;
     117           0 : }
     118             : 
     119             : 
     120             : //_____________________________________________________________________________
     121           0 : AliMpUID::AliMpUID(const char* pathname)
     122             : :
     123           0 : fCathodeId(2),
     124           0 : fStationId(-1),
     125           0 : fChamberId(-1),
     126           0 : fDetElemId(-1),
     127           0 : fBusPatchId(-1),
     128           0 : fManuId(-1),
     129           0 : fPCBId(-1)
     130           0 : {
     131             :   /// Build id from path
     132             :   
     133           0 :   if ( CheckTemplate(pathname,pathTemplateMANUPCB,fPCBId) && fPCBId >= 0 ) return;
     134           0 :   if ( CheckTemplate(pathname,pathTemplatePCB,fPCBId) && fPCBId >= 0 ) return;
     135             :   
     136           0 :   if ( CheckTemplate(pathname,pathTemplateMANU,fBusPatchId) ) return;
     137           0 :   if ( CheckTemplate(pathname,pathTemplateBP,fBusPatchId) ) return;
     138           0 :   if ( CheckTemplate(pathname,pathTemplateDE,fBusPatchId) ) return;
     139           0 :   if ( CheckTemplate(pathname,pathTemplateCHAMBER,fBusPatchId) ) return;
     140           0 :   if ( CheckTemplate(pathname,pathTemplateSTATION,fBusPatchId) ) return;
     141           0 : }
     142             : 
     143             : //_____________________________________________________________________________
     144             : TString
     145             : AliMpUID::BaseName() const
     146             : {
     147             :   /// Get the basename
     148           0 :   return gSystem->BaseName(PathName().Data());
     149           0 : }
     150             : 
     151             : //_____________________________________________________________________________
     152             : AliMp::CathodType 
     153             : AliMpUID::CathodeId() const
     154             : {
     155             :   /// return cathode id (not always valid)
     156           0 :   return AliMp::GetCathodType(fCathodeId);
     157             : }
     158             : 
     159             : //_____________________________________________________________________________
     160             : Bool_t
     161             : AliMpUID::CheckTemplate(const char* name, const char* pathTemplateName, Int_t& value)
     162             : {
     163             :   /// Check a name against a template
     164             :   
     165           0 :   if ( TString(name).Contains("Cathode") ) 
     166             :   {
     167           0 :     sscanf(name,pathTemplateName,&fCathodeId,&fStationId,&fChamberId,&fDetElemId,&value,&fManuId);
     168           0 :   }
     169             :   else
     170             :   {
     171           0 :     TString templ(pathTemplateName);
     172           0 :     Int_t i = templ.Index("/");
     173           0 :     templ = templ(i+1,templ.Length()-i-1);
     174           0 :     sscanf(name,templ.Data(),&fStationId,&fChamberId,&fDetElemId,&value,&fManuId);
     175           0 :   }
     176           0 :   return IsValid();
     177           0 : }
     178             : 
     179             : //_____________________________________________________________________________
     180             : TString
     181             : AliMpUID::DirName() const
     182             : {
     183             :   /// Get dirname
     184           0 :   return gSystem->DirName(PathName().Data());
     185           0 : }
     186             : 
     187             : //_____________________________________________________________________________
     188             : Bool_t 
     189             : AliMpUID::IsStation() const
     190             : {
     191             :   /// Whether we identify a station
     192           0 :   return fCathodeId >= 0 && fStationId >= 0 && fChamberId == -1 ;
     193             : }
     194             : 
     195             : //_____________________________________________________________________________
     196             : Bool_t 
     197             : AliMpUID::IsChamber() const
     198             : {
     199             :   /// Whether we identify a chamber
     200             : 
     201           0 :   return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId == -1;
     202             : }
     203             : 
     204             : //_____________________________________________________________________________
     205             : Bool_t 
     206             : AliMpUID::IsDetectionElement() const
     207             : {
     208             :   /// whether we identify a detection element
     209           0 :   return fCathodeId >= 0 &&  fStationId >= 0 && fChamberId >= 0 && fDetElemId >= 0 && fBusPatchId==-1 && fPCBId == -1;
     210             : }
     211             : 
     212             : //_____________________________________________________________________________
     213             : Bool_t 
     214             : AliMpUID::IsBusPatch() const
     215             : {
     216             :   /// whether we identify a bus patch
     217           0 :   return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId >= 0 && fBusPatchId>=0 && fManuId ==-1;
     218             : }
     219             : 
     220             : //_____________________________________________________________________________
     221             : Bool_t AliMpUID::IsManu() const
     222             : {
     223             :   /// whether we identify a manu
     224           0 :   return 
     225           0 :   fCathodeId >= 0 && 
     226           0 :   fStationId >= 0 && 
     227           0 :   fChamberId >= 0 && 
     228           0 :   fDetElemId >= 0 && 
     229           0 :   ( fBusPatchId>=0 || fPCBId >=0 ) && 
     230           0 :   fManuId >=0;
     231             : }
     232             : 
     233             : //_____________________________________________________________________________
     234             : Bool_t AliMpUID::IsPCB() const
     235             : {
     236             :   /// Whether we identify a PCB
     237           0 :   return fCathodeId >= 0 && fPCBId >= 0 && fManuId == -1;
     238             : }
     239             : 
     240             : //_____________________________________________________________________________
     241             : Bool_t AliMpUID::IsValid() const
     242             : {
     243             :   /// Whether we're a valid UID...
     244           0 :   return IsStation() || IsChamber() || IsDetectionElement() || IsBusPatch() || IsManu() || IsPCB();
     245             : }
     246             : 
     247             : //_____________________________________________________________________________
     248             : TString 
     249             : AliMpUID::Name() const
     250             : {
     251             :   /// Get our name
     252           0 :   if ( IsManu() ) 
     253             :   {
     254           0 :     return Form(nameTemplateMANU,ManuId());
     255             :   }
     256             :   
     257           0 :   if ( IsPCB() ) 
     258             :   {
     259           0 :     return Form(nameTemplatePCB,PCBId());
     260             :   }
     261             :   
     262           0 :   if ( IsBusPatch() ) 
     263             :   {
     264           0 :     return Form(nameTemplateBP,BusPatchId());
     265             :   }
     266             :   
     267           0 :   if ( IsDetectionElement() ) 
     268             :   {
     269           0 :     return Form(nameTemplateDE,DetElemId());
     270             :   }
     271             :   
     272           0 :   if ( IsChamber() ) 
     273             :   {
     274           0 :     return Form(nameTemplateCHAMBER,ChamberId());
     275             :   }
     276             :   
     277           0 :   if ( IsStation() ) 
     278             :   {
     279           0 :     return Form(nameTemplateSTATION,StationId());
     280             :   }
     281             :   
     282           0 :   return "INVALID NAME";
     283           0 : }
     284             : 
     285             : //_____________________________________________________________________________
     286             : TString 
     287             : AliMpUID::PathName() const
     288             : {
     289             :   /// Get our pathname
     290           0 :   if ( IsManu() ) 
     291             :   {
     292           0 :     if ( fPCBId >= 0 ) 
     293             :     {
     294           0 :       return StripCathode(Form(pathTemplateMANUPCB,CathodeId(),StationId(),ChamberId(),DetElemId(),PCBId(),ManuId()));
     295             :     }
     296             :     else
     297             :     {
     298           0 :       return StripCathode(Form(pathTemplateMANU,CathodeId(),StationId(),ChamberId(),DetElemId(),BusPatchId(),ManuId()));
     299             :     }
     300             :   }
     301             :   
     302           0 :   if ( IsPCB() ) 
     303             :   {
     304           0 :     return StripCathode(Form(pathTemplatePCB,CathodeId(),StationId(),ChamberId(),DetElemId(),PCBId()));
     305             :   }
     306             :   
     307           0 :   if ( IsBusPatch() ) 
     308             :   {
     309           0 :     return StripCathode(Form(pathTemplateBP,CathodeId(),StationId(),ChamberId(),DetElemId(),BusPatchId()));
     310             :   }
     311             :   
     312           0 :   if ( IsDetectionElement() ) 
     313             :   {
     314           0 :     return StripCathode(Form(pathTemplateDE,CathodeId(),StationId(),ChamberId(),DetElemId()));
     315             :   }
     316             :   
     317           0 :   if ( IsChamber() ) 
     318             :   {
     319           0 :     return StripCathode(Form(pathTemplateCHAMBER,CathodeId(),StationId(),ChamberId()));
     320             :   }
     321             :   
     322           0 :   if ( IsStation() ) 
     323             :   {
     324           0 :     return StripCathode(Form(pathTemplateSTATION,CathodeId(),StationId()));
     325             :   }
     326             :   
     327           0 :   return "INVALID PATHNAME";
     328           0 : }
     329             : 
     330             : //_____________________________________________________________________________
     331             : void 
     332             : AliMpUID::Print(Option_t*) const
     333             : {
     334             :   /// Printout
     335           0 :   cout << Name().Data() << " (" << PathName().Data() << ")" << endl;
     336           0 : }
     337             : 
     338             : //_____________________________________________________________________________
     339             : TString
     340             : AliMpUID::StripCathode(const char* name) const
     341             : {
     342             :   /// Remove cathode information if both cathodes are present
     343             :   
     344           0 :   TString rv(name);
     345             :   
     346           0 :   if ( fCathodeId == 2 ) 
     347             :   {
     348           0 :     rv.ReplaceAll("Cathode2/","");
     349             :   }
     350             :   
     351             :   return rv;
     352           0 : }
     353             : 
     354             : //_____________________________________________________________________________
     355             : TString
     356             : AliMpUID::Type() const
     357             : {
     358             :   /// Remove cathode information if both cathodes are present
     359           0 :   TString n(Name());
     360           0 :   TObjArray* s = n.Tokenize(" ");
     361           0 :   TString rv(static_cast<TObjString*>(s->At(0))->String());
     362           0 :   delete s;
     363             :   return rv;
     364           0 : }
     365             : 

Generated by: LCOV version 1.11