00001 #include "SctData/PipelineTestResult.h"
00002 #include "../../AnalysisTestFramework.h"
00003 #include "../../CutUtils.h"
00004 #include "../../TestFileUtil.h"
00005 #include "ipc/core.h"
00006
00007 struct Info {
00008 unsigned int runNumber;
00009 unsigned int scanNumber;
00010 unsigned int chip;
00011 unsigned int nScans;
00012 char serial[15];
00013 };
00014 string InfoStr = "Run/i:Scan:Chip:NScans:Serial/C";
00015
00016 struct SDData {
00017 int ngood;
00018 int pass;
00019 };
00020 string DataStr = "NGood/I:Pass/I";
00021
00022
00023 SDData RodDaq;
00024 SDData SctDaq;
00025 struct Info info;
00026
00027
00028 string Ext = "_Pipeline.dat";
00029 string Output = "${SCT_DAQ_ROOT}/SystemTests/logs/Pipeline.root";
00030 string Arg = "-3";
00031
00032 class PipelineCompare : public AnalysisTestFramework<PipelineTestResult> {
00033 public:
00034 virtual void publishData();
00035 virtual void downloadData(string serialNumber);
00036 virtual void compare(const PipelineTestResult& t);
00037 virtual void setup();
00038 virtual void summaryOutput();
00039 };
00040
00041
00042 string getFileName(string serial) {
00043 ostringstream oss;
00044 oss << serial << Ext;
00045
00046 return oss.str();
00047 }
00048
00049 void PipelineCompare::compare(const PipelineTestResult& sd) {
00050 strncpy(info.serial, sd.getModuleName().c_str(), 14);
00051 info.runNumber = sd.getRunNumber();
00052 info.scanNumber = sd.getScanNumberAt(0);
00053 info.nScans = sd.getNScans();
00054
00055 string fileName = getFileName(sd.getModuleName());
00056 ifstream file (fileName.c_str());
00057 if (!file.good())
00058 throw IllegalStateError("Failed to open comparison file: " + fileName, __FILE__, __LINE__);
00059
00060 SctDaq.pass = TestFileUtil::getPass(file);
00061 TestFileUtil::skipHeader(file);
00062
00063 for (unsigned int chip = 0; chip<nChipModule; ++chip) {
00064 string chipStr;
00065 info.chip = chip;
00066 file >> chipStr >> SctDaq.ngood;
00067
00068 file.ignore(256, '\n');
00069
00070 RodDaq.ngood = nChannelChip - sd.getDefects().getDefectsAffectingElement(ModuleElement::Chip(chip))->getAllDefects().size();
00071 RodDaq.pass = sd.getPassed();
00072
00073 tree->Fill();
00074 }
00075 }
00076
00077
00078 void PipelineCompare::summaryOutput() {
00079 if (cut(*tree, "ngood", "(RodDaq.NGood-SctDaq.NGood)", 0.01, 0.01, 0.01) > 0) {
00080 ++exitCode;
00081 cout << "Failed ngood tail check" << endl;
00082 }
00083 if (cut(*tree, "pass", "(RodDaq.Pass-SctDaq.Pass)", 0.01, 0.01, 0.01) > 0) {
00084 ++exitCode;
00085 cout << "Failed pass tail check" << endl;
00086 }
00087 exitCode += errorCode;
00088 }
00089
00093 void PipelineCompare::setup() {
00094 string name = Env::substituteVariables(Output);
00095 file = new TFile(name.c_str(), "RECREATE");
00096 tree = new TTree("PipeData", "Pipeline Comparison Data");
00097 tree->Branch("RodDaq", &RodDaq, DataStr.c_str());
00098 tree->Branch("SctDaq", &SctDaq, DataStr.c_str());
00099 tree->Branch("Info", &info, InfoStr.c_str());
00100 info.serial[14] = '\0';
00101 }
00102
00106 void PipelineCompare::downloadData(string serialNumber) {
00107 ostringstream oss;
00108 SctTest::TestInfo info = moduleData.getPipelineInfo(serialNumber);
00109 oss << "java -Dtdaq.ipc.init.ref=$TDAQ_IPC_INIT_REF ProdDatabase/getDBfiles " << Arg << " -d -r " << info.runNumber << " -s " << info.scanNumber << " " << serialNumber;
00110 system(oss.str().c_str());
00111 }
00112
00117 void PipelineCompare::publishData() {
00118 highLevelApi->pipeline();
00119 }
00120
00121
00122 int main(int argc, char** argv) {
00123 IPCCore::init(argc,argv);
00124 PipelineCompare sdc;
00125 sdc.analyzeAll(argc, argv);
00126 return sdc.getExitCode();
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139