Universita' di GenovaINFN Sezione di Genova  
AIRWATCH / EUSO Genova

ElectronicsFactory - source file

// Electronics Factory
// $Id: ElectronicsFactory.cc,v 1.30 2005/10/13 14:51:38 thea Exp $
// M. Pallavicini - created
// 

#include <iostream>
#include <string>

#include "ElectronicsFactory.hh"
#include "EusoElectronics.hh"
#include "Detector.hh"
#include "EusoDetector.hh"
#include "PhPToRootFileDetector.hh"
#include "OpticsFactory.hh"
#include "Photomultiplier.hh"
#include "R7600M64Photomultiplier.hh"
#include "R8900M36Photomultiplier.hh"
#include "FrontEndChip.hh"
#include "StandardMacroCell.hh"
#include "PmtGeometry.hh"
#include "SimpleTelemetry.hh"
#include "FullAnalogFrontEnd.hh"
#include "ElementaryCell.hh"
#include "MacroCellGeometry.hh"

ClassImp(ElectronicsFactory)

ElectronicsFactory* ElectronicsFactory::fMe = 0;

//______________________________________________________________________________
 ElectronicsFactory::ElectronicsFactory() : fEusoElec(0) {
    // private ctor
}

//______________________________________________________________________________
 ElectronicsFactory::~ElectronicsFactory() {
    //
    // Destructor
    //

    SafeDelete(fEusoElec);
}

//______________________________________________________________________________
 ElectronicsFactory* ElectronicsFactory::Get() {
    // singleton method
    
    if ( fMe == 0 )
        fMe = new ElectronicsFactory();
  return fMe;
}

//______________________________________________________________________________
 EusoElectronics* ElectronicsFactory::Build() {
    // build an EusoElectronics object

    if ( fEusoElec ) {
        delete fEusoElec;
        fEusoElec = 0;
    }
    
    // reset class variables for electronics objects
    FrontEndChip::ResetClass();
    MacroCell::ResetClass();
  
    fEusoElec = new EusoElectronics();
  
    // build child-parent associations before the electronics
    Config::Get()->AssociateParent(Conf()->GetStr("ElectronicsFactory.PmtType"),"Photomultiplier");

    // build the system 
    if ( !fEusoElec->Build() ) {
        FatalError("Cannot build Euso Electronics");
        return 0;
    }

    return fEusoElec;
}

//______________________________________________________________________________
 EusoElectronics* ElectronicsFactory::GetEusoElectronics() {
    // get euso electronics
    
    return fEusoElec;
}

//______________________________________________________________________________
 Detector* ElectronicsFactory::MakeDetector() {
    // get euso electronics

    Detector* detector(0); 
    string type = Conf()->GetStr("ElectronicsFactory.Detector");
    if ( type == "Euso" )
        detector = new EusoDetector();
    else if ( type == "PhPToRootFile" )
        detector = new PhPToRootFileDetector();
    else if ( type == "Test" )
        detector = new TestDetector();
    else 
        FatalError(type + ", unknown Detector");

    return detector;
}

//______________________________________________________________________________
 FrontEndChip* ElectronicsFactory::MakeFrontEndChip( Int_t size) {
    // build the selected front end chip object
    
    string type = Conf()->GetStr("ElectronicsFactory.FrontEndType");
    if ( type == "Standard" ) {
        return new FrontEndChip( size );
    }
    FatalError("Unknown FrontEndChip type");
    return 0;
}

//______________________________________________________________________________
 ElementaryCell* ElectronicsFactory::MakeElementaryCell() {
    // build the selected elementary cell
    
    string type = Conf()->GetStr("ElectronicsFactory.ElementaryCellType");
    if ( type == "Standard" ) {
        return new ElementaryCell();
    }
    FatalError("Unknown ElementaryCell type");
    return 0;
}

//______________________________________________________________________________
 AnalogFrontEnd* ElectronicsFactory::MakeAFEE( FrontEndChip* pChip, Int_t size) {
    // build the specified type of AFEE 

    string type = Conf()->GetStr("ElectronicsFactory.AfeeType");
    if ( type == "Full" ) {
        return new FullAnalogFrontEnd( pChip, size );
    }
    FatalError("Unknown AFEE Type");
    return 0;
}

//______________________________________________________________________________
 Photomultiplier* ElectronicsFactory::MakePmt(Int_t id, PmtGeometry *g) {
    // build the specified type of Photomultiplier object

    string type = Conf()->GetStr("ElectronicsFactory.PmtType");
    if ( type == "R7600M64Photomultiplier" ) {
        return new R7600M64Photomultiplier( id , g );
    }
    if ( type == "R8900M36Photomultiplier" ) {
        return new R8900M36Photomultiplier( id , g );
    }
    FatalError("Unknown Pmt Type");
    return 0;
}

//______________________________________________________________________________
 MacroCell* ElectronicsFactory::MakeMacroCell() {
    // build the specified type of Photomultiplier object

    string type = Conf()->GetStr("ElectronicsFactory.MacroCellType");
    if ( type == "Standard") {
        Int_t size = (Int_t)Config::Get()->GetCF("Electronics","MacroCell")->GetNum("MacroCell.fSize");
        if ( size <= 0 ) {
            FatalError("Invalid MacroCell size");
            return 0;
        }
        return new StandardMacroCell(size,size);
    }
    FatalError( "Unknown MacroCell type" );
    return 0;
}

//______________________________________________________________________________
 MacroCellGeometry *ElectronicsFactory::MakeMacroCellGeometry( MacroCell *pCell ) {
    // build the specified type of macrocell geometry

    string type = Conf()->GetStr("ElectronicsFactory.MacroCellType");
    if ( type == "Standard") {
        return new MacroCellGeometry( pCell );
    } 
    FatalError( "Unknown MacroCellGeometry type" );
    return 0;
}

//______________________________________________________________________________
 PmtGeometry* ElectronicsFactory::MakePmtGeometry( const EVector& pos, const EVector& norm, const EVector& dir) {
    // build PmtGeometry
    
    PmtGeometry* g = new PmtGeometry( pos , norm, dir);
    return g;
}

//______________________________________________________________________________
 Telemetry* ElectronicsFactory::MakeTelemetry() {
    // build specified Telemetry object
    
    string type = Conf()->GetStr("ElectronicsFactory.TelemetryType");
    if ( type == "Standard" ) {
        return new SimpleTelemetry();
    }
    FatalError( "Unknown Telemetry Type" );
    return 0;
}


About Us | EUSO Official Website | Web pages created by Roberto Pesce and Alessandro Thea - Last Update Wed Nov 16 16:57:39 2005 Wed Nov 16 16:29:22 2005