| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EventSelectorDataStream.cpp
Go to the documentation of this file.
1 //====================================================================
2 // EventSelectorDataStream.cpp
3 //--------------------------------------------------------------------
4 //
5 // Package : EventSelectorDataStream (The LHCb Event Selector Package)
6 //
7 //
8 // Author : M.Frank
9 // Created : 4/10/00
10 // Changes : R. Lambert 2009-09-04
11 //
12 //====================================================================
13 #define GAUDISVC_EVENTSELECTOR_EVENTSELECTORDATASTREAM_CPP 1
14 // Include files
15 #include "GaudiKernel/Tokenizer.h"
16 #include "GaudiKernel/IService.h"
17 #include "GaudiKernel/ISvcLocator.h"
18 #include "GaudiKernel/IConversionSvc.h"
19 #include "GaudiKernel/IDataManagerSvc.h"
20 #include "GaudiKernel/IPersistencySvc.h"
21 #include "GaudiKernel/PropertyMgr.h"
22 #include "GaudiKernel/MsgStream.h"
23 #include "GaudiKernel/EventSelectorDataStream.h"
24
25
26 // Output friend
27 MsgStream& operator<<(MsgStream& s, const EventSelectorDataStream& obj) {
28 s << "Stream:" << obj.name() << " Def:" << obj.definition();
29 return s;
30 }
31
32 // Output friend
33 std::ostream& operator<<(std::ostream& s, const EventSelectorDataStream& obj) {
34 s << "Stream:" << obj.name() << " Def:" << obj.definition();
35 return s;
36 }
37
38 // Standard Constructor
39 EventSelectorDataStream::EventSelectorDataStream(const std::string& nam, const std::string& def, ISvcLocator* svcloc)
40 : m_pSelector(0),
41 m_pSvcLocator(svcloc)
42 {
43 m_name = nam;
44 m_definition = def;
45 m_initialized = false;
46 m_properties = new Properties();
47 }
48
49 // Standard Constructor
50 EventSelectorDataStream::~EventSelectorDataStream() {
51 setSelector(0);
52 delete m_properties;
53 }
54
55 // Set selector
56 void EventSelectorDataStream::setSelector(IEvtSelector* pSelector) {
57 if ( 0 != pSelector ) pSelector->addRef();
58 if ( 0 != m_pSelector ) m_pSelector->release();
59 m_pSelector = pSelector;
60 }
61
62 // Allow access to individual properties by name
63 StringProperty* EventSelectorDataStream::property(const std::string& nam) {
64 for ( Properties::iterator i = m_properties->begin(); i != m_properties->end(); i++ ) {
65 if ( (*i).name() == nam ) {
66 return &(*i);
67 }
68 }
69 return 0;
70 }
71
72 // Allow access to individual properties by name
73 const StringProperty* EventSelectorDataStream::property(const std::string& nam) const {
74 for ( Properties::const_iterator i = m_properties->begin(); i != m_properties->end(); i++ ) {
75 if ( (*i).name() == nam ) {
76 return &(*i);
77 }
78 }
79 return 0;
80 }
81
82 // Parse input criteria
83 StatusCode EventSelectorDataStream::initialize() {
84 bool isData = true;
85 std::string auth, dbtyp, collsvc, item, crit, sel, svc, stmt;
86 std::string cnt = "/Event";
87 std::string db = "<Unknown>";
88 Tokenizer tok(true);
89
90 SmartIF<IDataManagerSvc> eds(m_pSvcLocator->service("EventDataSvc"));
91 if( !eds.isValid() ) {
92 std::cout << "ERROR: Unable to localize interface IDataManagerSvc from service EventDataSvc"
93 << std::endl;
94 return StatusCode::FAILURE;
95 }
96 else {
97 cnt = eds->rootName();
98 }
99 m_selectorType = m_criteria = m_dbName= "";
100 m_properties->erase(m_properties->begin(), m_properties->end());
101
102 tok.analyse(m_definition, " ", "", "", "=", "'", "'");
103 for ( Tokenizer::Items::iterator i = tok.items().begin(); i != tok.items().end(); i++ ) {
104 long hash = -1;
105 const std::string& tag = (*i).tag();
106 const std::string& val = (*i).value();
107 switch( ::toupper(tag[0]) ) {
108 case 'A':
109 auth = val;
110 break;
111 case 'C':
112 svc = "EvtTupleSvc";
113 isData = false;
114 case 'E':
115 hash = val.find('#');
116 if ( hash > 0 ) {
117 cnt = val.substr(0,hash);
118 item = val.substr(hash+1, val.length()-hash-1);
119 }
120 else {
121 cnt = val;
122 item = "Address";
123 }
124 break;
125 case 'D':
126 m_criteria = "FILE " + val;
127 m_dbName=val;
128 break;
129 case 'F':
130 switch( ::toupper(tag[1]) ) {
131 case 'I':
132 m_criteria = "FILE " + val;
133 m_dbName=val;
134 break;
135 case 'U':
136 stmt = val;
137 break;
138 default:
139 break;
140 }
141 break;
142 case 'J':
143 m_criteria = "JOBID " + val;
144 m_dbName=val;
145 dbtyp = "SICB";
146 break;
147 case 'T':
148 switch( ::toupper(tag[1]) ) {
149 case 'Y':
150 dbtyp = val;
151 break;
152 default:
153 break;
154 }
155 break;
156 case 'S':
157 switch( ::toupper(tag[1]) ) {
158 case 'E':
159 sel = val;
160 break;
161 case 'V':
162 svc = val;
163 collsvc = val;
164 break;
165 default:
166 break;
167 }
168 break;
169 default:
170 m_properties->push_back(StringProperty(tag,val));
171 break;
172 }
173 }
174 if ( !isData ) { // Unfortunately options do not come in order...
175 m_selectorType = "EventCollectionSelector";
176 svc = "EvtTupleSvc";
177 }
178 else if ( dbtyp.substr(0,4) == "POOL" ) {
179 m_selectorType = "PoolDbEvtSelector";
180 }
181 else if ( svc.empty() ) {
182 m_selectorType = "DbEvtSelector";
183 }
184 else {
185 m_selectorType = svc;
186 }
187 StatusCode status = StatusCode::SUCCESS;
188 if ( svc.length() == 0 && dbtyp.length() != 0 ) {
189 SmartIF<IPersistencySvc> ipers(m_pSvcLocator->service("EventPersistencySvc"));
190 if ( ipers.isValid() ) {
191 IConversionSvc* icnvSvc = 0;
192 status = ipers->getService(dbtyp, icnvSvc);
193 if ( status.isSuccess() ) {
194 IService* isvc = 0;
195 status = icnvSvc->queryInterface(IService::interfaceID(), pp_cast<void>(&isvc));
196 if ( status.isSuccess() ) {
197 svc = isvc->name();
198 isvc->release();
199 }
200 }
201 }
202 }
203 m_properties->push_back( StringProperty("Function", stmt));
204 m_properties->push_back( StringProperty("CnvService", svc));
205 m_properties->push_back( StringProperty("Authentication",auth));
206 m_properties->push_back( StringProperty("Container", cnt));
207 m_properties->push_back( StringProperty("Item", item));
208 m_properties->push_back( StringProperty("Criteria", sel));
209 m_properties->push_back( StringProperty("DbType", dbtyp));
210 m_properties->push_back( StringProperty("DB", m_criteria));
211 if ( !isData && !collsvc.empty() ) {
212 m_properties->push_back( StringProperty("DbService", collsvc));
213 }
214
215 m_initialized = status.isSuccess();
216 return status;
217 }
218
219 // Parse input criteria
220 StatusCode EventSelectorDataStream::finalize() {
221 setSelector(0);
222 if ( m_properties ) {
223 m_properties->clear();
224 }
225 m_initialized = false;
226 return StatusCode::SUCCESS;
227 }