// =====================================================================
//  $Id: St01CrateDefinition.cc,v 1.5 2003/10/06 16:28:18 goiwai Exp $
//  $Name: CLDAQ-1-14-03 $
//  $Log: St01CrateDefinition.cc,v $
//  Revision 1.5  2003/10/06 16:28:18  goiwai
//  *** empty log message ***
//
//  Revision 1.4  2003/07/30 16:16:10  goiwai
//  ファイルにコミットログをつけることにしました.
//
// =====================================================================
#include "TCrate.hh"
#include "TSoftwareScalerModule.hh"
#include "TSoftwareClockModule.hh"
#include "TSoftwareTimerModule.hh"
#include "TSoftwareRunInformationModule.hh"
#include "TRunInformationTable.hh"
#include "TVmeMpx201aModule.hh"
#include "TVmeRpv130Module.hh"
#include "TVmeDaughterBoardMemoryModule.hh"
#include "TEnvironmentVariableTable.hh"
#include "TRunManager.hh"
#include "TRunInformationTable.hh"
#include "TRunInformationList.hh"
#include "TRunInformation.hh"
#include "TRs232cKeithley2400Module.hh"
#include "St01CrateDefinition.hh"

St01CrateDefinition::St01CrateDefinition()
  : TCrateDefinition()
{;}

St01CrateDefinition::~St01CrateDefinition()
{;}

TCrate* St01CrateDefinition::Define()
{
  TRunInformationList infolist;
  infolist.push_back( TRunInformation( "OPERATOR", tInfoFreeValue ) );
  TstringList selectlist;
  selectlist.push_back( "SOURCE RUN" );
  selectlist.push_back( "DARK RUN" );
  selectlist.push_back( "TEST RUN" );
  infolist.push_back( TRunInformation( "RUN TYPE", selectlist ) );
  infolist.push_back( TRunInformation( "DEVICE ID", tInfoFreeValue ) );
  selectlist.clear();
  selectlist.push_back( "-120.0" );
  selectlist.push_back( "-110.0" );
  selectlist.push_back( "-100.0" );
  selectlist.push_back( "-90.0" );
  selectlist.push_back( "-80.0" );
  selectlist.push_back( "-70.0" );
  selectlist.push_back( "-60.0" );
  selectlist.push_back( "-50.0" );
  selectlist.push_back( "-40.0" );
  selectlist.push_back( "-30.0" );
  selectlist.push_back( "-20.0" );
  selectlist.push_back( "-10.0" );
  selectlist.push_back( "0.0" );
  selectlist.push_back( "10.0" );
  infolist.push_back( TRunInformation( "TEMPERATURE (C)", selectlist ) );
  infolist.push_back( TRunInformation( "RUN BEGIN RESISTANCE (ohm)", tInfoFreeValue ) );
  infolist.push_back( TRunInformation( "RUN END RESISTANCE (ohm)", tInfoFreeValue ) );
  infolist.push_back( TRunInformation( "RUN BEGIN PRESSURE (Pa)", tInfoFreeValue ) );
  infolist.push_back( TRunInformation( "RUN END PRESSURE (Pa)", tInfoFreeValue ) );
  selectlist.clear();
  selectlist.push_back( "2.0" );
  selectlist.push_back( "4.0" );
  selectlist.push_back( "6.0" );
  selectlist.push_back( "8.0" );
  selectlist.push_back( "10.0" );
  selectlist.push_back( "12.0" );
  selectlist.push_back( "14.0" );
  selectlist.push_back( "16.0" );
  infolist.push_back( TRunInformation( "PERIOD (sec)", selectlist ) );
  selectlist.clear();
  selectlist.push_back( "2.0" );
  selectlist.push_back( "3.0" );
  selectlist.push_back( "4.0" );
  selectlist.push_back( "5.0" );
  selectlist.push_back( "6.0" );
  selectlist.push_back( "6.1" );
  selectlist.push_back( "6.2" );
  selectlist.push_back( "6.3" );
  selectlist.push_back( "6.4" );
  selectlist.push_back( "6.5" );
  selectlist.push_back( "6.6" );
  selectlist.push_back( "6.7" );
  selectlist.push_back( "6.8" );
  selectlist.push_back( "6.9" );
  selectlist.push_back( "7.0" );
  selectlist.push_back( "7.1" );
  selectlist.push_back( "7.2" );
  selectlist.push_back( "7.3" );
  selectlist.push_back( "7.4" );
  selectlist.push_back( "7.5" );
  selectlist.push_back( "7.6" );
  selectlist.push_back( "7.7" );
  selectlist.push_back( "7.8" );
  selectlist.push_back( "7.9" );
  selectlist.push_back( "8.0" );
  selectlist.push_back( "9.0" );
  selectlist.push_back( "10.0" );
  selectlist.push_back( "11.0" );
  selectlist.push_back( "12.0" );
  infolist.push_back( TRunInformation( "NEGATIVE VOLTAGE (V)", selectlist ) );
  infolist.push_back( TRunInformation( "OTHER CONDITION", tInfoFreeText ) );
  infolist.push_back( TRunInformation( "COMMENT", tInfoFreeText ) );
  TRunInformationTable runinfotable( infolist );



  TCrate* crate = new TCrate();
  TstringList groups;

  // VME module
  const TEnvironmentVariableTable& envtable = 
    theRunManager -> GetEnvironmentVariableTable();

  Tint mpxoffset = envtable.GetIntegerValue( "ST01_MPX201A_OFFSET" );
  Tint samplerate = envtable.GetIntegerValue( "ST01_MPX201A_SAMPLING" );
  Tint nblock = envtable.GetIntegerValue( "ST01_MPX201A_BLOCK" );
  Tint memoffset = envtable.GetIntegerValue( "ST01_MPX201A_DAUGHTER" );
  Tint rpvoffset = envtable.GetIntegerValue( "ST01_RPV130_OFFSET" );


  TVmeMpx201aModule* mpx201a = new TVmeMpx201aModule( mpxoffset );
  mpx201a -> SetupCCDmeasurement( samplerate, nblock, memoffset );
  TVmeDaughterBoardMemoryModule* daughter
    = new TVmeDaughterBoardMemoryModule( mpx201a );
  TVmeRpv130Module* rpv130 = new TVmeRpv130Module( rpvoffset );

  groups.clear();
  groups.push_back( "run begin" );
  groups.push_back( "event" );
  crate -> InstallModule( mpx201a, "mpx201a", groups );
  crate -> InstallModule( daughter, "daughter", groups );
  crate -> InstallModule( rpv130, "rpv130", groups );



  // RS232C module
  Tstring dev = envtable.GetEnvironmentValue( "ST01_KEITHLEY_DEVICE" );
  TRs232cKeithley2400Module* sm2400 = new TRs232cKeithley2400Module( dev );
  crate -> InstallModule( sm2400, "source meter", groups );



  // software module
  TSoftwareClockModule* clock = new TSoftwareClockModule( 4 );
  TSoftwareTimerModule* timer = new TSoftwareTimerModule();
  TSoftwareScalerModule* evtid = new TSoftwareScalerModule( 1 );
  crate -> InstallModule( evtid, "evtid", groups );
  crate -> InstallModule( clock, "clock", groups );
  crate -> InstallModule( timer, "timer", groups );



  TSoftwareRunInformationModule* runinfo
    = new TSoftwareRunInformationModule( runinfotable );
  crate -> InstallModule( runinfo, "runinfo" );
  theRunManager -> SetRunInformationModule( runinfo );



  TSoftwareScalerModule* runid = new TSoftwareScalerModule( 1 );
  groups.clear();
  groups.push_back( "run begin" );
  crate -> InstallModule( runid, "runid", groups );

  return crate;
}
