From 01a036ee2729898040a08fefec91f31a6be79f07 Mon Sep 17 00:00:00 2001 From: Alexander Ivanov <alexander.ivanov@ligo.org> Date: Mon, 14 Jan 2013 22:53:53 +0000 Subject: [PATCH] Removed old dead code, mainly related to the use of old version of FrameCPP. Added and rearranged comments for use with doxygen. git-svn-id: https://redoubt.ligo-wa.caltech.edu/svn/advLigoRTS/trunk@3192 6dcd42c9-f523-4c6d-aada-af552506706e --- src/nds/config.h.in | 3 - src/nds/daqd.cc | 8 +- src/nds/daqd_net.cc | 88 -------- src/nds/daqd_net.hh | 131 ++++++----- src/nds/io.h | 7 +- src/nds/myframereadplan.hh | 33 +-- src/nds/nds.cc | 15 +- src/nds/nds.hh | 80 ++++--- src/nds/rawminutetrend.cc | 8 - src/nds/readtocframefilearchive.cc | 339 ----------------------------- src/nds/spec.cc | 23 -- src/nds/spec.hh | 81 +++++-- 12 files changed, 217 insertions(+), 599 deletions(-) diff --git a/src/nds/config.h.in b/src/nds/config.h.in index 3065f8b9a..4285680f5 100644 --- a/src/nds/config.h.in +++ b/src/nds/config.h.in @@ -187,7 +187,4 @@ /* Define if broadcast should be disabled */ #undef NO_BROADCAST -// This thing is gone from FrameCPP headers -#define FRAMECPP_DATAFORMAT_VERSION 6 - #endif diff --git a/src/nds/daqd.cc b/src/nds/daqd.cc index 9327526e4..717a4eec1 100644 --- a/src/nds/daqd.cc +++ b/src/nds/daqd.cc @@ -1,4 +1,6 @@ -// nds test driver +/// \file nds/daqd.cc +/// \brief NDS test driver program. + #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> @@ -11,8 +13,8 @@ #include <stdio.h> #include <string.h> -int -main(int argc, char* argv[]) { +/// \brief NDS test driver program. +int main(int argc, char* argv[]) { if (argc != 3) { fprintf(stderr,"usage: %s <pipe file name> <result file name>\n", argv[0]); return 1; diff --git a/src/nds/daqd_net.cc b/src/nds/daqd_net.cc index 7c2cba70e..642ef74ed 100644 --- a/src/nds/daqd_net.cc +++ b/src/nds/daqd_net.cc @@ -454,25 +454,12 @@ double htond(double in) { } bool -#if FRAMECPP_DATAFORMAT_VERSION >= 6 daqd_net::send_data(FrameCPP::Version::FrameH &frame, const char *file_name, unsigned frame_number, int *seq_num) -#elif FRAMECPP_DATAFORMAT_VERSION > 4 -daqd_net::send_data(FrameCPP::Version_6::FrameH &frame, const char *file_name, unsigned frame_number, int *seq_num) -#else -daqd_net::send_data(FrameCPP::Frame &frame, const char *file_name, unsigned frame_number, int *seq_num) -#endif { -#if FRAMECPP_DATAFORMAT_VERSION >= 6 FrameCPP::Version::FrRawData::firstAdc_type adc(frame.GetRawData()->RefFirstAdc()); -#elif FRAMECPP_DATAFORMAT_VERSION > 4 - FrameCPP::Version_6::FrRawData::AdcDataContainer &adc(frame.getRawData()->refAdc()); -#else - FrameCPP::RawData::AdcDataContainer &adc(frame.getRawData()->refAdc()); -#endif // Take care of the reconfiguration block bool config_changed = false; -#if FRAMECPP_DATAFORMAT_VERSION >= 6 for (int k = 0; k < num_signals; k++) { if (reconfig_data[k].signal_offset != adc[k]->GetBias() || reconfig_data[k].signal_slope != adc[k]->GetSlope() @@ -484,19 +471,6 @@ daqd_net::send_data(FrameCPP::Frame &frame, const char *file_name, unsigned fram reconfig_data[k].signal_status = adc[k]->GetDataValid(); } } -#else - for (int k = 0; k < num_signals; k++) { - if (reconfig_data[k].signal_offset != adc[k]->getBias() - || reconfig_data[k].signal_slope != adc[k]->getSlope() - || reconfig_data[k].signal_status != adc[k]->getDataValid()) - { - config_changed = true; - reconfig_data[k].signal_offset = adc[k]->getBias(); - reconfig_data[k].signal_slope = adc[k]->getSlope(); - reconfig_data[k].signal_status = adc[k]->getDataValid(); - } - } -#endif if (first_time || config_changed) { first_time = false; @@ -511,20 +485,10 @@ daqd_net::send_data(FrameCPP::Frame &frame, const char *file_name, unsigned fram // // Shift from the start of data in frame (in seconds or in minutes for the minute trend data) unsigned start_diff = 0; -#if FRAMECPP_DATAFORMAT_VERSION >= 6 unsigned dt = (unsigned) frame.GetDt(); -#else - unsigned dt = (unsigned) frame.getDt(); -#endif // How many seconds (or minutes for minute trend data) of data to send unsigned seconds_to_send = dt; -#if FRAMECPP_DATAFORMAT_VERSION >= 6 const FrameCPP::Version::GPSTime &gps = frame.GetGTime(); -#elif FRAMECPP_DATAFORMAT_VERSION > 4 - const FrameCPP::Version_6::GPSTime &gps = frame.getGTime(); -#else - const FrameCPP::Time &gps = frame.getGTime(); -#endif unsigned long start_time = mSpec.getStartGpsTime(); unsigned long end_time = mSpec.getEndGpsTime(); if (dt > 1) { @@ -583,110 +547,58 @@ daqd_net::send_data(FrameCPP::Frame &frame, const char *file_name, unsigned fram // :TODO: support 32 bit integer data type -- required changes to the frmebuilder too. // Check data type -#if FRAMECPP_DATAFORMAT_VERSION >= 6 unsigned int frameDataType = (unsigned int) adc[k]->RefData()[0]->GetType(); unsigned int file_rate = (unsigned int) adc[k]->GetSampleRate(); -#else - unsigned int frameDataType = (unsigned int) adc[k]->refData()[0]->getType(); - unsigned int file_rate = (unsigned int) adc[k]->getSampleRate(); -#endif switch (frameDataType) { -#if FRAMECPP_DATAFORMAT_VERSION > 4 case FrameCPP::Version::FrVect::FR_VECT_2S: case FrameCPP::Version::FrVect::FR_VECT_4S: case FrameCPP::Version::FrVect::FR_VECT_2U: case FrameCPP::Version::FrVect::FR_VECT_4R: case FrameCPP::Version::FrVect::FR_VECT_8R: -#else - case FrameCPP::FrVect::FR_VECT_2S: - case FrameCPP::FrVect::FR_VECT_2U: - case FrameCPP::FrVect::FR_VECT_4R: - case FrameCPP::FrVect::FR_VECT_8R: -#endif break; default: if (file_rate != rates[k]) { -#if FRAMECPP_DATAFORMAT_VERSION >= 6 system_log(1, "%s: frame %d has an ADC `%s' of unsupported framecpp data type %d", file_name, frame_number, adc[k]->GetName().c_str(), frameDataType); -#else - system_log(1, "%s: frame %d has an ADC `%s' of unsupported framecpp data type %d", - file_name, frame_number, adc[k]->getName().c_str(), frameDataType); -#endif return false; } else break; } // See if conversion is required and if so do it in place if (mSpec.getSignalTypes()[k] == Spec::_16bit_integer) { -#if FRAMECPP_DATAFORMAT_VERSION > 4 if (frameDataType == FrameCPP::Version::FrVect::FR_VECT_4R) -#else - if (frameDataType == FrameCPP::FrVect::FR_VECT_4R) -#endif { // Convert floats to shorts -#if FRAMECPP_DATAFORMAT_VERSION >= 6 short *sptr = (short *)adc[k]->RefData()[0]->GetData().get(); float *fptr = (float *)adc[k]->RefData()[0]->GetData().get(); -#else - short *sptr = (short *)adc[k]->refData()[0]->getData(); - float *fptr = (float *)adc[k]->refData()[0]->getData(); -#endif for (int l = 0; l < file_rate*seconds_to_send; l++) *sptr++ = (short) *fptr++; } -#if FRAMECPP_DATAFORMAT_VERSION > 4 else if (frameDataType == FrameCPP::Version::FrVect::FR_VECT_8R) -#else - else if (frameDataType == FrameCPP::FrVect::FR_VECT_8R) -#endif { // Convert doubles to shorts // Convert floats to shorts -#if FRAMECPP_DATAFORMAT_VERSION >= 6 short *sptr = (short *)adc[k]->RefData()[0]->GetData().get(); double *dptr = (double *)adc[k]->RefData()[0]->GetData().get(); -#else - short *sptr = (short *)adc[k]->refData()[0]->getData(); - double *dptr = (double *)adc[k]->refData()[0]->getData(); -#endif for (int l = 0; l < file_rate*seconds_to_send; l++) *sptr++ = (short) *dptr++; } } else if (mSpec.getSignalTypes()[k] == Spec::_32bit_float) { -#if FRAMECPP_DATAFORMAT_VERSION > 4 if (frameDataType == FrameCPP::Version::FrVect::FR_VECT_8R) -#else - if (frameDataType == FrameCPP::FrVect::FR_VECT_8R) -#endif { // Convert doubles to floats -#if FRAMECPP_DATAFORMAT_VERSION >= 6 float *fptr = (float *)adc[k]->RefData()[0]->GetData().get(); double *dptr = (double *)adc[k]->RefData()[0]->GetData().get(); -#else - float *fptr = (float *)adc[k]->refData()[0]->getData(); - double *dptr = (double *)adc[k]->refData()[0]->getData(); -#endif for (int l = 0; l < file_rate*seconds_to_send; l++) *fptr++ = (float) *dptr++; } } -#if FRAMECPP_DATAFORMAT_VERSION >= 6 char *sptr = ((char *)adc[k]->RefData()[0]->GetData().get()) + start_diff*bps[k]*rates[k]; -#else - char *sptr = ((char *)adc[k]->refData()[0]->getData()) + start_diff*bps[k]*rates[k]; -#endif if (mSpec.getDataType() != Spec::MinuteTrendData) { if (file_rate != rates[k]) { int samples_per_point = file_rate / rates[k]; DEBUG(1, cerr << "decimating " -#if FRAMECPP_DATAFORMAT_VERSION >= 6 << adc[k]->GetName() -#else - << adc[k]->getName() -#endif << " file_rate=" << file_rate << " rate=" << rates[k] << "samples_per_point=" << samples_per_point << endl); diff --git a/src/nds/daqd_net.hh b/src/nds/daqd_net.hh index d12a8e98b..bed4e9d91 100644 --- a/src/nds/daqd_net.hh +++ b/src/nds/daqd_net.hh @@ -6,125 +6,143 @@ #include <list> #include <map> #include "ldas/ldasconfig.hh" - -#if FRAMECPP_DATAFORMAT_VERSION >= 6 - #include "ldas/ldasconfig.hh" #include "framecpp/Common/FrameSpec.hh" #include "framecpp/Common/CheckSum.hh" #include "framecpp/Common/IOStream.hh" #include "framecpp/Version8/FrameStream.hh" #include "framecpp/Common/FrameBuffer.hh" - - #include "framecpp/FrameCPP.hh" - #include "framecpp/FrameH.hh" #include "framecpp/FrAdcData.hh" #include "framecpp/FrRawData.hh" #include "framecpp/FrVect.hh" - #include "framecpp/Dimension.hh" - -#else - -#ifdef LDAS_VERSION_NUMBER -#include "framecpp/Version6/FrameH.hh" -#else -#include "framecpp/frame.hh" -#if FRAMECPP_DATAFORMAT_VERSION > 4 -#include "framecpp/Version6/FrameH.hh" -#endif -#endif -#endif - #include "spec.hh" namespace CDS_NDS { -// DAQD network protocol reconfig data +/// DAQD network protocol reconfig data. typedef struct reconfig_data_t { float signal_offset; float signal_slope; unsigned int signal_status; } reconfig_data_t; +/// DAQD protocol communication back to client. class daqd_net { public: - // Subjob state + /// Subjob state. class SubjobReadState { public: + /// Constructor using a set of signal indices. SubjobReadState(const std::vector<unsigned int> &v) : finished(false), seq_num(-1), block_list(), signalIndices(v) {} - // Set if subjob finished + /// Set if subjob finished. bool finished; - // Sequence number send by the sub-NDS when subjob finished + /// Sequence number send by the sub-NDS when subjob finished. int seq_num; - // Subjob data block (input block) + //// Subjob data block (input block). class BT { public: + /// Default constructor. BT() : length(0), dt(0), data(0) {} + /// Constructor with length 'l' and data pointser 'p'. BT(unsigned long l, char *p) : length(l), dt(0), data(p) {} - unsigned long length; // 'data' length - unsigned long dt; // used for block splitting in combine_send_data() - char * data; // malloced block's data + /// 'data' length. + unsigned long length; + /// Used for block splitting in combine_send_data(). + unsigned long dt; + /// malloced block's data. + char * data; + /// Output some debugging information. void print_debug_info() { std::cerr << "BT: length=" << length << "; dt=" << dt << std::endl; } }; + /// A linked list of subjob data blocks. typedef std::list<BT> BLT; + /// A linked list of subjob data blocks. BLT block_list; + /// A const iterator on a linked list of subjob data blocks. typedef std::list<BT>::const_iterator BLI; + /// An iterator on a linked list of subjob data blocks. typedef std::list<BT>::iterator BLINC; - // Add new block to the list + /// Add new block to the list. void add_block(unsigned long size, char *block) { block_list.insert (block_list.end(), BT(size, block)); } - // Signal indices in 'spec.getSignalNames()' vector + /// Signal indices in 'spec.getSignalNames()' vector. std::vector<unsigned int> signalIndices; }; - // See if the data block 'd' is a reconfiguration block + /// See if the data block 'd' is a reconfiguration block. inline bool is_reconfig_block(const char * d) const { unsigned long l; memcpy(&l,d,sizeof(l)); return ntohl (l) == 0xffffffff; } - // Map FIFO read file descriptor onto the vector of signal indices + /// Map subjob FIFO read file descriptor onto the vector of signal indices. typedef std::map<int, std::vector<unsigned int> > CPT; typedef std::map<int, std::vector<unsigned int> >::const_iterator CPMI; - // Map FIFO read file descriptor into the read state object + /// Map subjob FIFO read file descriptor into the read state object typedef std::map<int, SubjobReadState> CRST; typedef std::map<int, SubjobReadState>::const_iterator CRMI; typedef std::map<int, SubjobReadState>::iterator CRMINC; + /// Constructor. daqd_net (int fd, Spec &spec); - daqd_net (int fd, Spec &spec, CPT &v); // Combination processing + /// Combination processing. + daqd_net (int fd, Spec &spec, CPT &v); + /// Default destructor. ~daqd_net (); -#ifdef LDAS_VERSION_NUMBER + /// \brief Send frame data to the client. + /// @param[in] &frame Frame object to send. + /// @param[in] *file_name Name of the file where the frame was read from. + /// @param[in] frame_number Frame number of the frame within the frame file. + /// @param[in, out] *seq_num Current data block sequencer number, gets incremented by one for each block transmitted. + /// @return True if data was sent successfully. bool send_data (FrameCPP::Version::FrameH &frame, const char *file_name, unsigned frame_number, int *seq_num); -#else -#if FRAMECPP_DATAFORMAT_VERSION > 4 - bool send_data (FrameCPP::Version::FrameH &frame, const char *file_name, unsigned frame_number, int *seq_num); -#else - bool send_data (FrameCPP::Frame &frame, const char *file_name, unsigned frame_number, int *seq_num); -#endif -#endif + /// Finalize the send. bool finish (); + /// \brief Read a block from fildes and do combination processing. + /// @param[in] fildes File descriptor to read from. + /// @return True if read, processed and transmitted the data successfully. bool comb_read(int fildes); + /// Finish one subjob processing. + /// @param[in] fildes File descriptor to read from. + /// @param[in] seq_num Current data block sequence number. + /// @return True if read, processed and transmitted the data successfully. bool comb_subjob_done(int fildes, int seq_num); + /// Assign the data an send one metadata reconfiguration block. + /// @param[in] &spec Job specification. + /// @return True if sent the block successfully. bool send_reconfig_data(Spec &spec); + /// Send one metadata reconfiguration block. + /// @return True if sent the block successfully. bool send_reconfig_block(); - + /// Read the number of bytes from the file descriptor. + /// @param[in] fd File descriptor to read from. + /// @param[in] *cptr Pointer where to write the bytes. + /// @param[in] numb The number of bytes to read. + /// @return The number of bytes read. static int read_bytes (int fd, char *cptr, int numb); + /// Read one 4 byte long integer from the file descriptor. + /// The four bytes are converted to long with ntohl() call. + /// @param[in] fd File descirptor to read from. + /// @return The integer rad from the file. static unsigned long read_long (int fd); + /// Average an array of shorts. + /// @param[in] *v A pointer to the array. + /// @param[in] num The number of elements in the array. + /// @return The average of the elements in the array. static inline short averaging (short *v, int num) { assert (num > 0 && num < SHRT_MAX); long res = 0; @@ -134,6 +152,10 @@ public: return (short) (res / num); } + /// Average an array of ints. + /// @param[in] *v A pointer to the array. + /// @param[in] num The number of elements in the array. + /// @return The average of the elements in the array. static inline int averaging (int *v, int num) { assert (num > 0 && num < SHRT_MAX); long long res = 0; @@ -143,6 +165,10 @@ public: return (int) (res / num); } + /// Average an array of floats. + /// @param[in] *v A pointer to the array. + /// @param[in] num The number of elements in the array. + /// @return The average of the elements in the array. static inline float averaging (float *v, int num) { assert (num > 0 && num < SHRT_MAX); double res = 0; @@ -152,6 +178,10 @@ public: return (float) (res / num); } + /// Average an array of doubles. + /// @param[in] *v A pointer to the array. + /// @param[in] num The number of elements in the array. + /// @return The average of the elements in the array. static inline double averaging (double *v, int num) { assert (num > 0 && num < SHRT_MAX); long double res = 0; @@ -161,7 +191,8 @@ public: return (double) (res / num); } - // Merge received data and send + /// Merge received data and send + /// @return True if transmitted all the data successfully. bool combine_send_data(); private: @@ -170,13 +201,13 @@ private: unsigned num_signals; reconfig_data_t *reconfig_data; bool first_time; - int mDataFd; // client data socket file descriptor - const Spec &mSpec; // job specification + int mDataFd; ///< Client data socket file descriptor. + const Spec &mSpec; ///< Job specification. const static unsigned long buf_size = 1024*1024; - unsigned long transmission_block_size; // merger output block size for one second of time - CRST subjobReadStateMap; // merger input state - unsigned long seq_num; // merged output block's sequence number - std::vector<unsigned long> mSignalBlockOffsets; // merged data block's signal offsets (for one unit of data) + unsigned long transmission_block_size; ///< Merger output block size for one second of time. + CRST subjobReadStateMap; ///< Merger input state. + unsigned long seq_num; ///< Merged output block's sequence number. + std::vector<unsigned long> mSignalBlockOffsets; ///< Merged data block's signal offsets (for one unit of data). }; } // namespace diff --git a/src/nds/io.h b/src/nds/io.h index e6a01d7b3..4498971b2 100644 --- a/src/nds/io.h +++ b/src/nds/io.h @@ -7,7 +7,8 @@ class basic_io { public: -static ssize_t /* Read "n" bytes from a descriptor. */ +/// Read "n" bytes from a descriptor. +static ssize_t readn(int fd, void *vptr, size_t n) { size_t nleft; @@ -32,7 +33,8 @@ readn(int fd, void *vptr, size_t n) } /* end readn */ -static ssize_t /* Write "n" bytes to a descriptor. */ +/// Write "n" bytes to a descriptor. +static ssize_t writen(int fd, const void *vptr, size_t n) { size_t nleft; @@ -56,6 +58,5 @@ writen(int fd, const void *vptr, size_t n) } /* end writen */ - }; #endif diff --git a/src/nds/myframereadplan.hh b/src/nds/myframereadplan.hh index 18f5e7e24..2b92dbf8e 100644 --- a/src/nds/myframereadplan.hh +++ b/src/nds/myframereadplan.hh @@ -5,31 +5,22 @@ #include "framecpp/Version6/IFrameStream.hh" #include "mmstream.hh" -//----------------------------------------------------------------------------- -// -//: Frame Reading Plan -// +/// Frame Reading Plan class myFrameReadPlan : public FrameCPP::Version_6::IFrameStream { public: - // - //: Constructor - // - //!exc: std::bad_alloc - Out of memory. - //!exc: read_failure - Read failed. - // + /// Constructor + /// @throw std::bad_alloc Out of memory. + /// @throw read_failure Read failed. myFrameReadPlan( std::istream& in ); - //: Destructor - // - //!exc: None. + /// Destructor + /// @throw None. ~myFrameReadPlan(); - //: Read frame data - // - //!exc: read_failure - Read failed. - //!exc: cannot_update - // + /// Read frame data + /// @thorw read_failure - Read failed. + /// @throw cannot_update FrameCPP::Version_6::FrameH& readFrame( INT_4U frameNumber, const std::vector<std::string> &adcNames ); #if 0 @@ -45,13 +36,13 @@ public: bool can_be_used_for_frame(char *fname); private: - //: Skeleton frame object + /// Skeleton frame object FrameCPP::Version_6::FrameH frame; - //: Skeleton raw data object + /// Skeleton raw data object FrameCPP::Version_6::FrRawData raw_data; - //: TOC offset variable read from the file, last 8 bytes + /// TOC offset variable read from the file, last 8 bytes char toc_offset[8]; }; // class FrameReadPlan diff --git a/src/nds/nds.cc b/src/nds/nds.cc index 010f5b220..c21c7c5d5 100644 --- a/src/nds/nds.cc +++ b/src/nds/nds.cc @@ -1,3 +1,6 @@ +/// \file nds.cc +/// \brief UNIX daemon forking, job spec file reading code. + #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> @@ -10,7 +13,6 @@ #include <sys/mman.h> #include <arpa/inet.h> #include <sys/wait.h> - #include <iostream> #include <fstream> #include <list> @@ -18,17 +20,9 @@ #include <map> #include <string> #include <algorithm> - #include "nds.hh" #include "io.h" -#if FRAMECPP_DATAFORMAT_VERSION < 6 - -#include "framecpp/daqframe.hh" -#include "framecpp/daqreader.hh" - -#endif - using namespace CDS_NDS; Nds::Nds(std::string p) @@ -43,8 +37,7 @@ Nds::Nds(std::string p) } -bool -Nds::run() +bool Nds::run() { int listenfd; struct sockaddr_un servaddr, cliaddr; diff --git a/src/nds/nds.hh b/src/nds/nds.hh index af67192de..e061c9c4e 100644 --- a/src/nds/nds.hh +++ b/src/nds/nds.hh @@ -7,27 +7,33 @@ namespace CDS_NDS { - +/// A pair of unsigned longs typedef std::pair<unsigned long, unsigned long > ulong_pair; typedef std::pair<unsigned long, ulong_pair > ulong_triple; -// order predicate +/// Order predicate class cmp2 { public: int operator()(ulong_pair p1, ulong_pair p2) { return p1.first < p2.first; }}; +/// Order predicate class cmp3 { public: int operator()(ulong_triple p1, ulong_triple p2) { return p1.first < p2.first; }}; -class Nds -{ +/// Network Data Server to process requests to read data from the data files. +class Nds { public: + /// Creates an Nds object. Nds(std::string); + /// Main processing loop. bool run(); - bool rawMinuteTrend(); // striped raw minute trend data reader - bool readFrameFileArchive(); // older code to read a frame files archive - bool readTocFrameFileArchive(); // newer code to read a frame files archive - bool combineMinuteTrend(); // minute trend combiner which does its processing if data is requested from more than one archive + /// Striped raw minute trend data reader. + bool rawMinuteTrend(); + /// Older code to read a frame file archive. + bool readFrameFileArchive(); + /// Newer code to read a frame file archive. + bool readTocFrameFileArchive(); + /// Minute trend combiner code, used when data is requested from multiple archives. + bool combineMinuteTrend(); + /// Discover archive data subdirectories. bool scanArchiveDir(std::vector<ulong_pair> *tstamps); - - // Determine program name (strip filesystem path) - // + /// Determine program name (strip filesystem path). static std::string basename( std::string s ) throw(){ try { std::string s1(s.substr(s.find_last_of ("/"))); @@ -37,8 +43,7 @@ public: } } - // Get the filesystem path without the name - // + /// Get the filesystem path without the name. static std::string dirname( std::string s ) throw(){ try { return s.substr(0, s.find_last_of ("/")); @@ -47,17 +52,24 @@ public: } } - private: - std::string mPipeFileName; // unix domain socket binding file name - std::string mSpecFileName; // job specification file name - std::string mResultFileName; // job result transmission image - int mDataFd; // client data socket file descriptor - Spec mSpec; // job specification + /// UNIX domain socket binding file name. + std::string mPipeFileName; + /// Job specification file name. + std::string mSpecFileName; + /// Job result transmission image. + std::string mResultFileName; + /// Client data socket file descriptor. + int mDataFd; + /// Job specification. + Spec mSpec; + /// Data block sequence number. int seq_num; + /// Maximum file name length. enum { filename_max = FILENAME_MAX }; }; +/// Raw minute trend data substructure. typedef struct { union {int I; double D; float F;} min; union {int I; double D; float F;} max; @@ -66,38 +78,52 @@ typedef struct { double mean; } trend_block_t; +/// Raw minute trend data file structure. typedef struct raw_trend_record_struct { unsigned int gps; trend_block_t tb; } raw_trend_record_struct; - +/// Data span using GPS time stamp and length. +/// Used for processing raw minute trend data. class data_span { public: + /// Class is only used for the minute trend data. const static int point_period = 60; + /// Default constructor. data_span():offs(0),gps(0),length(0){} - unsigned long offs; // in the file - unsigned long gps; // time stamp of the first data point - unsigned long length; // number of data points available in this span - inline bool operator<(data_span &y) { return gps < y.gps; } // compare spans - inline void operator()(data_span &y) { length += y.length; } // accumulate + /// Offset in the file. + unsigned long offs; + /// Time stamp of the first data point. + unsigned long gps; + /// The number of data points available in this span. + unsigned long length; + /// Compare two data spans by their GPS start times. + inline bool operator<(data_span &y) { return gps < y.gps; } + /// Accumulate the span length. + inline void operator()(data_span &y) { length += y.length; } + /// Calculate and returns this span's ending GPS time. inline unsigned long end_gps () { return gps+length*point_period; } + /// Calculate and returns this span's ending GPS time. inline unsigned long end_gps () const { return gps+length*point_period; } + /// Extend the data span. inline void extend (const data_span &s) { unsigned long new_length = (s.end_gps () - gps)/point_period; if (new_length > length) length = new_length; } }; - +/// Raw minute trend data span with added mapping data. class mapping_data_span : public data_span { public: + /// Default constructor. mapping_data_span () : data_span (), image_offs (0) {}; + /// Offset into the image. unsigned long image_offs; + /// Copy the data span and zero out the offset. inline mapping_data_span &operator=(const data_span &ds) {*(data_span *)this = ds; image_offs = 0;}; }; - } // namespace #endif diff --git a/src/nds/rawminutetrend.cc b/src/nds/rawminutetrend.cc index 1bb242c6f..00282e920 100644 --- a/src/nds/rawminutetrend.cc +++ b/src/nds/rawminutetrend.cc @@ -22,14 +22,6 @@ #include "daqd_net.hh" #include "../daqd/crc8.cc" -#if FRAMECPP_DATAFORMAT_VERSION < 6 - -#include "framecpp/daqframe.hh" -#include "framecpp/daqreader.hh" - -#endif - - using namespace CDS_NDS; using namespace std; diff --git a/src/nds/readtocframefilearchive.cc b/src/nds/readtocframefilearchive.cc index 4c3f1c839..8829645fc 100644 --- a/src/nds/readtocframefilearchive.cc +++ b/src/nds/readtocframefilearchive.cc @@ -22,14 +22,6 @@ #include "daqd_net.hh" #include "mmstream.hh" -#if FRAMECPP_DATAFORMAT_VERSION >= 6 -// nada -#elif FRAMECPP_DATAFORMAT_VERSION > 4 -#include "myframereadplan.hh" -#else -#include "framecpp/framereadplan.hh" -#endif - using namespace CDS_NDS; using namespace std; @@ -64,7 +56,6 @@ static void error_watch (const string& msg) { // read files of arbitrary length in seconds or frames bool Nds::readTocFrameFileArchive() -#if FRAMECPP_DATAFORMAT_VERSION >= 6 { unsigned long t_start = time(0); // mark the beginning of frame file read process bool archiveDirScanned = false; @@ -266,333 +257,3 @@ Nds::readTocFrameFileArchive() return true; } -#else -{ -#if 0 - { - FrameCPP::Dictionary *dict = FrameCPP::library.getCurrentVersionDictionary(); - // cerr << "Current version is " << dict->getVersion() << endl; - } -#endif - - unsigned long t_start = time(0); // mark the beginning of frame file read process - bool archiveDirScanned = false; - vector<ulong_pair> archive_gps; - - // Will have to read archive directory to determine GPS time ranges for each data directory - if (mSpec.getArchiveGps().size() == 0) { - if (!scanArchiveDir(&archive_gps)) return false; - archiveDirScanned = true; - } else archive_gps = mSpec.getArchiveGps(); - - vector<ulong_pair> gps = archive_gps; - unsigned long start_time = mSpec.getStartGpsTime(); - unsigned long end_time = mSpec.getEndGpsTime(); - sort(gps.begin(), gps.end(), cmp2()); // sort gps ranges - // remove ranges that aren't needed - gps.erase(remove_if(gps.begin(), gps.end(), - not1(intersect(ulong_pair(start_time, end_time)))), gps.end()); - - system_log(5, "%d pertinent range(s)", gps.size()); - for(int i=0;i<gps.size();i++) { - system_log(5, "%d %d", gps[i].first, gps[i].second); - } - -#if FRAMECPP_DATAFORMAT_VERSION > 4 - myFrameReadPlan *reader = 0; // frame reader -#else - FrameCPP::FrameReadPlan *reader = 0; // frame reader -#endif - const vector<string> &names = mSpec.getSignalNames(); // ADC signal names - unsigned long num_signals = names.size(); - unsigned int nfiles_read = 0; // number of files read - unsigned int nfiles_updated = 0; // number of files updated - unsigned int nfiles_open_failed = 0; // number of files that were missing - unsigned int nfiles_failed = 0; // number of times read failed - unsigned int nbad_failures = 0; // tracks the number of expensive failures - - // Buffer for the actual Adc data. - // It is desirable to write() as large buffer as possible. - // Data gaps in time are indicated by starting new data blocks (sending new header). - // Data gaps in channels are currently filled with zeros. - // Reconfig data change triggers new blocks too. - daqd_net daqd_net(mDataFd, mSpec); - - // Iterate over gps ranges, ie. over data directories - for (int i = 0; i < gps.size(); i++) { - // get directory number for the range `i' - - unsigned int dir_num = 0; - - if (archiveDirScanned) { - // directory number is based on GPS timestamp: all digits but the last 6 - dir_num = gps[i].first / 100000; - } else { - dir_num = distance(archive_gps.begin(), - find_first_of(archive_gps.begin(), - archive_gps.end(), - gps.begin() + i, - gps.begin() + i + 1) - ); - } - - // read file names in directory `i' and parse - DIR *dirp; - struct dirent *direntp; - char dirname [filename_max + 1]; - sprintf (dirname, "%s%d", mSpec.getArchiveDir().c_str(), dir_num); - if (! (dirp = opendir (dirname))) { - system_log(1,"Couldn't open directory `%s'", dirname); - return false; - } - char *buf = (char *) malloc (sizeof (struct dirent) + filename_max + 1); - vector<ulong_pair> tstamps; - typedef vector<ulong_pair>::const_iterator VITER; - - int prefix_len = mSpec.getArchivePrefix().size(); -#if defined(_POSIX_C_SOURCE) - while (! readdir_r (dirp, (struct dirent *) buf, &direntp)) -#else - while (direntp = readdir_r (dirp, (struct dirent *) buf)) -#endif - { - if (!direntp) - break; - if (strlen(direntp -> d_name) <= prefix_len) - continue; - char *cfile = direntp -> d_name + prefix_len; - int times, framedt; - char junk[1024]; - int scanned = sscanf (cfile, "%d-%d%s", ×, &framedt, junk); - if (strcmp(".gwf", junk)) scanned = 0xff; - switch (scanned) { -#if 0 - case 1: - tstamps.push_back(ulong_pair(times, 1)); - break; -#endif - case 3: - tstamps.push_back(ulong_pair(times, framedt)); - break; - default: - system_log(1, "scan(): `%s' is invalid filename -- skipped", direntp -> d_name); - } - } - (void) closedir (dirp); - free ((void *) buf); - - if (tstamps.size() == 0) - { - system_log(1, "FATAL: directory %s%d is empty", mSpec.getArchiveDir().c_str(), dir_num); - return false; - } - - // sort the timestamps - sort(tstamps.begin(), tstamps.end(), cmp2()); - - VITER i = find_if(tstamps.begin(), tstamps.end(), falls_in(start_time)); - if (i == tstamps.end()) { - system_log(1, "FATAL: data for time %d not found in directory %s%d", start_time, mSpec.getArchiveDir().c_str(), dir_num); - return false; - } - -#if FRAMECPP_DATAFORMAT_VERSION > 4 - mm_istream in; -#endif - - // Iterate over the frame files - for (;i != tstamps.end() && end_time >= i->first; i++) { - unsigned long gps, dt; - gps = i->first; - dt = i->second; - - DEBUG1(cerr << "gps=" << gps << "; dt=" << dt << endl); - - char file_name[filename_max+1]; - if (dt == 1) { - sprintf(file_name, "%s%d/%s%d%s", - mSpec.getArchiveDir().c_str(), dir_num, - mSpec.getArchivePrefix().c_str(), gps, mSpec.getArchiveSuffix().c_str() - ); - } else { - sprintf(file_name, "%s%d/%s%d-%d%s", - mSpec.getArchiveDir().c_str(), dir_num, - mSpec.getArchivePrefix().c_str(), gps, dt, mSpec.getArchiveSuffix().c_str() - ); - } - - // stat file here and see if its size changed - // delete frame read plan, if it changed - { - static unsigned long fsize; // this is set to current file size that should match - struct stat buf; - if (stat (file_name, &buf)) { - system_log(3, "%s: frame file stat failed", file_name); - nfiles_open_failed++; - continue; - } - if (reader && buf.st_size != fsize) { // if plan exists and file size changed - system_log(2, "%s: file size changed", file_name); - delete(reader); - reader = 0; // will create new frame reading plan - } - if (reader) { - // Check the TOC offset, it should be the same as before - // If the TOC offset is different, it probably because they changed - // endianess, so we will have to recreate the reader - if (!reader -> can_be_used_for_frame(file_name)) { - system_log(2, "%s: file attributes changed", file_name); - delete(reader); - reader = 0; // will create new frame reading plan - } - } - fsize = buf.st_size; - } - -#if FRAMECPP_DATAFORMAT_VERSION > 4 - in.close(); - in.open(file_name); -#else - mm_istream in(file_name); -#endif - if (! in ) { - system_log(3, "%s: frame file open failed", file_name); - nfiles_open_failed++; - continue; - } - -#if FRAMECPP_DATAFORMAT_VERSION > 4 - FrameCPP::Version::FrameH *frame = 0; -#else - FrameCPP::Frame *frame = 0; -#endif -#ifdef __linux__ - if (reader) { - delete(reader); - in.seekg(0); - reader = 0; - frame = 0; - } -#else - if (reader) { - // Read first frame in this file using existing plan - try { -#if FRAMECPP_DATAFORMAT_VERSION > 4 - frame = &reader->readFrame(0, names); - - // Set times using file name data - frame -> SetDt(dt); - *(const_cast<FrameCPP::Version::GPSTime *>(&(frame -> getGTime()))) = FrameCPP::Version::GPSTime(gps,0); -#else - frame = &reader->readFrame(in, 0); -#endif - nfiles_updated++; - } catch (...) { - delete(reader); - in.seekg(0); - reader = 0; - frame = 0; - } - } -#endif - - // There is no reader plan and it needs to be created - // - if (! reader) { - try { -#if FRAMECPP_DATAFORMAT_VERSION > 4 - reader = new myFrameReadPlan(in); -#else - reader = new FrameCPP::FrameReadPlan(in); -#endif - } catch (...) { - system_log(1, "%s: failed to new FrameReadPlan()", file_name); - nfiles_failed++; - reader = 0; - continue; - } - -#if FRAMECPP_DATAFORMAT_VERSION <= 4 - reader->setErrorWatch(error_watch); - - try { - reader->daqTriggerADC(names); - } catch (...) { - system_log(1, "%s: failed to activate signals", file_name); - nfiles_failed++; - delete(reader); - reader = 0; - continue; - } -#endif - nfiles_read++; - } - - if ( !frame ) { - // Read first frame in this file using the new plan - try { -#if FRAMECPP_DATAFORMAT_VERSION > 4 - frame = &reader->readFrame(0, names); -#else - frame = &reader->readFrame(in, 0); -#endif - } catch (...) { - system_log(1, "%s: failed to read first frame", file_name); - nfiles_failed++; - delete(reader); - reader = 0; - continue; - } - } - - // Iterate over frames in the frame file -#if FRAMECPP_DATAFORMAT_VERSION > 4 - int frames = reader->GetNumberOfFrames(); -#else - int frames = reader->getFrame().size(); -#endif - for (unsigned long j = 0; j < frames; j++) { - if (j > 0) { - try { -#if FRAMECPP_DATAFORMAT_VERSION > 4 - (void) reader->readFrame(j, names); - - // Set times using file name data - frame -> SetDt(dt); - *(const_cast<FrameCPP::Version::GPSTime *>(&(frame -> getGTime()))) = FrameCPP::Version::GPSTime(gps,0); -#else - (void) reader->readFrame(in, j); // Read subsequent frame -#endif - nfiles_updated++; - } catch (...) { - system_log(1, "%s: failed to read frame %d", file_name, j); - nfiles_failed++; - delete(reader); - reader = 0; - continue; - } - } - - DEBUG1(cerr << frame->getGTime().getSec() << "." << frame->getGTime().getNSec() - << " dt=" << frame->getDt() << endl); - - // decimate and send the data, taking care of DAQD network protocol - // ... - - if (!daqd_net.send_data(*frame, file_name, j, &seq_num)) - return false; - } - } - } // data directories - if (!daqd_net.finish()) - return false; -#ifndef __linux__ - delete(reader); -#endif - reader = 0; - system_log(1, "time=%d read=%d updated=%d missing=%d failed=%d", - time(0)-t_start, nfiles_read, nfiles_updated, nfiles_open_failed, nfiles_failed); - - return true; -} -#endif diff --git a/src/nds/spec.cc b/src/nds/spec.cc index 00b1ea9c4..1cea91c35 100644 --- a/src/nds/spec.cc +++ b/src/nds/spec.cc @@ -24,29 +24,6 @@ Spec::Spec() , mArchiveGps() {} -#if 0 -Spec::Spec(DataClassType dataType, unsigned long startGpsTime, unsigned long endGpsTime, - const std::vector<std::string> &signalNames, const std::vector<DataTypeType> &signalTypes, - const std::string &archiveDir, const std::string &prefix, const std::string &suffix, - const std::vector<std::pair<unsigned long, unsigned long> > &gps) - : mDataType(dataType) - , mStartGpsTime(startGpsTime) - , mEndGpsTime(endGpsTime) - , mFilter() - , mSignalNames(signalNames) - , mSignalRates() - , mSignalBps() - , mSignalTypes(signalTypes) - , mDaqdResultFile() - , mArchiveDir(archiveDir) - , mArchivePrefix(prefix) - , mArchiveSuffix(suffix) - , mAddedArchives() - , mAddedFlags() - , mArchiveGps(gps) -{} -#endif // 0 - const std::vector<std::string> Spec::split(std::string value) throw() { diff --git a/src/nds/spec.hh b/src/nds/spec.hh index 4cc05407e..e71b643eb 100644 --- a/src/nds/spec.hh +++ b/src/nds/spec.hh @@ -1,4 +1,5 @@ #ifndef CDS_NDS_SPEC_HH + #define CDS_NDS_SPEC_HH #include <string> @@ -15,11 +16,14 @@ namespace CDS_NDS namespace CDS_NDS { +/// Job specification. class Spec { public: + /// Requested data type. typedef enum {FullData, TrendData, MinuteTrendData, RawMinuteTrendData} DataClassType; + /// Sample data type. typedef enum { _undefined = 0, _16bit_integer = 1, @@ -30,6 +34,7 @@ public: _32bit_complex = 6 } DataTypeType; + /// Get the data type string inline static const std::string dataTypeString( DataTypeType d ) { switch (d) { case _undefined: return "unknown"; @@ -42,68 +47,98 @@ public: } } + /// Default constructor. Spec(); + /// Parse the job specification file. + /// + /// @param[in] s Job specification file name. + /// @return True if he input file was parse successfully. + bool parse(std::string s); -#if 0 - Spec(DataClassType dataType, unsigned long startGpsTime, unsigned long endGpsTime, - const std::vector<std::string> &signalNames, const std::vector<DataTypeType> &signalTypes, - const std::string &archiveDir, const std::string &prefix, const std::string &suffix, - const std::vector<std::pair<unsigned long, unsigned long> > &gps); -#endif - - bool parse(std::string); - + /// Auxiliary data archive outside of the frame builder domain. class AddedArchive { public: + /// Default constructor. AddedArchive() : prefix(), suffix(), gps() {} + /// Constructor. + /// @param[in] &d Directory. + /// @param[in] &p Prefix. + /// @param[in] &s Suffix. + /// @param[in] &g A vector of GPS time ranges. AddedArchive(std::string &d, std::string &p, std::string &s, std::vector<std::pair<unsigned long, unsigned long> > &g) : dir(d), prefix(p), suffix(s), gps(g) {} - // see whether all fields are set + /// See whether all fields are set. inline bool complete() { return (dir.length() > 0 && prefix.length() > 0 && suffix.length() > 0 && gps.size() > 0); } + /// Archive directory. std::string dir; + /// Archive file name prefix. std::string prefix; + /// Archive file name suffix. std::string suffix; std::vector<std::pair<unsigned long, unsigned long> >gps; }; + /// Get the type of data requested. DataClassType getDataType() const throw() { return mDataType; }; + /// Get the GPS timestamp of the first data sample. unsigned long getStartGpsTime() const throw() { return mStartGpsTime; }; + /// Get the GPS timestamp of the last data sample. unsigned long getEndGpsTime() const throw() { return mEndGpsTime; }; + /// Get the name of decimation filter. std::string getFilter() const throw() { return mFilter; }; + /// Get the vector of signal names. const std::vector<std::string>& getSignalNames() const throw() { return mSignalNames; }; + /// Get the offsets of the signals. const std::vector<float>& getSignalOffsets() const throw() { return mSignalOffsets; }; + /// Get the slopes of the data channels. const std::vector<float>& getSignalSlopes() const throw() { return mSignalSlopes; }; + /// Get sampling rates of the data channels. const std::vector<unsigned int>& getSignalRates() const throw() { return mSignalRates; }; + /// Get signal types of the data channels. const std::vector<DataTypeType>& getSignalTypes() const throw() { return mSignalTypes; }; + /// Get bytes per second values for the data channels. const std::vector<unsigned int>& getSignalBps() const throw() { return mSignalBps; }; + /// Return the name of the results file. const std::string getDaqdResultFile() const throw() { return mDaqdResultFile; }; + /// Return the name of the primary archive directory. const std::string getArchiveDir() const throw() { return mArchiveDir; }; + /// Return the prefix of the primary archive. const std::string getArchivePrefix() const throw() { return mArchivePrefix; }; + /// Return the suffix of the primary archive. const std::string getArchiveSuffix() const throw() { return mArchiveSuffix; }; + /// Return the vector of additional archives. const std::vector<AddedArchive>& getAddedArchives() const throw() { return mAddedArchives; }; + /// Return the vector if the additional flags. const std::vector<std::string>& getAddedFlags() const throw() { return mAddedFlags; }; + /// Split the string on whie space into vector if strings. static const std::vector<std::string> split(std::string) throw(); + /// Get the vector of GPS ranges for the additional archives. const std::vector<std::pair<unsigned long, unsigned long> > getArchiveGps() const throw() { return mArchiveGps; }; + /// Assign the main data archive. void setMainArchive(const AddedArchive &a) { mArchiveDir = a.dir; mArchivePrefix = a.prefix; mArchiveSuffix = a.suffix; mArchiveGps = a.gps; } + /// Set the type of the data requested. void setDataType(DataClassType t) { mDataType = t; } + /// Get the vector of sampling rates of the data channels. void setSignalRates(const std::vector<unsigned int> &v) { mSignalRates = v; } + /// Set the all the data channel slopes to the passed value. void setSignalSlopes(double val) { for (int i = 0; i < mSignalSlopes.size(); i++) mSignalSlopes[i] = val; } + /// Is the values a power of r? static int power_of (int value, int r) { int rm; @@ -121,23 +156,23 @@ public: } private: - DataClassType mDataType; // type of the data + DataClassType mDataType; //< Type of the data. unsigned long mStartGpsTime; unsigned long mEndGpsTime; - std::string mFilter; // how to decimate data - std::vector<std::string> mSignalNames; // list of signals - std::vector<unsigned int> mSignalRates; // list of requested signal rates - std::vector<unsigned int> mSignalBps; // list of signals' bytes per sample - std::vector<DataTypeType> mSignalTypes; // list of signal data types - std::vector<float> mSignalOffsets; // list of signal offset conversion values - std::vector<float> mSignalSlopes; // list of signal slope conversion values - std::string mDaqdResultFile; // results produced by the DAQD - std::string mArchiveDir; // location of main data archive + std::string mFilter; //< How to decimate data + std::vector<std::string> mSignalNames; //< The list of signals. + std::vector<unsigned int> mSignalRates; //< The list of requested signal rates. + std::vector<unsigned int> mSignalBps; //< List of signals' bytes per sample. + std::vector<DataTypeType> mSignalTypes; //< List of signal data types. + std::vector<float> mSignalOffsets; //< List of signal offset conversion values. + std::vector<float> mSignalSlopes; //< List of signal slope conversion values. + std::string mDaqdResultFile; //< Results produced by the DAQD. + std::string mArchiveDir; //< Location of main data archive std::string mArchivePrefix; std::string mArchiveSuffix; - std::vector<AddedArchive> mAddedArchives; // list of added archives (identified by dir name) - std::vector<std::string> mAddedFlags; // establishes signal membership in archives, "0" means main archive, dir name for added archive - // Gps times for the data archive "Data*" directories + std::vector<AddedArchive> mAddedArchives; //< List of added archives (identified by dir namea). + std::vector<std::string> mAddedFlags; //< Establishes signal membership in archives, "0" means main archive, dir name for added archive + /// Gps times for the data archive "Data*" directories. std::vector<std::pair<unsigned long, unsigned long> > mArchiveGps; }; -- GitLab