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 
15  std::pair<std::string,int> parseToken( const std::string& source ){
16  if( source.empty() ) ora::throwException("Provided token is empty.","PoolToken::parseToken");
18  std::pair<std::string,int> oid;
19  oid.first = "";
20  oid.second = -1;
21  for(char* p1 = (char*)tmp.c_str(); p1; p1 = ::strchr(++p1,'[')) {
22  char* p2 = ::strchr(p1, '=');
23  char* p3 = ::strchr(p1, ']');
24  if ( p2 && p3 ) {
25  char* val = p2+1;
26  if ( ::strncmp("[DB=", p1, 4) == 0 ) {
27  *p3 = 0;
28  } else if ( ::strncmp("[CNT=", p1, 5) == 0 ) {
29  *p3 = 0;
30  oid.first = val;
31  } else if ( ::strncmp(fmt_oid, p1, 5) == 0 ) {
32  int nn;
33  ::sscanf(p1, fmt_oid, &nn, &oid.second);
34  } else {
35  *p3 = *p2 = 0;
36  }
37  *p3 = ']';
38  *p2 = '=';
39  }
40  }
41  return oid;
42  }
43 
44  std::string writeToken( const std::string& containerName,
45  int oid0,
46  int oid1,
47  const std::string& className ){
48  std::string str = writeTokenContainerFragment( containerName, className );
49  char text[128];
50  ::sprintf(text, fmt_oid, oid0, oid1);
51  str += text;
52  return str;
53  }
54 
56  const std::string& className ){
57 
58  char buff[20];
59  std::string clguid("");
60  // first lookup the class guid in the dictionary
61  Reflex::Type containerType = Reflex::Type::ByName( className );
62  if( containerType ){
63  Reflex::PropertyList props = containerType.Properties();
64  if( props.HasProperty("ClassID")){
65  clguid = props.PropertyAsString("ClassID");
66  }
67  }
68  // if not found, generate one...
69  if( clguid.empty() ){
70  genMD5(className,buff);
71  Guid* gd = reinterpret_cast<Guid*>(buff);
72  clguid = gd->toString();
73  }
74  int tech = 0xB01;
75  char text[128];
76  std::string str = "[DB="+Guid::null()+"][CNT=" + containerName + "][CLID="+clguid+"]";
77  ::sprintf(text, fmt_tech, tech);
78  str += text;
79  return str;
80  }
81 
82 
83 }
84 
85 
std::string toString() const
Definition: Guid.cc:27
static std::string null()
Definition: Guid.cc:11
std::pair< std::string, int > parseToken(const std::string &objectId)
Definition: PoolToken.cc:15
static const char * fmt_oid
Definition: PoolToken.cc:13
std::string writeTokenContainerFragment(const std::string &containerName, const std::string &className)
Definition: PoolToken.cc:55
static const char * fmt_tech
Definition: PoolToken.cc:12
void * genMD5(void *buffer, unsigned long len, void *code)
Definition: GenMD5.cc:358
tuple text
Definition: runonSM.py:42
double p2[4]
Definition: TauolaWrapper.h:90
Definition: Guid.h:10
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:44
double p3[4]
Definition: TauolaWrapper.h:91