Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

DataDisplayer.cpp

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

Generated on Sat Jul 31 14:18:07 2004 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5