00001
00015
00016 #ifndef CLDAQ_IODLL__TTYPES_H
00017 #define CLDAQ_IODLL__TTYPES_H
00018
00019 #include <iostream>
00020 #include <iomanip>
00021 #include <fstream>
00022 #include <string>
00023 #include <list>
00024 #include <vector>
00025 #include <map>
00026 #if (__GNUC__==3) && (__GNUC_MINOR__>0)
00027 #undef __DEPRECATED
00028 #endif
00029 #include <strstream>
00030 #include <stdio.h>
00031 #include <unistd.h>
00032
00033 #define Tfalse 0
00034 #define Ttrue 1
00035 #define Tstd std
00036 #define Tios std::ios
00037 #define Tlist std::list
00038 #define Tvector std::vector
00039 #define Tmap std::map
00040 #define Tmultimap std::multimap
00041 #define Tpair std::pair
00042 #define Tcout std::cout
00043 #define Tcin std::cin
00044 #define Tcerr std::cerr
00045 #define Tendl std::endl
00046 #define Tends std::ends
00047 #define Tdec std::dec
00048 #define Thex std::hex
00049 #define Toct std::oct
00050 #define Tflush std::flush
00051 #define Tsizeof(_type_) sizeof(_type_)
00052
00053
00054 typedef double Tdouble;
00055 typedef int Tint;
00056 typedef float Tfloat;
00057 typedef char Tchar;
00058 typedef long Tlong;
00059 typedef unsigned char TUchar;
00060 typedef unsigned int TUint;
00061 typedef unsigned long TUlong;
00062 typedef short Tshort;
00063 typedef unsigned short TUshort;
00064 typedef bool Tbool;
00065 typedef Tbool Tbit;
00066 typedef FILE TFileStream;
00067 typedef size_t Tsize_t;
00068 typedef void Tvoid;
00069
00070
00071 typedef std::string Tstring;
00072 typedef std::ofstream Tofstream;
00073 typedef std::ifstream Tifstream;
00074 typedef std::ostream Tostream;
00075 typedef std::ostrstream Tostrstream;
00076 typedef std::istream Tistream;
00077
00078
00079 typedef Tvector<Tint> TintList;
00080 typedef Tvector<TUint> TUintList;
00081 typedef Tvector<TUshort> TUshortList;
00082 typedef Tvector<Tdouble> TdoubleList;
00083 typedef Tvector<Tfloat> TfloatList;
00084 typedef Tvector<Tstring> TstringList;
00085
00086
00087
00088 const Tstring Tslash = "/";
00089 const Tstring Ttab = "\t";
00090 const Tstring Thour = "h";
00091 const Tstring Tmin = "m";
00092 const Tstring Tsec = "s";
00093 const Tstring Tmsec = "ms";
00094 const Tstring Tusec = "us";
00095 const Tstring Tnsec = "ns";
00096 const Tchar Tkey = '\x01';
00097
00098 enum Tobject_t {
00099 tObjectDataRecord,
00100 tObjectDataSection,
00101 tObjectDataSegment,
00102 tObjectDataElement,
00103 tObject1DHistogram,
00104 tObject2DHistogram,
00105 tObjectAppendGraph,
00106 tObjectSubstituteGraph,
00107 tObjectNtuple,
00108 tNumberOfObjectTypes,
00109 tObjectUnknown = -1
00110 };
00111
00112 enum Telement_t {
00113 tTypeInt,
00114 tTypeString,
00115 tTypeDouble,
00116 tTypeObject,
00117 tTypeFloat,
00118 tTypeUnsignedShort,
00119 tTypeShort,
00120 tTypeWord,
00121 tTypeLong,
00122 tTypeUnsignedLong,
00123 tTypeUnsignedInt,
00124 tNumberOfElementTypes,
00125 tTypeUnknown = -1
00126 };
00127
00128 enum Tstream_t {
00129 tFileStream,
00130 tSocketStream,
00131 tSharedMemoryStream,
00132 tNumberOfStreamTypes,
00133 tUnknownStream = -1
00134 };
00135
00136 enum Trandom_t {
00137 tRandomExponential,
00138 tRandomGaussian,
00139 tRandomChiSquare,
00140 tRandomLandau,
00141 tRandomGamma,
00142 tRandomPoisson,
00143 tNumberOfRandomTypes,
00144 tRandomUnknown = -1
00145 };
00146
00147 enum Tstatus_t {
00148 tStatusStandby,
00149 tStatusReady,
00150 tStatusBusy,
00151 tStatusIdle,
00152 tStatusWaitingReady,
00153 tStatusJustTakingEvent,
00154 tStatusJustRecordingEvent,
00155 tStatusSleep,
00156 tStatusDead,
00157 tNumberOfStatusTypes,
00158 tStatusUnknown = -1
00159 };
00160
00161 enum TvmeTransfer_t {
00162 tA16D16,
00163 tA16D32,
00164 tA24D16,
00165 tA24D32,
00166 tA32D16,
00167 tA32D32,
00168 tA24D16dma,
00169 tA32D16dma,
00170 tA24D32dma,
00171 tA32D32dma,
00172 tNumberOfVmeTransferModes,
00173 tTransferModeUnknown = -1
00174 };
00175
00176 enum {
00177 tIDunknown = -1
00178 };
00179
00180 const Tstring TunknownID = "unkown ID";
00181
00182
00183 inline static Tstring itostr( Tint i, Tint digits = 6 )
00184 {
00185 static const Tsize_t _buflen = 0x100;
00186 static Tchar buf[ _buflen + 1 ];
00187 Tostrstream os( buf, _buflen );
00188
00189 if ( i >= 0 ) {
00190 os << std::setfill( '0' ) << std::setiosflags( Tios::right ) << std::setw( digits );
00191 os << i << Tends;
00192 Tstring s = os.str();
00193 return s;
00194 } else {
00195 os << i << Tends;
00196 Tstring s = os.str();
00197 Tint nzero = digits - s.size();
00198 if ( nzero > 0 ) {
00199 s.insert( 1, nzero, '0' );
00200 }
00201 return s;
00202 }
00203 }
00204
00205 inline static Tstring ltostr( Tlong l, Tint digits = 6 )
00206 {
00207 static const Tsize_t _buflen = 0x100;
00208 static Tchar buf[ _buflen + 1 ];
00209 Tostrstream os( buf, _buflen );
00210
00211 if ( l >= 0 ) {
00212 os << std::setfill( '0' ) << std::setiosflags( Tios::right ) << std::setw( digits );
00213 os << l << Tends;
00214 Tstring s = os.str();
00215 return s;
00216 } else {
00217 os << l << Tends;
00218 Tstring s = os.str();
00219 Tint nzero = digits - s.size();
00220 if ( nzero > 0 ) {
00221 s.insert( 1, nzero, '0' );
00222 }
00223 return s;
00224 }
00225 }
00226
00227 inline static Tstring ultostr( TUlong ul, Tint digits = 6 )
00228 {
00229 static const Tsize_t _buflen = 0x100;
00230 static Tchar buf[ _buflen + 1 ];
00231 Tostrstream os( buf, _buflen );
00232
00233 if ( ul >= 0 ) {
00234 os << std::setfill( '0' ) << std::setiosflags( Tios::right ) << std::setw( digits );
00235 os << ul << Tends;
00236 Tstring s = os.str();
00237 return s;
00238 } else {
00239 os << ul << Tends;
00240 Tstring s = os.str();
00241 Tint nzero = digits - s.size();
00242 if ( nzero > 0 ) {
00243 s.insert( 1, nzero, '0' );
00244 }
00245 return s;
00246 }
00247 }
00248
00249 inline static Tstring dtostr( Tdouble d, Tint precision = 6 )
00250 {
00251 static const Tsize_t _buflen = 0x100;
00252 static Tchar buf[ _buflen + 1 ];
00253 Tostrstream os( buf, _buflen );
00254
00255 os << std::setprecision( precision ) << d << Tends;
00256 Tstring s = os.str();
00257 return s;
00258 }
00259
00260 inline static Tstring ftostr( Tfloat f, Tint precision = 6 )
00261 {
00262 return dtostr( (Tdouble)f, precision );
00263 }
00264
00265 #include <unistd.h>
00266
00267 inline static Tbool isexist( const Tstring& filename, Tint mode = R_OK|F_OK )
00268 {
00269 if ( access( filename.c_str(), mode ) == 0 ) {
00270 return Ttrue;
00271 } else {
00272 return Tfalse;
00273 }
00274 }
00275
00276 #include <stdlib.h>
00277 inline static Tint strtoi( const Tstring& nptr, Tchar** endptr = 0, Tint base = 0 )
00278 {
00279 return (Tint)strtol( nptr.c_str(), endptr, base );
00280 }
00281
00282 inline static Tdouble strtod( const Tstring& nptr, Tchar** endptr )
00283 {
00284 return strtod( nptr.c_str(), endptr );
00285 }
00286
00287 #include <libgen.h>
00288 inline static Tstring basename( const Tstring& path )
00289 {
00290 const Tsize_t len = path.size() + 1;
00291 Tchar* copy = new Tchar[ len ];
00292
00293 strncpy( copy, path.c_str(), len );
00294 Tchar* b = basename( copy );
00295 Tstring base( b );
00296 delete [] copy;
00297 return base;
00298 }
00299
00300 inline static Tstring dirname( const Tstring& path )
00301 {
00302 const Tsize_t len = path.size() + 1;
00303 Tchar* copy = new Tchar[ len ];
00304
00305 strncpy( copy, path.c_str(), len );
00306 Tchar* d = dirname( copy );
00307 Tstring dir( d );
00308 delete [] copy;
00309 return dir;
00310 }
00311
00312
00313 #define CLDAQ_DEBUG(m) \
00314 if ( strlen(m) ) {\
00315 Tcout << "[CLDAQ:DEBUG]: " << m << " in \"" << __PRETTY_FUNCTION__ << "\" at " << __FILE__ << " line " << __LINE__ << "." << Tendl;\
00316 } else {\
00317 Tcout << "[CLDAQ:DEBUG]: in \"" << __PRETTY_FUNCTION__ << "\" at " << __FILE__ << " line " << __LINE__ << "." << Tendl;\
00318 }
00319 #define CLDAQ_WARN(m) \
00320 if ( strlen(m) ) {\
00321 Tcerr << "[CLDAQ:WARNIG]: " << m << " in \"" << __PRETTY_FUNCTION__ << "\" at " << __FILE__ << " line " << __LINE__ << "." << Tendl;\
00322 } else {\
00323 Tcerr << "[CLDAQ:WARNIG]: in \"" << __PRETTY_FUNCTION__ << "\" at " << __FILE__ << " line " << __LINE__ << "." << Tendl;\
00324 }\
00325 perror( "[CLDAQ:WARNING]" );
00326 #define CLDAQ_EMERG(m) \
00327 if ( strlen(m) ) {\
00328 Tcerr << "[CLDAQ:EMERG]: " << m << " in \"" << __PRETTY_FUNCTION__ << "\" at " << __FILE__ << " line " << __LINE__ << "." << Tendl;\
00329 } else {\
00330 Tcerr << "[CLDAQ:EMERG]: in \"" << __PRETTY_FUNCTION__ << "\" at " << __FILE__ << " line " << __LINE__ << "." << Tendl;\
00331 }\
00332 perror( "[CLDAQ:EMERG]" );\
00333 abort();
00334 #define CLDAQ_ABORT(m) CLDAQ_EMERG(m)
00335 #define CLDAQ_EXIT(m) \
00336 if ( strlen(m) ) {\
00337 Tcerr << "[CLDAQ:EXIT]: " << m << " in \"" << __PRETTY_FUNCTION__ << "\" at " << __FILE__ << " line " << __LINE__ << "." << Tendl;\
00338 } else {\
00339 Tcerr << "[CLDAQ:EXIT]: in \"" << __PRETTY_FUNCTION__ << "\" at " << __FILE__ << " line " << __LINE__ << "." << Tendl;\
00340 }\
00341 perror( "[CLDAQ:EXIT]" );\
00342 exit(EXIT_SUCCESS);
00343
00344
00345 using namespace Tstd;
00346
00347 #endif