![]() |
|
|
Generated: 8 Jan 2009 |
00001 //==================================================================== 00002 // EventSelectorDataStream.cpp 00003 //-------------------------------------------------------------------- 00004 // 00005 // Package : EventSelectorDataStream (The LHCb Event Selector Package) 00006 // 00007 // 00008 // Author : M.Frank 00009 // Created : 4/10/00 00010 // Changes : 00011 // 00012 //==================================================================== 00013 #define GAUDISVC_EVENTSELECTOR_EVENTSELECTORDATASTREAM_CPP 1 00014 // Include files 00015 #include "GaudiKernel/Tokenizer.h" 00016 #include "GaudiKernel/IService.h" 00017 #include "GaudiKernel/ISvcLocator.h" 00018 #include "GaudiKernel/IConversionSvc.h" 00019 #include "GaudiKernel/IDataManagerSvc.h" 00020 #include "GaudiKernel/IPersistencySvc.h" 00021 #include "GaudiKernel/PropertyMgr.h" 00022 #include "GaudiKernel/MsgStream.h" 00023 #include "GaudiKernel/EventSelectorDataStream.h" 00024 00025 00026 // Output friend 00027 MsgStream& operator<<(MsgStream& s, const EventSelectorDataStream& obj) { 00028 s << "Stream:" << obj.name() << " Def:" << obj.definition(); 00029 return s; 00030 } 00031 00032 // Output friend 00033 std::ostream& operator<<(std::ostream& s, const EventSelectorDataStream& obj) { 00034 s << "Stream:" << obj.name() << " Def:" << obj.definition(); 00035 return s; 00036 } 00037 00038 // Standard Constructor 00039 EventSelectorDataStream::EventSelectorDataStream(const std::string& nam, const std::string& def, ISvcLocator* svcloc) 00040 : m_refCount(0), 00041 m_pSelector(0), 00042 m_pSvcLocator(svcloc) 00043 { 00044 m_name = nam; 00045 m_definition = def; 00046 m_initialized = false; 00047 m_properties = new Properties(); 00048 } 00049 00050 // Standard Constructor 00051 EventSelectorDataStream::~EventSelectorDataStream() { 00052 setSelector(0); 00053 delete m_properties; 00054 } 00055 00056 //--- IInterface::addRef 00057 unsigned long EventSelectorDataStream::addRef() { 00058 m_refCount++; 00059 return m_refCount; 00060 } 00061 00062 //--- IInterface::release 00063 unsigned long EventSelectorDataStream::release() { 00064 unsigned long count = --m_refCount; 00065 if( count <= 0) { 00066 delete this; 00067 } 00068 return count; 00069 } 00070 00071 //--- IInterface::queryInterface 00072 StatusCode EventSelectorDataStream::queryInterface(const InterfaceID& riid, void** ppvInterface) { 00073 if ( riid == IID_IInterface ) { 00074 *ppvInterface = (IInterface*)this; 00075 } 00076 else { 00077 return NO_INTERFACE; 00078 } 00079 addRef(); 00080 return SUCCESS; 00081 } 00082 00083 // Set selector 00084 void EventSelectorDataStream::setSelector(IEvtSelector* pSelector) { 00085 if ( 0 != pSelector ) pSelector->addRef(); 00086 if ( 0 != m_pSelector ) m_pSelector->release(); 00087 m_pSelector = pSelector; 00088 } 00089 00090 // Allow access to individual properties by name 00091 StringProperty* EventSelectorDataStream::property(const std::string& nam) { 00092 for ( Properties::iterator i = m_properties->begin(); i != m_properties->end(); i++ ) { 00093 if ( (*i).name() == nam ) { 00094 return &(*i); 00095 } 00096 } 00097 return 0; 00098 } 00099 00100 // Allow access to individual properties by name 00101 const StringProperty* EventSelectorDataStream::property(const std::string& nam) const { 00102 for ( Properties::const_iterator i = m_properties->begin(); i != m_properties->end(); i++ ) { 00103 if ( (*i).name() == nam ) { 00104 return &(*i); 00105 } 00106 } 00107 return 0; 00108 } 00109 00110 // Parse input criteria 00111 StatusCode EventSelectorDataStream::initialize() { 00112 bool isData = true; 00113 std::string auth, dbtyp, item, crit, sel, svc, stmt; 00114 std::string cnt = "/Event"; 00115 std::string db = "<Unknown>"; 00116 Tokenizer tok(true); 00117 00118 IDataManagerSvc* eds; 00119 StatusCode sc = m_pSvcLocator->service("EventDataSvc", eds); 00120 if( !sc.isSuccess() ) { 00121 std::cout << "ERROR: Unable to localize interface IID_IDataManagerSvc from service EventDataSvc" 00122 << std::endl; 00123 return sc; 00124 } 00125 else { 00126 cnt = eds->rootName(); 00127 } 00128 eds->release(); 00129 m_selectorType = m_criteria = ""; 00130 m_properties->erase(m_properties->begin(), m_properties->end()); 00131 00132 tok.analyse(m_definition, " ", "", "", "=", "'", "'"); 00133 for ( Tokenizer::Items::iterator i = tok.items().begin(); i != tok.items().end(); i++ ) { 00134 long hash = -1; 00135 const std::string& tag = (*i).tag(); 00136 const std::string& val = (*i).value(); 00137 switch( ::toupper(tag[0]) ) { 00138 case 'A': 00139 auth = val; 00140 break; 00141 case 'C': 00142 svc = "EvtTupleSvc"; 00143 isData = false; 00144 case 'E': 00145 hash = val.find('#'); 00146 if ( hash > 0 ) { 00147 cnt = val.substr(0,hash); 00148 item = val.substr(hash+1, val.length()-hash-1); 00149 } 00150 else { 00151 cnt = val; 00152 item = "Address"; 00153 } 00154 break; 00155 case 'D': 00156 m_criteria = "FILE " + val; 00157 break; 00158 case 'F': 00159 switch( ::toupper(tag[1]) ) { 00160 case 'I': 00161 dbtyp = "SICB"; 00162 m_criteria = "FILE " + val; 00163 break; 00164 case 'U': 00165 stmt = val; 00166 break; 00167 default: 00168 break; 00169 } 00170 break; 00171 case 'J': 00172 m_criteria = "JOBID " + val; 00173 dbtyp = "SICB"; 00174 break; 00175 case 'T': 00176 switch( ::toupper(tag[1]) ) { 00177 case 'Y': 00178 dbtyp = val; 00179 break; 00180 case 'A': 00181 m_criteria = "TAPE " + val; 00182 dbtyp = "SICB"; 00183 break; 00184 default: 00185 break; 00186 } 00187 break; 00188 case 'S': 00189 switch( ::toupper(tag[1]) ) { 00190 case 'E': 00191 sel = val; 00192 break; 00193 case 'V': 00194 svc = val; 00195 break; 00196 default: 00197 break; 00198 } 00199 break; 00200 default: 00201 m_properties->push_back(StringProperty(tag,val)); 00202 break; 00203 } 00204 } 00205 if ( !isData ) { // Unfortunaltely options do not come in order... 00206 m_selectorType = "EventCollectionSelector"; 00207 } 00208 else if ( dbtyp == "SICB" ) { 00209 m_selectorType = "SicbEventSelector"; 00210 } 00211 else if ( dbtyp.substr(0,4) == "POOL" ) { 00212 m_selectorType = "PoolDbEvtSelector"; 00213 } 00214 else if ( svc.empty() ) { 00215 m_selectorType = "DbEvtSelector"; 00216 } 00217 else { 00218 m_selectorType = svc; 00219 } 00220 StatusCode status = StatusCode::SUCCESS; 00221 if ( svc.length() == 0 && dbtyp.length() != 0 ) { 00222 IPersistencySvc* ipers = 0; 00223 status = m_pSvcLocator->getService("EventPersistencySvc", IID_IPersistencySvc, *pp_cast<IInterface>(&ipers)); 00224 if ( status.isSuccess() ) { 00225 IConversionSvc* icnvSvc = 0; 00226 status = ipers->getService(dbtyp, icnvSvc); 00227 if ( status.isSuccess() ) { 00228 IService* isvc = 0; 00229 status = icnvSvc->queryInterface(IID_IService, pp_cast<void>(&isvc)); 00230 if ( status.isSuccess() ) { 00231 svc = isvc->name(); 00232 isvc->release(); 00233 } 00234 } 00235 } 00236 } 00237 m_properties->push_back( StringProperty("Function", stmt)); 00238 m_properties->push_back( StringProperty("CnvService", svc)); 00239 m_properties->push_back( StringProperty("Authentication",auth)); 00240 m_properties->push_back( StringProperty("Container", cnt)); 00241 m_properties->push_back( StringProperty("Item", item)); 00242 m_properties->push_back( StringProperty("Criteria", sel)); 00243 m_properties->push_back( StringProperty("DbType", dbtyp)); 00244 m_properties->push_back( StringProperty("DB", m_criteria)); 00245 m_initialized = status.isSuccess(); 00246 return status; 00247 } 00248 00249 // Parse input criteria 00250 StatusCode EventSelectorDataStream::finalize() { 00251 setSelector(0); 00252 if ( m_properties ) { 00253 m_properties->clear(); 00254 } 00255 m_initialized = false; 00256 return StatusCode::SUCCESS; 00257 }