/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/DistBoss/DistBossServer/DistBossServer-00-00-04/src/JobOptionsMgr.cxx

Go to the documentation of this file.
00001 #include "DistBossServer/JobOptionsMgr.h"
00002 
00003 #include "GaudiKernel/IMessageSvc.h"
00004 #include "GaudiKernel/ISvcLocator.h"
00005 #include "GaudiKernel/Bootstrap.h"
00006 #include "GaudiKernel/Service.h"
00007 #include "GaudiKernel/StatusCode.h"
00008 #include "GaudiKernel/Property.h"
00009 #include "GaudiKernel/Parsers.h"  //in "GaudiSvc/JobOptionsSvc"
00010 #include "JobOptionsSvc.h"  //in "GaudiSvc/JobOptionsSvc"
00011 #include <fstream>
00012 
00013 #define CheckSTATUS(msg) \
00014    if ( sc.isFailure() ) { \
00015       std::cout << "[JobOptionsMgr] " << msg << std::endl; \
00016       exit(1); \
00017    }
00018 
00019 #define MyPARSE(var) \
00020 { \
00021    sc = Gaudi::Parsers::parse(var, pprop->toString()); \
00022    if ( sc.isFailure() ) { \
00023       std::cout << "[JobOptionsMgr] Failed to parse " << #var << std::endl; \
00024       exit(1); \
00025    } \
00026 }
00027 
00028 
00029 JobOptionsMgr::JobOptionsMgr(const std::string& optname)
00030    : m_optName(optname),
00031      m_iFileType(-1),
00032      m_evtMax(10),
00033      m_dstFile("digi.root"),
00034      m_recFile("digi.root")
00035 {
00036    IService* svc;
00037    StatusCode sc = Gaudi::svcLocator()->service("JobOptionsSvc", svc);
00038    CheckSTATUS("Failed to retrieve the JobOptionsSvc");
00039    m_svc = dynamic_cast<JobOptionsSvc*>(svc);
00040 
00041    sc = m_svc->setProperty( StringProperty("TYPE", "FILE") );
00042    sc = m_svc->setProperty( StringProperty("PATH", optname) );
00043    CheckSTATUS("Failed to set the property of DistBossServer");
00044 
00045    sc = m_svc->initialize();
00046    CheckSTATUS("Failed to initialize JobOptionsSvc");
00047 
00048    const Property* pprop = getProperty("ApplicationMgr", "EvtMax");
00049    if ( pprop != NULL ) {
00050       MyPARSE( m_evtMax );
00051    }
00052    
00053    if ( (pprop = getProperty("RawDataInputSvc", "InputFiles")) != NULL ) {
00054       m_iFileType = 0;
00055       MyPARSE( m_inputFiles );
00056    }
00057    else if ( (pprop = getProperty("BesSim", "TDSFlag")) != NULL ) {
00058       m_iFileType = 1;
00059       // to be continued ...
00060    }
00061    else if ( (pprop = getProperty("EventCnvSvc", "digiRootInputFile")) != NULL ) {
00062       m_iFileType = 2;
00063       MyPARSE( m_inputFiles );
00064    }
00065    else {
00066       std::cout << "[JobOptionsMgr] Unknown Job Type!" << std::endl;
00067       exit(1);
00068    }
00069 
00070    if ( (pprop = getProperty("EventPreSelect","WriteDst")) != NULL ) {
00071       bool status;
00072       MyPARSE(status);
00073       if ( status ) {
00074          m_oFileTypes.push_back(3);
00075          if ( (pprop = getProperty("WriteDst", "digiRootOutputFile")) != NULL ) {
00076             MyPARSE( m_dstFile );
00077          }
00078       }
00079    }
00080 
00081    if ( (pprop = getProperty("EventPreSelect","WriteRec")) != NULL ) {
00082       bool status;
00083       MyPARSE(status);
00084       if ( status ) {
00085          m_oFileTypes.push_back(4);
00086          if ( (pprop = getProperty("WriteRec", "digiRootOutputFile")) != NULL ) {
00087             MyPARSE( m_recFile );
00088          }
00089       }
00090    }
00091 
00092    if ( (pprop = getProperty("NTupleSvc", "Output")) != NULL ) {
00093       m_oFileTypes.push_back(5);
00094       MyPARSE( m_tupleOpts );
00095    }
00096 
00097    if ( (pprop = getProperty("THistSvc", "Output")) != NULL ) {
00098       m_oFileTypes.push_back(6);
00099       MyPARSE( m_histOpts);
00100    }
00101 }
00102 
00103 JobOptionsMgr::~JobOptionsMgr()
00104 {
00105    StatusCode sc = m_svc->finalize();
00106    CheckSTATUS("Failed to finalize JobOptionsSvc!");
00107 }
00108 
00109 #define ignorePROPERTY(client, pname) \
00110    if ( clients[i] == client && property->name() == pname ) continue
00111 
00112 void JobOptionsMgr::clientOptsTemplate(const std::string& svrName)
00113 {
00114    //Gaudi::Parsers::Catalogue* m_clientCatalogue = new Gaudi::Parsers::Catalogue;
00115          SvcCatalog* m_clientCatalogue = new SvcCatalog;
00116 
00117    StatusCode sc;
00118 
00119    std::vector<std::string> clients = m_svc->getClients();
00120    for ( unsigned int i = 0; i < clients.size(); ++i ) {
00121       const std::vector<const Property*>* properties = m_svc->getProperties(clients[i]);
00122       for ( unsigned int j = 0; j < properties->size(); ++j ) {
00123          const Property* property = properties->at(j);
00124 
00125          ignorePROPERTY("ApplicationMgr", "EvtMax");
00126 
00127          ignorePROPERTY("RawDataInputSvc", "InputFiles");
00128          //ignorePROPERTY("BesRndmGenSvc", "RndmSeed");  //placeholder for simulation
00129          ignorePROPERTY("EventCnvSvc", "digiRootInputFile");
00130 
00131          ignorePROPERTY("WriteDst", "digiRootOutputFile");
00132          ignorePROPERTY("WriteRec", "digiRootOutputFile");
00133          //ignorePROPERTY("NTupleSvc", "Output");  //placeholder for NTupleSvc
00134          //ignorePROPERTY("THistSvc", "Output");  //placeholder for THistSvc
00135 
00136          StringProperty* tmp= new StringProperty(property->name(), property->toString());
00137          sc = m_clientCatalogue->addProperty(clients[i], tmp);
00138          if ( sc.isFailure() ) {
00139                         StringProperty* tmp2 = new StringProperty(property->name(), '"'+property->toString()+'"');
00140             m_clientCatalogue->addProperty(clients[i], tmp2);
00141          }
00142       }
00143    }
00144 
00145          StringProperty* tmpservername = new StringProperty("ServerName", '"'+svrName+'"');
00146    m_clientCatalogue->addProperty("DistBoss", tmpservername);
00147    if ( m_iFileType == 0 ) {
00148                   StringProperty* tmprunmode = new StringProperty("RunMode", "3");
00149       m_clientCatalogue->addProperty("RawDataInputSvc", tmprunmode);
00150    }
00151    //else if ( m_iFileType == 1 ) {  //placeholder for simulation
00152    //   m_clientCatalogue->addProperty("BesRndmGenSvc", "RunMode", "3");
00153    //}
00154    //else if ( m_iFileType == 2 ) {
00155    //   m_clientCatalogue->addProperty("EventCnvSvc", "RunMode", "3");
00156    //}
00157    for ( unsigned int i = 0; i < m_oFileTypes.size(); ++i ) {
00158       int type = m_oFileTypes[i];
00159       if ( type == 3 ) {
00160          m_clientCatalogue->addProperty("WriteDst", new StringProperty("RunMode", "3"));
00161       }
00162       else if ( type == 4 ) {
00163          m_clientCatalogue->addProperty("WriteRec", new StringProperty("RunMode", "3"));
00164       }
00165       //else if ( type == 5 ) {
00166       //   m_clientCatalogue->addProperty("NTupleSvc", "RunMode", "3");
00167       //}
00168       //else if ( type == 6 ) {
00169       //   m_clientCatalogue->addProperty("THistSvc", "RunMode", "3");
00170       //}
00171    }
00172 
00173    std::string client_opt_name = m_optName + ".distboss_client";
00174    std::ofstream os(client_opt_name.c_str(), std::ios::out|std::ios::trunc);
00175    if ( ! os ) {
00176       std::cout << "[JobOptionsMgr] Failed to open client_template file!" << std::endl;
00177       exit(1);
00178    }
00179 
00180    m_clientCatalogue->fillStream( os );
00181 
00182    delete m_clientCatalogue;
00183 }
00184 
00185 const Property* JobOptionsMgr::getProperty(const std::string& client, const std::string& name)
00186 {
00187    const Property* pprop = NULL;
00188 
00189    const std::vector<const Property*>* properties = m_svc->getProperties(client);
00190    if ( properties != NULL ) {
00191       for ( unsigned int i = 0; i < properties->size(); ++i ) {
00192          if ( properties->at(i)->name() == name) {
00193             pprop = properties->at(i);
00194             break;
00195          }
00196       }
00197    }
00198 
00199    return pprop;
00200 }

Generated on Tue Nov 29 22:58:02 2016 for BOSS_7.0.2 by  doxygen 1.4.7