BrRdoModuleBB

From: Claus O. E. Jorgensen (ekman@nbi.dk)
Date: Mon Nov 13 2000 - 11:22:34 EST

  • Next message: Jens Ivar Jordre: "Re: dEdx for tracks in the tpcs"

    Hi everybody
    
    My program crashes when I call the Init() method 
    of the BrRdoModuleBB class, and I found out that 
    the method tries to open a file (BrCalibrBB.dat)
    and then reads things without checking if this
    file really exists (this is done later, but then 
    it's too late). You'll have to put this check 
    before reading anything. Here is the code that's 
    in brat right now, and afterwards a example on 
    how it can be fixed (still a bit messy code, but 
    it works):
    
    //______________________________________________________________________________
    void BrRdoModuleBB::Init()
    {
      //
      // Get Calibration Numbers
      //
      const Char_t *bratsys = gSystem->Getenv("BRATSYS");
      const Char_t *pwd = gSystem->Getenv("PWD");
      Char_t CalibrFileName[100];
      sprintf(CalibrFileName, "%s/BrCalibrBB.dat",pwd);
      ifstream ReadNumbers(CalibrFileName);                     <---- no check 
      for(int i=1; i<45; i++){
        ReadNumbers>>DtLeft[i]>>DtRight[i]>>LPedMean[i]>>LPedRMS[i]
                   >>RPedMean[i]>>RPedRMS[i]>>LAdcGain0[i]>>RAdcGain0[i]
                   >>kL[i]>>kR[i]>>DtTdcLSlew[i]>>DtTdcRSlew[i];
      }
      if(!ReadNumbers){
        sprintf(CalibrFileName, "%s/params/bb/BrCalibrBB.dat",bratsys);
        ifstream ReadNumbers(CalibrFileName);
        for(int i=1; i<45; i++){
          ReadNumbers>>DtLeft[i]>>DtRight[i]>>LPedMean[i]>>LPedRMS[i]
                     >>RPedMean[i]>>RPedRMS[i]>>LAdcGain0[i]>>RAdcGain0[i]
                     >>kL[i]>>kR[i]>>DtTdcLSlew[i]>>DtTdcRSlew[i];
        }
      }
    }
    //----------------------------------------------------------------------------
    
    
    Suggestion:
    //______________________________________________________________________________
    void BrRdoModuleBB::Init()
    {
      //
      // Get Calibration Numbers
      //
      const Char_t *bratsys = gSystem->Getenv("BRATSYS");
      const Char_t *pwd = gSystem->Getenv("PWD");
    
      Char_t CalibrFileName[100];
    
      sprintf(CalibrFileName, "%s/BrCalibrBB.dat", pwd);
      ifstream ReadNumbers(CalibrFileName);
      
      // 1st: check if file is in current directory
      if(ReadNumbers) 
        for(int i=1; i<45; i++) {
          ReadNumbers>>DtLeft[i]>>DtRight[i]>>LPedMean[i]>>LPedRMS[i]
    		 >>RPedMean[i]>>RPedRMS[i]>>LAdcGain0[i]>>RAdcGain0[i]
    		 >>kL[i]>>kR[i]>>DtTdcLSlew[i]>>DtTdcRSlew[i]
    		 >>LGapSt[i]>>LGap[i]>>RGapSt[i]>>RGap[i];
        }
      
      // 2nd: if not in current dir., look in $BRATSYS	
      else {
        sprintf(CalibrFileName, "%s/params/bb/BrCalibrBB.dat",bratsys);
        ifstream ReadNumbers(CalibrFileName);
        if(ReadNumbers)
          for(int i=1; i<45; i++) {
    	ReadNumbers>>DtLeft[i]>>DtRight[i]>>LPedMean[i]>>LPedRMS[i]>>RPedMean[i]>>RPedRMS[i]>>LAdcGain0[i]>>RAdcGain0[i]
    		      >>kL[i]>>kR[i]>>DtTdcLSlew[i]>>DtTdcRSlew[i]
    		      >>LGapSt[i]>>LGap[i]>>RGapSt[i]>>RGap[i];
          }
        
        // 3rd: if not there, abort!
        else if (!ReadNumbers) {
          cerr << "No 'BrCalibrBB.dat' found!" << endl;
          exit(1);
        }
      }
      
    }
    
    
    Cheers,
    
    Claus Jorgensen & Djamel Ouerdane 
    



    This archive was generated by hypermail 2b29 : Mon Nov 13 2000 - 11:23:23 EST