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"
25#include "McEventSelector/McEventSelector.h"
26#include "McEventSelector/McAddress.h"
27#include "EventModel/EventModel.h"
28#include "RealizationSvc/RealizationSvc.h"
29#include "RealizationSvc/IRealizationSvc.h"
30#include "DataInfoSvc/DataInfoSvc.h"
31#include "DataInfoSvc/IDataInfoSvc.h"
47 std::string m_criteria;
48 std::vector<int> m_runList;
49 std::vector<int> m_evtNoList;
52 IProperty* m_appMgrProperty;
55 unsigned int m_initEventNo;
56 unsigned int m_eventsP;
59 unsigned int m_eventNo;
68 const int &initRunNo,
const unsigned int &initEventNo,
69 const unsigned int &evPR);
75 return (
void*)m_pSelector;
87 m_eventNo = m_initEventNo;
88 m_runNo = m_initRunNo;
95 m_eventNo = m_initEventNo;
96 m_runNo = m_initRunNo;
101 if(m_RealizationSvc->
UseDBFlag() ==
false)
return;
102 if(m_eventNo>=(m_initEventNo + m_evtNoList[m_lumiBlockNo])){
104 m_runNo = -std::abs(m_runList[m_lumiBlockNo]);
105 m_RealizationSvc->
setRunId(m_runNo);
106 m_RealizationSvc->
setRunEvtNum(m_evtNoList[m_lumiBlockNo]);
107 m_eventNo= m_initEventNo;
124 m_pSelector(pSelector), m_firstEvent(
true), m_lumiBlockNo(0), m_initEventNo(0) {
127 SmartIF<IProperty> prpMgr(Gaudi::svcLocator());
128 if ( ! prpMgr.isValid() ) {
129 std::cout <<
"IProperty interface not found in ApplicationMgr." << std::endl;
132 m_appMgrProperty = prpMgr;
135 ISvcLocator* svcLocator = Gaudi::svcLocator();
137 StatusCode status = svcLocator->service(
"RealizationSvc", tmpReal);
138 if (!status.isSuccess())
140 std::cout <<
" Could not initialize Realization Service" << std::endl;
147 status = svcLocator->service(
"DataInfoSvc",tmpInfoSvc);
148 if (status.isSuccess()) {
149 std::cout <<
"get the DataInfoSvc" << std::endl;
150 jobInfoSvc=
dynamic_cast<DataInfoSvc *
>(tmpInfoSvc);
152 std::cout <<
"could not get the DataInfoSvc." << std::endl;
159 status = m_appMgrProperty->getProperty(
"EvtMax", sMax);
160 int EvtMax = std::atoi(sMax.c_str());
162 if(m_RealizationSvc->
UseDBFlag() ==
true) {
163 std::vector<int> totEvtNo;
165 std::vector<float> lumi;
166 std::vector<int> tmp_runList = m_RealizationSvc->
getRunList();
168 for(
unsigned int i = 0; i < tmp_runList.size(); i++)
170 float lumi_value = m_RealizationSvc->
getLuminosity(tmp_runList[i]);
171 lumi.push_back(lumi_value);
172 totLumi += lumi_value;
180 for(
unsigned int i = 0; i < lumi.size(); i++) {
182 double ratio = lumi[i]/totLumi*EvtMax;
183 evtSubNo = int (ratio);
184 if((ratio-evtSubNo) >= 0.5) evtSubNo = evtSubNo + 1;
185 totSimEvt += evtSubNo;
187 std::cout <<
"The run " <<tmp_runList[i]<<
" is not simulated, due to the luminosity is too small!" << std::endl;
191 m_evtNoList.push_back(evtSubNo);
192 m_runList.push_back(tmp_runList[i]);
193 totEvtNo.push_back(tmp_runList[i]);
194 totEvtNo.push_back(evtSubNo);
196 std::cout <<
"Total "<< evtSubNo <<
" events need to be simulated in run " <<tmp_runList[i]<< std::endl;
199 if((EvtMax - totSimEvt) != 0) {
200 unsigned int effRunSize = m_evtNoList.size();
202 m_evtNoList[effRunSize - 1] = m_evtNoList[effRunSize - 1] + (EvtMax - totSimEvt);
203 effRunSize = totEvtNo.size();
204 totEvtNo[effRunSize - 1] = totEvtNo[effRunSize - 1] + (EvtMax - totSimEvt);
205 std::cout <<
"Additional "<< EvtMax - totSimEvt <<
" events need to be simulated in run " << m_runList[m_runList.size() - 1]<< std::endl;
209 for(
unsigned int i = 0; i < lumi.size(); i++) {
211 m_evtNoList.push_back(EvtMax - totSimEvt);
212 m_runList.push_back(tmp_runList[i]);
213 totEvtNo.push_back(tmp_runList[i]);
214 totEvtNo.push_back(EvtMax - totSimEvt);
216 std::cout <<
"The max event number maybe too small, all "<< evtSubNo <<
" events need to be simulated in run " <<tmp_runList[i]<< std::endl;
221 std::cerr <<
"ERORR: " <<
"Total luminosity is ZERO, please check your run list. " << std::endl;
228 std::cerr <<
"ERORR: " <<
"Total luminosity is ZERO!!! Please check your run list. " << std::endl;
231 m_RealizationSvc->
setRunId(-std::abs(m_runList[0]));
233 m_initRunNo = -std::abs(m_runList[0]);
237 m_initRunNo = -std::abs((m_RealizationSvc->
getRunList())[0]);
242 const int &initRunNo,
243 const unsigned int &initEventNo,
244 const unsigned int &evPR):
245 m_pSelector(pSelector),
246 m_initRunNo(initRunNo), m_initEventNo(initEventNo), m_eventsP(evPR),
247 m_firstEvent(
true), m_lumiBlockNo(0) {
258 if ( riid == IEvtSelector::interfaceID() ) {
259 *ppvIf = (IEvtSelector*)
this;
263 return Service::queryInterface( riid, ppvIf );
269 Service( name, svcloc)
275 m_runNo.verifier().setLower( 0 );
276 m_eventsPerRun.verifier().setLower( 0 );
277 m_firstEventNo.verifier().setLower( 0 );
295 return StatusCode::SUCCESS;
299 MsgStream log(messageService(), name());
300 log << MSG::INFO <<
" Enter McEventSelector Initialization " << endreq;
301 StatusCode sc = Service::initialize();
302 if( sc.isSuccess() ) {
304 log << MSG::ERROR <<
"Unable to initialize service " << endreq;
308 log << MSG::INFO <<
" McEventSelector Initialized Properly ... " << endreq;
313 MsgStream log(messageService(), name());
314 log << MSG::INFO <<
"finalize" << endreq;
316 return StatusCode::SUCCESS;
322 MsgStream log(messageService(), name());
323 log << MSG::DEBUG <<
"............. Next Event ............." << endreq;
329 return StatusCode::SUCCESS;
331 MsgStream log(messageService(), name());
332 log <<
"Could not dcast to McContext" << endreq;
333 return StatusCode::FAILURE;
340 for (
int i = 0; i < jump; ++i ) {
341 StatusCode status =
next(ctxt);
342 if ( !status.isSuccess() ) {
346 return StatusCode::SUCCESS;
348 return StatusCode::FAILURE;
359 return StatusCode::SUCCESS;
361 MsgStream log(messageService(), name());
362 log <<
"Could not dcast to McContext" << endreq;
363 return StatusCode::FAILURE;
372 for (
int i = 0; i < jump; ++i ) {
374 if ( !status.isSuccess() ) {
378 return StatusCode::SUCCESS;
380 return StatusCode::FAILURE;
385 MsgStream log(messageService(), name());
387 <<
"............. Last Event Not Implemented ............."
389 return StatusCode::FAILURE;
401 return StatusCode::SUCCESS;
403 MsgStream log(messageService(), name());
404 log <<
"Could not dcast to McContext" << endreq;
405 return StatusCode::FAILURE;
413 IOpaqueAddress*& addr)
const {
422 MsgStream log(messageService(), name());
423 log << MSG::ERROR <<
"casting to a McContext" << endreq;
424 return StatusCode::FAILURE;
427 return StatusCode::SUCCESS;
434 MsgStream log(messageService(), name());
436 <<
"............. releaseContext Not Implemented ............."
439 return StatusCode::FAILURE;
446 MsgStream log(messageService(), name());
448 <<
"............. resetCriteria Not Implemented ............."
451 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()