CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/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     
00015   std::pair<std::string,int> parseToken( const std::string& source ){
00016     if( source.empty() ) ora::throwException("Provided token is empty.","PoolToken::parseToken");
00017     std::string tmp = source;
00018     std::pair<std::string,int> oid;
00019     oid.first = "";
00020     oid.second = -1;
00021     for(char* p1 = (char*)tmp.c_str(); p1; p1 = ::strchr(++p1,'[')) {
00022       char* p2 = ::strchr(p1, '=');
00023       char* p3 = ::strchr(p1, ']');
00024       if ( p2 && p3 )   {
00025         char* val = p2+1;
00026         if ( ::strncmp("[DB=", p1, 4) == 0 )  {
00027           *p3 = 0;
00028         } else if ( ::strncmp("[CNT=", p1, 5) == 0 )  {
00029           *p3 = 0;
00030           oid.first = val;
00031         } else if ( ::strncmp(fmt_oid, p1, 5) == 0 )  {
00032           int nn;
00033           ::sscanf(p1, fmt_oid, &nn, &oid.second);
00034         } else    {
00035           *p3 = *p2 = 0;
00036         }
00037         *p3 = ']';
00038         *p2 = '=';
00039       }
00040     }
00041     return oid;
00042   }
00043 
00044   std::string writeToken( const std::string& containerName,
00045                           int oid0,
00046                           int oid1,
00047                           const std::string& className ){
00048     std::string str = writeTokenContainerFragment( containerName, className );
00049     char text[128];
00050     ::sprintf(text, fmt_oid, oid0, oid1);
00051     str += text;
00052     return str;
00053   }
00054 
00055   std::string writeTokenContainerFragment( const std::string& containerName, 
00056                                            const std::string& className ){
00057     
00058     char buff[20];
00059     std::string clguid("");
00060     //  first lookup the class guid in the dictionary
00061     Reflex::Type containerType = Reflex::Type::ByName( className );
00062     if( containerType ){
00063       Reflex::PropertyList props = containerType.Properties();
00064       if( props.HasProperty("ClassID")){
00065         clguid = props.PropertyAsString("ClassID");
00066       }
00067     }
00068     // if not found, generate one...
00069     if( clguid.empty() ){
00070       genMD5(className,buff);
00071       Guid* gd = reinterpret_cast<Guid*>(buff);
00072       clguid = gd->toString();
00073     }
00074     int tech = 0xB01;
00075     char text[128];
00076     std::string str = "[DB="+Guid::null()+"][CNT=" + containerName + "][CLID="+clguid+"]";
00077     ::sprintf(text, fmt_tech, tech);
00078     str += text;
00079     return str;
00080   }
00081 
00082 
00083 }
00084 
00085