CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PoolToken.cc
Go to the documentation of this file.
4 //
5 #include <cstring>
6 #include <cstdio>
7 // externals
8 #include "Reflex/Reflex.h"
9 
10 namespace cond {
11 
12  static const char* fmt_tech = "[TECH=%08X]";
13  static const char* fmt_oid = "[OID=%08X-%08X]";
14  static const char* guid_null = "00000000-0000-0000-0000-000000000000";
15 
16  std::pair<std::string,int> parseToken( const std::string& source ){
17  if( source.empty() ) ora::throwException("Provided token is empty.","PoolToken::parseToken");
18  std::string tmp = source;
19  std::pair<std::string,int> oid;
20  oid.first = "";
21  oid.second = -1;
22  for(char* p1 = (char*)tmp.c_str(); p1; p1 = ::strchr(++p1,'[')) {
23  char* p2 = ::strchr(p1, '=');
24  char* p3 = ::strchr(p1, ']');
25  if ( p2 && p3 ) {
26  char* val = p2+1;
27  if ( ::strncmp("[DB=", p1, 4) == 0 ) {
28  *p3 = 0;
29  } else if ( ::strncmp("[CNT=", p1, 5) == 0 ) {
30  *p3 = 0;
31  oid.first = val;
32  } else if ( ::strncmp(fmt_oid, p1, 5) == 0 ) {
33  int nn;
34  ::sscanf(p1, fmt_oid, &nn, &oid.second);
35  } else {
36  *p3 = *p2 = 0;
37  }
38  *p3 = ']';
39  *p2 = '=';
40  }
41  }
42  return oid;
43  }
44 
45  std::string writeToken( const std::string& containerName,
46  int oid0,
47  int oid1,
48  const std::string& className ){
49  std::string str = writeTokenContainerFragment( containerName, className );
50  char text[128];
51  ::sprintf(text, fmt_oid, oid0, oid1);
52  str += text;
53  return str;
54  }
55 
56  std::string writeTokenContainerFragment( const std::string& containerName,
57  const std::string& className ){
58 
59  char buff[20];
60  std::string clguid("");
61  // first lookup the class guid in the dictionary
62  Reflex::Type containerType = Reflex::Type::ByName( className );
63  if( containerType ){
64  Reflex::PropertyList props = containerType.Properties();
65  if( props.HasProperty("ClassID")){
66  clguid = props.PropertyAsString("ClassID");
67  }
68  }
69  // if not found, generate one...
70  if( clguid.empty() ){
71  genMD5(className,buff);
72  Guid* gd = reinterpret_cast<Guid*>(buff);
73  clguid = gd->toString();
74  }
75  int tech = 0xB01;
76  char text[128];
77  std::string str = "[DB="+std::string(guid_null)+"][CNT=" + containerName + "][CLID="+clguid+"]";
78  ::sprintf(text, fmt_tech, tech);
79  str += text;
80  return str;
81  }
82 
83 
84 }
85 
86 
std::string toString() const
Definition: Guid.h:16
std::pair< std::string, int > parseToken(const std::string &objectId)
Definition: PoolToken.cc:16
static const char * fmt_oid
Definition: PoolToken.cc:13
std::string writeTokenContainerFragment(const std::string &containerName, const std::string &className)
Definition: PoolToken.cc:56
static const char * fmt_tech
Definition: PoolToken.cc:12
void * genMD5(void *buffer, unsigned long len, void *code)
Definition: GenMD5.cc:358
static const char * guid_null
Definition: PoolToken.cc:14
tuple text
Definition: runonSM.py:42
double p2[4]
Definition: TauolaWrapper.h:90
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
double p1[4]
Definition: TauolaWrapper.h:89
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
char const * className(const std::type_info &t)
Definition: ClassID.cc:8
std::string writeToken(const std::string &containerName, int oid0, int oid1, const std::string &className)
Definition: PoolToken.cc:45
double p3[4]
Definition: TauolaWrapper.h:91