27 #include <FairMQLogger.h>
28 #include <FairMQMessage.h>
29 #include <TClonesArray.h>
30 #include <TCollection.h>
32 #include <TObjArray.h>
34 #include <TVirtualMC.h>
45 , fTransportDeviceId(0)
46 , fGeneratorChannelName(
"primariesChannel")
47 , fRunConditional(false)
48 , fRunInitialized(false)
51 , fMCApplication(nullptr)
54 , fTransportName(
"TGeant3")
56 , fMagneticField(nullptr)
57 , fDetectorArray(nullptr)
58 , fStoreTrajFlag(false)
60 , fFirstParameter(nullptr)
61 , fSecondParameter(nullptr)
63 , fMCSplitEventHeader(nullptr)
82 if (fFirstParameter || fSecondParameter) {
90 fRunSim->SetName(fTransportName.data());
92 if (fUserConfig.Length() > 0)
94 if (fUserCuts.Length() > 0)
105 for (
int idet = 0; idet < fDetectorArray->GetEntries(); idet++) {
106 fRunSim->
AddModule(dynamic_cast<FairModule*>(fDetectorArray->At(idet)));
109 std::vector<std::string> detectorLibraries = fConfig->GetValue<std::vector<std::string>>(
"detector-library");
111 for (
unsigned int ilib = 0; ilib < detectorLibraries.size(); ilib++) {
112 LOG(info) <<
" -----> library \"" << detectorLibraries.at(ilib) <<
"\"";
114 void* handle = dlopen(detectorLibraries.at(ilib).c_str(), RTLD_LAZY);
117 LOG(fatal) <<
"Cannot open library: " << dlerror();
122 LOG(info) <<
"Loading symbol ...";
123 typedef void (*det_t)();
128 const char* dlsym_error = dlerror();
130 LOG(fatal) <<
"Cannot load symbol 'ExternCreateDetector': " << dlsym_error;
139 LOG(info) <<
"NOT closing library...";
151 std::string* askForRunNumber =
new string(
"ReportSimDevice");
152 FairMQMessagePtr req(NewMessage(
153 const_cast<char*>(askForRunNumber->c_str()),
154 askForRunNumber->length(),
155 [](
void* ,
void* object) {
delete static_cast<string*
>(object); },
157 FairMQMessagePtr rep(NewMessage());
159 if (Send(req, fUpdateChannelName) > 0) {
160 if (Receive(rep, fUpdateChannelName) > 0) {
161 std::string repString = string(static_cast<char*>(rep->GetData()), rep->GetSize());
162 LOG(info) <<
" -> " << repString.data();
163 fRunId = stoi(repString);
164 fMCSplitEventHeader->
SetRunID(fRunId);
165 repString = repString.substr(repString.find_first_of(
'_') + 1, repString.length());
166 fTransportDeviceId = stoi(repString);
167 LOG(info) <<
"runId = " << fRunId <<
" /// fTransportDeviceId = " << fTransportDeviceId;
175 for (
int itask = 0; itask < fTaskArray->GetEntries(); itask++) {
176 fRunSim->
AddTask(dynamic_cast<FairTask*>(fTaskArray->At(itask)));
184 fVMC = TVirtualMC::GetMC();
186 fStack = fMCApplication->
GetStack();
189 UpdateParameterServer();
191 LOG(info) <<
" name/title/classname = " << fRunSim->
GetMCEventHeader()->GetName() <<
"/"
194 fRunInitialized =
true;
199 if (!fRunInitialized) {
206 if (!fRunConditional)
209 std::string* requestString =
new string(
"RequestData");
210 FairMQMessagePtr req(NewMessage(
211 const_cast<char*>(requestString->c_str()),
212 requestString->length(),
213 [](
void* ,
void* object) {
delete static_cast<string*
>(object); },
218 if (Send(req, fGeneratorChannelName) > 0) {
219 if (Receive(parts, fGeneratorChannelName) > 0) {
238 TClonesArray* chunk =
nullptr;
240 for (
int ipart = 0; ipart < mParts.Size(); ipart++) {
241 TObject* obj =
nullptr;
242 Deserialize<RootSerializer>(*mParts.At(ipart), obj);
243 if (strcmp(obj->GetName(),
"MCEvent") == 0)
245 else if (strcmp(obj->GetName(),
"TParticles") == 0)
246 chunk =
dynamic_cast<TClonesArray*
>(obj);
248 if (chunk !=
nullptr) {
257 void FairMQTransportDevice::UpdateParameterServer()
261 LOG(info) <<
"FairMQTransportDevice::UpdateParameterServer() (" << rtdb->
getListOfContainers()->GetEntries()
267 while ((cont = static_cast<FairParSet*>(next()))) {
268 std::string ridString = std::string(
"RUNID") + std::to_string(fRunSim->
GetRunId()) + std::string(
"RUNID")
269 + std::string(cont->getDescription());
274 LOG(info) <<
"FairMQTransportDevice::UpdateParameterServer() finished";
list of container factories
virtual bool ConditionalRun()
void SetField(FairField *field)
FairMCEventHeader * GetMCEventHeader()
Bool_t setSecondInput(FairParIo *)
void SetRunId(UInt_t runId)
virtual void SetParticleArray(__attribute__((unused)) TClonesArray *partArray)
FairGenericStack * GetStack()
void SetSink(FairSink *tempSink)
TList * getListOfContainers()
void SendObject(TObject *obj, const std::string &chan)
static FairMCApplication * Instance()
void SetUserCuts(const TString &Cuts)
FairRuntimeDb * GetRuntimeDb(void)
void SetMaterials(const char *MatFileName)
void SetUserConfig(const TString &Config)
virtual void AddTask(FairTask *t)
void ExternCreateDetector()
void AddModule(FairModule *Mod)
Bool_t setFirstInput(FairParIo *)
void SetMCEventHeader(FairMCEventHeader *McHeader)
void setDescription(const char *s)
bool TransportData(FairMQParts &, int)
virtual ~FairMQTransportDevice()
void SetStoreTraj(Bool_t storeTraj=kTRUE)