File indexing completed on 2024-04-06 12:08:39
0001 #include <iostream>
0002 #include <cstdio>
0003 #include <TDirectory.h>
0004 #include <TFile.h>
0005 #include <TKey.h>
0006 #include <TH1.h>
0007 #include <Riostream.h>
0008 #include <string>
0009 #include <vector>
0010 #include <set>
0011 #include <fstream>
0012 #include <sstream>
0013 #include <string>
0014 #include <cstdint>
0015 #include <cstdlib>
0016 #include <cstdio>
0017
0018 #include "listbadmodule.h"
0019
0020
0021
0022 int main(int argc, char *argv[]) {
0023 if (argc == 3) {
0024 char *filename = argv[1];
0025 char *pclfilename = argv[2];
0026
0027 std::cout << "ready to prepare list of bad modules " << filename << std::endl;
0028
0029 listbadmodule(filename, pclfilename);
0030
0031 } else {
0032 std::cout << "Too few arguments: " << argc << std::endl;
0033 return -1;
0034 }
0035 return 0;
0036 }
0037
0038 void listbadmodule(std::string filename, std::string pclfilename) {
0039 int debug = 1;
0040
0041
0042
0043 std::set<unsigned int> pclbadmods;
0044
0045 std::ifstream pclfile(pclfilename);
0046
0047 char line[400];
0048 unsigned int pcldetid;
0049 char sixapvs[] = "1 1 1 1 1 1";
0050 char fourapvs[] = "1 1 x x 1 1";
0051
0052 while (pclfile.getline(line, 400)) {
0053 if (strstr(line, sixapvs) || strstr(line, fourapvs)) {
0054 std::stringstream linestream;
0055 linestream << line;
0056 linestream >> pcldetid;
0057
0058 pclbadmods.insert(pcldetid);
0059 }
0060 }
0061
0062 std::vector<std::string> subdet;
0063 subdet.push_back("TIB");
0064 subdet.push_back("TID/MINUS");
0065 subdet.push_back("TID/PLUS");
0066 subdet.push_back("TOB");
0067 subdet.push_back("TEC/MINUS");
0068 subdet.push_back("TEC/PLUS");
0069
0070 std::string nrun = filename.substr(filename.find("_R000") + 5, 6);
0071 int fileNum = atoi(nrun.c_str());
0072 std::cout << " ------ Run " << fileNum << std::endl;
0073
0074 std::ofstream outfile;
0075 std::string namefile;
0076 namefile = "QualityTestOBSOLETE_run" + nrun + ".txt";
0077 outfile.open(namefile.c_str());
0078
0079 TFile *myfile = TFile::Open(filename.c_str());
0080 if (debug == 1) {
0081 std::cout << " Opened " << filename << std::endl;
0082 }
0083 std::string topdir = "DQMData/Run " + nrun + "/SiStrip/Run summary/MechanicalView";
0084 gDirectory->cd(topdir.c_str());
0085 TDirectory *mec1 = gDirectory;
0086
0087
0088 std::vector<int> nbadmod;
0089 for (unsigned int i = 0; i < subdet.size(); i++) {
0090 int nbad = 0;
0091 std::string badmodule_dir = subdet[i] + "/BadModuleList";
0092 if (gDirectory->cd(badmodule_dir.c_str())) {
0093 TIter next(gDirectory->GetListOfKeys());
0094 TKey *key;
0095 while ((key = dynamic_cast<TKey *>(next()))) {
0096 std::string sflag = key->GetName();
0097 if (sflag.empty())
0098 continue;
0099 nbad++;
0100 }
0101 }
0102 nbadmod.push_back(nbad);
0103 mec1->cd();
0104 }
0105
0106 outfile << "Number of bad modules in total excluding PCL-only bad modules:" << std::endl;
0107 outfile << "--------------------------------------------------------------" << std::endl;
0108 outfile << subdet.at(0) << ": " << nbadmod.at(0) << std::endl;
0109 outfile << subdet.at(1) << ": " << nbadmod.at(1) << std::endl;
0110 outfile << subdet.at(2) << ": " << nbadmod.at(2) << std::endl;
0111 outfile << subdet.at(3) << ": " << nbadmod.at(3) << std::endl;
0112 outfile << subdet.at(4) << ": " << nbadmod.at(4) << std::endl;
0113 outfile << subdet.at(5) << ": " << nbadmod.at(5) << std::endl;
0114 outfile << "-------------------------------" << std::endl;
0115
0116 outfile << std::endl << "List of bad modules per partition:" << std::endl;
0117 outfile << "----------------------------------" << std::endl;
0118
0119 std::set<unsigned int>::const_iterator pclbadmod = pclbadmods.begin();
0120
0121 for (unsigned int i = 0; i < subdet.size(); i++) {
0122 std::string badmodule_dir = subdet[i] + "/BadModuleList";
0123 outfile << " " << std::endl;
0124 outfile << "SubDetector " << subdet[i] << std::endl;
0125 outfile << " " << std::endl;
0126 std::cout << badmodule_dir.c_str() << std::endl;
0127 if (gDirectory->cd(badmodule_dir.c_str())) {
0128
0129
0130
0131 TIter next(gDirectory->GetListOfKeys());
0132 TKey *key;
0133
0134 while ((key = dynamic_cast<TKey *>(next()))) {
0135 std::string sflag = key->GetName();
0136 if (sflag.empty())
0137 continue;
0138 std::string detid = sflag.substr(sflag.find('<') + 1, 9);
0139 size_t pos1 = sflag.find('/');
0140 sflag = sflag.substr(sflag.find('<') + 13, pos1 - 2);
0141 int flag = atoi(sflag.c_str());
0142 sscanf(detid.c_str(), "%u", &pcldetid);
0143
0144
0145 while (pclbadmod != pclbadmods.end() && pcldetid > *pclbadmod) {
0146 outfile << "Module " << *pclbadmod << " PCLBadModule " << std::endl;
0147 pclbadmod++;
0148 }
0149 std::string message;
0150 message = "Module " + detid;
0151 if (((flag >> 0) & 0x1) > 0)
0152 message += " Fed BadChannel : ";
0153 if (((flag >> 1) & 0x1) > 0)
0154 message += " # of Digi : ";
0155 if (((flag >> 2) & 0x1) > 0)
0156 message += " # of Clusters :";
0157 if (((flag >> 3) & 0x1) > 0)
0158 message += " Excluded FED Channel ";
0159 if (((flag >> 4) & 0x1) > 0)
0160 message += " DCSError ";
0161 if (pclbadmods.find(pcldetid) != pclbadmods.end()) {
0162 message += " PCLBadModule ";
0163 pclbadmod = pclbadmods.find(pcldetid);
0164 pclbadmod++;
0165 }
0166 outfile << message.c_str() << std::endl;
0167 }
0168 }
0169 mec1->cd();
0170 }
0171 myfile->Close();
0172 outfile.close();
0173 }