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