DataDisplayerMain.cxx

00001 #include "DisplayManager.h"
00002 #include "DisplayInfo.h"
00003 #include "Displayer.h"
00004 #include "DataDisplayerMainRootHelper.h"
00005 #include "Sct/SctParameters.h"
00006 #include "Sct/Serializable.h"
00007 #include "Sct/IoExceptions.h"
00008 #include "Sct/IS/IOManagerIS.h"
00009 #include "Sct/File/IOManagerFile.h"
00010 #include "Sct/Archive/IOManagerArchiveFile.h"
00011 
00012 #include <iostream>
00013 #include <vector>
00014 #include <string>
00015 #include <fstream>
00016 #include <ipc/core.h>
00017 
00018 using namespace std;
00019 using namespace Sct;
00020 using namespace Sct::IS;
00021 using namespace Sct::File;
00022 using namespace Sct::Archive;
00023 using namespace SctDataDisplay;
00024 
00025 //Holds the list of things to display
00026 vector<string> isNames;
00027 
00028 /* 
00029    Very strange symptom:
00030     Apparently if TString.h gets included (gets included by TApplication) then 
00031     the ofstream constructor fails with -O3 (the overloading of (char* + int) 
00032     confuses the compiler).
00033 
00034     I'm not sure whether this is ROOT's fault or the compiler's... though would 
00035     certainly help if the TString stuff was in a different namespace.
00036 
00037    Solution:
00038     Put access to TApplication in a different file
00039  */
00040 
00041 
00045 DisplayInfo getDefaultInfo() {
00046     DisplayInfo info;
00047     for (unsigned int i=0; i<nChipModule; ++i) {
00048     info.displayChips.push_back(i);
00049     }
00050     
00051     return info;
00052 }
00053 
00054 void printHelp() {
00055     cerr << "Usage: DataDisplayer [-batch] [-dir <dirname>] [-chip <start> <end>]* [-chan <start> <end>]* <Names> ..." << endl << endl;
00056     cerr << "DataDisplayer is a program that shows data that has been stored in IS" << endl;
00057     cerr << "If no -chip or -chan arguments are given, it will show information about all 12 chips and no channels by default"<< endl;
00058     cerr << "Overall module information is always shown." << endl;
00059     cerr << "Arguments: " << endl;
00060     cerr << "-batch (flag)                     : Don't display windows, but instead create postscript files" << endl;
00061     cerr << "-root (flag)                      : Don't display windows, but instead create root files" << endl;
00062     cerr << "-dir <dirname> (optional)         : like -batch but write files to a named directory" << endl;
00063     cerr << "-occ (flag)                       : Show occupancy per event data for RawScanResult" << endl;
00064     cerr << "-chip <start> <end> (optional)    : A range of chips to display (may be specified more than once)" << endl;
00065     cerr << "-chan <start> <end> (optional)    : A range of channels to display (may be specified more than once)" << endl;
00066     cerr << "<Names> (at least 1)          : A list of names in IS or filenames of archived data" << endl;
00067     cerr << "--help                : Show this help message" << endl;
00068     cerr << "All numbers are in base 0" << endl;
00069     
00070     exit(-1);
00071 }
00072 
00073 void parseChip(DisplayInfo& info, string start, string end) {
00074     istringstream iss1(start);
00075     unsigned int chipStart = nChipModule;
00076     iss1 >> chipStart;
00077     if (chipStart >= nChipModule) {
00078     cerr << "Invalid argument: " << start << " to -chip" << endl;
00079     printHelp();
00080     }
00081     
00082     istringstream iss2(end);
00083     unsigned int chipEnd = nChipModule;
00084     iss2 >> chipEnd;
00085     if (chipEnd >= nChipModule) {
00086     cerr << "Invalid argument: " << end << " to -chip" << endl;
00087     printHelp();
00088     }
00089     
00090     for (unsigned int i=chipStart; i<=chipEnd; ++i) {
00091     info.displayChips.push_back(i);
00092     }
00093 }
00094 
00095 void parseChan(DisplayInfo& info, string start, string end) {    
00096     istringstream iss1(start);
00097     unsigned int chanStart = nChannelModule;
00098     iss1 >> chanStart;
00099     if (chanStart >= nChannelModule) {
00100     cerr << "Invalid argument: " << start << " to -chan" << endl;
00101     printHelp();
00102     }
00103     
00104     istringstream iss2(end);
00105     unsigned int chanEnd = nChannelModule;
00106     iss2 >> chanEnd;
00107     if (chanEnd >= nChannelModule) {
00108     cerr << "Invalid argument: " << end << " to -chan" << endl;
00109     printHelp();
00110     }
00111     
00112     for (unsigned int i=chanStart; i<=chanEnd; ++i) {
00113     info.displayChannels.push_back(i);
00114     }    
00115 }
00116 
00117 DisplayInfo handleArgs(int argc, char** argv) {
00118    if (argc == 1) printHelp();
00119     
00120     DisplayInfo info;
00121     
00122     for (int i=1; i<argc; ++i) {
00123     if (string(argv[i]) == "--help") printHelp();
00124     
00125     if (string(argv[i]) == "-chip") {
00126         if (i+2 >= argc) {
00127         cerr << "Invalid arguments for option -chip" << endl;
00128         printHelp();
00129         }
00130         parseChip(info, argv[i+1], argv[i+2]);      
00131         i += 2;
00132     } else if (string(argv[i]) == "-chan") {
00133         if (i+2 >= argc) {
00134         cerr << "Invalid arguments for option -chip" << endl;
00135         printHelp();
00136         }
00137         parseChan(info, argv[i+1], argv[i+2]);          
00138         i += 2;
00139     } else if (string(argv[i]) == "-dir") {
00140             if (i+1 >= argc) {
00141                cerr << "Invalid arguments for option -dir" << endl;
00142                printHelp();
00143             }
00144         DisplayManager::setBatchMode();
00145         DisplayManager::setOutputDir(argv[i+1]);
00146             i ++;
00147     } else if (string(argv[i]) == "-batch") {
00148       DisplayManager::setBatchMode();
00149     } else if (string(argv[i]) == "-root") {
00150       DisplayManager::setBatchMode();
00151       DisplayManager::setRootMode();
00152     } else if (string(argv[i]) == "-occ" || string(argv[i])=="-ope") {
00153           std::cout << "OPE data requested" << std::endl;
00154           info.occupancyHistograms=true; 
00155     } else {
00156       isNames.push_back(argv[i]);
00157     }
00158     }
00159     
00160     if (info.displayChannels.size() == 0 && info.displayChips.size() == 0){
00161     DisplayInfo info2 = getDefaultInfo(); 
00162         info2.occupancyHistograms = info.occupancyHistograms;
00163         info=info2;
00164     }
00165     return info;
00166 }
00167 
00168 shared_ptr<Serializable> readObject(string name) {
00169     FILE* f = fopen(name.c_str(), "rb");
00170     if (f) {
00171     fclose(f);
00172     if (name.substr(name.size()-3) == ".gz"){
00173       cout << "Reading from archive file" << std::endl;
00174       return IOManagerArchiveFile::instance().read(name);
00175     } else {
00176       cout << "Reading from scratch space" << std::endl;      
00177       return IOManagerFile::instance().read(name);
00178     }
00179     } else {
00180       cout << "Reading from information service" << std::endl;    
00181     return IOManagerIS::instance().read(name);
00182     }
00183 }
00184 
00185 //The main for the program...
00186 //Handles input that passes the rest to the Displayers
00187 
00188 int main(int argc, char** argv) {
00189     IPCCore::init(argc,argv);
00190     setExceptionHandlers(argv[0]);
00191 
00192     DisplayInfo info = handleArgs(argc, argv);
00193 
00194     SctDataDisplayHelper::createApp(DisplayManager::batchMode());
00195     
00196     int errorCount = 0;
00197     
00198     vector<shared_ptr<DisplayData> > displayObjs;
00199     for (unsigned int i=0; i<isNames.size(); ++i) {
00200     try {
00201         shared_ptr<Serializable> ob = readObject(isNames[i]);
00202         if (!ob) 
00203         throw IoException("No object `" + isNames[i] + "' in IS, scratch space or data archive", __FILE__, __LINE__);
00204 
00205           if (DisplayManager::batchMode()){
00206             std::ostringstream oss;
00207         oss << DisplayManager::getOutputDir();
00208         displayObjs.push_back(DisplayManager::display(ob, info, oss));
00209         if (oss.str()!=""){
00210           std::string filename=DisplayManager::getOutputDir() + ob->getClassName();
00211           filename+=".";
00212           filename+=ob->getUniqueID();
00213           std::ofstream f(filename.c_str());
00214           f << oss.str();
00215           std::cout << "TEXT " << filename << std::endl;
00216         }
00217           }else{
00218         displayObjs.push_back(DisplayManager::display(ob, info, std::cout));
00219           }
00220     } catch (Sct::Exception& e) {
00221       e.sendToMrs(MRS_DIAGNOSTIC);
00222       ++errorCount;
00223     }
00224     }
00225     
00226     SctDataDisplayHelper::runCanvas();
00227  
00228     return errorCount;
00229 }

Generated on Mon Feb 6 14:01:18 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6