17#include "GaudiKernel/ISvcLocator.h"
18#include "GaudiKernel/GenericAddress.h"
19#include "GaudiKernel/StatusCode.h"
20#include "GaudiKernel/SvcFactory.h"
21#include "GaudiKernel/MsgStream.h"
22#include "GaudiKernel/SmartIF.h"
23#include "GaudiKernel/Property.h"
24#include "GaudiKernel/Bootstrap.h"
48 std::string m_criteria;
49 std::vector<int> m_runList;
50 std::vector<int> m_evtNoList;
53 IProperty* m_appMgrProperty;
56 unsigned int m_initEventNo;
57 unsigned int m_eventsP;
60 unsigned int m_eventNo;
69 const int &initRunNo,
const unsigned int &initEventNo,
70 const unsigned int &evPR);
76 return (
void*)m_pSelector;
88 m_eventNo = m_initEventNo;
89 m_runNo = m_initRunNo;
96 m_eventNo = m_initEventNo;
97 m_runNo = m_initRunNo;
102 if(m_RealizationSvc->
UseDBFlag() ==
false)
return;
103 if(m_eventNo>=(m_initEventNo + m_evtNoList[m_lumiBlockNo])){
105 m_runNo = -std::abs(m_runList[m_lumiBlockNo]);
106 m_RealizationSvc->
setRunId(m_runNo);
107 m_RealizationSvc->
setRunEvtNum(m_evtNoList[m_lumiBlockNo]);
108 m_eventNo= m_initEventNo;
125 m_pSelector(pSelector), m_firstEvent(
true), m_lumiBlockNo(0), m_initEventNo(0) {
128 SmartIF<IProperty> prpMgr(Gaudi::svcLocator());
129 if ( ! prpMgr.isValid() ) {
130 std::cout <<
"IProperty interface not found in ApplicationMgr." << std::endl;
133 m_appMgrProperty = prpMgr;
136 ISvcLocator* svcLocator = Gaudi::svcLocator();
138 StatusCode status = svcLocator->service(
"RealizationSvc", tmpReal);
139 if (!status.isSuccess())
141 std::cout <<
" Could not initialize Realization Service" << std::endl;
148 status = svcLocator->service(
"DataInfoSvc",tmpInfoSvc);
149 if (status.isSuccess()) {
150 std::cout <<
"get the DataInfoSvc" << std::endl;
151 jobInfoSvc=
dynamic_cast<DataInfoSvc *
>(tmpInfoSvc);
153 std::cout <<
"could not get the DataInfoSvc." << std::endl;
160 status = m_appMgrProperty->getProperty(
"EvtMax", sMax);
161 int EvtMax = std::atoi(sMax.c_str());
163 if(m_RealizationSvc->
UseDBFlag() ==
true) {
164 std::vector<int> totEvtNo;
166 std::vector<float> lumi;
167 std::vector<int> tmp_runList = m_RealizationSvc->
getRunList();
169 for(
unsigned int i = 0; i < tmp_runList.size(); i++)
171 float lumi_value = m_RealizationSvc->
getLuminosity(tmp_runList[i]);
172 lumi.push_back(lumi_value);
173 totLumi += lumi_value;
181 for(
unsigned int i = 0; i < lumi.size(); i++) {
183 double ratio = lumi[i]/totLumi*EvtMax;
184 evtSubNo = int (ratio);
185 if((ratio-evtSubNo) >= 0.5) evtSubNo = evtSubNo + 1;
186 totSimEvt += evtSubNo;
188 std::cout <<
"The run " <<tmp_runList[i]<<
" is not simulated, due to the luminosity is too small!" << std::endl;
192 m_evtNoList.push_back(evtSubNo);
193 m_runList.push_back(tmp_runList[i]);
194 totEvtNo.push_back(tmp_runList[i]);
195 totEvtNo.push_back(evtSubNo);
197 std::cout <<
"Total "<< evtSubNo <<
" events need to be simulated in run " <<tmp_runList[i]<< std::endl;
200 if((EvtMax - totSimEvt) != 0) {
201 unsigned int effRunSize = m_evtNoList.size();
203 m_evtNoList[effRunSize - 1] = m_evtNoList[effRunSize - 1] + (EvtMax - totSimEvt);
204 effRunSize = totEvtNo.size();
205 totEvtNo[effRunSize - 1] = totEvtNo[effRunSize - 1] + (EvtMax - totSimEvt);
206 std::cout <<
"Additional "<< EvtMax - totSimEvt <<
" events need to be simulated in run " << m_runList[m_runList.size() - 1]<< std::endl;
210 for(
unsigned int i = 0; i < lumi.size(); i++) {
212 m_evtNoList.push_back(EvtMax - totSimEvt);
213 m_runList.push_back(tmp_runList[i]);
214 totEvtNo.push_back(tmp_runList[i]);
215 totEvtNo.push_back(EvtMax - totSimEvt);
217 std::cout <<
"The max event number maybe too small, all "<< evtSubNo <<
" events need to be simulated in run " <<tmp_runList[i]<< std::endl;
222 std::cerr <<
"ERORR: " <<
"Total luminosity is ZERO, please check your run list. " << std::endl;
229 std::cerr <<
"ERORR: " <<
"Total luminosity is ZERO!!! Please check your run list. " << std::endl;
232 m_RealizationSvc->
setRunId(-std::abs(m_runList[0]));
234 m_initRunNo = -std::abs(m_runList[0]);
238 m_initRunNo = -std::abs((m_RealizationSvc->
getRunList())[0]);
243 const int &initRunNo,
244 const unsigned int &initEventNo,
245 const unsigned int &evPR):
246 m_pSelector(pSelector),
247 m_initRunNo(initRunNo), m_initEventNo(initEventNo), m_eventsP(evPR),
248 m_firstEvent(
true), m_lumiBlockNo(0) {
259 if ( riid == IEvtSelector::interfaceID() ) {
260 *ppvIf = (IEvtSelector*)
this;
264 return Service::queryInterface( riid, ppvIf );
270 Service( name, svcloc)
276 m_runNo.verifier().setLower( 0 );
277 m_eventsPerRun.verifier().setLower( 0 );
278 m_firstEventNo.verifier().setLower( 0 );
296 return StatusCode::SUCCESS;
300 MsgStream log(messageService(), name());
301 log << MSG::INFO <<
" Enter McEventSelector Initialization " << endreq;
302 StatusCode sc = Service::initialize();
303 if( sc.isSuccess() ) {
305 log << MSG::ERROR <<
"Unable to initialize service " << endreq;
309 log << MSG::INFO <<
" McEventSelector Initialized Properly ... " << endreq;
314 MsgStream log(messageService(), name());
315 log << MSG::INFO <<
"finalize" << endreq;
317 return StatusCode::SUCCESS;
323 MsgStream log(messageService(), name());
324 log << MSG::DEBUG <<
"............. Next Event ............." << endreq;
330 return StatusCode::SUCCESS;
332 MsgStream log(messageService(), name());
333 log <<
"Could not dcast to McContext" << endreq;
334 return StatusCode::FAILURE;
341 for (
int i = 0; i < jump; ++i ) {
342 StatusCode status =
next(ctxt);
343 if ( !status.isSuccess() ) {
347 return StatusCode::SUCCESS;
349 return StatusCode::FAILURE;
360 return StatusCode::SUCCESS;
362 MsgStream log(messageService(), name());
363 log <<
"Could not dcast to McContext" << endreq;
364 return StatusCode::FAILURE;
373 for (
int i = 0; i < jump; ++i ) {
375 if ( !status.isSuccess() ) {
379 return StatusCode::SUCCESS;
381 return StatusCode::FAILURE;
386 MsgStream log(messageService(), name());
388 <<
"............. Last Event Not Implemented ............."
390 return StatusCode::FAILURE;
402 return StatusCode::SUCCESS;
404 MsgStream log(messageService(), name());
405 log <<
"Could not dcast to McContext" << endreq;
406 return StatusCode::FAILURE;
414 IOpaqueAddress*& addr)
const {
423 MsgStream log(messageService(), name());
424 log << MSG::ERROR <<
"casting to a McContext" << endreq;
425 return StatusCode::FAILURE;
428 return StatusCode::SUCCESS;
435 MsgStream log(messageService(), name());
437 <<
"............. releaseContext Not Implemented ............."
440 return StatusCode::FAILURE;
447 MsgStream log(messageService(), name());
449 <<
"............. resetCriteria Not Implemented ............."
452 return StatusCode::FAILURE;
void setTotEvtNo(std::vector< int > i)
void setCriteria(const std::string &crit)
virtual ~McContext()
Standard destructor.
virtual void * identifier() const
unsigned int eventNumber() const
void setRunNumber(int runNo)
void setEventNumber(unsigned int eventNo)
McContext(const McEventSelector *pSelector)
Standard constructor.
virtual StatusCode initialize()
virtual StatusCode previous(Context &refCtxt) const
virtual StatusCode resetCriteria(const std::string &cr, Context &c) const
virtual StatusCode rewind(Context &refCtxt) const
virtual StatusCode releaseContext(Context *&refCtxt) const
McEventSelector(const std::string &name, ISvcLocator *svcloc)
virtual StatusCode finalize()
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
virtual StatusCode createAddress(const Context &refCtxt, IOpaqueAddress *&) const
virtual StatusCode createContext(Context *&refpCtxt) const
virtual StatusCode last(Context &refContext) const
virtual StatusCode next(Context &refCtxt) const
std::vector< int > getRunList()