mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 00:31:14 +00:00
a) move the XML parser into the FairMQ/options/FairMQParser.h b) add a routine in FairMQProgOption to check whether the necessary XML or JSON input files are there, and send an error message if not there - Policy based devices: a) rename GenericSampler to base_GenericSampler and use an alias template named GenericSampler b) in base_GenericSampler, rename template parameter to simple variables <T,U,… > and use typedef for clarity c) introduce an anonymous function container in the base_GenericSampler host class with a register task template member function and an Executetasks() d) add two new template parameters in base_GenericSampler for the anonymous function container map. parameter is K for the key type (default=int) and L for the value type (default=std::function<void()>) - Tutorial7: a) use FairMQProgOption to configure devices in tutorial7 b) introduce several template functions helper in tutorial7 to reduce code redundancy c) show examples in tutorial7 of task registration with callback and lambda expression for the sampler devices d) separate the executable build of the tutorial7 data generator to remove the Roofit banner when executing the MQdevices
204 lines
5.6 KiB
Smarty
204 lines
5.6 KiB
Smarty
/*
|
|
* File: GenericSampler.tpl
|
|
* Author: winckler
|
|
*
|
|
* Created on November 24, 2014, 3:59 PM
|
|
*/
|
|
|
|
template <typename T, typename U, typename K, typename L>
|
|
base_GenericSampler<T,U,K,L>::base_GenericSampler()
|
|
: fOutChanName("data-out")
|
|
, fNumEvents(0)
|
|
, fCurrentIdx(0)
|
|
, fEventRate(1)
|
|
, fEventCounter(0)
|
|
, fContinuous(false)
|
|
{
|
|
}
|
|
|
|
template <typename T, typename U, typename K, typename L>
|
|
base_GenericSampler<T,U,K,L>::~base_GenericSampler()
|
|
{
|
|
}
|
|
|
|
template <typename T, typename U, typename K, typename L>
|
|
void base_GenericSampler<T,U,K,L>::SetTransport(FairMQTransportFactory* factory)
|
|
{
|
|
FairMQDevice::SetTransport(factory);
|
|
}
|
|
|
|
template <typename T, typename U, typename K, typename L>
|
|
void base_GenericSampler<T,U,K,L>::InitTask()
|
|
{
|
|
BindingSendPart();
|
|
BindingGetSocketNumber();
|
|
BindingGetCurrentIndex();
|
|
|
|
source_type::InitSampler();
|
|
fNumEvents = source_type::GetNumberOfEvent();
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T, typename U, typename K, typename L>
|
|
void base_GenericSampler<T,U,K,L>::Run()
|
|
{
|
|
// boost::thread resetEventCounter(boost::bind(&GenericSampler::ResetEventCounter, this));
|
|
|
|
int sentMsgs = 0;
|
|
|
|
boost::timer::auto_cpu_timer timer;
|
|
|
|
LOG(INFO) << "Number of events to process: " << fNumEvents;
|
|
|
|
do {
|
|
for (fCurrentIdx = 0; fCurrentIdx < fNumEvents; fCurrentIdx++)
|
|
{
|
|
for(auto& p : fChannels[fOutChanName])
|
|
{
|
|
FairMQMessage* msg = fTransportFactory->CreateMessage();
|
|
serialization_type::SetMessage(msg);
|
|
source_type::SetIndex(fCurrentIdx);
|
|
ExecuteTasks();
|
|
p.Send(serialization_type::SerializeMsg(source_type::GetOutData()));
|
|
if (msg)
|
|
msg->CloseMessage();
|
|
sentMsgs++;
|
|
|
|
if(fChannels[fOutChanName].size()>1)
|
|
fCurrentIdx++;
|
|
|
|
// Optional event rate limiting
|
|
// --fEventCounter;
|
|
// while (fEventCounter == 0) {
|
|
// boost::this_thread::sleep(boost::posix_time::milliseconds(1));
|
|
// }
|
|
|
|
if (GetCurrentState() != RUNNING)
|
|
break;
|
|
}
|
|
// if more than one socket, remove the last incrementation
|
|
if(fChannels[fOutChanName].size()>1)
|
|
fCurrentIdx--;
|
|
}
|
|
}
|
|
while ( GetCurrentState() == RUNNING && fContinuous );
|
|
|
|
boost::timer::cpu_times const elapsed_time(timer.elapsed());
|
|
LOG(INFO) << "Sent everything in:\n" << boost::timer::format(elapsed_time, 2);
|
|
LOG(INFO) << "Sent " << sentMsgs << " messages!";
|
|
}
|
|
|
|
|
|
template <typename T, typename U, typename K, typename L>
|
|
void base_GenericSampler<T,U,K,L>::SendPart(int socketIdx)
|
|
{
|
|
fCurrentIdx++;
|
|
if(fCurrentIdx<fNumEvents)
|
|
{
|
|
FairMQMessage* msg = fTransportFactory->CreateMessage();
|
|
serialization_type::SetMessage(msg);
|
|
source_type::SetIndex(fCurrentIdx);
|
|
fChannels[fOutChanName].at(socketIdx).Send(serialization_type::SerializeMsg(source_type::GetOutData()), "snd-more");
|
|
if (msg)
|
|
msg->CloseMessage();
|
|
}
|
|
}
|
|
|
|
|
|
template <typename T, typename U, typename K, typename L>
|
|
int base_GenericSampler<T,U,K,L>::GetSocketNumber() const
|
|
{
|
|
return fChannels.at(fOutChanName).size();
|
|
}
|
|
|
|
template <typename T, typename U, typename K, typename L>
|
|
int base_GenericSampler<T,U,K,L>::GetCurrentIndex() const
|
|
{
|
|
return fCurrentIdx;
|
|
}
|
|
|
|
template <typename T, typename U, typename K, typename L>
|
|
void base_GenericSampler<T,U,K,L>::SetContinuous(bool flag)
|
|
{
|
|
fContinuous = flag;
|
|
}
|
|
|
|
template <typename T, typename U, typename K, typename L>
|
|
void base_GenericSampler<T,U,K,L>::ResetEventCounter()
|
|
{
|
|
while (GetCurrentState() == RUNNING)
|
|
{
|
|
try
|
|
{
|
|
fEventCounter = fEventRate / 100;
|
|
boost::this_thread::sleep(boost::posix_time::milliseconds(10));
|
|
}
|
|
catch (boost::thread_interrupted &)
|
|
{
|
|
LOG(DEBUG) << "resetEventCounter interrupted";
|
|
break;
|
|
}
|
|
}
|
|
LOG(DEBUG) << ">>>>>>> stopping resetEventCounter <<<<<<<";
|
|
}
|
|
|
|
template <typename T, typename U, typename K, typename L>
|
|
void base_GenericSampler<T,U,K,L>::SetProperty(const int key, const int value)
|
|
{
|
|
switch (key)
|
|
{
|
|
case EventRate:
|
|
fEventRate = value;
|
|
break;
|
|
default:
|
|
FairMQDevice::SetProperty(key, value);
|
|
break;
|
|
}
|
|
}
|
|
|
|
template <typename T, typename U, typename K, typename L>
|
|
int base_GenericSampler<T,U,K,L>::GetProperty(const int key, const int default_/*= 0*/)
|
|
{
|
|
switch (key)
|
|
{
|
|
case EventRate:
|
|
return fEventRate;
|
|
default:
|
|
return FairMQDevice::GetProperty(key, default_);
|
|
}
|
|
}
|
|
|
|
template <typename T, typename U, typename K, typename L>
|
|
void base_GenericSampler<T,U,K,L>::SetProperty(const int key, const std::string& value)
|
|
{
|
|
switch (key)
|
|
{
|
|
case OutChannelName:
|
|
fOutChanName = value;
|
|
break;
|
|
default:
|
|
FairMQDevice::SetProperty(key, value);
|
|
break;
|
|
}
|
|
}
|
|
|
|
template <typename T, typename U, typename K, typename L>
|
|
std::string base_GenericSampler<T,U,K,L>::GetProperty(const int key, const std::string& default_)
|
|
{
|
|
switch (key)
|
|
{
|
|
case OutChannelName:
|
|
return fOutChanName;
|
|
default:
|
|
return FairMQDevice::GetProperty(key, default_);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template<typename T, typename U>
|
|
using GenericSampler = base_GenericSampler<T,U,int,std::function<void()> >;
|
|
typedef std::map<int, std::function<void()> > SamplerTasksMap;
|