Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages

TApi.cxx

00001 // File: TApi.cxx
00002 
00003 #include <iostream>
00004 #include <list>
00005 
00006 #include "TApi.h"
00007 #include "autoConfig.h"
00008 
00009 // For BOCChannelConfig
00010 #include "sctConf/configRegistry.h"
00011 #include "SctApiException.h"
00012 #include "TriggerImpl.h"
00013 #include "ScanDefImpl.h"
00014 #include "ScanMonitorImpl.h"
00015 
00016 #include <boost/bind.hpp>
00017 #include "SctApiDDC.h"
00018 #include "SctApi/Idiosyncrasy.h"
00019 
00020 // Template to check for exceptions 
00021 //  ::result_type is implemented by the boost bind stuff
00022 
00023 template <class Call> typename Call::result_type checkCall(const Call &call) {
00024   try {
00025     return call();
00026   } catch(SctApi::SctApiException &e) {
00027     std::cout << "SctApiException " << e.what() << " thrown\n";
00028   }
00029 }
00030 
00031 ClassImp(TApi)
00032 ClassImp(TScanDef)
00033 ClassImp(TTrigger)
00034 ClassImp(TScanMonitor)
00035 
00036 // TApi *tapi;
00037 
00038 // Constructor
00039 TApi::TApi(std::string plugin){
00040   SctApi::Idiosyncrasy id(0,0);
00041 
00042   SctConfiguration::FactoryManager::instance().loadPlugin(plugin); 
00043   SctConfiguration::Factory &f = SctConfiguration::FactoryManager::instance().getFactory(plugin);
00044 
00045   boost::shared_ptr<SctConfiguration::Configuration> config(f.defaultConfig());
00046 
00047   worker = new SctApi::SctApi(id, config);
00048 }
00049 
00050 // Destructor
00051 /*
00052   The destructor.
00053 */
00054 TApi::~TApi(){
00055   delete worker;
00056 }
00057 
00058 // ROD Diagnostics
00059 
00060 void TApi::initialiseAll(int scanNumber) {
00061   worker->initialiseAll(scanNumber);
00062 }
00063 
00064 void TApi::shutdownAll() {
00065   worker->shutdownAll();
00066 }
00067 
00068 void TApi::setRunNumber(int newRun) {
00069   worker->setRunNumber(newRun);
00070 }
00071 
00072 void TApi::setScanNumber(int newScan) {
00073   worker->setScanNumber(newScan);
00074 }
00075 
00076 void TApi::changeRunMode(SctApi::RunType mode) {
00077   worker->changeRunMode(mode);
00078 }
00079 
00080 void TApi::flashLED(unsigned int rod,
00081                     long slaveNumber, long period, long flashes) {
00082   worker->flashLED(rod, slaveNumber, period, flashes);
00083 }
00084 
00085 void TApi::echo(unsigned int rod,
00086                 unsigned int length, unsigned long *data) {
00087   worker->echo(rod, length, data);
00088 }
00089 
00090 void TApi::echoAll(unsigned int length, unsigned long *data) {
00091   worker->echoAll(length, data);
00092 }
00093 
00094 void TApi::echoSlave(unsigned int rod,
00095                      unsigned int slave, unsigned int length, unsigned long *data) {
00096   worker->echoSlave(rod, slave, length, data);
00097 }
00098 
00099 void TApi::awaitResponse(unsigned int rod, int timeout) {
00100   worker->awaitResponse(rod, timeout);
00101 }
00102 
00103 unsigned long *TApi::getResponse(unsigned int rod) {
00104   unsigned long length;
00105   unsigned long *result = worker->getResponse(rod, length);
00106   if(result == 0) {
00107     std::cout << "No response at TApi\n";
00108     return 0;
00109   }
00110   if(length < 2) result = 0;
00111   else {
00112     if(result[0] != length) {
00113       std::cout << "Result length mismatch!\n";
00114     }
00115   }
00116   return result;
00117 }
00118 
00119 unsigned long *TApi::getResponse(unsigned int rod, 
00120                                  unsigned long *length) {
00121   unsigned long myLength;
00122   unsigned long *result = worker->getResponse(rod, myLength);
00123   *length = myLength;
00124   return result;
00125 }
00126 
00127 // Get a message from a ROD text buffer
00128 bool TApi::getRodMessage(unsigned int rod, 
00129                          char *buffer, unsigned long &length) {
00130   return worker->getRodMessage(rod, buffer, length);
00131 }
00132 
00133 UINT32 TApi::findModule(const char *sn) {
00134   return worker->findModule(sn);
00135 }
00136 
00137 UINT32 TApi::findModule(INT32 mur, INT32 module) {
00138   return worker->findModule(mur, module);
00139 }
00140 
00141 void TApi::sendABCDModules(UINT32 bank, UINT32 type) {
00142   try {
00143     worker->sendAllABCDModules(SctApi::BankType(bank), SctApi::ConfigType(type));
00144   } catch(SctApi::SctApiException &e) {
00145     std::cout << "Got exception: " << e.what() << std::endl;
00146   }
00147 }
00148 
00149 void TApi::sendABCDModule(UINT32 mid, UINT32 bank, UINT32 type) {
00150   try {
00151     worker->sendABCDModule(mid, SctApi::BankType(bank), SctApi::ConfigType(type));
00152   } catch(SctApi::SctApiException &e) {
00153     std::cout << "Got exception: " << e.what() << std::endl;
00154   }
00155 }
00156 
00157 void TApi::getABCDModules(UINT32 bank) {
00158   worker->getABCDModules(SctApi::BankType(bank));
00159 }
00160 
00161 void TApi::getABCDModule(UINT32 mid, UINT32 bank) {
00162   worker->getABCDModule(mid, SctApi::BankType(bank));
00163 }
00164 
00165 void TApi::modifyABCDMask(UINT32 mid, UINT32* mask) {
00166   worker->modifyABCDMask(mid, mask);
00167 }
00168 
00169 void TApi::modifyABCDTrims(UINT32 mid, UINT8* trims) {
00170   worker->modifyABCDTrims(mid, trims);
00171 }
00172 
00173 void TApi::modifyABCDVar(UINT32 typ, FLOAT32 var) {
00174   worker->modifyABCDVar(typ, var);
00175 }
00176 
00177 void TApi::modifyABCDVar(UINT32 mid, UINT32 typ, FLOAT32 var) {
00178   worker->modifyABCDVar(mid, typ, var);
00179 }
00180 
00181 void TApi::modifyABCDVar(UINT32 mid, UINT32 c, UINT32 typ, FLOAT32 var) {
00182   worker->modifyABCDVar(mid, c, typ, var);
00183 }
00184 
00185 void TApi::setAutoUpdateBanks(std::list<UINT32> banks){
00186   std::list<SctApi::BankType> api_banks;
00187   for (std::list<UINT32>::const_iterator i=banks.begin(); i!=banks.end(); ++i){ 
00188     api_banks.push_back(SctApi::BankType(*i));
00189   }
00190   worker->setAutoUpdateBanks(api_banks);
00191 }
00192 
00193 void TApi::setAutoUpdateBank(UINT32 bank){
00194   std::list<SctApi::BankType> api_banks;
00195   api_banks.push_back(SctApi::BankType(bank));
00196   worker->setAutoUpdateBanks(api_banks);
00197 }
00198 
00199 void TApi::modifyABCDVarROD(UINT32 mid, UINT32 chip, UINT32 typ, FLOAT32 var, UINT32 bank) {
00200   worker->modifyABCDVarROD(mid, chip, typ, var, std::list<SctApi::BankType>(1,SctApi::BankType(bank)));
00201 }
00202 
00203 void TApi::modifyABCDVarROD(UINT32 mid, UINT32 chip, UINT32 typ, FLOAT32 var, std::list<UINT32> banks) {
00204   std::list<SctApi::BankType> api_banks;
00205   for (std::list<UINT32>::const_iterator i=banks.begin(); i!=banks.end(); ++i){ 
00206     api_banks.push_back(SctApi::BankType(*i));
00207   }
00208   worker->modifyABCDVarROD(mid, chip, typ, var, api_banks);
00209 }
00210 
00211 void TApi::modifyABCDVarROD(UINT32 mid, UINT32 typ, FLOAT32 var, UINT32 bank) {
00212   worker->modifyABCDVarROD(mid, typ, var, std::list<SctApi::BankType>(1,SctApi::BankType(bank)));
00213 }
00214 
00215 void TApi::modifyABCDVarROD(UINT32 mid, UINT32 typ, FLOAT32 var, std::list<UINT32> banks) {
00216   std::list<SctApi::BankType> api_banks;
00217   for (std::list<UINT32>::const_iterator i=banks.begin(); i!=banks.end(); ++i){ 
00218     api_banks.push_back(SctApi::BankType(*i));
00219   }
00220   worker->modifyABCDVarROD(mid, typ, var, api_banks);
00221 }
00222 
00223 void TApi::modifyABCDVarROD(UINT32 typ, FLOAT32 var, UINT32 bank) {
00224   worker->modifyABCDVarROD(typ, var, std::list<SctApi::BankType>(1,SctApi::BankType(bank)));
00225 }
00226 
00227 void TApi::modifyABCDVarROD(UINT32 typ, FLOAT32 var, std::list<UINT32> banks) {
00228   std::list<SctApi::BankType> api_banks;
00229   for (std::list<UINT32>::const_iterator i=banks.begin(); i!=banks.end(); ++i){ 
00230     api_banks.push_back(SctApi::BankType(*i));
00231   }
00232   worker->modifyABCDVarROD(typ, var, api_banks);
00233 }
00234 
00235 void TApi::modifyBOCParam(unsigned int rod,
00236                             unsigned int channel, unsigned int type, unsigned int val) {
00237   checkCall(boost::bind(&SctApi::SctApi::modifyBOCParam, worker, 
00238                         rod, channel, type, val));
00239 }
00240 
00241 void TApi::modifyBOCParam(unsigned int type, unsigned int val) {
00242   checkCall(boost::bind(&SctApi::SctApi::modifyBOCParam, worker, type, val));
00243 }
00244 
00245 void TApi::loadConfiguration() {
00246   worker->loadConfiguration();
00247 }
00248 
00249 void TApi::loadModuleConfigurations() {
00250   worker->loadModuleConfigurations();
00251 }
00252 
00253 void TApi::configureBOC(unsigned int rod) {
00254   worker->configureBOC(rod);
00255 }
00256 
00257 UINT32 TApi::findBarrelModule(INT32 barrel, INT32 row, INT32 number) {
00258   return worker->findBarrelModule(barrel, row, number);
00259 }
00260 
00261 UINT32 TApi::findEndcapModule(INT32 disk, INT32 ring, INT32 number) {
00262   return worker->findEndcapModule(disk, ring, number);
00263 }
00264 
00265 void TApi::addDebugPrimList(unsigned long length, long index, long id, long version,
00266                             unsigned long * body) {
00267   worker->addDebugPrimList(length, index, id, version, body);
00268 }
00269 
00270 void TApi::sendDebugPrimList(unsigned int rod) {
00271   worker->sendDebugPrimList(rod);
00272 }
00273 
00274 void TApi::sendDebugPrimListAll() {
00275   worker->sendDebugPrimListAll();
00276 }
00277 
00278 void TApi::sendDebugSlavePrimList(unsigned int rod,
00279                                   unsigned int slave, bool await, bool response) {
00280   worker->sendDebugSlavePrimList(rod, slave, await, response);
00281 }
00282 
00283 void TApi::createDebugPrimList() {
00284   worker->createDebugPrimList();
00285 }
00286 
00287 void TApi::debugPrimListFromFile(const char *fileName) {
00288   worker->debugPrimListFromFile(fileName);
00289 }
00290 
00291 void TApi::dumpDebugPrimList() {
00292   worker->dumpDebugPrimList();
00293 }
00294 
00295 std::list<SctApi::RodLabel> TApi::listRods() {
00296   return worker->listRods();
00297 }
00298 
00299 /*
00300   Dump contents of a block of DSP memory to cout.
00301 */
00302 int TApi::dspBlockDump(unsigned int rod,
00303                        long dspStart, long numWords, long dspNumber, bool usePrimitive){
00304   return worker->dspBlockDump(rod, dspStart, numWords, dspNumber, usePrimitive);
00305 }
00306 
00307 int TApi::dspBlockDumpFile(unsigned int rod,
00308                            long dspStart, long numWords, long dspNumber, const char *filename, bool usePrimitive)
00309 {
00310   return worker->dspBlockDumpFile(rod, dspStart, numWords, dspNumber, filename, usePrimitive);
00311 }
00312 
00313 /*
00314   Read contents of a block of DSP memory.
00315 */
00316 unsigned long *TApi::dspBlockRead(unsigned int rod,
00317                                   long dspStart, long numWords, long dspNumber, 
00318                                   unsigned long *length, bool usePrimitive) {
00319   unsigned long thing;
00320   unsigned long *result = worker->dspBlockRead(rod, dspStart, numWords, 
00321                                                dspNumber, thing, usePrimitive);
00322   *length = thing;
00323   return result;
00324 }
00325 
00326 int TApi::dspBlockWrite(unsigned int rod,
00327                         unsigned long *buffer, unsigned long dspAddress, long numWords, 
00328                         long dspNumber, bool usePrimitive) {
00329   return worker->dspBlockWrite(rod, 
00330                                buffer, dspAddress, numWords, dspNumber, usePrimitive);
00331 }
00332 
00333 unsigned long TApi::dspSingleRead(unsigned int rod,
00334                                   const unsigned long dspAddr, long dspNumber) {
00335   return worker->dspSingleRead(rod, dspAddr, dspNumber);
00336 }
00337 
00339 void TApi::dspSingleWrite(unsigned int rod,
00340                    unsigned long dspAddr, unsigned long value, long dspNumber) {
00341   worker->dspSingleWrite(rod, dspAddr, value, dspNumber);
00342 }
00343 
00344 void TApi::defaultScan(int type) {
00345   worker->defaultScan(type);
00346 }
00347 
00348 void TApi::tidyHistogramming() {
00349   worker->tidyHistogramming();
00350 }
00351 
00352 TScanMonitor *TApi::startAsyncScan(TScanDef tScan) {
00353   TScanMonitor *monitor = 0;
00354   tScan.update();
00355   boost::shared_ptr<SctApi::Scan> scan = tScan.getScan();
00356 
00357   try {
00358     if(scan)
00359       monitor = ScanMonitorWrapper::createMonitor(worker->startAsyncScan(scan));
00360     else 
00361       std::cout << "Bad scan at Root interface level\n";
00362   } catch(SctApi::SctApiException &s) {
00363     std::cout << "Exception thrown by startAsyncScan:\n";
00364     std::cout << s.what() << std::endl;
00365   } catch(std::exception &s) {
00366     std::cout << "Exception thrown by startAsyncScan:\n";
00367     std::cout << s.what() << std::endl;
00368   }
00369 
00370   return monitor;
00371 }
00372 
00373 void TApi::doScan(TScanDef tScan) {
00374   tScan.update();
00375   boost::shared_ptr<SctApi::Scan> scan = tScan.getScan();
00376 
00377   try {
00378     if(scan)
00379       worker->doScan(scan);
00380     else 
00381       std::cout << "Bad scan at Root interface level\n";
00382   } catch(SctApi::SctApiException &s) {
00383     std::cout << "Exception thrown by doScan:\n";
00384     std::cout << s.what() << std::endl;
00385   } catch(std::exception &s) {
00386     std::cout << "Exception thrown by doScan:\n";
00387     std::cout << s.what() << std::endl;
00388   }
00389 }
00390 
00391 void TApi::awaitScan() {
00392   worker->awaitScan();
00393 }
00394 
00395 void TApi::doRawScan(TScanDef tScan, int delay, int width, bool configure, bool clkBy2) {
00396   tScan.update();
00397   boost::shared_ptr<SctApi::Scan> scan = tScan.getScan();
00398 
00399   try {
00400     if(scan)
00401       worker->doRawScan(scan, delay, width, configure, clkBy2);
00402     else 
00403       std::cout << "Bad scan at Root interface level\n";
00404   } catch(SctApi::SctApiException &s) {
00405     std::cout << "SctApi Exception thrown by doRawScan:\n";
00406     std::cout << s.what() << std::endl;
00407   } catch(...) {
00408     std::cout << "Unknown Exception thrown by doRawScan:\n";
00409   }
00410 }
00411 
00412 unsigned long TApi::sendTriggers(TTrigger tTrig, unsigned long count) {
00413   tTrig.update();
00414   boost::shared_ptr<SctApi::Trigger> trig = tTrig.getTrigger();
00415   if(trig){
00416     return worker->sendTriggers(trig.get(), count);
00417   }else{ 
00418     std::cout << "Bad trigger at Root interface level\n";
00419     return 0;
00420   }
00421 }
00422 
00423 void TApi::sendRodTrigger(unsigned int rod, TTrigger tTrig, unsigned long count, int scan_point) {
00424   tTrig.update();
00425 
00426   boost::shared_ptr<SctApi::Trigger> trig = tTrig.getTrigger();
00427 
00428   if(trig)
00429     worker->sendRodTrigger(rod, trig.get(), count, scan_point);
00430   else 
00431     std::cout << "Bad trigger at Root interface level\n";
00432 }
00433 
00434 void TApi::status() {
00435   std::cout << worker->status() << std::endl;
00436 }
00437 
00438 unsigned long TApi::readRodCommandReg(unsigned int rod,
00439                                       long regNumber) {
00440   return worker->readRodCommandReg(rod, regNumber);
00441 }
00442 
00443 unsigned long TApi::readRodStatusReg(unsigned int rod,
00444                                      long regNumber) {
00445   return worker->readRodStatusReg(rod, regNumber);
00446 }
00447 
00448 void TApi::setABCDModule(UINT32 mid, UINT32 bank) {
00449   try {
00450     worker->setABCDModule(mid, std::list<SctApi::BankType>(1,SctApi::BankType(bank)));
00451   } catch(SctApi::SctApiException &s) {
00452     std::cout << "Exception thrown by setABCDModule:\n";
00453     std::cout << s.what() << std::endl;
00454   }
00455 }
00456 
00457 void TApi::setABCDModules(std::list<UINT32> banks){
00458   try {
00459     std::list<SctApi::BankType> api_banks;
00460     for (std::list<UINT32>::const_iterator i=banks.begin(); i!=banks.end(); ++i){ 
00461       api_banks.push_back(SctApi::BankType(*i));
00462     }
00463     worker->setABCDModules(api_banks);
00464   } catch(SctApi::SctApiException &s) {
00465     std::cout << "Exception thrown by setABCDModules:\n";
00466     std::cout << s.what() << std::endl;
00467   }
00468 }
00469 
00470 void TApi::setABCDModules(UINT32 bank) {
00471   try {
00472     worker->setABCDModules(std::list<SctApi::BankType>(1,SctApi::BankType(bank)));
00473   } catch(SctApi::SctApiException &s) {
00474     std::cout << "Exception thrown by setABCDModules:\n";
00475     std::cout << s.what() << std::endl;
00476   }
00477 }
00478 
00479 void TApi::copyABCDModules(UINT32 from, std::list<UINT32> to) {
00480   try {
00481     std::list<SctApi::BankType> api_banks;
00482     for (std::list<UINT32>::const_iterator i=to.begin(); i!=to.end(); ++i){ 
00483       api_banks.push_back(SctApi::BankType(*i));
00484     }
00485     worker->copyABCDModules(SctApi::BankType(from), api_banks);
00486   } catch(SctApi::SctApiException &s) {
00487     std::cout << "Exception thrown by setABCDModules:\n";
00488     std::cout << s.what() << std::endl;
00489   }
00490 }
00491 
00492 void TApi::copyABCDModules(UINT32 mid, UINT32 from, std::list<UINT32> to) {
00493   try {
00494     std::list<SctApi::BankType> api_banks;
00495     for (std::list<UINT32>::const_iterator i=to.begin(); i!=to.end(); ++i){ 
00496       api_banks.push_back(SctApi::BankType(*i));
00497     }
00498     worker->copyABCDModule(mid, SctApi::BankType(from), api_banks);
00499   } catch(SctApi::SctApiException &s) {
00500     std::cout << "Exception thrown by setABCDModules:\n";
00501     std::cout << s.what() << std::endl;
00502   }
00503 }
00504 
00505 unsigned long *TApi::retrieveModule(UINT32 mid) {
00506   return (unsigned long*)worker->retrieveModule(mid);
00507 }
00508 
00509 void TApi::printABCDModule(int mid) {
00510   worker->printABCDModule(mid);
00511 }
00512 
00513 void TApi::printABCDRodModule(int mid, int bank) {
00514   checkCall(boost::bind(&SctApi::SctApi::printABCDRodModule, worker, 
00515                         mid, SctApi::BankType(bank)));
00516 }
00517 
00518 void TApi::printBOCSetup(unsigned int rod) {
00519   checkCall(boost::bind(&SctApi::SctApi::printBOCSetup, worker, 
00520                         rod));
00521 }
00522 
00523 void TApi::currentBOCSetup(unsigned int rod) {
00524   try {
00525     std::vector<SctConfiguration::BOCChannelConfig> setup = worker->currentBOCSetup(rod);
00526 
00527     std::cout << "Got setup length " << setup.size() << std::endl;
00528 
00529     for(unsigned int i=0; i<setup.size(); i++) {
00530       SctConfiguration::BOCChannelConfig conf = setup[i];
00531 
00532       std::cout << conf.current << " " << conf.delay << " " << conf.markSpace << std::endl;
00533       std::cout << conf.threshold0 << " " << conf.delay0 << std::endl;
00534       std::cout << conf.threshold1 << " " << conf.delay1 << std::endl;
00535     }
00536   } catch(SctApi::SctApiException &s) {
00537     std::cout << "Exception in currentBOCSetup " << s.what() << std::endl;
00538   }
00539 }
00540 
00541 void TApi::printBOCRegisters(unsigned int rod) {
00542   checkCall(boost::bind(&SctApi::SctApi::printBOCRegisters, worker, rod));
00543 }
00544 
00545 // void TApi::currentBOCRegisters(unsigned int rod) {
00546 //   checkCall(boost::bind(&SctApi::SctApi::currentBOCRegisters, worker, rod));
00547 // }
00548 
00549 void TApi::saveBOCSetup(unsigned int rod, UINT32 bank) {
00550   worker->saveBOCSetup(rod, SctApi::BankType(bank));
00551 }
00552 
00553 void TApi::saveBOCRegisters(unsigned int rod, UINT32 bank) {
00554   worker->saveBOCRegisters(rod, SctApi::BankType(bank));
00555 }
00556 
00557 void TApi::restoreBOCSetup(unsigned int rod, UINT32 bank) {
00558   worker->restoreBOCSetup(rod, SctApi::BankType(bank));
00559 }
00560 
00561 void TApi::restoreBOCRegisters(unsigned int rod, UINT32 bank) {
00562   worker->restoreBOCRegisters(rod, SctApi::BankType(bank));
00563 }
00564 
00565 void TApi::rawData(unsigned int rod, 
00566                    int delay, int units, bool setMask, TTrigger tTrig) {
00567   tTrig.update();
00568 
00569   boost::shared_ptr<SctApi::Trigger> trig = tTrig.getTrigger();
00570 
00571   if(trig)
00572     worker->rawData(rod, delay, units, setMask, trig.get());
00573   else 
00574     std::cout << "Bad trigger to raw data at Root interface level\n";
00575 }
00576 
00577 char *TApi::probe(unsigned int rod, signed int harness) {
00578   std::vector<char> result = worker->probe(rod, harness);
00579   int length = result.size();
00580   char *buffer = new char[length + 1];
00581 
00582   for (int i=0; i<length; i++) {
00583     buffer[i] = result[i];
00584   }
00585 
00586   buffer[length] = 0;
00587 
00588   return buffer;
00589 }
00590 
00591 char *TApi::probeWithTrigger(unsigned int rod, 
00592                              TTrigger tTrig, signed int harness) {
00593   tTrig.update();
00594 
00595   boost::shared_ptr<SctApi::Trigger> trig = tTrig.getTrigger();
00596 
00597   if(trig) {
00598     std::vector<char> result = worker->probeWithTrigger(rod, trig.get(), harness);
00599     int length = result.size();
00600     char *buffer = new char[length + 1];
00601 
00602     for (int i=0; i<length; i++) {
00603       buffer[i] = result[i];
00604     }
00605 
00606     buffer[length] = 0;
00607 
00608     return buffer;
00609   } else {
00610     std::cout << "Bad trigger to raw data at Root interface level\n";
00611     return 0;
00612   }
00613 }
00614 
00615 void TApi::probeScan(unsigned int rod, 
00616                      TScanDef tScan, signed int harness) {
00617   tScan.update();
00618   boost::shared_ptr<SctApi::Scan> scan = tScan.getScan();
00619 
00620   if(!scan) {
00621     std::cout << "Bad scan at Root interface level\n";
00622     return;
00623   }
00624 
00625   std::cout << "Summary\n";
00626   std::vector< std::vector <char> > result = worker->probeScan(rod, scan, harness);
00627   int outerLength = result.size();
00628   int innerLength = 0;
00629   if(outerLength > 0) {
00630     innerLength = result[0].size();
00631   }
00632   for(int i=0; i<innerLength; i++) {
00633     for(int j=0; j<outerLength; j++) {
00634       std::cout << result[j][i];
00635     }
00636     std::cout << std::endl;
00637   }
00638 }
00639 
00640 bool TApi::checkAllModulesProbe(const char *value) {
00641   return worker->checkAllModulesProbe(value);
00642 }
00643 
00644 void TApi::autoConfigure() {
00645   ::SctApi::AutoConf::AutoConfigurer configurer(*worker);
00646   configurer.run();
00647 
00648   std::list< ::SctApi::AutoConf::AutoResult> results = configurer.getResults();
00649 
00650   std::cout << results.size() << " auto-configure results:\n";
00651 
00652   for(std::list< ::SctApi::AutoConf::AutoResult>::const_iterator autoIter = results.begin();
00653       autoIter != results.end(); autoIter ++) {
00654     const ::SctApi::AutoConf::AutoResult &autoResult = *autoIter;
00655 
00656     std::cout << "r: " << autoResult.rod << " tx: " << autoResult.tx << " rx: " << autoResult.rx << std::endl;
00657   }
00658 }
00659 
00660 void TApi::rodMode(unsigned int rod,
00661                    int mode, int flag, int fifoSetup, int nBins, int delay, int message) {
00662   worker->rodMode(rod, 
00663                   mode, flag, fifoSetup, nBins, delay, message);
00664 }
00665 
00666 void TApi::bocHistogram(unsigned int rod, 
00667                         unsigned int samples, unsigned int numLoops)
00668 {
00669   worker->bocHistogram(rod, samples, numLoops);
00670 }
00671 
00672 void TApi::testLinkOutSelect(unsigned int rod,
00673                              unsigned int link) {
00674   worker->testLinkOutSelect(rod, link);
00675 }
00676 
00677 void TApi::setDebugOption(const char *opt) {
00678   worker->setDebugOption(opt);
00679 }
00680 
00681 void TApi::unsetDebugOption(const char *opt) {
00682   worker->unsetDebugOption(opt);
00683 }
00684 
00685 void TApi::listEnabledDebugOptions() {
00686   std::list<std::string> theList = worker->listEnabledDebugOptions();
00687   for(std::list<std::string>::const_iterator i = theList.begin();
00688       i != theList.end();
00689       i++) {
00690     std::cout << *i << std::endl;
00691   }
00692 }
00693 
00694 void TApi::listDebugOptions() {
00695   std::vector<std::string> theList = worker->listDebugOptions();
00696   for(std::vector<std::string>::const_iterator i = theList.begin();
00697       i != theList.end();
00698       i++) {
00699     std::cout << *i << std::endl;
00700   }
00701 }
00702 
00703 void TApi::debugStepHistogram() 
00704 {
00705   worker->debugStepHistogram();
00706 }
00707 
00708 void TApi::debugContinueHistogram()
00709 {
00710   worker->debugContinueHistogram();
00711 }
00712 
00713 void TApi::debugAbortHistogram()
00714 {
00715   worker->debugAbortHistogram();
00716 }
00717 
00718 void TApi::standardRegisterDump(unsigned int rod) 
00719 {
00720   worker->standardRegisterDump(rod);
00721 }
00722 
00723 void TApi::lasersOff() {
00724   worker->lasersOff();
00725 }
00726 
00727 void TApi::scanEvents(unsigned int rod, int sl, 
00728                       bool extFlag, bool errorType) {
00729   worker->scanEvents(rod, sl, extFlag, errorType);
00730 }
00731 
00732 void TApi::decodeEvent(unsigned int rod, 
00733                        int sl, int index, bool extFlag, bool errorType) {
00734   worker->decodeEvent(rod, sl, index, extFlag, errorType);
00735 }
00736 
00737 void TApi::decodeConfig(unsigned int rod, 
00738                         bool skipTrim, bool bypass) {
00739   worker->decodeConfig(rod, skipTrim, bypass);
00740 }
00741 
00742 void TApi::timSetFrequency(
00743                            double trigFreq, double rstFreq) {
00744   worker->timSetFrequency(trigFreq, rstFreq);
00745 }
00746 
00747 double TApi::timGetTriggerFrequency(){
00748   return worker->timGetTriggerFrequency();
00749 }
00750 
00751 double TApi::timGetResetFrequency(){
00752   return worker->timGetResetFrequency();
00753 }
00754 
00755 void TApi::freeTriggers() {
00756   worker->freeTriggers();
00757 }
00758 
00759 void TApi::stopTriggers() {
00760   worker->stopTriggers();
00761 }
00762 
00763 void TApi::timL1A() {
00764   worker->timL1A();
00765 }
00766 
00767 void TApi::timCalL1A(int delay) {
00768   worker->timCalL1A(delay);
00769 }
00770 
00771 void TApi::timSoftReset() {
00772   worker->timSoftReset();
00773 }
00774 
00775 void TApi::timBCReset() {
00776   worker->timBCReset();
00777 }
00778 
00779 unsigned long TApi::sendTimBurst(unsigned long count, int random, bool external) {
00780   return checkCall(boost::bind(&SctApi::SctApi::sendTimBurst, worker, count, random, external));
00781 }
00782 
00783 unsigned long TApi::runTimSequence(unsigned long count, int random, bool external) {
00784   return checkCall(boost::bind(&SctApi::SctApi::timRunSequence, worker, count, random, external));
00785 }
00786 
00787 void TApi::timVerbose() {
00788   worker->timVerbose();
00789 }
00790 
00791 void TApi::timRegLoad(int reg, UINT16 val) {
00792   worker->timWriteRegister(reg, val);
00793 }
00794 
00795 UINT16 TApi::timReadRegister(int reg) {
00796   return worker->timReadRegister(reg);
00797 }
00798 
00799 void TApi::requestHardReset(UINT32 mid) {
00800   worker->getSctApiDDC()->requestHardReset(mid);
00801 }
00802 
00803 void TApi::resumePolling() {
00804   worker->resumePolling();
00805 }
00806 
00807 void TApi::stopPolling() {
00808   worker->stopPolling();
00809 }
00810 
00811 
00812 TScanDef::TScanDef() :
00813   trigsPerBurst(200),
00814   scanVariable(1),  scanVariable2(1),
00815   full(0), bits32(1), loopCalLine(0),
00816   distSlave(1), debug(0), tim(0), nth(0), nth_rem(0),
00817   enableDataMode(true), ccode(0), ope(0)
00818 {
00819   worker.reset(new SctApi::ScanDefImpl);
00820   // A large threshold scan
00821   configure(1, 0.0, 400.0, 5.0);
00822 
00823   // With a single L1A trigger
00824   trigSequence.singleL1A();
00825 
00826   // So the worker has pointers to the TriggerImpl's in the trigsequences
00827   update();
00828 }
00829 
00830 TScanDef::~TScanDef() {
00831 //   delete worker;
00832 }
00833 
00834 TScanDef::TScanDef(const TScanDef &other) :
00835   trigsPerBurst(other.trigsPerBurst),
00836 
00837   scanVariable(other.scanVariable),
00838   scanVariable2(other.scanVariable2),
00839 
00840   trigSequence(other.trigSequence),
00841   trigSequence2(other.trigSequence2),
00842 
00843   full(other.full), 
00844   bits32(other.bits32),
00845   loopCalLine(other.loopCalLine),
00846 
00847   distSlave(other.distSlave),
00848   debug(other.debug),
00849   tim(other.tim),
00850   nth(other.nth),
00851   nth_rem(other.nth_rem),
00852   enableDataMode(other.enableDataMode),
00853   ccode(other.ccode),
00854   ope(other.ope)
00855 {
00856   worker.reset(new SctApi::ScanDefImpl(*other.worker));
00857 }
00858 
00859 void TScanDef::update() {
00860   // Only copy the things which are defined as parameters
00861   // (ScanPoints are set up in worker by the configure method)
00862   if(trigsPerBurst != -1)
00863     worker->setNTrigs(trigsPerBurst);
00864 
00865   worker->setScanVariable1(scanVariable);
00866   worker->setScanVariable2(scanVariable2);
00867 
00868   // Copy triggers
00869   trigSequence.update();
00870   worker->setTrigger1(trigSequence.getTrigger());
00871   trigSequence2.update();
00872   worker->setTrigger2(trigSequence2.getTrigger());
00873 
00874   // Set options
00875   worker->setOption(SctApi::Scan::FULL, full);
00876   worker->setOption(SctApi::Scan::BITS32, bits32);
00877   worker->setOption(SctApi::Scan::LOOPCALLINE, loopCalLine);
00878   worker->setOption(SctApi::Scan::DISTSLAVE, distSlave);
00879   worker->setOption(SctApi::Scan::DEBUG, debug);
00880   worker->setOption(SctApi::Scan::TIM, tim);
00881   worker->setOption(SctApi::Scan::NTH, nth);
00882   worker->setOption(SctApi::Scan::NTH_REM, nth_rem);
00883   worker->setOption(SctApi::Scan::ENABLE_DATA_MODE, enableDataMode);
00884   worker->setOption(SctApi::Scan::USE_CCODE, ccode);
00885   worker->setOption(SctApi::Scan::OPE, ope);
00886 }
00887 
00888 void TScanDef::print() {
00889   update();
00890   std::cout << worker->print(); // copyScan(this).print();
00891 }
00892 
00893 void TScanDef::configure(UINT16 type, FLOAT32 start, FLOAT32 stop, FLOAT32 step) {
00894   scanVariable = type;
00895   worker->configure(type, start, stop, step);
00896 }
00897 
00898 void TScanDef::configure2(UINT16 type, FLOAT32 start, FLOAT32 stop, FLOAT32 step) {
00899   scanVariable2 = type;
00900   worker->configure2(type, start, stop, step);
00901 }
00902 
00903 void TScanDef::setScanPoint(int index, FLOAT32 value) {
00904   worker->scanPoints[index] = value;
00905 }
00906 
00907 void TScanDef::setScanPoint2(int index, FLOAT32 value) {
00908   worker->scanPoints2[index] = value;
00909 }
00910 
00911 void TScanDef::setTriggersPoint(int index, UINT32 nTrigs) {
00912   if(trigsPerBurst != -1) {
00913     worker->setNTrigs(trigsPerBurst);
00914   }
00915   trigsPerBurst = -1;
00916   worker->allTrigsSame = false;
00917   worker->trigPoints[index] = nTrigs;
00918 }
00919 
00920 // This is the default for both set 0 and set 1
00921 TTrigger::TTrigger() {
00922   worker.reset(new SctApi::TriggerImpl);
00923   incCmd = 0;
00924   incData = 0;
00925   source = 0;
00926   frequency = 40.;
00927   random=0;
00928   update();
00929 }
00930 
00931 TTrigger::TTrigger(const TTrigger &other) {
00932   worker.reset(new SctApi::TriggerImpl(*other.worker));
00933   incCmd = other.incCmd;
00934   incData = other.incData;
00935   source = other.source;
00936   frequency = other.frequency;
00937   random = other.random;
00938 }
00939 
00940 TTrigger::~TTrigger() {
00941   // This is deleted by ScanDefImpl not via TScanDef
00942   //  delete worker;
00943 }
00944 
00945 void TTrigger::singleL1A() {
00946   worker->singleL1A();
00947 }
00948 
00949 void TTrigger::doubleL1A(int delay) {
00950   worker->doubleL1A(delay);
00951 }
00952 
00953 void TTrigger::delayedL1A(int delay) {
00954   worker->delayedL1A(delay);
00955 }
00956 
00957 void TTrigger::calL1A(int delay) {
00958   worker->calL1A(delay);
00959 }
00960 
00961 void TTrigger::pulseL1A(int delay) {
00962   worker->pulseL1A(delay);
00963 }
00964 
00965 void TTrigger::softL1A(int delay) {
00966   worker->softL1A(delay);
00967 }
00968 
00969 void TTrigger::print() {
00970   update();
00971   std::cout << worker->print() << std::endl;
00972 }
00973 
00974 void TTrigger::softCalL1A(int delay, int delay2) {
00975   worker->softCalL1A(delay, delay2);
00976 }
00977 
00978 void TTrigger::softPulseL1A(int delay, int delay2) {
00979   worker->softPulseL1A(delay, delay2);
00980 }
00981 
00982 void TTrigger::bcL1A(int delay) {
00983   worker->bcL1A(delay);
00984 }
00985 
00986 void TTrigger::bcCalL1A(int delay, int delay2) {
00987   worker->bcCalL1A(delay, delay2);
00988 }
00989 
00990 void TTrigger::bcPulseL1A(int delay, int delay2) {
00991   worker->bcPulseL1A(delay, delay2);
00992 }
00993 
00994 void TTrigger::update() {
00995   worker->setCommIncr(incCmd, incData);
00996   worker->setSource((::SctApi::Trigger::Source)source);
00997   worker->setFrequency(frequency);
00998   worker->setRandom(random);
00999 }
01000 
01001 TScanMonitor::TScanMonitor() {
01002 }
01003 
01004 TScanMonitor::~TScanMonitor() {
01005   //  delete worker;
01006 }
01007 
01008 void TScanMonitor::newBin(int prevTriggers, int newBin) {
01009   worker->newBin(prevTriggers, newBin);
01010 }
01011 
01012 void TScanMonitor::finishScan() {
01013   worker->finishScan();
01014 }
01015 
01016 boost::shared_ptr<SctApi::Trigger> TriggerWrapper::getTrigger() {
01017   return worker;
01018 }
01019 
01020 // Copy TScanDef scan to implementation of Scan interface 
01021 //   update(); must be called on the scan first
01022 boost::shared_ptr<SctApi::Scan> ScanDefWrapper::getScan() {
01023 //   if((tScan.trigSequence.trigCommand.GetSize() != tScan.trigSequence.trigData.GetSize()) ||
01024 //      (tScan.trigSequence2.trigCommand.GetSize() != tScan.trigSequence2.trigData.GetSize()) ||
01025 //      ((tScan.trigSequence.trigCommand.GetSize() != tScan.trigSequence2.trigCommand.GetSize()) && 
01026 //       (tScan.trigSequence2.trigData.GetSize() != 0))) {
01027 //     cout << "Trigger arrays not compatible! Aborting scan...\n";
01028 //     return;
01029 //   }
01030 
01031   return worker;
01032 }
01033 
01034 /*
01035   "Constructor" that root doesn't have to see
01036  */
01037 TScanMonitor *ScanMonitorWrapper::createMonitor(boost::shared_ptr<SctApi::ScanMonitor> monitor) {
01038   TScanMonitor *tMonitor = new TScanMonitor;
01039   tMonitor->worker = monitor;
01040   return tMonitor;
01041 }

Generated on Fri Dec 16 19:38:20 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5