00001 #include "SctData/FullBypassTestResult.h"
00002 #include "../../AnalysisTestFramework.h"
00003 #include "../../TestFileUtil.h"
00004 #include "../../CutUtils.h"
00005
00006 struct Info {
00007 unsigned int runNumber;
00008 unsigned int scanNumber;
00009 unsigned int chip;
00010 unsigned int nScans;
00011 float SCTDAQVersion;
00012 char serial[15];
00013 };
00014 string InfoStr = "Run/i:Scan:Chip:NScans:SCTDAQVersion/F:Serial/C";
00015
00016 struct FBData {
00017 double vddDirect;
00018 double vddBypass;
00019 int statusDirect;
00020 int statusBypass;
00021 int pass;
00022 };
00023 string DataStr = "VddDirect/D:VddBypass:StatusDirect/I:StatusBypass:Pass";
00024
00025
00026 FBData RodDaq;
00027 FBData SctDaq;
00028 Info info;
00029
00030
00031 string Ext = "_FullByPass.dat";
00032 string Output = "${SCT_DAQ_ROOT}/SystemTests/logs/FullBypass.root";
00033 string Arg = "-2";
00034
00035 class FullBypassCompare : public AnalysisTestFramework<FullBypassTestResult> {
00036 public:
00037 virtual void publishData(SctTestApiStatus* status);
00038 virtual void downloadData(string serialNumber);
00039 virtual void compare(const FullBypassTestResult& t);
00040 virtual void summaryOutput();
00041 virtual void setup();
00042 };
00043
00044
00045 string getFileName(string serial) {
00046 ostringstream oss;
00047 oss << serial << Ext;
00048
00049 return oss.str();
00050 }
00051
00052 void FullBypassCompare::summaryOutput() {
00053 if (cut(*tree, "pass", "(RodDaq.Pass-SctDaq.Pass)", 0.1, 0.1, 0, true) > 0) {
00054 ++exitCode;
00055 cout << "Failed pass check" << endl;
00056 }
00057 if (cut(*tree, "VddDirect", "(RodDaq.VddDirect-SctDaq.VddDirect)", 0.1, 0.1, 0, true) > 0) {
00058 ++exitCode;
00059 cout << "Failed VddDirect check" << endl;
00060 }
00061 if (cut(*tree, "VddBypass", "(RodDaq.VddBypass-SctDaq.VddBypass)", 0.1, 0.1, 0, true) > 0) {
00062 ++exitCode;
00063 cout << "Failed VddBypass check" << endl;
00064 }
00065 if (cut(*tree, "StatusDirect", "(RodDaq.StatusDirect-SctDaq.StatusDirect)", 0.1, 0.1, 0, true) > 0) {
00066 ++exitCode;
00067 cout << "Failed StatusDirect check" << endl;
00068 }
00069 if (cut(*tree, "StatusBypass", "(RodDaq.StatusBypass-SctDaq.StatusBypass)", 0.1, 0.1, 0, true) > 0) {
00070 ++exitCode;
00071 cout << "Failed StatusBypass check" << endl;
00072 }
00073 exitCode += errorCode;
00074 }
00075
00076 int getStatus(string comment) {
00077 if (comment == "Minimal tested") return 1;
00078 if (comment == "Not Tested") return -2;
00079 return -4;
00080 }
00081
00082 void FullBypassCompare::compare(const FullBypassTestResult& sd) {
00083 strncpy(info.serial, sd.getModuleName().c_str(), 14);
00084 info.runNumber = sd.getRunNumber();
00085 info.scanNumber = sd.getScanNumberAt(0);
00086 info.nScans = sd.getNScans();
00087
00088 string fileName = getFileName(sd.getModuleName());
00089 ifstream file (fileName.c_str());
00090 if (!file.good())
00091 throw IllegalStateError("Failed to open comparison file: " + fileName, __FILE__, __LINE__);
00092
00093 SctDaq.pass = TestFileUtil::getPass(file);
00094 info.SCTDAQVersion = TestFileUtil::skipHeader(file);
00095 char buffer[1024];
00096
00097 for (unsigned int chip = 0; chip<nChipModule; ++chip) {
00098 info.chip = chip;
00099 string chipStr;
00100 string directComment;
00101 string bypassComment;
00102
00103 file >> chipStr >> SctDaq.vddDirect >> SctDaq.vddBypass;
00104
00105
00106 file.ignore(1, '\t');
00107 file.getline(buffer, 1024, '\t');
00108 directComment = buffer;
00109 file.getline(buffer, 1024, '\n');
00110 bypassComment = buffer;
00111
00112 SctDaq.statusBypass = getStatus(bypassComment);
00113 SctDaq.statusDirect = getStatus(directComment);
00114
00115 RodDaq.pass = sd.getPassed();
00116 RodDaq.statusBypass = sd.getChipResult(chip).status_bypass;
00117 RodDaq.statusDirect = sd.getChipResult(chip).status_direct;
00118 RodDaq.vddBypass = sd.getChipResult(chip).vdd_bypass;
00119 RodDaq.vddDirect = sd.getChipResult(chip).vdd_direct;
00120
00121 tree->Fill();
00122 }
00123 }
00124
00125
00129 void FullBypassCompare::setup() {
00130 string name = Env::substituteVariables(Output);
00131 file = new TFile(name.c_str(), "RECREATE");
00132 tree = new TTree("FBData", "FullBypass Comparison Data");
00133 tree->Branch("RodDaq", &RodDaq, DataStr.c_str());
00134 tree->Branch("SctDaq", &SctDaq, DataStr.c_str());
00135 tree->Branch("Info", &info, InfoStr.c_str());
00136 info.serial[14] = '\0';
00137 }
00138
00142 void FullBypassCompare::downloadData(string serialNumber) {
00143 ostringstream oss;
00144 TestInfo info = moduleData.getFullBypassInfo(serialNumber);
00145 oss << "java ProdDatabase/getDBfiles " << Arg << " -d -r " << info.runNumber << " -s " << info.scanNumber << " " << serialNumber;
00146 system(oss.str().c_str());
00147 }
00148
00153 void FullBypassCompare::publishData(SctTestApiStatus* status) {
00154 highLevelApi->fullBypass(status);
00155
00156 sleep(1);
00157 }
00158
00159
00160 int main(int argc, char** argv) {
00161 FullBypassCompare sdc;
00162 sdc.analyzeAll(argc, argv);
00163 return sdc.getExitCode();
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176