// // ReadoutConfig.cpp // #include "ReadoutConfig.h" #include "LogFile.h" #include // ======================================================== // Constructor // ======================================================== ReadoutConfig::ReadoutConfig () { cout << "initilieze Readout config " << endl; for ( int i = 0; i < 4; i++ ) { _detPlaneList[i] = 0; } _dspCardList [0] = 0; _nr_of_detPlanes = 0; _linkList_forDetPlanes = 0; _dspList_forDetPlanes = 0; } ReadoutConfig::~ReadoutConfig () { cout << "end Readout config " << endl; // ------------------------------- // delete all detPlanes // ------------------------------- for ( int i = 0; i < 4; i++ ) { if ( _detPlaneList[i] != 0 ) { delete _detPlaneList[i]; } } // --------------------------- // delete dsp card // --------------------------- if ( _dspCardList [0] != 0 ) { delete _dspCardList [0]; } } // ========================================================== // add detector plane to readout chain // ========================================================== int ReadoutConfig::add_detPlane (int linkNr, int dspNr) { if ( linkNr < 0 || linkNr >= 4 ) { return 0; } if ( _dspCardList [0] == 0 ) return 0; if ( _dspCardList[0]->dspNr () != dspNr ) { return 0; } if ( _detPlaneList [linkNr] != 0 ) { delete _detPlaneList [linkNr]; _detPlaneList [linkNr] = 0; } _detPlaneList [linkNr] = new DetPlane (linkNr, _dspCardList[0]); ReadoutConfig::makeList (); return 1; } // ================================================== // remove detector plane from readout // ================================================== int ReadoutConfig::remove_detPlane (int linkNr, int dspNr) { if ( linkNr < 0 || linkNr >= 4 ) { return 0; } if ( _detPlaneList [linkNr] != 0 ) { delete _detPlaneList [linkNr]; _detPlaneList [linkNr] = 0; } ReadoutConfig::makeList (); return 1; } // ========================================================== // get detctor plane pointer // ========================================================== DetPlane* ReadoutConfig::get_detPlane (int linkNr, int dspNr) { if ( linkNr < 0 || linkNr >= 4 ) { return 0; } if ( _detPlaneList[linkNr] == 0 ) { logFile << " Wrong detector plane " << endl; return 0; } return _detPlaneList[linkNr]; } // ==================================================== // number of detector planes // ==================================================== int ReadoutConfig::nrOfPlanes () { int n_planes = 0; for ( int i = 0; i < 4; i++ ) { if ( _detPlaneList[i] != 0 ) n_planes++; } return n_planes; } // ========================================================== // add dsp Card to readout chain // ========================================================== int ReadoutConfig::add_dspCard (int dspNr) { if ( dspNr != 0 ) { return 0; } if ( _dspCardList [dspNr] != 0 ) { delete _dspCardList [dspNr]; _dspCardList [dspNr] = 0; } _dspCardList [dspNr] = new DspCard (dspNr); return 1; } // ================================================== // remove detector plane from readout // ================================================== int ReadoutConfig::remove_dspCard (int dspNr) { if ( dspNr != 0 ) { return 0; } if ( _dspCardList [dspNr] != 0 ) { delete _dspCardList [dspNr]; _dspCardList [dspNr] = 0; } return 1; } // ================================================== // // ================================================== DspCard* ReadoutConfig::get_dspCard (int dspNr) { if ( _dspCardList [0] == 0 ) return 0; if ( _dspCardList[0]->dspNr () == dspNr ) { return _dspCardList[0]; } else { return 0; } } // =================================================== // provide a reaout list for a client // =================================================== int ReadoutConfig::readoutList (int index, int* link, int* dspNr) { if ( index < 0 || index >= _nr_of_detPlanes ) return 0; *link = _linkList_forDetPlanes [index]; *dspNr = _dspList_forDetPlanes [index]; return 1; } // ============================================== // // ============================================== void ReadoutConfig::makeList () { // --- delete old lists --- if ( _linkList_forDetPlanes != 0 ) { delete []_linkList_forDetPlanes; _linkList_forDetPlanes = 0; } if ( _dspList_forDetPlanes != 0 ) { delete []_dspList_forDetPlanes; _dspList_forDetPlanes = 0; } // --- find number of planes --- int i; _nr_of_detPlanes = 0; for ( i = 0; i < 4; i++ ) { if ( _detPlaneList [i] != 0 ) _nr_of_detPlanes ++; } if ( _nr_of_detPlanes == 0 ) { return; } // --- allocate memory and fill new list --- _linkList_forDetPlanes = new int [_nr_of_detPlanes]; _dspList_forDetPlanes = new int [_nr_of_detPlanes]; int index = 0; for ( i = 0; i < 4; i++ ) { if ( _detPlaneList [i] != 0 ) { _linkList_forDetPlanes [index] = _detPlaneList[i]->link (); _dspList_forDetPlanes [index] = _dspCardList[0]->dspNr (); index++; } } return ; }