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

Generated on Mon Feb 6 14:01:30 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6