00001 #include "SummaryWriter.h"
00002
00003 #include "Sct/SctParameters.h"
00004 #include "Sct/SctNames.h"
00005
00006 #include "SctData/DefectList.h"
00007 #include "SctData/TestResult.h"
00008 #include "SctData/ConfigurationVariable.h"
00009 #include "SctData/DcsData.h"
00010 #include "SctData/Stat.h"
00011 #include "Sct/Version.h"
00012 #include <boost/date_time/posix_time/posix_time.hpp>
00013 #include <unistd.h>
00014
00015 using namespace std;
00016
00017 namespace SctData {
00018 namespace TestSummary{
00019
00020 const unsigned geneva_upload_points=16;
00021
00022 SummaryWriter::SummaryWriter() {}
00023
00024 SummaryWriter::~SummaryWriter() {}
00025
00026 string getHostName() {
00027 char name[255];
00028 if (gethostname(name, 255)) return "";
00029 return string(name);
00030 }
00031
00032 void SummaryWriter::writeHeader(const TestResult& r, ostream& out) const throw() {
00033 boost::posix_time::ptime t(boost::posix_time::second_clock::local_time());
00034 out << "#\n%NewTest\n#\n" ;
00035 out << "SERIAL NUMBER : " << r.getModuleName() <<endl;
00036 out << "TEST MADE BY : " << SctNames::getUser() << endl;
00037 out << "LOCATION MADE : " << SctNames::getLocation() << endl;
00038 out << "Run number : " << r.getRunNumber() << "-" << r.getScanNumberAt(0) << endl;
00039 out << "TEST_DATE : " << (short)t.date().day() << "/" << (short)t.date().month() << "/" << (short)t.date().year() << endl;
00040 out << "PASSED : " ;
00041 if (r.getPassed()) out << "YES";
00042 else out << "NO";
00043 out << endl;
00044 out << "PROBLEM : ";
00045 if (r.getProblem()) out << "YES";
00046 else out << "NO";
00047 out << endl;
00048 out << "#\n%DAQ_INFO\n#HOST\n\"" << getHostName() << "\"" << endl;
00049 out << "#VERSION \n\"" << Sct::VersionString << "\"" << endl;
00050 out << "#DUT\n\"module\"" << endl;
00051 out << "#TIME\n\"" << boost::posix_time::to_simple_string(t.time_of_day()) << "\"\n#" << endl;
00052
00053 vector<string> comments = r.getComments();
00054 out << endl;
00055 for (unsigned int i=0; i<comments.size(); ++i) {
00056 out << "%Comment" << endl << "COMMENT : " << comments[i] << endl;
00057 }
00058
00059 boost::shared_ptr<const DcsData> dcs = r.getDcsData();
00060 if (dcs.get()) {
00061 out << "#\n%DCS_INFO\n#\n#T0 T1" << std::endl
00062 << dcs->getT0() << "\t" << dcs->getT1() << std::endl;
00063
00064 out << "#VDET IDET" << std::endl
00065 << dcs->getVbias() << "\t" << dcs->getIbias() << std::endl;
00066
00067 out << "#VCC ICC" << std::endl
00068 << dcs->getVcc() << "\t" << dcs->getIcc() << std::endl;
00069
00070 out <<"#VDD IDD" << std::endl
00071 << dcs->getVdd() << "\t" << dcs->getIdd() << std::endl;
00072
00073 out << "#TIME_POWERED\n"
00074 << "."
00075 << "\n#\n";
00076 }
00077
00078 if (r.getNScans()>1){
00079 out << "%SCAN_INFO\n#"<<endl;
00080 out << "#POINT_TYPE\n\"" << r.getTestVariable().getVariableName() << "\"" << endl;
00081 out << "#N_POINTS\n" << r.getNScans() << endl;
00082 out << "#POINTS";
00083 for (unsigned ipt=0; ipt<geneva_upload_points; ++ipt){
00084 if (ipt%8==0) out << "\n";
00085 if (ipt<r.getNScans()){
00086 out << r.getTestPointAt(ipt) << "\t";
00087 } else {
00088 out << "." << "\t";
00089 }
00090 }
00091 out << "\n#" << endl;
00092 }
00093 }
00094
00095 void SummaryWriter::write(const DefectList& list, std::ostream& out) const throw(Sct::IoError, Sct::LogicError){
00096 const std::list<Defect>& defects = list.getAllDefects();
00097
00098 if ( defects.empty() ){
00099 out << "#No defects found\n#" << endl; return;
00100 }
00101
00102 unsigned largestDefect=0;
00103
00104 Stats<int> channels(nChannelModule, Stat<int>(0, true) );
00105
00106 for (std::list<Defect>::const_iterator i =defects.begin(); i!=defects.end(); ++i){
00107 const ModuleElement& e = (*i).getModuleElement();
00108
00109 for (unsigned ichannel = e.getFirst(); ichannel <= e.getLast(); ++ichannel ){
00110 channels.modifyAt(ichannel).valid=false;
00111 }
00112
00113 if (e.getNChannels() > largestDefect) largestDefect=e.getNChannels() ;
00114
00115 out << "\n%Defect" << endl;
00116 out << "DEFECT NAME : " << (*i).getPrototype().getName()<<endl;
00117 out << "FIRST CHANNEL : " << (*i).getModuleElement().getFirst()<<endl;
00118 out << "LAST CHANNEL : " << (*i).getModuleElement().getLast()<<endl;
00119 out << "#"<<endl;
00120 }
00121 out << "#" << defects.size() << " defects found"
00122 << " affecting " << nChannelModule-channels.n() << " strips\n"
00123 << "#" << largestDefect << " maximum consecutive defects\n#"<< endl;
00124 }
00125
00126 string SummaryWriter::getChipName(const unsigned short ichip) throw() {
00127 short unsigned id=ichip;
00128 if (id>=6) id+=2;
00129 switch(id){
00130 case (0) : return string("M0"); break;
00131 case (5) : return string("E5"); break;
00132 case (8) : return string("M8"); break;
00133 case (13) : return string("E13"); break;
00134 default : {
00135 char name[5];
00136 sprintf(name,"S%d",id);
00137 return string(name);
00138 break;
00139 }
00140 }
00141 }
00142 }
00143 }