Go to the documentation of this file.00001 #include <iostream>
00002 #include <stdio.h>
00003 #include <TDirectory.h>
00004 #include <TFile.h>
00005 #include <TKey.h>
00006 #include <TH1.h>
00007 #include <Riostream.h>
00008 #include <string>
00009 #include <vector>
00010 #include <fstream>
00011 #include <string>
00012 #include <stdint.h>
00013 #include <cstdlib>
00014 #include <cstdio>
00015
00016 #include "listbadmodule.h"
00017
00018
00019
00020 int main(int argc , char *argv[]) {
00021
00022 if(argc==2) {
00023 char* filename = argv[1];
00024
00025 std::cout << "ready to prepare list of bad modules " << filename << std::endl;
00026
00027 listbadmodule(filename);
00028
00029 }
00030 else {std::cout << "Too few arguments: " << argc << std::endl; return -1; }
00031 return 0;
00032
00033 }
00034
00035
00036 void listbadmodule(std::string filename) {
00037
00038 int debug = 1;
00039
00040 std::vector<std::string> subdet;
00041 subdet.push_back("TIB");
00042 subdet.push_back("TID/side_1");
00043 subdet.push_back("TID/side_2");
00044 subdet.push_back("TOB");
00045 subdet.push_back("TEC/side_1");
00046 subdet.push_back("TEC/side_2");
00047
00048 std::string nrun = filename.substr(filename.find("_R000")+5, 6);
00049 int fileNum = atoi(nrun.c_str());
00050 cout << " ------ Run " << fileNum << endl;
00051
00052 ofstream outfile;
00053 std::string namefile;
00054 namefile = "QualityTest_run" + nrun + ".txt";
00055 outfile.open(namefile.c_str());
00056
00057 TFile *myfile = TFile::Open(filename.c_str());
00058 if (debug == 1){
00059 std::cout <<" Opened "<< filename << std::endl;
00060 }
00061 std::string topdir = "DQMData/Run " + nrun + "/SiStrip/Run summary/MechanicalView";
00062 gDirectory->cd(topdir.c_str());
00063 TDirectory* mec1 = gDirectory;
00064
00065
00066 vector <int> nbadmod;
00067 for (unsigned int i=0; i < subdet.size(); i++){
00068 int nbad = 0;
00069 string badmodule_dir = subdet[i] + "/BadModuleList";
00070 if (gDirectory->cd(badmodule_dir.c_str())){
00071 TIter next(gDirectory->GetListOfKeys());
00072 TKey *key;
00073 while ( (key = dynamic_cast<TKey*>(next())) ) {
00074 string sflag = key->GetName();
00075 if (sflag.size() == 0) continue;
00076 nbad++;
00077 }
00078 }
00079 nbadmod.push_back(nbad);
00080 mec1->cd();
00081 }
00082
00083 outfile << "Number of bad modules in total:" << std::endl;
00084 outfile << "-------------------------------" << std::endl;
00085 outfile << subdet.at(0) << ": " << nbadmod.at(0) << std::endl;
00086 outfile << subdet.at(1) << ": " << nbadmod.at(1) << std::endl;
00087 outfile << subdet.at(2) << ": " << nbadmod.at(2) << std::endl;
00088 outfile << subdet.at(3) << ": " << nbadmod.at(3) << std::endl;
00089 outfile << subdet.at(4) << ": " << nbadmod.at(4) << std::endl;
00090 outfile << subdet.at(5) << ": " << nbadmod.at(5) << std::endl;
00091 outfile << "-------------------------------" << std::endl;
00092
00093 outfile << std::endl
00094 << "List of bad modules per partition:" << std::endl;
00095 outfile << "----------------------------------" << std::endl;
00096
00097 for (unsigned int i=0; i < subdet.size(); i++){
00098 std::string badmodule_dir = subdet[i] + "/BadModuleList";
00099 outfile << " " << endl;
00100 outfile << "SubDetector " << subdet[i] << endl;
00101 outfile << " " << endl;
00102 cout << badmodule_dir.c_str() << endl;
00103 if (gDirectory->cd(badmodule_dir.c_str())){
00104
00105
00106
00107 TIter next(gDirectory->GetListOfKeys());
00108 TKey *key;
00109
00110 while ( (key = dynamic_cast<TKey*>(next())) ) {
00111 std::string sflag = key->GetName();
00112 if (sflag.size() == 0) continue;
00113 std::string detid = sflag.substr(sflag.find("<")+1,9);
00114 size_t pos1 = sflag.find("/");
00115 sflag = sflag.substr(sflag.find("<")+13,pos1-2);
00116 int flag = atoi(sflag.c_str());
00117 std::string message;
00118 message = "Module " + detid;
00119 if (((flag >> 0) & 0x1) > 0) message += " Fed BadChannel : ";
00120 if (((flag >> 1) & 0x1) > 0) message += " # of Digi : ";
00121 if (((flag >> 2) & 0x1) > 0) message += " # of Clusters :";
00122 if (((flag >> 3) & 0x1) > 0) message += " Excluded FED Channel ";
00123 if (((flag >> 4) & 0x1) > 0) message += " DCSError ";
00124 outfile << message.c_str() << std::endl;
00125
00126 }
00127 }
00128 mec1->cd();
00129 }
00130 myfile->Close();
00131 outfile.close();
00132 }
00133
00134
00135