LCOV - code coverage report
Current view: top level - MUON/MUONmapping - AliMpMotifReader.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 103 117 88.0 %
Date: 2016-06-14 17:26:59 Functions: 9 9 100.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: AliMpMotifReader.cxx,v 1.10 2006/05/24 13:58:41 ivana Exp $
      18             : // Category: sector
      19             : 
      20             : //-----------------------------------------------------------------------------
      21             : // Class AliMpMotifReader
      22             : // -------------------
      23             : // Class that takes care of reading the sector data.
      24             : // Included in AliRoot: 2003/05/02
      25             : // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
      26             : //-----------------------------------------------------------------------------
      27             : 
      28             : #include "AliMpFiles.h"
      29             : #include "AliMpDataStreams.h"
      30             : #include "AliMpMotifReader.h"
      31             : #include "AliMpMotifMap.h"
      32             : #include "AliMpMotif.h"
      33             : #include "AliMpMotifSpecial.h"
      34             : #include "AliMpMotifType.h"
      35             : #include "AliMpConnection.h"
      36             : #include "AliMpEncodePair.h"
      37             : 
      38             : #include "AliLog.h"
      39             : 
      40             : #include <TSystem.h>
      41             : #include <TMath.h>
      42             : #include <Riostream.h>
      43             : #include <Rstrstream.h>
      44             : 
      45             : #if !defined(__HP_aCC) && !defined(__alpha)
      46             :   #include <sstream>
      47             : #endif
      48             : 
      49             : /// \cond CLASSIMP
      50          18 : ClassImp(AliMpMotifReader)
      51             : /// \endcond
      52             : 
      53             : //_____________________________________________________________________________
      54             : AliMpMotifReader::AliMpMotifReader(AliMp::StationType station,
      55             :                                    AliMq::Station12Type station12,
      56             :                                    AliMp::PlaneType plane)
      57        4788 :   : TObject(),
      58        4788 :     fStationType(station),
      59        4788 :     fStation12Type(station12),
      60        4788 :     fPlaneType(plane)
      61       23940 : {
      62             : /// Standard constructor
      63        9576 : }
      64             : 
      65             : //_____________________________________________________________________________
      66             : AliMpMotifReader::~AliMpMotifReader() 
      67        9600 : {
      68             : /// Destructor  
      69       14376 : }
      70             : 
      71             : //
      72             : // public methods
      73             : //
      74             : 
      75             : //_____________________________________________________________________________
      76             : AliMpMotifType* AliMpMotifReader::BuildMotifType(
      77             :                                        const AliMpDataStreams& dataStreams,
      78             :                                        const TString& motifTypeId)
      79             : {
      80             : /// Read the streams describing a motif in the "$MINSTALL/data" directory
      81             : /// and fill the AliMpMotifType structure with.
      82             : /// The streams mentioned are named padPos<maskName>.dat
      83             : /// and connect<maskName>.dat
      84             : 
      85             :   // Open streams
      86             :   //
      87             :   istream& padPosStream 
      88        1278 :     = dataStreams.
      89         639 :         CreateDataStream(AliMpFiles::PadPosFilePath(
      90        1278 :                             fStationType, fStation12Type, fPlaneType, motifTypeId));
      91             :   istream& bergToGCStream 
      92        1278 :     = dataStreams.
      93         639 :         CreateDataStream(AliMpFiles::BergToGCFilePath(fStationType, fStation12Type));
      94             :       
      95             :   istream& motifTypeStream 
      96        1278 :     = dataStreams.
      97         639 :         CreateDataStream(AliMpFiles::MotifFilePath(
      98         639 :                             fStationType, fStation12Type, fPlaneType, motifTypeId));
      99             : 
     100         639 :   AliMpMotifType*  motifType = new AliMpMotifType(motifTypeId); 
     101             : 
     102         639 :   TExMap positions;
     103             : 
     104         639 :   char line[256];
     105         639 :   do {
     106       39450 :     padPosStream.getline(line,255);
     107       78900 :     if (!padPosStream) break;
     108             : 
     109             : #if defined (__HP_aCC) || (__alpha)
     110             :     strstream strline;
     111             :     strline << line;
     112             : #else
     113      116433 :     istringstream strline(line);
     114             : #endif    
     115       38811 :     string key;
     116             : 
     117       38811 :     strline>>key;
     118       77637 :     if ((key=="#") || (key=="") ) continue;
     119             : 
     120       38796 :     int i,j;
     121       77592 :     strline>>i>>j;
     122      155184 :     positions.Add( AliMpExMap::GetIndex(key), 
     123       77592 :                    AliMp::Pair(i,j) + 1 );
     124             :               // we have to add 1 to the AliMp::Pair in order to 
     125             :               // its value always != 0, as the TExMap returns 0 value
     126             :               // if given key does not exists      
     127      116418 :   } while (!padPosStream.eof());
     128             : 
     129             :   const Int_t knbergpins = 
     130         639 :     (fStationType == AliMp::kStation12 ) ? 80 : 100;
     131             :   // Station1 & 2 Bergstak connectors have 80 pins, while for stations
     132             :   // 3, 4 and 5 they have 100 pins.
     133         639 :   Int_t gassiChannel[100];
     134      129078 :   for (Int_t i=0; i<100; ++i) gassiChannel[i] = 0;
     135         639 :   while(1) {
     136       58179 :     Int_t bergNum;
     137       58179 :     TString gcStr;
     138      116358 :     bergToGCStream>>bergNum>>gcStr;
     139      116997 :     if (!bergToGCStream.good()) break;
     140      122643 :     if (gcStr=="GND") continue;
     141       49977 :     if (bergNum>knbergpins) {
     142           0 :         Fatal("BuildMotifType","Berg number > 80 ...");
     143           0 :         continue;
     144             :     }
     145       49977 :     if ( bergNum <= 0 || bergNum >= 101 ) {
     146           0 :       AliErrorStream() << "Wrong bergNum: " << bergNum << endl;
     147           0 :       return 0;
     148             :     }  
     149      149931 :     gassiChannel[bergNum-1]= atoi(gcStr);
     150      108156 :   }
     151             :   
     152             :   Int_t nofPadsX=0;
     153             :   Int_t nofPadsY=0;
     154             : 
     155         639 :   do {
     156             :   
     157             :     Int_t ix,iy,numBerg,numKapton,padNum,gassiNum;
     158             : 
     159       98292 :     TString lineStr,token;
     160       49146 :     lineStr.ReadLine(motifTypeStream);
     161       98931 :     if (!motifTypeStream.good()) break;
     162             : #if defined (__HP_aCC) || (__alpha)
     163             :     strstream tokenList;
     164             :     tokenList << lineStr.Data();
     165             : #else
     166      194028 :     istringstream tokenList(lineStr.Data());
     167             : #endif    
     168             :     
     169       48507 :     token.ReadToken(tokenList);
     170       97668 :     if (!tokenList.good()) continue; // column is missing...
     171      193929 :     if ( (token.Length()>0) && (token[0]=='#') ) continue; // this is a comment line
     172             :     
     173       90672 :     numBerg = atoi(token.Data());
     174       45336 :     if (numBerg==0) {
     175           0 :       AliWarning(Form("Berg number %s invalid",token.Data()));
     176           0 :       continue;
     177             :     }
     178             :     
     179       45336 :     token.ReadToken(tokenList);
     180       94164 :     if (!tokenList.good()) continue; // column is missing...
     181       83688 :     numKapton = atoi(token.Data());
     182       42168 :     if (numKapton==0) continue;
     183             : 
     184             :     
     185       41520 :     token.ReadToken(tokenList);
     186       85455 :     if (!tokenList.good()) continue; // column is missing...
     187       78519 :     if (token=="GND") continue;
     188       77592 :     string padName = token.Data();
     189       38796 :     padNum = motifType->PadNum(token);
     190             :     
     191       38796 :      token.ReadToken(tokenList);
     192       77592 :      if (token.IsNull() ) continue; // column is missing...
     193             : //     if (token[0]!='E') {
     194             : //       cerr<<"Problem : gassinumber isn't begining with E:"<<token<<endl;
     195             : //       continue;
     196             : //     }  else {
     197             : //        gassiNum = atoi(token.Data() +1 )-1;
     198             : //     }
     199       77592 :     if ( (numBerg<1) || (numBerg>knbergpins) ) {
     200           0 :       AliWarning(Form("Berg number %d outside range (1..%d)",numBerg,knbergpins));
     201           0 :       continue;
     202             :     }
     203             :     
     204       38796 :     gassiNum  = gassiChannel[numBerg-1];
     205             : 
     206      155184 :     Long_t value = positions.GetValue(AliMpExMap::GetIndex(padName));
     207       38796 :     if (!value) {
     208           0 :       AliWarningStream()
     209           0 :         << "Problem: Pad number " << padNum
     210           0 :         << " for motif type " << motifTypeId.Data() 
     211           0 :         << " found in the motifType stream, but not in the padPos stream" << endl;
     212           0 :       continue;
     213             :     }
     214             : 
     215             :     AliMpConnection* connection 
     216       77592 :       = new AliMpConnection(padNum,numBerg,numKapton,gassiNum, --value);
     217             :     
     218       77592 :     Bool_t ok = motifType->AddConnection(connection);
     219             :     
     220       38796 :     if (!ok)
     221             :     {
     222           0 :       AliFatal("Could not add connection");
     223             :     }
     224             :                   
     225       38796 :     ix = AliMp::PairFirst(value);
     226       38796 :     iy = AliMp::PairSecond(value);
     227             :     
     228       41961 :     if (ix>=nofPadsX) nofPadsX=ix+1;
     229       48681 :     if (iy>=nofPadsY) nofPadsY=iy+1;
     230             : 
     231      272259 :   } while (!motifTypeStream.eof());    
     232             : 
     233             : 
     234         639 :   motifType->SetNofPads(nofPadsX, nofPadsY);
     235             :   
     236        1278 :   delete &padPosStream;
     237        1278 :   delete &bergToGCStream;
     238        1278 :   delete &motifTypeStream;
     239             : 
     240             :   return motifType;
     241         639 : }
     242             : 
     243             : //_____________________________________________________________________________
     244             : AliMpMotifSpecial*  
     245             : AliMpMotifReader::BuildMotifSpecial(const AliMpDataStreams& dataStreams,
     246             :                                     const TString& motifID,
     247             :                                     AliMpMotifType* motifType,
     248             :                                     Double_t scale)
     249             : {
     250             : /// Build a special motif by reading the file motifSpecial<motifId>.dat
     251             : /// in the data directory
     252             : 
     253             :   // Open streams
     254             :   //
     255             :   istream& in 
     256          54 :     = dataStreams.
     257          27 :         CreateDataStream(AliMpFiles::MotifSpecialFilePath(
     258          54 :                              fStationType, fStation12Type, fPlaneType, motifID));
     259             : 
     260          27 :   TString id = MotifSpecialName(motifID,scale);
     261             :   
     262          54 :   AliMpMotifSpecial* res = new AliMpMotifSpecial(id,motifType);
     263          27 :   Int_t i,j;
     264          27 :   Double_t x,y;
     265          27 :   in >> i;
     266        2262 :   while (!in.eof()){
     267        3312 :     in >>j >>x >> y;
     268        1104 :     res->SetPadDimensions(i,j,x*scale/2.,y*scale/2.);
     269        1104 :     in >> i;
     270             :   }
     271          27 :   res->CalculateDimensions();
     272             :   
     273          54 :   delete &in;
     274             :   
     275             :   return res;
     276          27 : }
     277             : 
     278             : //_____________________________________________________________________________
     279             : TString 
     280             : AliMpMotifReader::MotifSpecialName(const TString& motifID, Double_t scale)
     281             : {
     282             :   /// Build the name taking into the scale, if not 1.0
     283         486 :   TString id;
     284             :   
     285         243 :   if ( scale != 1.0 )
     286             :   {
     287         513 :     id = Form("%s-%e",motifID.Data(),scale);
     288             :   }
     289             :   else
     290             :   {
     291          72 :     id = motifID;
     292             :   }
     293             :   return id;
     294         486 : }
     295             : 

Generated by: LCOV version 1.11