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

HighLevelApi.cpp

00001 #include "HighLevelApi.h"
00002 #include "XmlSummaryFile.h"
00003 #include "ModuleData.h"
00004 #include "SctDaqRootFile.h"
00005 #include "Exceptions.h"
00006 #include "Globals.h"
00007 
00008 #include "Sct/Env.h"
00009 #include "Sct/IoExceptions.h"
00010 #include "Sct/OmniMarshalling.h"
00011 #include "Sct/SctNames.h"
00012 #include "Sct/ISProxy/IOManagerISProxy.h"
00013 #include "Sct_SctApi/SctApiServer.h"
00014 
00015 #include "SctData/ModuleConfiguration.h"
00016 #include "SctData/mVThresholdVariable.h"
00017 #include "SctData/mVfromTrimTargetThresholdVariable.h"
00018 #include "SctData/StrobeDelayVariable.h"
00019 #include "SctData/DefaultVariable.h"
00020 #include "SctData/NullVariable.h"
00021 #include "SctData/RawScanResult.h"
00022 #include "SctData/ScanPoints.h"
00023 
00024 #include "CalibrationController/IS/TestData.h"
00025 #include "CommonWithDsp/ABCD/ABCDscans.h"
00026 
00027 #include <TH1.h>
00028 #include <TH2.h>
00029 
00030 #include <sstream>
00031 
00032 using namespace SctData;
00033 using namespace Sct;
00034 using namespace Sct::IS;
00035 using namespace Sct::ISProxy;
00036 using namespace std;
00037 using namespace boost;
00038 using namespace SctConfiguration;
00039 
00040 namespace SctTest {
00041 
00042 HighLevelApi::HighLevelApi() : IPCNamedObject<POA_SctTestApi::HighLevelApi>(Sct::SctNames::getPartition(),SctTestApi::HighLevelApi::instanceName){
00043     try {
00044     handy_setDataFile("${SCT_DAQ_ROOT}/installed/config/TestConfig/ModuleData.txt");
00045     } catch (Sct::FileException& fe) {
00046         fe.sendToMrs(MRS_INFORMATION);
00047     throw SctTestApi::NoSuchFileException();
00048     }
00049 
00050     try {
00051     handy_setXmlSummaryFile("${SCT_DAQ_ROOT}/installed/config/TestConfig/XmlSummary.txt");
00052     } catch (Sct::FileException& fe) {
00053         fe.sendToMrs(MRS_INFORMATION);
00054     throw SctTestApi::NoSuchFileException();
00055     }
00056 
00057     try {
00058         XmlSummaryFile file(handy_getXmlSummaryFile());
00059         XmlSummaryRecord record = file.getNextRecord();
00060         handy_setModuleSerial(record.serialNumber);
00061     } catch (Exception& e) {
00062         e.sendToMrs(MRS_INFORMATION);
00063     throw SctTestApi::NoSuchFileException();
00064     }
00065 }
00066 
00067 HighLevelApi& HighLevelApi::instance() {
00068     static HighLevelApi api;
00069     return api;
00070 }
00071 
00072 void HighLevelApi::handy_setModuleSerial(const string & serial) {
00073     getConfig(serial);
00074     this->serial = serial;
00075     if (!data.dataExists(serial)) throw NoDataException("No data for module " + serial, __FILE__, __LINE__);
00076 }
00077 
00078 string HighLevelApi::handy_getModuleSerial() const {
00079     return serial;
00080 }
00081 
00082 void HighLevelApi::handy_setDataFile(const string & file) {
00083     data.load(file);
00084 }
00085 
00086 string HighLevelApi::handy_getDataFile() const {
00087     return data.getFileName();
00088 }
00089 
00090 void HighLevelApi::handy_setXmlSummaryFile(const string & file) {
00091     xmlFile = Env::substituteVariables(file);;
00092 }
00093 
00094 string HighLevelApi::handy_getXmlSummaryFile() const {
00095     return xmlFile;
00096 }
00097 
00098 
00099 void HighLevelApi::getConfig(string serial) {
00100     try {
00101         ModuleConfiguration* c = new ModuleConfiguration();
00102         if (!config) config = shared_ptr<ModuleConfiguration>(c);
00103         config->getABCDModule() = configServer->getModuleConfig(serial);
00104     } catch (ConfigurationException& e) {
00105         addAndGetConfig(serial);
00106     }
00107 }
00108 
00109 void HighLevelApi::addAndGetConfig(string serial) {
00110     XmlSummaryFile file(handy_getXmlSummaryFile());
00111     string xmlFile = "";
00112 
00113     while (xmlFile.length() == 0 && file.hasMoreRecords()) {
00114         XmlSummaryRecord xsr = file.getNextRecord();
00115         if (xsr.serialNumber == serial) xmlFile = xsr.xmlFile;
00116     }
00117 
00118     if (xmlFile.length() == 0) {
00119         throw NoDataException("No data for module " + serial, __FILE__, __LINE__);
00120     }
00121 
00122     try {
00123         configServer->configureModuleFromFile(xmlFile);
00124         config->getABCDModule() = configServer->getModuleConfig(serial);
00125     } catch (ConfigurationException& e) {
00126         throw NoDataException("Could not configure module " + serial, __FILE__, __LINE__);
00127     }
00128 }
00129 
00130 void HighLevelApi::doTest(const TestInfo& info, TestData& data, const SctData::ConfigurationVariable& var) const {
00131     if (!config) return;
00132     data.nScans = data.testPoints_size;
00133     data.runNumber = info.runNumber;
00134     data.startScanNumber = info.scanNumber;
00135     data.status = TestData::COMPLETED;
00136 
00137     publishTest(data);
00138     for (unsigned int i=0; i<data.nScans; ++i) {
00139         publishScan(info, data.startScanNumber + i, var, *config);        
00140     }
00141 }
00142 
00143 void HighLevelApi::publishTest(TestData& t) const {
00144     string name = SctNames::getControlDataName();
00145     name += ".";
00146 
00147     ostringstream s;
00148     s << "TestData." << t.runNumber << "." << t.startScanNumber;
00149 
00150     name += s.str();
00151     ISInfoDictionary& is = SctNames::getISDictionary();
00152     ISInfo::Status stat = is.contains(name);
00153     if (stat == ISInfo::Success) {
00154         stat = is.update(name, t);
00155     } else if (stat==ISInfo::NotFound) {
00156         stat = is.insert(name, t);
00157     }
00158     if (stat!=ISInfo::Success) throw IsException(stat, string("could not publish ")+name, __FILE__, __LINE__);
00159 }
00160 
00161 string HighLevelApi::getFileName(const TestInfo& info, unsigned int scanNumber) const{
00162     ostringstream filename;
00163     filename << info.path << "/strun" << info.runNumber << "_" << scanNumber << ".root";
00164     return filename.str();
00165 }
00166 
00167 void HighLevelApi::publishScan(const TestInfo& info, unsigned int scanNumber, const ConfigurationVariable& scan_variable, const SctData::ModuleConfiguration& config) const {
00168     cout << getFileName(info, scanNumber) << endl;
00169     SctDaqRootFile file(getFileName(info, scanNumber));
00170 
00171     int cycleNum = file.getCycleNum(serial);
00172     auto_ptr<TH1F> hist0Data = file.getHistData(cycleNum, 0);
00173     auto_ptr<TH1F> hist1Data = file.getHistData(cycleNum, 1);
00174     auto_ptr<TH1F> triggerData = file.getTriggerData();
00175 
00176     file.dealWithOccupancy(*hist0Data, *hist1Data, *triggerData, ConfigurationVariableIOHelper::getTypeRep(scan_variable), false);
00177 
00178     auto_ptr<TH2D> link0Data = file.fillData(*hist0Data);
00179     auto_ptr<TH2D> link1Data = file.fillData(*hist1Data);
00180 
00181     ResultHeader* s = new ResultHeader(scanNumber, info.runNumber, serial, scan_variable);
00182     ScanPoints* pts = new ScanPoints();
00183 
00184     for (int i=1; i<=triggerData->GetNbinsX(); ++i) {
00185         pts->addPoint(triggerData->GetBinCenter(i),triggerData->GetBinContent(i),0);
00186     }
00187 
00188     RawScanResult r(*s, config, *pts, *link0Data.release(), *link1Data.release());
00189 
00190     // Publish
00191     IOParamsIS params(SctNames::getEventDataName());
00192     IOManagerISProxy::instance().write(r, &params);    
00193 }
00194 
00195 
00196 //Corba  methods
00197 void HighLevelApi::setDataFile (const char * file) {
00198     try {
00199         handy_setDataFile(file);
00200     } catch (Sct::FileException& e) {
00201         throw SctTestApi::NoSuchFileException();
00202     }
00203 }
00204 
00205 char * HighLevelApi::getDataFile () {
00206     return copyStringToCorba(handy_getDataFile());
00207 }
00208 
00209 void HighLevelApi::setXmlSummaryFile (const char * file) {
00210     try {
00211         handy_setXmlSummaryFile(file);
00212     } catch (Sct::FileException& e) {
00213         throw SctTestApi::NoSuchFileException();
00214     }
00215 }
00216 
00217 char * HighLevelApi::getXmlSummaryFile () {
00218     return copyStringToCorba(handy_getXmlSummaryFile());
00219 }
00220 
00221 
00222 void HighLevelApi::setModuleSerial (const char * serial) {
00223     try {
00224         handy_setModuleSerial(serial);
00225     } catch(Sct::FileException& e) {
00226         throw SctTestApi::NoSuchModuleException();
00227     }
00228 }
00229 
00230 char * HighLevelApi::getModuleSerial () {
00231     return copyStringToCorba(handy_getModuleSerial());
00232 }
00233 
00234 void HighLevelApi::fullBypass() {
00235     TestData test;
00236     test.testName="FullBypassTest";
00237     test.testPoints_size = 6;
00238     test.testPoints = new double[test.testPoints_size];
00239     test.testVariable = 0;
00240     for (unsigned index=0; index<test.testPoints_size; ++index) {
00241         test.testPoints[index]=4.0-0.1*index;
00242     }
00243     try {
00244     doTest(data.getFullBypassInfo(handy_getModuleSerial()), test, *DefaultVariable::instance(ST_TOKEN));
00245     } catch (Exception& e) {
00246     e.sendToMrs(MRS_ERROR);
00247     std::cout << "LESTERDEBUGWARNING 4532 in " << __FILE__ << std::endl;
00248     throw SctTestApi::NoDataException();
00249     }
00250 }
00251 
00252 void HighLevelApi::timeWalk() {
00253     TestData test;
00254     test.testName="TimeWalkTest";
00255     test.testPoints_size = 10;
00256     test.testPoints = new double[test.testPoints_size];
00257     test.testVariable = ST_QCAL;
00258     test.testPoints[0]=1.25;
00259     test.testPoints[1]=1.5;
00260     test.testPoints[2]=1.75;
00261     test.testPoints[3]=2.0;
00262     test.testPoints[4]=3.0;
00263     test.testPoints[5]=4.0;
00264     test.testPoints[6]=5.0;
00265     test.testPoints[7]=6.0;
00266     test.testPoints[8]=8.0;
00267     test.testPoints[9]=10.0;
00268     try {
00269     doTest(data.getTimeWalkInfo(handy_getModuleSerial()), test, StrobeDelayVariable::instance());
00270     } catch (Exception& e) {
00271     e.sendToMrs(MRS_ERROR);
00272     throw SctTestApi::NoDataException();
00273     }
00274     
00275 }
00276 
00277 void HighLevelApi::strobeDelay() {
00278     TestData test;
00279     test.testName="StrobeDelayTest";
00280     test.testPoints_size = 1;
00281     test.testPoints = new double[test.testPoints_size];
00282     test.testVariable = 0;
00283     test.testPoints[0] = 0;
00284     try {
00285     doTest(data.getStrobeDelayInfo(handy_getModuleSerial()), test, StrobeDelayVariable::instance());
00286     } catch (Exception& e) {
00287     e.sendToMrs(MRS_ERROR);
00288     throw SctTestApi::NoDataException();
00289     }
00290 
00291 }
00292 
00293 void HighLevelApi::threePointGain() {
00294     TestData test;
00295     test.testName="NPtGainTest";
00296     test.testPoints_size = 3;
00297     test.testPoints = new double[test.testPoints_size];
00298     test.testVariable = ST_QCAL;
00299     test.testPoints[0] = 1.50;
00300     test.testPoints[1] = 2.00;
00301     test.testPoints[2] = 2.50;
00302     try {
00303     doTest(data.get3PtGainInfo(handy_getModuleSerial()), test, mVThresholdVariable::instance());
00304     } catch (Exception& e) {
00305     e.sendToMrs(MRS_ERROR);
00306     throw SctTestApi::NoDataException();
00307     }
00308 }
00309 
00310 void HighLevelApi::responseCurve() {
00311     TestData test;
00312     test.testName="NPtGainTest";
00313     test.testPoints_size = 10;
00314     test.testPoints = new double[test.testPoints_size];
00315     test.testVariable = ST_QCAL;
00316     test.testPoints[0]=0.50;
00317     test.testPoints[1]=0.75;
00318     test.testPoints[2]=1.00;
00319     test.testPoints[3]=1.25;
00320     test.testPoints[4]=1.50;
00321     test.testPoints[5]=2.00;
00322     test.testPoints[6]=3.00;
00323     test.testPoints[7]=4.00;
00324     test.testPoints[8]=6.00;
00325     test.testPoints[9]=8.00;
00326     try {
00327     doTest(data.getResponseCurveInfo(handy_getModuleSerial()), test, mVThresholdVariable::instance());
00328     } catch (Exception& e) {
00329     e.sendToMrs(MRS_ERROR);
00330     throw SctTestApi::NoDataException();
00331     }
00332 }
00333 
00334 void HighLevelApi::noiseOccupancy() {
00335     TestData test;
00336     test.testName="NoiseOccupancyTest";
00337     test.testPoints_size = 1;
00338     test.testPoints = new double[test.testPoints_size];
00339     test.testVariable = 0;
00340     test.testPoints[0] = 0;
00341     
00342     try {
00343     TestInfo info = data.getNoiseOccupancyInfo(getModuleSerial());
00344     //Check if it is relative to trim target or not
00345     SctDaqRootFile file(getFileName(info, info.scanNumber));
00346     int cycleNum = file.getCycleNum(serial);
00347     auto_ptr<TH1F> hist0Data = file.getHistData(cycleNum, 0);
00348     double firstBin = hist0Data->GetYaxis()->GetBinCenter(1);
00349     
00350     if (firstBin < 0) 
00351         doTest(info, test, mVfromTrimTargetThresholdVariable::instance());
00352     else 
00353         doTest(info, test, mVThresholdVariable::instance());
00354     } catch (Exception& e) {
00355     e.sendToMrs(MRS_ERROR);
00356     throw SctTestApi::NoDataException();
00357     }
00358 }
00359 
00360 void HighLevelApi::trim() {
00361     if (!config) return;
00362  
00363     try {
00364     TestInfo info = data.getTrimInfo(handy_getModuleSerial());
00365 
00366     TestData test;
00367     test.testName="TrimRangeTest";
00368     test.testPoints_size = 28;
00369     test.testPoints = new double[28];
00370     test.testVariable = ST_TRIM;
00371     test.nScans = test.testPoints_size;
00372     for(unsigned int i=0; i<test.testPoints_size; i++) {
00373         if (i<16) {
00374         test.testPoints[i]=i;
00375         } else {
00376         test.testPoints[i]=((i%4)+1)*4-1;
00377         }
00378     }
00379     
00380     //unsigned int index = 4;
00381     test.runNumber = info.runNumber;
00382     test.startScanNumber = info.scanNumber;
00383     test.status = TestData::COMPLETED;
00384     
00385     publishTest(test);
00386     ModuleConfiguration tempConfig(*config);
00387     
00388     for(unsigned int i=0; i<test.nScans; i++) {
00389         short range, point, value;
00390         if (i<16) {
00391         range=0;
00392         point=i;
00393         value=point;
00394         } else {
00395         range=(i-16)/4+1;
00396         point=(i-16)%4;
00397         value=(point+1)*4-1;
00398         }
00399         
00400         for (unsigned ichip=0; ichip<12; ++ichip) {
00401         tempConfig.getChipConfiguration(ichip).setTrimRange(range);
00402         for (unsigned ichannel=0; ichannel<128; ++ichannel) {
00403             tempConfig.getChipConfiguration(ichip).setTrim(ichannel,value);
00404         }
00405         }
00406         
00407         try {
00408         publishScan(info, test.startScanNumber + i, mVThresholdVariable::instance(), tempConfig);
00409         } catch (SctTestException& e) {
00410         e.sendToMrs(MRS_DIAGNOSTIC);
00411         throw SctTestApi::NoDataException();
00412         }
00413     }
00414     } catch (Exception& e) {
00415     e.sendToMrs(MRS_ERROR);
00416     throw SctTestApi::NoDataException();
00417     return;
00418     }
00419 }
00420 
00421 void HighLevelApi::pipeline() {
00422     TestData test;
00423     test.testName="PipelineTest";
00424     test.testPoints_size = 2;
00425     test.testPoints = new double[test.testPoints_size];
00426     test.testVariable = 0;
00427     test.testPoints[0] = 0;
00428     test.testPoints[1] = 0;
00429     try {
00430     doTest(data.getPipelineInfo(handy_getModuleSerial()), test, *DefaultVariable::instance(ST_MASK));
00431     } catch (Exception& e) {
00432     e.sendToMrs(MRS_ERROR);
00433     throw SctTestApi::NoDataException();
00434     }
00435 }
00436 
00437 }
00438 

Generated on Fri Sep 16 18:01:51 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5