Re: BrCalibrBB.dat

From: Christian Holm Christensen (cholm@hehi03.nbi.dk)
Date: Mon Oct 30 2000 - 03:06:10 EST

  • Next message: Djamel Ouerdane: "new brat version (bis)"

    Hi Yury, 
    
    On Fri, 27 Oct 2000 17:00:24 -0400
    Yury Blyakhman <Yury_B@physics.nyu.edu> wrote
    concerning ": BrCalibrBB.dat":
    
    The code below is buggy at best:
    
    > Int_t DtLeft[45], DtRight[45], LPedMean[45], LPedRMS[45], RPedMean[45], 
    >   RPedRMS[45], LAdcGain0[45], RAdcGain0[45], kL[45], kR[45],
    > DtTdcLSlew[45],
    >   DtTdcRSlew[45];
    > //___________________________________________________
    > void BBCalibrate(){
    >   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);
    >   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];
    >     }
    >   }
    > }
    
    
    What you should do is along the lines of: 
    
    Int_t 
    //___________________________________________________
    void BBCalibrate(){
    
      Int_t *DtLeft       = new Int_t[45];  
      Int_t *DtRight      = new Int_t[45];
      Int_t *LPedMean     = new Int_t[45];
      Int_t *LPedRMS      = new Int_t[45];
      Int_t *RPedMean     = new Int_t[45];
      Int_t *RPedRMS      = new Int_t[45];
      Int_t *LAdcGain0    = new Int_t[45];
      Int_t *RAdcGain0    = new Int_t[45];
      Int_t *kL           = new Int_t[45];
      Int_t *kR           = new Int_t[45];
      Int_t *DtTdcLSlew   = new Int_t[45]; 
      Int_t *DtTdcRSlew   = new Int_t[45];   
    
      ifstream readNumbers(Form("%s/BrCalibrBB.dat", 
                           gSystem->Getenv("PWD")));
      if (!readNumbers) {
        readNumbers.open(Form("%s/BrCalibrBB.dat", 
                              gSystem->Getenv("BRATSYS")));
        if(!readNumbers) {
          cerr << "Coulnd't open file 'BrCalibrBB.dat'" << endl;
          return; 
        }
      }
    
      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.fail() || readNumbers.eof()) {
          cerr << "Premature end of file" << endl;
          return;
        }
      }
     
      // Do what ever, using the calibrations stuff read from ASCII file
    
      delete [] DtLeft    ;
      delete [] DtRight   ;
      delete [] LPedMean  ;
      delete [] LPedRMS   ;
      delete [] RPedMean  ;
      delete [] RPedRMS   ;
      delete [] LAdcGain0 ;
      delete [] RAdcGain0 ;
      delete [] kL        ;
      delete [] kR        ;
      delete [] DtTdcLSlew;
      delete [] DtTdcRSlew;
    }
    
    The code above is not so error-prone as the one Yury suggested (due to
    the checks). Also, please avoid using global variables. In fact, I
    urge you Yury to commit some (temporary) class to BRAT that does the
    above and stores the calibrated data in some eventnode, so that a
    vertex module may picl it up there. Rather then putting the above into
    a vertex module directly, I suggset this approac, since that'll be
    more flexible in terms of migrating to the real MySQL database. 
    
    Yours, 
    
    Christian  -----------------------------------------------------------
    Holm Christensen                             Phone:  (+45) 35 35 96 91 
      Sankt Hansgade 23, 1. th.                  Office: (+45) 353  25 305 
      DK-2200 Copenhagen N                       Web:    www.nbi.dk/~cholm    
      Denmark                                    Email:       cholm@nbi.dk
    



    This archive was generated by hypermail 2b29 : Mon Oct 30 2000 - 03:22:27 EST