Parameter class example




FairTutorialDetDigiPar.h


// -------------------------------------------------------------------------
// -----              FairTutorialDetDigiPar header file                  -----
// -----                 Created 15/05/08  by F. Uhlig                 -----
// -------------------------------------------------------------------------

#ifndef FAIRTUTORIALDETDIGIPAR_H
#define FAIRTUTORIALDETDIGIPAR_H


#include "FairParGenericSet.h"

#include "TObject.h"
#include "TObjArray.h"
#include "TArrayF.h"
#include "TArrayI.h"

class FairParIo;
class FairParamList;


class FairTutorialDetDigiPar : public FairParGenericSet
{

  public:

    /** Standard constructor **/
    FairTutorialDetDigiPar(const char* name    = "FairTutorialDetDigiPar",
                           const char* title   = "Tutorial Det digi parameters",
                           const char* context = "Default");


    /** Destructor **/
    virtual ~FairTutorialDetDigiPar();


    /** Initialisation from input device**/
    //virtual Bool_t init(FairParIo* input);


    /** Output to file **/
    //  virtual Int_t write(FairParIo* output);

    //  virtual void print();
    virtual void printparams();


    /** Reset all parameters **/
    virtual void clear();

    void putParams(FairParamList*);
    Bool_t getParams(FairParamList*);

  private:

    TArrayF* ftutdetdigipar;  //
    TArrayI ftutdetdigiparsector; //
    Int_t ftutdetdigiparstation; //

    FairTutorialDetDigiPar(const FairTutorialDetDigiPar&);
    FairTutorialDetDigiPar& operator=(const FairTutorialDetDigiPar&);

    ClassDef(FairTutorialDetDigiPar,1);


};


#endif







FairTutorialDetDigiPar.cxx


// -------------------------------------------------------------------------
// -----                FairTutorialDetDigiPar source file              -----
// -----                  Created 05/06/08  by F. Uhlig                -----
// -------------------------------------------------------------------------

#include "FairTutorialDetDigiPar.h"

#include "FairParamList.h"
#include "FairDetParIo.h"
#include "FairParIo.h"

#include "TString.h"
#include "TMath.h"

#include <iostream>

using std::cout;

using std::endl;

// -----   Standard constructor   ------------------------------------------
FairTutorialDetDigiPar::FairTutorialDetDigiPar(const char* name,

    const char* title,
    const char* context)
  : FairParGenericSet(name, title, context)

{
  detName="TutorialDet";
  ftutdetdigipar= new TArrayF(10);

  //ftutdetdigipar= new TArrayF(10);
}
// -------------------------------------------------------------------------



// -----   Destructor   ----------------------------------------------------
FairTutorialDetDigiPar::~FairTutorialDetDigiPar()

{
  clear();

}
// -------------------------------------------------------------------------


// -----   Public method clear   -------------------------------------------
void FairTutorialDetDigiPar::clear()

{
  status = kFALSE;
  resetInputVersions();
}
// -------------------------------------------------------------------------

// -----   Public method printParams ---------------------------------------
void FairTutorialDetDigiPar::printparams()
{

  cout <<"Print"<<endl;

  cout << "ftutdetdigiparstation: " << ftutdetdigiparstation << endl;
  Int_t size =  ftutdetdigiparsector.GetSize();

  cout <<"size: " << size << endl;
  for ( Int_t i=0; i< size; i++) {

    cout << i <<" :" << ftutdetdigiparsector.GetAt(i) << endl;

  }
  size =  ftutdetdigipar->GetSize();
  cout <<"size: " << size << endl;

  for ( Int_t i=0; i< size; i++) {

    cout << i <<" :" << ftutdetdigipar->GetAt(i) << endl;

  }

}
// -------------------------------------------------------------------------

void FairTutorialDetDigiPar::putParams(FairParamList* l)

{
  //   print();
  cout << " I am in FairTutorialDetDigiPar::putParams " << endl;
  if (!l) { return; }

  l->add("FairTutorialDetDigiStations", ftutdetdigiparstation);
  l->add("FairTutorialDetDigiSectorsPerStation", ftutdetdigiparsector);

  Int_t count_sectors = 0;
  for ( Int_t i=0; i< ftutdetdigiparstation; i++) {

    count_sectors+=ftutdetdigiparsector[i];
  }
  Int_t array_size = (count_sectors * 10 + ftutdetdigiparstation * 3);

  cout << "Array Size: " << array_size << endl;
  /*   Float_t zwischen[array_size];
     for ( Int_t i=0; i< array_size; i++) {

       zwischen[i] = ftutdetdigipar.GetAt(i);
     }
   */
  ftutdetdigipar->Set(array_size);

  l->add("FairTutorialDetDigiPar",*ftutdetdigipar);
}

//------------------------------------------------------

Bool_t FairTutorialDetDigiPar::getParams(FairParamList* l)

{
  //print();

  cout << " I am in FairTutorialDetDigiPar::getParams " << endl;

  if (!l) { return kFALSE; }
  if ( ! l->fill("FairTutorialDetDigiStations", &ftutdetdigiparstation) ) { return kFALSE; }

  ftutdetdigiparsector.Set(ftutdetdigiparstation);

  if ( ! l->fill("FairTutorialDetDigiSectorsPerStation", &ftutdetdigiparsector) ) { return kFALSE; }

  Int_t count_sectors = 0;
  for ( Int_t i=0; i< ftutdetdigiparstation; i++) {

    count_sectors+=ftutdetdigiparsector[i];
  }
  cout << "Total number of sectors: " << count_sectors<<endl;

  Int_t array_size = (count_sectors * 10 + ftutdetdigiparstation * 3);

  cout << "Array Size: " << array_size << endl;
  ftutdetdigipar->Set(array_size);

  //Float_t zwischen[array_size];
  if (!(l->fill("FairTutorialDetDigiPar",ftutdetdigipar))) {
    cout << "--W-- Could not initialize FairTutorialDetDigiPar"<< endl;

    return kFALSE;
  }
  //ftutdetdigipar.Set(array_size, zwischen);
  return kTRUE;

}



ClassImp(FairTutorialDetDigiPar)