// // Analyse of Amas@Nancay runs by J.E Campagne (LAL) // Version 0: 1/6/2011 //----------------------------- // Utilisation de SOPHYA pour faciliter les tests ... #include "sopnamsp.h" #include "machdefs.h" #include #include #include // include standard c/c++ #include #include #include #include #include #include #include #include #include #include // include sophya mesure ressource CPU/memoire ... #include "resusage.h" #include "ctimer.h" #include "timing.h" #include "timestamp.h" #include "strutilxx.h" #include "ntuple.h" #include "fioarr.h" #include "tarrinit.h" #include "histinit.h" #include "fitsioserver.h" #include "fiosinit.h" #include "ppersist.h" const sa_size_t NUMBER_OF_CHANNELS = 2; const sa_size_t NUMBER_OF_FREQ = 8192; const r_4 LOWER_FREQUENCY = 1250.0; //MHz const r_4 TOTAL_BANDWIDTH = 250.0; //MHz //decalration of non class members functions extern "C" { int Usage(bool); } //---------------------------------------------------------- //Utility fonctions // Function for deleting pointers in map. template struct DeleteMapFntor { // Overloaded () operator. // This will be called by for_each() function. bool operator()(pair x) const { // Assuming the second item of map is to be // deleted. Change as you wish. delete x.second; return true; } }; //----- bool compare(const pair& i, const pair& j) { return i.second < j.second; } //----- sa_size_t round_sa(r_4 r) { return static_cast((r > 0.0) ? (r + 0.5) : (r - 0.5)); } //----- string StringToLower(string strToConvert){ //change each element of the string to lower case for(unsigned int i=0;i tolower( *rit ) ) return false; return false; ///////TO BE FIXED }//JEC 22/9/11 comparison, not case sensitive to sort File liste END //----- list ListOfFileInDir(string dir, string filePettern) throw(string) { list theList; DIR *dip; struct dirent *dit; string msg; string fileName; string fullFileName; size_t found; if ((dip=opendir(dir.c_str())) == NULL ) { msg = "opendir failed on directory "+dir; throw msg; } while ( (dit = readdir(dip)) != NULL ) { fileName = dit->d_name; found=fileName.find(filePettern); if (found != string::npos) { fullFileName = dir + "/"; fullFileName += fileName; theList.push_back(fullFileName); } }//eo while if (closedir(dip) == -1) { msg = "closedir failed on directory "+dir; throw msg; } //JEC 22/9/11 START theList.sort(stringCompare); //JEC 22/9/11 END return theList; } //Declaration of local classes //---------------------------------------------- //Process Interface class IProcess { public: IProcess() {} virtual ~IProcess() {} virtual int processCmd() throw(string) =0; }; //------------ //Common Process class ProcessBase : public IProcess { public: ProcessBase(); virtual ~ProcessBase(); void SetInputPath(const string& inputPath) {inputPath_ = inputPath;} void SetOutputPath(const string& outputPath) {outputPath_ = outputPath;} void SetSourceName(const string& sourceName) {sourceName_ = sourceName;} void SetDateOfRun(const string& dateOfRun) {dateOfRun_ = dateOfRun;} void SetSpectraDirectory(const string& spectraDirectory) {spectraDirectory_ = spectraDirectory;} void SetTypeOfFile(const string& typeOfFile) { typeOfFile_ = typeOfFile; } void SetNumCycle(const string& numcycle) {numcycle_ = numcycle; } void SetScaFileName(const string& scaFileName) { scaFileName_ =scaFileName; } void SetDebugLevel(const string& debuglev) { debuglev_ = atoi(debuglev.c_str()); } virtual int processCmd() throw(string); protected: string inputPath_; string outputPath_; string sourceName_; string dateOfRun_; string spectraDirectory_; string typeOfFile_; string numcycle_; //cycle numbers format="first,last" sa_size_t ifirstCycle_; sa_size_t ilastCycle_; uint_4 debuglev_; string scaFileName_; NTuple* scaTuple_; map idCycleInTuple_; }; ProcessBase::ProcessBase() { scaTuple_ = 0; } ProcessBase::~ProcessBase() { if (scaTuple_) delete scaTuple_; scaTuple_ = 0; } //------------ //Process ON/OFF data //------------ class ProcessONOFFData : public ProcessBase { protected: string freqBAOCalibration_;//string MHz public: ProcessONOFFData(){} virtual ~ProcessONOFFData(){} void SetFreqBAOCalibration(const string& freqBAOCalibration) { freqBAOCalibration_ = freqBAOCalibration; } virtual int processCmd() throw(string); }; //JEC 22/9/11 Make ON-OFF analysis WO any calibration START //------------ //Process ON/OFF Raw data //------------ class ProcessONOFFRawData : public ProcessBase { public: ProcessONOFFRawData(){} virtual ~ProcessONOFFRawData(){} virtual int processCmd() throw(string); }; //JEC 22/9/11 Make ON-OFF analysis WO any calibration END //------------ //Process Gain //------------ class ProcessGain : public ProcessBase { protected: string mode_; //mode of data taken for gain computation On || Off public: ProcessGain(){} virtual ~ProcessGain(){} void SetMode(const string& mode) {mode_ = mode;} virtual int processCmd() throw(string); }; //------------ //Process Calibration //------------ class ProcessCalibration : public ProcessBase { protected: string option_; //option of calibration procedure string freqBAOCalibration_;//string MHz r_4 valfreqBAOCalibration_; //value MHz string bandWidthBAOCalibration_;//string MHz r_4 valbandWidthBAOCalibration_;//value MHz sa_size_t lowerFreqBin_; sa_size_t upperFreqBin_; public: ProcessCalibration() {} virtual ~ProcessCalibration(){} void SetOption(const string& option) {option_ = option;} void SetFreqBAOCalibration(const string& freqBAOCalibration) { freqBAOCalibration_ = freqBAOCalibration; valfreqBAOCalibration_ = atof(freqBAOCalibration_.c_str()); } void SetBandWidthBAOCalibration(const string& bandWidthBAOCalibration) { bandWidthBAOCalibration_ = bandWidthBAOCalibration; valbandWidthBAOCalibration_ = atof(bandWidthBAOCalibration_.c_str()); } void ComputeLowerUpperFreqBin(); virtual int processCmd() throw(string); }; void ProcessCalibration::ComputeLowerUpperFreqBin() { sa_size_t c0 = round_sa(NUMBER_OF_FREQ*(valfreqBAOCalibration_-LOWER_FREQUENCY)/TOTAL_BANDWIDTH); sa_size_t dc = round_sa(NUMBER_OF_FREQ*valbandWidthBAOCalibration_/TOTAL_BANDWIDTH); lowerFreqBin_ = c0-dc/2; upperFreqBin_ = c0+dc/2; } //---------------------------------------------------- //---------------------------------------------------- int main(int narg, char* arg[]) { //Init process types map process; //JEC 22/9/11 Make ON-OFF analysis WO any calibration START process["rawOnOff"] = new ProcessONOFFRawData(); //JEC 22/9/11 Make ON-OFF analysis WO any calibration END process["dataOnOff"] = new ProcessONOFFData(); process["gain"] = new ProcessGain(); process["calib"] = new ProcessCalibration(); //Init Sophya related modules // SophyaInit(); TArrayInitiator _inia; //nneded for TArray persistancy FitsIOServerInit(); //needed for input file //message used in Exceptions string msg; //Return code int rc = 0; //Arguments managements if ((narg>1)&&(strcmp(arg[1],"-h")==0)) return Usage(false); if (narg<11) return Usage(true); string action; string inputPath = "."; string outputPath = "."; string sourceName; string scaFile; string dateOfRun; string spectraDirectory; string freqBAOCalib = ""; string bandWidthBAOCalib = ""; string debuglev = "0"; string mode = ""; string numcycle; string calibrationOpt = ""; string typeOfFile="medfiltmtx"; // bool okarg=false; int ka=1; while (ka<(narg-1)) { if (strcmp(arg[ka],"-debug")==0) { debuglev=arg[ka+1]; ka+=2; } else if (strcmp(arg[ka],"-act")==0) { action=arg[ka+1]; ka+=2; } else if (strcmp(arg[ka],"-inPath")==0) { inputPath=arg[ka+1]; ka+=2; } else if (strcmp(arg[ka],"-outPath")==0) { outputPath=arg[ka+1]; ka+=2; } else if (strcmp(arg[ka],"-source")==0) { sourceName=arg[ka+1]; ka+=2; } else if (strcmp(arg[ka],"-sca")==0) { scaFile=arg[ka+1]; ka+=2; } else if (strcmp(arg[ka],"-date")==0) { dateOfRun=arg[ka+1]; ka+=2; } else if (strcmp(arg[ka],"-specdir")==0) { spectraDirectory=arg[ka+1]; ka+=2; } else if (strcmp(arg[ka],"-specname")==0) { typeOfFile=arg[ka+1]; ka+=2; } else if (strcmp(arg[ka],"-freqBAOCalib")==0) { freqBAOCalib = arg[ka+1]; ka+=2; } else if (strcmp(arg[ka],"-bwBAOCalib")==0) { bandWidthBAOCalib = arg[ka+1]; ka+=2; } else if (strcmp(arg[ka],"-mode")==0) { mode =arg[ka+1]; ka+=2; } else if (strcmp(arg[ka],"-numcycle")==0) { numcycle =arg[ka+1]; ka+=2; } else if (strcmp(arg[ka],"-calibopt")==0) { calibrationOpt =arg[ka+1]; ka+=2; } else ka++; }//eo while //JEC 21/9/11 Give the input parameters START cout << "Dump Iiitial parameters ............" << endl; cout << " action = " << action << "\n" << " inputPath = " << inputPath << "\n" << " outputPath = " << outputPath << "\n" << " sourceName = " << sourceName << "\n" << " scaFile = " << scaFile << "\n" << " dateOfRun = " << dateOfRun << "\n" << " spectraDirectory = " << spectraDirectory << "\n" << " freqBAOCalib = " << freqBAOCalib << "\n" << " bandWidthBAOCalib = " << bandWidthBAOCalib << "\n" << " debuglev = " << debuglev << "\n" << " mode = " << mode << "\n" << " numcycle = " << numcycle << "\n" << " calibrationOpt = " << calibrationOpt << endl; cout << "...................................." << endl; //JEC 21/9/11 Give the input parameters END try { //verification of action if(process.find(action) == process.end()) { msg = "action "; msg += action + " not valid... FATAL"; rc = 999; throw msg; } // //Process initialisation... // try { ProcessBase* procbase = dynamic_cast(process[action]); if (procbase == 0) { msg= "action "; msg += action + "Not a type...FATAL"; rc = 999; throw msg; } procbase->SetInputPath(inputPath); procbase->SetOutputPath(outputPath); if ("" == sourceName) { msg = "(FATAL) missingsourceName for action " + action; Usage(true); throw msg; } procbase->SetSourceName(sourceName); if ("" == dateOfRun) { msg = "(FATAL) missing dateOfRun for action " + action; Usage(true); throw msg; } procbase->SetDateOfRun(dateOfRun); if ("" == spectraDirectory) { msg = "(FATAL) missing spectraDirectory for action " + action; Usage(true); throw msg; } procbase->SetSpectraDirectory(spectraDirectory); if ("" == scaFile) { msg = "(FATAL) missing scaFile for action " + action; Usage(true); throw msg; } procbase->SetScaFileName(scaFile); if ("" == numcycle) { msg = "(FATAL) missing cycle number for action " + action; Usage(true); throw msg; } procbase->SetNumCycle(numcycle); procbase->SetTypeOfFile(typeOfFile); procbase->SetDebugLevel(debuglev); } catch(exception& e){ throw e.what(); } //JEC 22/9/11 Make ON-OFF analysis WO any calibration START // try { // ProcessONOFFRawData* procRawdata = dynamic_cast(process[action]); // } // catch(exception& e){ // throw e.what(); // } //JEC 22/9/11 Make ON-OFF analysis WO any calibration END try { ProcessONOFFData* procdata = dynamic_cast(process[action]); if (procdata) { if (freqBAOCalib == "") { msg = "(FATAL) missing calibration BAO frequency for action " + action; Usage(true); throw msg; } procdata->SetFreqBAOCalibration(freqBAOCalib); } } catch(exception& e){ throw e.what(); } try { ProcessGain* procgain = dynamic_cast(process[action]); if(procgain) { if (mode == "") { msg = "(FATAL) missing mode-type for action " + action; Usage(true); throw msg; } procgain->SetMode(mode); } } catch(exception& e){ throw e.what(); } try { ProcessCalibration* proccalib = dynamic_cast(process[action]); if(proccalib) { if (calibrationOpt == "") { msg = "(FATAL) missing calibration option"; Usage(true); throw msg; } if (freqBAOCalib == "") { msg = "(FATAL) missing calibration BAO frequency for action " + action; Usage(true); throw msg; } if (bandWidthBAOCalib == "") { msg = "(FATAL) missing calibration BAO frequency band width for action " + action; Usage(true); throw msg; } proccalib->SetOption(calibrationOpt); proccalib->SetFreqBAOCalibration(freqBAOCalib); proccalib->SetBandWidthBAOCalibration(bandWidthBAOCalib); proccalib->ComputeLowerUpperFreqBin(); } } catch(exception& e){ throw e.what(); } // //execute command // rc = process[action]->processCmd(); } catch (std::exception& sex) { cerr << "\n analyse.cc std::exception :" << (string)typeid(sex).name() << "\n msg= " << sex.what() << endl; rc = 78; } catch ( string str ) { cerr << "analyse.cc Exception raised: " << str << endl; } catch (...) { cerr << " analyse.cc catched unknown (...) exception " << endl; rc = 79; } cout << ">>>> analyse.cc ------- END ----------- RC=" << rc << endl; //Delete processes for_each(process.begin(),process.end(), DeleteMapFntor()); return rc; } //--------------------------------------------------- int Usage(bool flag) { cout << "Analyse.cc usage...." << endl; cout << "analyse -act : dataOnOff, rawOnOff, gain, calib\n" << " -inPath \n" << " -outPath \n" << " -source \n" << " -date \n" << " -sca \n" << " -specdir \n" << " -specname \n" << " -freqBAOCalib freq. of calibration BAO\n" << " valid for act=dataOnOff\n" << " -bwBAOCalib band width arround central freq. for calibration BAO\n" << " valid for act=calib\n" << " -mode :\n" << " valid for act=gain, mode_type: On, Off\n" << " -numcycle ,:\n" << " valid for all actions" << " -calibopt