LCOV - code coverage report
Current view: top level - MUON/MUONmapping - AliMpDEStore.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 79 108 73.1 %
Date: 2016-06-14 17:26:59 Functions: 12 15 80.0 %

          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: AliMpDEStore.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
      18             : // Category: management
      19             : 
      20             : //-----------------------------------------------------------------------------
      21             : // Class AliMpDEStore
      22             : // --------------------
      23             : // The container class for detection element objects
      24             : // Authors: Ivana Hrivnacova, IPN Orsay
      25             : //          Laurent Aphecetche, Christian Finck, SUBATECH Nantes
      26             : //-----------------------------------------------------------------------------
      27             : 
      28             : #include <cstdlib>
      29             : #include "AliMpDEStore.h"
      30             : #include "AliMpDEManager.h"
      31             : #include "AliMpDetElement.h"
      32             : #include "AliMpConstants.h"
      33             : #include "AliMpFiles.h"
      34             : #include "AliMpDataStreams.h"
      35             : #include "AliMpHelper.h"
      36             : #include "AliMpConstants.h"
      37             : #include "AliMpExMapIterator.h"
      38             : 
      39             : #include "AliLog.h"
      40             : 
      41             : #include <Riostream.h>
      42             : #include <TClass.h>
      43             : #include <TSystem.h>
      44             : #include <TObjString.h>
      45             : #include <TObjArray.h>
      46             : #include <TMap.h>
      47             : 
      48             : /// \cond CLASSIMP
      49          18 : ClassImp(AliMpDEStore)
      50             : /// \endcond
      51             : 
      52             : AliMpDEStore* AliMpDEStore::fgInstance = 0;
      53             : const char    AliMpDEStore::fgkCommentPrefix = '#'; 
      54             : 
      55             : //
      56             : // static methods
      57             : //
      58             : 
      59             : //______________________________________________________________________________
      60             : AliMpDEStore* AliMpDEStore::Instance(Bool_t warn)
      61             : {
      62             : /// Create the DE store if it does not yet exist
      63             : /// and return its instance
      64             : 
      65     2546038 :   if ( ! fgInstance && warn  ) {
      66           0 :     AliWarningClass("DE Store has not been loaded");
      67           0 :   }  
      68             :      
      69     2546035 :   return fgInstance;
      70             : }    
      71             : 
      72             : //______________________________________________________________________________
      73             : AliMpDEStore* AliMpDEStore::ReadData(const AliMpDataStreams& dataStreams, 
      74             :                                      Bool_t warn)
      75             : {
      76             : /// Load the DE store data from ASCII data files
      77             : /// and return its instance
      78             : 
      79           3 :   if ( fgInstance ) {
      80           0 :     if ( warn )
      81           0 :       AliWarningClass("DE Store has been already loaded");
      82           0 :     return fgInstance;
      83             :   }  
      84             :   
      85           3 :   if ( dataStreams.GetReadFromFiles() )
      86           0 :     AliInfoClass("Reading DE Store from ASCII files.");
      87             : 
      88           6 :   fgInstance = new AliMpDEStore(dataStreams);
      89           3 :   return fgInstance;
      90           3 : }    
      91             : 
      92             : //
      93             : // ctors, dtor
      94             : //
      95             : 
      96             : //______________________________________________________________________________
      97             : AliMpDEStore::AliMpDEStore(const AliMpDataStreams& dataStreams)
      98           3 : : TObject(),
      99           3 :   fDetElements()
     100          15 : {  
     101             : /// Standard constructor
     102             : 
     103          15 :   AliDebug(1,"");
     104           3 :   fDetElements.SetOwner(true);
     105             : 
     106             :   // Create all detection elements
     107           3 :   FillDEs(dataStreams);
     108           6 : }
     109             : 
     110             : //______________________________________________________________________________
     111             : AliMpDEStore::AliMpDEStore(TRootIOCtor* ioCtor)
     112           0 : : TObject(),
     113           0 :   fDetElements(ioCtor)
     114           0 : {  
     115             : /// Constructor for IO
     116             : 
     117           0 :   AliDebug(1,"");
     118             : 
     119           0 :   fgInstance = this;
     120           0 : }
     121             : 
     122             : 
     123             : //______________________________________________________________________________
     124             : AliMpDEStore::~AliMpDEStore()
     125          12 : {
     126             : /// Destructor
     127             : 
     128          10 :   AliDebug(1,"");
     129             : 
     130             :   // Segmentations are deleted with fMpSegmentations 
     131             :   // El cards arrays are deleted with fElCardsMap
     132             :   
     133           2 :   fgInstance = 0;
     134           6 : }
     135             : 
     136             : //
     137             : // private methods
     138             : //
     139             : 
     140             : //______________________________________________________________________________
     141             : Bool_t AliMpDEStore::IsPlaneType(const TString& planeTypeName)
     142             : {
     143             : /// Return true if the planeTypeName corresponds to a valid plane type
     144             : 
     145          87 :   if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) ||
     146          24 :        planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) ) 
     147           6 :     return true;   
     148             : 
     149           9 :   return false;
     150          15 : }  
     151             : 
     152             : //______________________________________________________________________________
     153             : Bool_t
     154             : AliMpDEStore::ReadDENames(const AliMpDataStreams& dataStreams,
     155             :                           AliMp::StationType station,
     156             :                           AliMq::Station12Type station12)
     157             : { 
     158             : /// Read det element names for cath = 0 from the file specified by name
     159             : /// and fill the map 
     160             : 
     161             :   // Open stream
     162             :   istream& in 
     163          24 :     = dataStreams.
     164          24 :         CreateDataStream(AliMpFiles::DENamesFilePath(station, station12));
     165             :   
     166             :   // Read plane types per cathods
     167             :   //
     168          12 :   char line[80];
     169          12 :   TString word;
     170          24 :   TString cathName1, cathName2;
     171          12 :   in >> word;
     172         144 :   while ( ! in.eof() && cathName1.Length() == 0 ) {
     173          48 :     if ( word[0] == '#' ) 
     174          12 :       in.getline(line, 80);
     175             :     else { 
     176          12 :       cathName1 = word;
     177          12 :       in >> cathName2;
     178             :     }
     179          24 :     in >> word;
     180             :   }
     181             :   
     182             :   Bool_t isCathNameDefined = false;
     183          30 :   if ( IsPlaneType(cathName1) &&  IsPlaneType(cathName2) )
     184           3 :     isCathNameDefined = true;
     185             :     
     186             :   // Read DE names
     187             :   //
     188             :   Int_t detElemId;
     189          48 :   TString name, name0, name1, name2;
     190             :   AliMp::PlaneType planeForCathode[2];
     191             :   
     192        1488 :   while ( ! in.eof() ) 
     193             :   {
     194        1452 :     if ( word[0] == '#' ) 
     195             :     {
     196          42 :       in.getline(line, 80);
     197             :     }
     198             :     else 
     199             :     {  
     200         684 :       detElemId = word.Atoi();
     201         684 :       in >> name;
     202         684 :       in >> name0;
     203             :       // warning : important to check non bending first (=nbp),
     204             :       // as bp is contained within nbp...
     205        2052 :       if ( name0.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
     206             :       {
     207             :         planeForCathode[0] = AliMp::kNonBendingPlane;
     208         234 :       }
     209             :       else
     210             :       {
     211             :         planeForCathode[0] = AliMp::kBendingPlane;
     212             :       }
     213             :  
     214         684 :       if ( !isCathNameDefined ) 
     215             :       { 
     216         468 :         in >> name2;
     217         468 :         name1 = name0; 
     218         468 :         Ssiz_t pos = name1.First(AliMpDetElement::GetNameSeparator());
     219         936 :         name0 = name1(0,pos);
     220             : 
     221             :         // Other cathode is other plane...
     222         468 :         planeForCathode[1] = OtherPlaneType(planeForCathode[0]);
     223         468 :       }
     224             :       else 
     225             :       {
     226         864 :         name1 = name0 + AliMpDetElement::GetNameSeparator() + cathName1;
     227         864 :         name2 = name0 + AliMpDetElement::GetNameSeparator() + cathName2;
     228         648 :         if ( name2.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
     229             :         {
     230             :           planeForCathode[1] = AliMp::kNonBendingPlane;
     231         216 :         }
     232             :         else
     233             :         {
     234             :           planeForCathode[1] = AliMp::kBendingPlane;
     235             :         }        
     236             :       }   
     237             : 
     238         684 :       if ( planeForCathode[0]==planeForCathode[1] )
     239             :       {
     240           0 :         AliFatalClass(Form("Got the same cathode type for both planes"
     241             :                       " of DetElemId %d",detElemId));
     242             :       }
     243             :       
     244        1368 :       AliMpDetElement* detElement = new AliMpDetElement(detElemId, name, name0, planeForCathode[0]);
     245             :       
     246        1368 :       if ( ! fDetElements.GetValue(detElemId) ) 
     247             :       {
     248        2052 :         AliDebugClassStream(3)  
     249        3420 :           << "Adding DE name "  << detElemId << "  " << name << endl;
     250         684 :         fDetElements.Add(detElemId, detElement); 
     251             :       } 
     252             :       else 
     253             :       {
     254           0 :         AliWarningClassStream()
     255           0 :           << "Det element "  << detElemId << "  " << name << " already defined." << endl;
     256             :       } 
     257             :     } 
     258         726 :     in >> word;
     259             :   }
     260             :   
     261          24 :   delete &in;
     262             : 
     263             :   return true;
     264          12 : }
     265             : 
     266             : //______________________________________________________________________________
     267             : void AliMpDEStore::FillDEs(const AliMpDataStreams& dataStreams)
     268             : {
     269             : /// Fill DE names from files
     270          12 :   AliDebugClass(2,"");
     271           3 :   Bool_t result1 = ReadDENames(dataStreams, AliMp::kStation12, AliMq::kStation1);
     272           3 :   Bool_t result2 = ReadDENames(dataStreams, AliMp::kStation12, AliMq::kStation2);
     273           3 :   Bool_t result3 = ReadDENames(dataStreams, AliMp::kStation345);
     274           3 :   Bool_t result4 = ReadDENames(dataStreams, AliMp::kStationTrigger);
     275             :   
     276          15 :   Bool_t result = result1 && result2 && result3 && result4;
     277           3 :   if ( ! result ) {
     278           0 :     AliErrorClassStream() << "Error in reading DE names files" << endl;
     279           0 :   }  
     280           9 :   AliDebug(1,Form("%d detection elements were read in",fDetElements.GetSize()));
     281           3 : }
     282             : 
     283             : //
     284             : // public methods
     285             : //
     286             : 
     287             : 
     288             : //______________________________________________________________________________
     289             : AliMpDetElement* AliMpDEStore::GetDetElement(Int_t detElemId, Bool_t warn) const
     290             : {
     291             : /// Return det element for given detElemId
     292             : 
     293             :   AliMpDetElement* detElement
     294     2202507 :     = (AliMpDetElement*)fDetElements.GetValue(detElemId);
     295             :     
     296     2202507 :   if ( ! detElement && warn ) {  
     297           0 :     AliErrorClassStream() 
     298           0 :         << "Detection element " << detElemId << " not defined." << endl;
     299           0 :   }     
     300             : 
     301     2202507 :   return detElement;
     302             : }    
     303             : 
     304             : //______________________________________________________________________________
     305             : AliMpDetElement* AliMpDEStore::GetDetElement(const TString& deName, Bool_t warn) const
     306             : {
     307             : /// Return det element for given deName
     308             : 
     309           0 :   TIter next(fDetElements.CreateIterator());
     310             :   AliMpDetElement* detElement;
     311             :   
     312           0 :   while ( ( detElement = static_cast<AliMpDetElement*>(next()) ) )
     313             :   {
     314             :              
     315           0 :     if (deName.CompareTo(detElement->GetDEName()) == 0) 
     316             : 
     317           0 :       return detElement;
     318             :   }
     319             : 
     320           0 :   if (warn) {  
     321           0 :     AliErrorClassStream() 
     322           0 :         << "Detection element with name" << deName.Data() << " not defined." << endl;
     323             :   }     
     324             : 
     325           0 :   return 0x0;   
     326             : 
     327           0 : }

Generated by: LCOV version 1.11