CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/CondCore/ORA/src/PoolToken.cc

Go to the documentation of this file.
00001 #include "CondCore/ORA/interface/PoolToken.h"
00002 #include "CondCore/ORA/interface/Exception.h"
00003 #include "CondCore/ORA/interface/Guid.h"
00004 //
00005 #include <cstring>
00006 #include <cstdio>
00007 // externals
00008 #include "Reflex/Reflex.h"
00009 
00010 namespace cond {
00011   
00012   static const char* fmt_tech = "[TECH=%08X]";
00013   static const char* fmt_oid  = "[OID=%08X-%08X]";
00014   static const char* guid_null = "00000000-0000-0000-0000-000000000000";
00015     
00016   std::pair<std::string,int> parseToken( const std::string& source ){
00017     if( source.empty() ) ora::throwException("Provided token is empty.","PoolToken::parseToken");
00018     std::string tmp = source;
00019     std::pair<std::string,int> oid;
00020     oid.first = "";
00021     oid.second = -1;
00022     for(char* p1 = (char*)tmp.c_str(); p1; p1 = ::strchr(++p1,'[')) {
00023       char* p2 = ::strchr(p1, '=');
00024       char* p3 = ::strchr(p1, ']');
00025       if ( p2 && p3 )   {
00026         char* val = p2+1;
00027         if ( ::strncmp("[DB=", p1, 4) == 0 )  {
00028           *p3 = 0;
00029         } else if ( ::strncmp("[CNT=", p1, 5) == 0 )  {
00030           *p3 = 0;
00031           oid.first = val;
00032         } else if ( ::strncmp(fmt_oid, p1, 5) == 0 )  {
00033           int nn;
00034           ::sscanf(p1, fmt_oid, &nn, &oid.second);
00035         } else    {
00036           *p3 = *p2 = 0;
00037         }
00038         *p3 = ']';
00039         *p2 = '=';
00040       }
00041     }
00042     return oid;
00043   }
00044 
00045   std::string writeToken( const std::string& containerName,
00046                           int oid0,
00047                           int oid1,
00048                           const std::string& className ){
00049     std::string str = writeTokenContainerFragment( containerName, className );
00050     char text[128];
00051     ::sprintf(text, fmt_oid, oid0, oid1);
00052     str += text;
00053     return str;
00054   }
00055 
00056   std::string writeTokenContainerFragment( const std::string& containerName, 
00057                                            const std::string& className ){
00058     
00059     char buff[20];
00060     std::string clguid("");
00061     //  first lookup the class guid in the dictionary
00062     Reflex::Type containerType = Reflex::Type::ByName( className );
00063     if( containerType ){
00064       Reflex::PropertyList props = containerType.Properties();
00065       if( props.HasProperty("ClassID")){
00066         clguid = props.PropertyAsString("ClassID");
00067       }
00068     }
00069     // if not found, generate one...
00070     if( clguid.empty() ){
00071       genMD5(className,buff);
00072       Guid* gd = reinterpret_cast<Guid*>(buff);
00073       clguid = gd->toString();
00074     }
00075     int tech = 0xB01;
00076     char text[128];
00077     std::string str = "[DB="+std::string(guid_null)+"][CNT=" + containerName + "][CLID="+clguid+"]";
00078     ::sprintf(text, fmt_tech, tech);
00079     str += text;
00080     return str;
00081   }
00082 
00083 
00084 }
00085 
00086