Re: BrRdoModuleBB

From: Yury Blyakhman (Yury_B@physics.nyu.edu)
Date: Mon Nov 13 2000 - 12:26:16 EST

  • Next message: Claus O. E. Jorgensen: "Re: BrRdoModuleBB"

    	Hello.
     That shouldn't be the reason of crushing! It works perfectly well for
    me. When this code looks for BrCalibrBB.dat in your running directory
    and doesn't find it, it simple doesn't read from there (or reads and
    gets nothing from it, however you prefer it), doesn't crush and proceed
    to the /brat/params/bb/  place. I checked it zillion times and it works
    fine! 
    The reason for not checking file existence before reading is to decrease
    number of "if" and "else" 's in the code!
    As for the "exit", $BRATSYS/params/bb/BrCalibrBB.dat is always there!!!
    There's now way you can't find it, if your $BRATSYS is set correctly!
    
    
    "Claus O. E. Jorgensen" wrote:
    > 
    > 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
    
    -- 
    	Yury Blyakhman.
    			     \\\|///
                               \\  - -  //
                                (  @ @  )
     +------------------------o00o-(_)-o00o-------------+
     | New York University      Phone: (212)998-7762    |
     | Department of Physics    Fax: (212) 995-4016     |
     | 4 Washington Place       E-mail:                 |
     | New York, N.Y. 10003     Yury_B@physics.nyu.edu  |
     |         Mobile: (646)528-7187                    |
     |     Home phone: (718)934-1851      ICQ# 2330402  |
     +--------------------------------0ooo--------------+
                              ooo0   (   )
                             (   )    ) /
                              \ (    (_/
                               \_)
    



    This archive was generated by hypermail 2b29 : Mon Nov 13 2000 - 12:26:38 EST