24 #include <FairMQLogger.h>
26 #include <TGeoManager.h>
35 , fFirstInputName(
"first_input.root")
36 , fFirstInputType(
"ROOT")
37 , fSecondInputName(
"")
38 , fSecondInputType(
"ROOT")
41 , fRequestChannelName(
"data")
42 , fUpdateChannelName(
"")
47 fRequestChannelName = fConfig->GetValue<
string>(
"channel-name");
48 fUpdateChannelName = fConfig->GetValue<
string>(
"update-channel-name");
50 if (fRequestChannelName !=
"") {
53 if (fUpdateChannelName !=
"") {
60 fFirstInputName = fConfig->GetValue<
string>(
"first-input-name");
61 fFirstInputType = fConfig->GetValue<
string>(
"first-input-type");
62 fSecondInputName = fConfig->GetValue<
string>(
"second-input-name");
63 fSecondInputType = fConfig->GetValue<
string>(
"second-input-type");
64 fOutputName = fConfig->GetValue<
string>(
"output-name");
65 fOutputType = fConfig->GetValue<
string>(
"output-type");
67 if (::getenv(
"DDS_SESSION_ID")) {
68 std::string ddsSessionId = ::getenv(
"DDS_SESSION_ID");
69 if (fOutputName.length() > 5) {
70 ddsSessionId =
"." + ddsSessionId +
".root";
71 fOutputName.replace(fOutputName.length() - 5, 5, ddsSessionId.c_str());
77 if (fFirstInputName !=
"") {
78 if (fFirstInputType ==
"ROOT") {
80 par1R->
open(fFirstInputName.data(),
"UPDATE");
82 }
else if (fFirstInputType ==
"ASCII") {
84 par1A->
open(fFirstInputName.data(),
"in");
90 if (fSecondInputName !=
"") {
91 if (fSecondInputType ==
"ROOT") {
93 par2R->
open(fSecondInputName.data(),
"UPDATE");
95 }
else if (fSecondInputType ==
"ASCII") {
97 par2A->
open(fSecondInputName.data(),
"in");
103 if (fUpdateChannelName ==
"") {
104 if (fOutputName !=
"") {
105 if (fOutputType ==
"ROOT") {
107 parOut->
open(fOutputName.data());
119 string parameterName =
"";
122 string reqStr(static_cast<char*>(req->GetData()), req->GetSize());
123 LOG(info) <<
"Received parameter request from client: \"" << reqStr <<
"\"";
125 size_t pos = reqStr.rfind(
",");
126 string newParameterName = reqStr.substr(0, pos);
127 int runId = stoi(reqStr.substr(pos + 1));
128 LOG(info) <<
"Parameter name: " << newParameterName;
129 LOG(info) <<
"Run ID: " << runId;
131 LOG(info) <<
"Retrieving parameter...";
133 if (newParameterName != parameterName) {
134 parameterName = newParameterName;
139 LOG(info) <<
"Sending following parameter to the client:";
143 FairMQMessagePtr rep(NewMessage());
144 Serialize<RootSerializer>(*rep,
par);
146 if (Send(rep, fRequestChannelName, 0) < 0) {
147 LOG(
ERROR) <<
"failed sending reply";
151 LOG(
ERROR) <<
"Parameter uninitialized! Sending empty message back";
153 FairMQMessagePtr rep(NewMessage());
154 if (Send(rep, fRequestChannelName, 0) < 0) {
155 LOG(
ERROR) <<
"failed sending reply";
170 LOG(info) <<
"got process update message with size = " << update->GetSize() <<
" !";
171 if (update->GetSize() < 20) {
172 std::string repString = string(static_cast<char*>(update->GetData()), update->GetSize());
173 LOG(info) <<
"Received string " << repString <<
" !";
174 if (fNofSimDevices == 0) {
178 string messageToSend = to_string(fRunId) +
"_" + to_string(fNofSimDevices);
179 text =
new string(messageToSend);
181 LOG(info) <<
"Replying with \"" << messageToSend <<
"\"";
185 Deserialize<RootSerializer>(*update, newPar);
188 if (parDescr.find(
"RUNID") != std::string::npos) {
189 parDescr.erase(0, parDescr.find(
"RUNID") + 5);
190 runId = atoi(parDescr.data());
191 if (parDescr.find(
"RUNID") != std::string::npos) {
192 parDescr.erase(0, parDescr.find(
"RUNID") + 5);
202 text =
new string(
"SUCCESS");
204 text =
new string(
"FAIL");
209 parOut->
open(fOutputName.data());
215 FairMQMessagePtr msg(NewMessage(
216 const_cast<char*>(text->c_str()),
218 [](
void* ,
void* object) {
delete static_cast<string*
>(object); },
221 if (Send(msg, fUpdateChannelName) < 0) {
list of container factories
Bool_t open(const Text_t *fname, const Text_t *status="in")
bool ProcessUpdate(FairMQMessagePtr &, int)
void setStatic(Bool_t flag=kTRUE)
unsigned int generateId(void)
void setChanged(Bool_t flag=kTRUE)
Bool_t setSecondInput(FairParIo *)
const char * getDescription() const
virtual ~ParameterMQServer()
FairParSet * getContainer(const Text_t *)
Bool_t initContainers(Int_t runId, Int_t refId=-1, const Text_t *fileName="")
FairParRootFileIo * parOut
Bool_t addContainer(FairParSet *)
FairMQExParamsParOne * par
Bool_t setOutput(FairParIo *)
Bool_t open(const Text_t *fname, Option_t *option="READ", const Text_t *ftitle="", Int_t compress=1)
bool ProcessRequest(FairMQMessagePtr &, int)
Bool_t setFirstInput(FairParIo *)