unique_id.cc

Go to the documentation of this file.
00001 // $Id: unique_id.cc,v 1.2 2007/02/25 22:37:35 edwards Exp $
00002 /*! \file
00003  *  \brief Generate a unique id
00004  */
00005 
00006 #include "chromabase.h"
00007 #include "util/info/unique_id.h"
00008 #include <time.h>
00009 
00010 namespace Chroma 
00011 {
00012   //! Return a unique id
00013   /*!
00014    * \ingroup info
00015    *
00016    *  The id is return type a string. This gives maximal flexibility allowing
00017    *  the way the ID is generated to change in the future.
00018    */
00019   std::string uniqueId()
00020   {
00021     START_CODE();
00022 
00023     // The id is the seconds since RGE started work at JLab...
00024     // Chroma certainly did not live before this date.
00025     struct tm Oct_1_struct = {0};
00026     time_t Oct_1_t;
00027     Oct_1_struct.tm_year = 99;
00028     Oct_1_struct.tm_mon  = 10;
00029     Oct_1_struct.tm_mday = 1;
00030     Oct_1_t = mktime(&Oct_1_struct);
00031     if (Oct_1_t == (time_t)-1)
00032     {
00033       QDPIO::cerr << __func__ << ": some error generating ID" << endl;
00034       exit(1);
00035     }
00036 
00037     double dd = difftime(time(NULL), Oct_1_t);
00038     unsigned long int ld = (unsigned long int)(dd);
00039     std::ostringstream foo;
00040     foo << ld;
00041 
00042     END_CODE();
00043 
00044     return foo.str();
00045   }
00046 
00047 }  // end namespace Chroma

Generated on Sun Nov 22 04:37:56 2009 for CHROMA by  doxygen 1.4.7