BRAT 2.4.5
Class index
Full class index
brahmlib
BRAHMS
ROOT page
//  $Id: BrDetectorParamsBase.cxx,v 1.2 2001/09/23 01:46:52 videbaek Exp $
//  $Author: videbaek $
//  $Date: 2001/09/23 01:46:52 $
//
#ifndef WIN32
#include <cstdio>
#include <iostream>
#include <iomanip>
#else 
#include <stdio.h>
#include <iostream.h>
#include <iomanip.h>
#endif
#ifndef BRAT_BrPathManager
#include "BrPathManager.h"
#endif
#ifndef ROOT_TClass
#include "TClass.h"
#endif
#ifndef ROOT_TSystem
#include "TSystem.h"
#endif
#include "BrDetectorParamsBase.h"

ClassImp(BrDetectorParamsBase);


////////////////////////////////////////////////////////////
//
// BrDetectorParamsBase is a BRAHMS base data class for detector
// parameter classes.
// The baseclass opens file, while interpreting the lines 
// is done in the derived classes
// This is implemented by pure virtual functions
// 
////////////////////////////////////////////////////////////

//_______________________________________________________________
BrDetectorParamsBase::BrDetectorParamsBase() 
  : fVerbose(kFALSE)
{
// Constructor. Set counter and list data members to zero.
// Don't use this constructor unless you have to and know
// what you are doing
// Use BrDetectorParams(Char_t, Char_t ) instead
}

//_______________________________________________________________
BrDetectorParamsBase::BrDetectorParamsBase(Char_t *name, Char_t *title)
  : TNamed(name,title), fVerbose(kFALSE)
{
}

BrDetectorParamsBase::BrDetectorParamsBase(Char_t *name, Char_t *title, Char_t *filename)
  : TNamed(name,title), fVerbose(kFALSE)
{
}

//_______________________________________________________________
 BrDetectorParamsBase::~BrDetectorParamsBase()
{
}

//_________________________________________________________________________
 void BrDetectorParamsBase::ListParameters() const
{
  cout<<"This method must be overridden!!!"<<endl;
  return;
}

//_________________________________________________________________________
 void BrDetectorParamsBase::ReadASCIIFile(Char_t *ASCIIFileName) {
  // Read parameters in using an ascii configuration file.  The format
  // of this file is: 
  //  TYPE:BrDetectorParamsDC
  //  NAME:T3
  //  fTwoPar:  0.20
  //  fEff:     0.95
  //  fDriftv:0.0052
  //  fPldis:1.0
  //  fNplane:8
  //  fPosres:.025
  //  DCPlane: xa00 xa00 0 1.0 0.
  //  DCPlane: xa01 xa01 1 1.0 0.
  //  DCPlane: ya00 ya00 0 1.0 -90.
  //  DCPlane: ya01 ya00 1 1.0 -90.
  //  DCPlane: ua00 ua00 0 1.0 30.
  //  DCPlane: ua01 ua01 1 1.0 30.
  //  DCPlane: va00 va00 0 1.0 -30.
  //  DCPlane: va01 va01 1 1.0 -30.
  // This method should probably go into some kind of base class.  The
  // only thing that is detector specific is SetASCIIParameters()
  // which is called from here.  The rest is general and too
  // complicated to be always messing around with when changing
  // configuration of parameters. 
  FILE *ParamFile;
  const Int_t maxparamline=80;
  Char_t line[maxparamline];
  Bool_t found;
  
  Char_t *c;
  if (fVerbose) 
    printf("%s:Opening Parameter file %sn",GetName(),ASCIIFileName);
  
  if(!(ParamFile = fopen( ASCIIFileName,"r"))) {
    if (fVerbose) {
      cout << "File not present in current directory" << endl;
      cout << "Trying in BRATSYS file"<<endl;
    }
    
    BrPathManager* pathMan = BrPathManager::Instance();
    // const Char_t *bratsys = gSystem->Getenv("BRATSYS");
    const Char_t *bratsys = pathMan->GetDataDir();
    Char_t system_parameter_file[64];
    if(bratsys) {
      sprintf(system_parameter_file,
	      "%s/params/DetectorParameters.txt",bratsys);
      if(!strncmp(system_parameter_file,"//",2)) {
	// Coming here means we are on an NT system and need to repair
	// filename from Cygnus stuff.  For Cygnus, Filenames are
	// e.g. //D/user/hagel... Need to convert to D:/user/hagel... 
	system_parameter_file[0] = system_parameter_file[2];
	system_parameter_file[1] = ':';
	strcpy(&system_parameter_file[2],&system_parameter_file[3]);
      }
      if (fVerbose) 
	printf("%s:Opening Parameter file %sn",GetName(),ASCIIFileName);

      if( !(ParamFile = fopen( system_parameter_file,"r"))){
	cout << "System parameter file not found.  " 
	     << "Contact BRAT administrator!!!" << endl;
	return;
      }
    }
    else {
      cout << "BRATSYS not set, "
	   << "how did you manage to get this far?!!!!!?" << endl
	   << "No way to open file" << endl;
      return;
    }
  }
  
  TClass *cl = IsA();      //Get information on this class
  found = kFALSE;
  
  while(( c = fgets(line,maxparamline,ParamFile))) {
    if(line[0] != '#') { //check if not comment line
      if(!strncasecmp(line,"TYPE:",5)) {
	Char_t *type_line = &line[5];
	if(!strncasecmp(type_line,cl->GetName(),strlen(cl->GetName()))) {
	  if((c = fgets(line,maxparamline,ParamFile))) {
	    if(!strncasecmp(line,"NAME:",5)) {
	      Char_t *name_line = &line[5];
	      if(!strncasecmp(name_line,GetName(),strlen(GetName()))) {
		// Coming here means we have found a set of parameters
		// for this detector 
		if (fVerbose) 
		  cout<< "Found parameters for " << cl->GetName() 
		      << ":" << GetName() <<endl;
		found = kTRUE;
		while((c=fgets(line,maxparamline,ParamFile))) {
		  if(line[0] != '#') {    //check if not comment line.
		    if(!strncasecmp(line,"TYPE:",5)) {
		      // Coming here means we are at the beginning of
		      // a new detector 
		      fclose(ParamFile);
		      return;
		    }
		    if(strchr(line,':')) SetASCIIParameters(line);
		  }
		}
		fclose(ParamFile);
		return;            //we have come to the end of the file
	      }
	    }
	  }
	  else {
	    cout<<"Unexpected end of file reached"<<endl;
	    return;
	  }
	}
      }
    }
  }
  cout << "Parameter type " << cl->GetName() 
       << " or detector name " << GetName() << " not found!!!" << endl;
  cout << "Parameters will not be changed from their current values"
       << endl;
}

//void BrDetectorParamsBase::SetASCIIParameters(Char_t *line) {
//  cout<<"This method must be overridden!!!"<<endl;
//  return;
//}


//  $Log: BrDetectorParamsBase.cxx,v $
//  Revision 1.2  2001/09/23 01:46:52  videbaek
//  Mainly cosmetic changes, in regard to log information and
//  some in regard toi override in derived classes
//
//  Revision 1.1.1.1  2001/06/21 14:55:17  hagel
//  Initial revision of brat2
//
//  Revision 1.8  2001/06/04 13:36:06  cholm
//  Changes to use BrPathManager, BrVersion, and perpare to use BrFileTag.
//
//  Revision 1.7  2000/12/27 21:34:48  videbaek
//  Moved cvs log
//
//  Revision 1.6  2000/04/06 20:17:47  cholm
//  Added the classes BrAppOption, BrAppOptionManager, and
//  BrDetectorList. The first two are for command line processing,
//  the third for easy detector list, can be used for many purposes.
//
//  Revision 1.5  2000/03/21 21:21:41  cholm
//  Several changes: A few hacks where needed to compile on Digital Unix, noticably in my - Christian Holm - classes for the DB and Exceptions. Proberly still need to do something to some of Konstantins stuff. Also, I removed a lot of warnings fromt the compiler, by teddying up the code. Several places, old C-style indecies in for loops were assumed. Corrected. Unused variables have been commented out.
//
//  Revision 1.4  1999/12/30 19:43:08  videbaek
//  D
//  D
//  imple cleanup of code
//
//  Revision 1.3  1999/04/09 19:36:44  videbaek
//  Clean up code; add ListStatistics to container class
//  Improve include guards.
//
//  Revision 1.2  1999/03/16 21:01:10  hagel
//  Added handling for comment lines
//
//  Revision 1.1  1999/03/02 23:45:04  hagel
//  Initial revision
//
//

This page automatically generated by script docBrat by Christian Holm

Copyright ; 2002 BRAHMS Collaboration <brahmlib@rcf.rhic.bnl.gov>
Last Update on by

Validate HTML
Validate CSS