CHROMA
unique_id.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Generate a unique id
3  */
4 
5 #include "chromabase.h"
6 #include "util/info/unique_id.h"
7 #include <time.h>
8 
9 namespace Chroma
10 {
11  //! Return a unique id
12  /*!
13  * \ingroup info
14  *
15  * The id is return type a std::string. This gives maximal flexibility allowing
16  * the way the ID is generated to change in the future.
17  */
19  {
20  START_CODE();
21 
22  // The id is the seconds since RGE started work at JLab...
23  // Chroma certainly did not live before this date.
24  struct tm Oct_1_struct = {0};
25  time_t Oct_1_t;
26  Oct_1_struct.tm_year = 99;
27  Oct_1_struct.tm_mon = 10;
28  Oct_1_struct.tm_mday = 1;
29  Oct_1_t = mktime(&Oct_1_struct);
30  if (Oct_1_t == (time_t)-1)
31  {
32  QDPIO::cerr << __func__ << ": some error generating ID" << std::endl;
33  exit(1);
34  }
35 
36  double dd = difftime(time(NULL), Oct_1_t);
37  unsigned long int ld = (unsigned long int)(dd);
38  std::ostringstream foo;
39  foo << ld;
40 
41  END_CODE();
42 
43  return foo.str();
44  }
45 
46 } // end namespace Chroma
Primary include file for CHROMA library code.
std::string uniqueId()
Return a unique id.
Definition: unique_id.cc:18
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
START_CODE()
::std::string string
Definition: gtest.h:1979
Generate a unique id.