diff --git a/base/sim/FairGenericStack.h b/base/sim/FairGenericStack.h index 71e6c22504..c5fa8e99fa 100644 --- a/base/sim/FairGenericStack.h +++ b/base/sim/FairGenericStack.h @@ -97,6 +97,8 @@ class FairGenericStack : public TVirtualMCStack virtual void Register() {} virtual TClonesArray* GetListOfParticles() { return 0; } + virtual void SetParticleArray(TClonesArray* partArray) {} + virtual void SetParticleArray(TClonesArray* partArray, Int_t partFrom, Int_t partTo) {} /** Clone this object (used in MT mode only) */ virtual FairGenericStack* CloneStack() const; diff --git a/base/steer/FairRunSim.cxx b/base/steer/FairRunSim.cxx index 6b88d221c6..7f2f3b71ab 100644 --- a/base/steer/FairRunSim.cxx +++ b/base/steer/FairRunSim.cxx @@ -415,14 +415,18 @@ void FairRunSim::SetMCConfig() cuts =work_config+ fUserCuts; } //--------------------------------------Now load the Config and Cuts------------------------------------ + LOG(info) << "Now load the Config and Cuts"; if (!LibMacro.IsNull()) { + LOG(info) << "LibMacro " << LibMacro.Data(); gROOT->LoadMacro(LibMacro.Data()); gROOT->ProcessLine(LibFunction.Data()); } + LOG(info) << "ConfigMacro " << ConfigMacro.Data(); gROOT->LoadMacro(ConfigMacro.Data()); gROOT->ProcessLine("Config()"); + LOG(info) << "CutsMacro " << cuts; gROOT->LoadMacro(cuts); gROOT->ProcessLine("SetCuts()"); } diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index de03945e47..014fe90823 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -19,6 +19,7 @@ If(GEANT3_FOUND) add_subdirectory(MQ/serialization) add_subdirectory(MQ/pixelDetector) add_subdirectory(MQ/pixelAlternative) + add_subdirectory(MQ/simulation_split) add_subdirectory(advanced/Tutorial3) EndIf() add_subdirectory(simulation/rutherford) diff --git a/examples/MQ/pixelDetector/run/CMakeLists.txt b/examples/MQ/pixelDetector/run/CMakeLists.txt index d8234adc7e..17266ac8d3 100644 --- a/examples/MQ/pixelDetector/run/CMakeLists.txt +++ b/examples/MQ/pixelDetector/run/CMakeLists.txt @@ -12,6 +12,7 @@ GENERATE_TEST_SCRIPT(${CMAKE_BINARY_DIR}/bin/examples/MQ/pixelDetector/startFair Add_Test(pixel_simulation ${CMAKE_CURRENT_BINARY_DIR}/startFairMQPixelSimulation.sh --work-dir ${CMAKE_BINARY_DIR} -n 1000 -g TGeant3 -c static -s 6 --force-kill true -m 20 -v veryhigh -l false) +Set_Tests_Properties(pixel_simulation PROPERTIES DEPENDS pixel_static) Set_Tests_Properties(pixel_simulation PROPERTIES TIMEOUT ${MaxTestTime}) Set_Tests_Properties(pixel_simulation PROPERTIES PASS_REGULAR_EXPRESSION "Shell script finished successfully") diff --git a/examples/MQ/pixelDetector/run/runMQSim.cxx b/examples/MQ/pixelDetector/run/runMQSim.cxx index 24d09ff840..f9eee2898a 100644 --- a/examples/MQ/pixelDetector/run/runMQSim.cxx +++ b/examples/MQ/pixelDetector/run/runMQSim.cxx @@ -27,82 +27,80 @@ namespace bpo = boost::program_options; void addCustomOptions(bpo::options_description& options) { - options.add_options() - ("random-seed", bpo::value ()->default_value(0) , "Random seed number") - ("transport-name", bpo::value()->default_value("TGeant3") , "Transport name") - ("nof-events", bpo::value ()->required() , "Number of events to simulate") - ("fairroot-config-dir", bpo::value()->default_value("") , "FairRoot config dir") - ("param-channel-name", bpo::value()->default_value("updateChannel"), "Parameter update channel name") + options.add_options() + ("random-seed", bpo::value ()->default_value(0) , "Random seed number") + ("transport-name", bpo::value()->default_value("TGeant3") , "Transport name") + ("nof-events", bpo::value ()->required() , "Number of events to simulate") + ("fairroot-config-dir", bpo::value()->default_value("") , "FairRoot config dir") + ("param-channel-name", bpo::value()->default_value("updateChannel"), "Parameter update channel name") + ("run-digi-tasks", bpo::value ()->default_value(false) , "Run digi tasks") ; } FairMQDevicePtr getDevice(const FairMQProgOptions& config) { - gRandom->SetSeed(config.GetValue ("random-seed")); - - TString dir = getenv("VMCWORKDIR"); - TString tutdir = dir + "/MQ/pixelDetector"; - - TString tut_geomdir = dir + "/common/geometry"; - gSystem->Setenv("GEOMPATH",tut_geomdir.Data()); - - TString tut_configdir = config.GetValue("fairroot-config-dir"); - if ( tut_configdir.Length() < 1 ) - tut_configdir = dir + "/common/gconfig"; - gSystem->Setenv("CONFIG_DIR",tut_configdir.Data()); - - FairMQSimDevice* run = new FairMQSimDevice(); - - // TString outputfilename = Form("outputfile_%d.root",(int)(getpid())); - // FairRootFileSink* sink = new FairRootFileSink(outputfilename); - FairOnlineSink* sink = new FairOnlineSink(); - sink->SetMQSimDevice(run); - run->SetSink(sink); - - run->SetParamUpdateChannelName(config.GetValue("param-channel-name")); - - run->SetNofEvents (config.GetValue ("nof-events")); - run->SetTransportName (config.GetValue("transport-name")); - run->SetMaterials ("media.geo"); - - TObjArray* detArray = new TObjArray(); - FairModule* cave= new FairCave("CAVE"); - cave->SetGeometryFileName("cave_vacuum.geo"); - detArray->Add(cave); - Pixel* det = new Pixel("PixelDetector", kTRUE); - det->SetGeometryFileName("pixel.geo"); - detArray->Add(det); - run->SetDetectorArray (detArray); - - TString partName[] = {"pions","eplus","proton"}; - Int_t partPdgC[] = { 211, 11, 2212}; - Int_t chosenPart = 0; - - FairPrimaryGenerator* primGen = new FairPrimaryGenerator(); - FairBoxGenerator* boxGen = new FairBoxGenerator(partPdgC[chosenPart], 5); - boxGen->SetPRange(1,2); - boxGen->SetThetaRange(0,40); - boxGen->SetPhiRange(0,360); - primGen->AddGenerator(boxGen); - run->SetGenerator (primGen); - - run->SetStoreTraj (false); - - // --------------------------------------------------- - if ( 1==0 ) - { - // try to run digi task in the simulation device - TString digParFile = tutdir + "/param/pixel_digi.par"; - FairParAsciiFileIo* parIo1 = new FairParAsciiFileIo(); - parIo1->open(digParFile.Data(),"in"); - run->SetFirstParameter(parIo1); - - TObjArray* taskArray = new TObjArray(); - PixelDigitize* digiTask = new PixelDigitize(); - taskArray->Add(digiTask); - run->SetTaskArray(taskArray); + gRandom->SetSeed(config.GetValue ("random-seed")); + + TString dir = getenv("VMCWORKDIR"); + TString tutdir = dir + "/MQ/pixelDetector"; + + TString tut_geomdir = dir + "/common/geometry"; + gSystem->Setenv("GEOMPATH",tut_geomdir.Data()); + + TString tut_configdir = config.GetValue("fairroot-config-dir"); + if ( tut_configdir.Length() < 1 ) + tut_configdir = dir + "/common/gconfig"; + gSystem->Setenv("CONFIG_DIR",tut_configdir.Data()); + + FairMQSimDevice* run = new FairMQSimDevice(); + + // TString outputfilename = Form("outputfile_%d.root",(int)(getpid())); + // FairRootFileSink* sink = new FairRootFileSink(outputfilename); + FairOnlineSink* sink = new FairOnlineSink(); + sink->SetMQRunDevice(run); + run->SetSink(sink); + + run->SetParamUpdateChannelName(config.GetValue("param-channel-name")); + + run->SetNofEvents (config.GetValue ("nof-events")); + run->SetTransportName (config.GetValue("transport-name")); + run->SetMaterials ("media.geo"); + + TObjArray* detArray = new TObjArray(); + FairModule* cave= new FairCave("CAVE"); + cave->SetGeometryFileName("cave_vacuum.geo"); + detArray->Add(cave); + Pixel* det = new Pixel("PixelDetector", kTRUE); + det->SetGeometryFileName("pixel.geo"); + detArray->Add(det); + run->SetDetectorArray (detArray); + + TString partName[] = {"pions","eplus","proton"}; + Int_t partPdgC[] = { 211, 11, 2212}; + Int_t chosenPart = 0; + + FairPrimaryGenerator* primGen = new FairPrimaryGenerator(); + FairBoxGenerator* boxGen = new FairBoxGenerator(partPdgC[chosenPart], 100); + boxGen->SetPRange(1,2); + boxGen->SetThetaRange(0,180); + boxGen->SetPhiRange(0,360); + primGen->AddGenerator(boxGen); + run->SetGenerator (primGen); + + run->SetStoreTraj (false); + + if ( (config.GetValue("run-digi-tasks")) == true ) { + // Attach tasks if needed + TString digParFile = tutdir + "/param/pixel_digi.par"; + FairParAsciiFileIo* parIo1 = new FairParAsciiFileIo(); + parIo1->open(digParFile.Data(),"in"); + run->SetFirstParameter(parIo1); + + TObjArray* taskArray = new TObjArray(); + PixelDigitize* digiTask = new PixelDigitize(); + taskArray->Add(digiTask); + run->SetTaskArray(taskArray); } - // --------------------------------------------------- - return run; + return run; } diff --git a/examples/MQ/pixelDetector/run/runPixelFileSink.cxx b/examples/MQ/pixelDetector/run/runPixelFileSink.cxx index 83ceb90c75..ff60fc822b 100644 --- a/examples/MQ/pixelDetector/run/runPixelFileSink.cxx +++ b/examples/MQ/pixelDetector/run/runPixelFileSink.cxx @@ -17,8 +17,6 @@ void addCustomOptions(bpo::options_description& options) { options.add_options() ("file-name", bpo::value () , "Path to the output file") - ("class-name", bpo::value>() , "class name") - ("branch-name", bpo::value>() , "branch name") ("in-channel", bpo::value ()->default_value("data-in") , "input channel name") ("ack-channel", bpo::value () , "ack channel name"); } diff --git a/examples/MQ/pixelDetector/run/scripts/startFairMQPixel.sh.in b/examples/MQ/pixelDetector/run/scripts/startFairMQPixel.sh.in index 6ff49eb52a..889e440f77 100755 --- a/examples/MQ/pixelDetector/run/scripts/startFairMQPixel.sh.in +++ b/examples/MQ/pixelDetector/run/scripts/startFairMQPixel.sh.in @@ -76,8 +76,6 @@ if [ "$FAIRTASKNAME" == "--task-name PixelFindHits" ] ; then # output file for sink OUTPUTFILE="$WORKDIR/examples/MQ/pixelDetector/macros/MQ.pixel_TGeant3.hits.root" - OUTPUTCLASS="--class-name TClonesArray(PixelHit)" - OUTPUTBRANCH="--branch-name PixelHits" elif [ "$FAIRTASKNAME" == "--task-name PixelFindTracks" ] ; then # input file and branch for the sampler device FAIRTASKNAME+=" --keep-data PixelHits" @@ -86,8 +84,6 @@ elif [ "$FAIRTASKNAME" == "--task-name PixelFindTracks" ] ; then # output file for sink OUTPUTFILE="$WORKDIR/examples/MQ/pixelDetector/macros/MQ.pixel_TGeant3.hits_tracks.root" - OUTPUTCLASS="--class-name TClonesArray(PixelHit) --class-name TClonesArray(PixelTrack)" - OUTPUTBRANCH="--branch-name PixelHits --branch-name PixelTracks" elif [ "$FAIRTASKNAME" == "--task-name PixelFitTracks" ] ; then # input file and branch for the sampler device INPUTFILE="$WORKDIR/examples/MQ/pixelDetector/macros/MQ.pixel_TGeant3.hits_tracks.root" @@ -95,8 +91,6 @@ elif [ "$FAIRTASKNAME" == "--task-name PixelFitTracks" ] ; then # output file for sink OUTPUTFILE="$WORKDIR/examples/MQ/pixelDetector/macros/MQ.pixel_TGeant3.fitTracks.root" - OUTPUTCLASS="--class-name TClonesArray(PixelTrack)" - OUTPUTBRANCH="--branch-name PixelFitTracks" else echo "TASK $FAIRTASKNAME UNKNOWN!!!" exit @@ -145,7 +139,7 @@ FILESINK+=" --id pixDet-sink1 --channel-config name=data-in,type=pull,method=bin if [ "$COMMAND" == "static" ]; then FILESINK+=" --ack-channel ack --channel-config name=ack,type=push,method=connect,rateLogging=0,address=tcp://localhost:5108" fi -FILESINK+=" --file-name $OUTPUTFILE --class-name FairEventHeader --branch-name EventHeader. $OUTPUTCLASS $OUTPUTBRANCH $CONTROL" +FILESINK+=" --file-name $OUTPUTFILE $CONTROL" ########################## run all if [ "$COMMAND" == "print" ]; then diff --git a/examples/MQ/pixelDetector/run/scripts/startFairMQPixelMerger.sh.in b/examples/MQ/pixelDetector/run/scripts/startFairMQPixelMerger.sh.in index 8d2fa13a41..a3ce345204 100755 --- a/examples/MQ/pixelDetector/run/scripts/startFairMQPixelMerger.sh.in +++ b/examples/MQ/pixelDetector/run/scripts/startFairMQPixelMerger.sh.in @@ -140,7 +140,7 @@ xterm +aw -geometry 80x25+500+700 -hold -e @PIXEL_BIN_LOCATION@/$MERGER & ########################## start FILESINK FILESINK="pixel-sink $TRANSPORT" FILESINK+=" --id sink 1 --channel-config name=data-in,type=pull,method=bind,rateLogging=1,address=tcp://*:5230" -FILESINK+=" --file-name $OUTPUTFILE --class-name FairEventHeader --branch-name EventHeader. --class-name $OUTPUTCLASS --branch-name $OUTPUTBRANCH" +FILESINK+=" --file-name $OUTPUTFILE" xterm +aw -geometry 80x25+1000+700 -hold -e @PIXEL_BIN_LOCATION@/$FILESINK & diff --git a/examples/MQ/pixelDetector/run/scripts/startFairMQPixelSimulation.sh.in b/examples/MQ/pixelDetector/run/scripts/startFairMQPixelSimulation.sh.in index 9ee0eefbda..4fa0c07775 100755 --- a/examples/MQ/pixelDetector/run/scripts/startFairMQPixelSimulation.sh.in +++ b/examples/MQ/pixelDetector/run/scripts/startFairMQPixelSimulation.sh.in @@ -181,9 +181,6 @@ FILESINK+=" $SEVERITY " FILESINK+=" $VERBOSITY " FILESINK+=" $COLOR " FILESINK+=" --id pixSim-sink1 --channel-config name=data#all#,type=pull,method=bind,rateLogging=1,address=tcp://*:5206" -FILESINK+=" --class-name FairMCEventHeader --branch-name MCEventHeader." -FILESINK+=" --class-name TClonesArray(PixelPoint) --branch-name PixelPoint" -FILESINK+=" --class-name TClonesArray(FairMCTrack) --branch-name MCTrack" FILESINK+=" --file-name $OUTPUTFILE $CONTROL" ########################## run all diff --git a/examples/MQ/pixelDetector/run/scripts/startFairMQPixel_3Levels.sh.in b/examples/MQ/pixelDetector/run/scripts/startFairMQPixel_3Levels.sh.in index 6ae02f28eb..b2bf6740f9 100755 --- a/examples/MQ/pixelDetector/run/scripts/startFairMQPixel_3Levels.sh.in +++ b/examples/MQ/pixelDetector/run/scripts/startFairMQPixel_3Levels.sh.in @@ -40,8 +40,6 @@ INPUTBRANCH="PixelDigis" # output file for sink OUTPUTFILE="@PIXEL_FILE_LOCATION@/examples/MQ/pixelDetector/macros/MQ.pixel_TGeant3.3Levels.fitTracks.root" -OUTPUTCLASS="--class-name TClonesArray(PixelTrack)" -OUTPUTBRANCH="--branch-name PixelFitTracks" ########################### @@ -109,7 +107,7 @@ xterm -geometry 80x22+1000+700 -hold -e @PIXEL_BIN_LOCATION@/$PROCESSOR3_2 & ########################## start FILESINK FILESINK="pixel-sink $TRANSPORT" FILESINK+=" --id sink1 --channel-config name=data-in,type=pull,method=bind,rateLogging=1,address=tcp://*:5330" -FILESINK+=" --file-name $OUTPUTFILE --class-name FairEventHeader --branch-name EventHeader. $OUTPUTCLASS $OUTPUTBRANCH" +FILESINK+=" --file-name $OUTPUTFILE" xterm +aw -geometry 80x22+0+700 -hold -e @PIXEL_BIN_LOCATION@/$FILESINK & diff --git a/examples/MQ/pixelDetector/src/CMakeLists.txt b/examples/MQ/pixelDetector/src/CMakeLists.txt index beac85f5ba..f8a4c55226 100644 --- a/examples/MQ/pixelDetector/src/CMakeLists.txt +++ b/examples/MQ/pixelDetector/src/CMakeLists.txt @@ -42,6 +42,7 @@ devices/PixelFindHitsTask.cxx devices/FairMQPixelMerger.cxx devices/FairMQPixelFileSink.cxx devices/FairMQPixelFileSinkBin.cxx +devices/FairMQRunDevice.cxx devices/FairMQSimDevice.cxx FairOnlineSink.cxx ) @@ -57,6 +58,7 @@ devices/FairMQPixelTaskProcessor.h devices/FairMQPixelTaskProcessor.tpl devices/FairMQPixelTaskProcessorBin.h devices/FairMQPixelTaskProcessorBin.tpl +devices/FairMQRunDevice.h devices/FairMQSimDevice.h FairOnlineSink.h ) diff --git a/examples/MQ/pixelDetector/src/FairOnlineSink.cxx b/examples/MQ/pixelDetector/src/FairOnlineSink.cxx index dd4a13842e..76a102bbd1 100644 --- a/examples/MQ/pixelDetector/src/FairOnlineSink.cxx +++ b/examples/MQ/pixelDetector/src/FairOnlineSink.cxx @@ -18,7 +18,7 @@ #include "FairMQMessage.h" #include "FairMQProgOptions.h" -#include "FairMQSimDevice.h" +#include "FairMQRunDevice.h" #include "FairRootManager.h" #include "FairEventHeader.h" @@ -41,7 +41,7 @@ using namespace std; FairOnlineSink::FairOnlineSink() : FairSink() - , fMQSimDevice(NULL) + , fMQRunDevice(NULL) { } @@ -66,8 +66,8 @@ void FairOnlineSink::Fill() /// Fill the Root tree. LOG(DEBUG) << "called FairOnlineSink::Fill()!!!!"; - if ( fMQSimDevice ) - fMQSimDevice->SendBranches(); + if ( fMQRunDevice ) + fMQRunDevice->SendBranches(); } Bool_t FairOnlineSink::InitSink() diff --git a/examples/MQ/pixelDetector/src/FairOnlineSink.h b/examples/MQ/pixelDetector/src/FairOnlineSink.h index 231b2a0868..f1f9805842 100644 --- a/examples/MQ/pixelDetector/src/FairOnlineSink.h +++ b/examples/MQ/pixelDetector/src/FairOnlineSink.h @@ -21,7 +21,7 @@ #include "FairSink.h" class FairEventHeader; -class FairMQSimDevice; +class FairMQRunDevice; class FairOnlineSink : public FairSink { @@ -52,10 +52,10 @@ class FairOnlineSink : public FairSink virtual void WriteObject(TObject* /* f */, const char*, Int_t /* option = 0 */) {} virtual void WriteGeometry() {} - virtual void SetMQSimDevice(FairMQSimDevice* mrs) { fMQSimDevice = mrs;} + virtual void SetMQRunDevice(FairMQRunDevice* mrs) { fMQRunDevice = mrs;} private: - FairMQSimDevice* fMQSimDevice; + FairMQRunDevice* fMQRunDevice; FairOnlineSink(const FairOnlineSink&); FairOnlineSink& operator=(const FairOnlineSink&); diff --git a/examples/MQ/pixelDetector/src/Pixel.cxx b/examples/MQ/pixelDetector/src/Pixel.cxx index 7137afcfd3..17193de250 100644 --- a/examples/MQ/pixelDetector/src/Pixel.cxx +++ b/examples/MQ/pixelDetector/src/Pixel.cxx @@ -20,6 +20,7 @@ #include "FairGeoVolume.h" // for FairGeoVolume #include "FairRootManager.h" // for FairRootManager #include "FairRun.h" // for FairRun +#include "FairRunSim.h" // for FairRunSim #include "FairRuntimeDb.h" // for FairRuntimeDb #include "FairStack.h" // for FairStack #include "FairVolume.h" // for FairVolume @@ -260,4 +261,17 @@ PixelPoint* Pixel::AddHit(Int_t trackID, Int_t detID, time, length, eLoss); } +extern "C" void ExternCreateDetector() { + using std::cout; + using std::endl; + + cout << "-- ExternCreateDetector() START --" << endl; + FairRunSim* run = FairRunSim::Instance(); + + Pixel* det = new Pixel("PixelDetector", kTRUE); + det->SetGeometryFileName("pixel.geo"); + run->AddModule(det); + cout << "-- ExternCreateDetector(" << det->GetName() << ") DONE --" << endl; +} + ClassImp(Pixel) diff --git a/examples/MQ/pixelDetector/src/devices/FairMQPixelFileSink.cxx b/examples/MQ/pixelDetector/src/devices/FairMQPixelFileSink.cxx index 813fb6b925..325ecf758b 100644 --- a/examples/MQ/pixelDetector/src/devices/FairMQPixelFileSink.cxx +++ b/examples/MQ/pixelDetector/src/devices/FairMQPixelFileSink.cxx @@ -17,7 +17,6 @@ #include "RootSerializer.h" -#include "FairMCEventHeader.h" #include "FairMQPixelFileSink.h" #include "FairMQLogger.h" #include @@ -31,8 +30,6 @@ FairMQPixelFileSink::FairMQPixelFileSink() , fFileName() , fTreeName() - , fBranchNames() - , fClassNames() , fFileOption() , fFlowMode(false) , fWrite(false) @@ -48,8 +45,6 @@ FairMQPixelFileSink::FairMQPixelFileSink() void FairMQPixelFileSink::Init() { fFileName = fConfig->GetValue ("file-name"); - fClassNames = fConfig->GetValue>("class-name"); - fBranchNames = fConfig->GetValue>("branch-name"); fInputChannelName = fConfig->GetValue ("in-channel"); fAckChannelName = fConfig->GetValue ("ack-channel"); @@ -57,11 +52,6 @@ void FairMQPixelFileSink::Init() fFileOption = "RECREATE"; fTreeName = "cbmsim"; - // fBranchNames.push_back("EventHeader."); - // fClassNames .push_back("FairEventHeader"); - // fBranchNames.push_back("PixelHits"); - // fClassNames .push_back("TClonesArray(PixelHit)"); - if ( ::getenv("DDS_SESSION_ID") ) { std::string DDS_SESSION_ID = ::getenv("DDS_SESSION_ID"); if ( fFileName.length() > 5 ) { @@ -72,80 +62,41 @@ void FairMQPixelFileSink::Init() fOutFile = TFile::Open(fFileName.c_str(),fFileOption.c_str()); - fTree = new TTree(fTreeName.c_str(), "/cbmout"); - - fFolder = new TFolder("cbmout", "Main Output Folder"); - TFolder* foldEventHeader = fFolder->AddFolder("EvtHeader","EvtHeader"); - TFolder* foldPixel = fFolder->AddFolder("Pixel","Pixel"); - - TList* BranchNameList = new TList(); - - for ( fNObjects = 0 ; fNObjects < fBranchNames.size() ; fNObjects++ ) { - LOG(INFO) << "Creating output branch \"" << fClassNames[fNObjects] << "\" with name \"" << fBranchNames[fNObjects] << "\""; - if ( fClassNames[fNObjects].find("TClonesArray(") == 0 ) { - fClassNames [fNObjects] = fClassNames[fNObjects].substr(13,fClassNames[fNObjects].length()-12-2); - fOutputObjects [fNObjects] = new TClonesArray(fClassNames[fNObjects].c_str()); - fTree->Branch(fBranchNames[fNObjects].c_str(),"TClonesArray", &fOutputObjects[fNObjects]); - foldPixel->Add(fOutputObjects[fNObjects]); - BranchNameList->AddLast(new TObjString(fBranchNames[fNObjects].c_str())); - } - else if ( fClassNames[fNObjects].find("FairEventHeader") == 0 ) { - fOutputObjects [fNObjects] = new FairEventHeader(); - fTree->Branch(fBranchNames[fNObjects].c_str(),"FairEventHeader", &fOutputObjects[fNObjects]); - foldEventHeader->Add(fOutputObjects[fNObjects]); - BranchNameList->AddLast(new TObjString(fBranchNames[fNObjects].c_str())); - } - else if ( fClassNames[fNObjects].find("FairMCEventHeader") == 0 ) { - fOutputObjects [fNObjects] = new FairMCEventHeader(); - fTree->Branch(fBranchNames[fNObjects].c_str(),"FairMCEventHeader", &fOutputObjects[fNObjects]); - foldEventHeader->Add(fOutputObjects[fNObjects]); - BranchNameList->AddLast(new TObjString(fBranchNames[fNObjects].c_str())); - } - else { - LOG(ERROR) << "!!! Unknown output object \"" << fClassNames[fNObjects] << "\" !!!"; - } - } - - fFolder->Write(); - BranchNameList->Write("BranchList", TObject::kSingleKey); - BranchNameList->Delete(); - delete BranchNameList; - OnData(fInputChannelName, &FairMQPixelFileSink::StoreData); } bool FairMQPixelFileSink::StoreData(FairMQParts& parts, int /*index*/) -{ - std::vector tempObjects; - for ( int ipart = 0 ; ipart < parts.Size() ; ipart++ ) - { - TObject* obj = nullptr; - Deserialize(*parts.At(ipart),obj); - tempObjects.push_back(obj); - for ( unsigned int ibr = 0 ; ibr < fBranchNames.size() ; ibr++ ) - { - if ( strcmp(tempObjects.back()->GetName(),fBranchNames[ibr].data()) == 0 ) - { - fOutputObjects[ibr] = tempObjects.back(); - fTree->SetBranchAddress(fBranchNames[ibr].c_str(),&fOutputObjects[ibr]); - } - } +{ + bool creatingTree = false; + std::vector tempObjects; + if ( !fTree ) { + creatingTree = true; + fTree = new TTree(fTreeName.c_str(), "/cbmout"); + } - fTree->Fill(); - - for ( unsigned int ipart = 0 ; ipart < tempObjects.size() ; ipart++ ) - { - if ( tempObjects[ipart] ) - delete tempObjects[ipart]; + + for ( int ipart = 0 ; ipart < parts.Size() ; ipart++ ) { + fOutputObjects[ipart] = nullptr; + Deserialize (*parts.At(ipart),fOutputObjects[ipart]); + tempObjects.push_back(fOutputObjects[ipart]); + if ( creatingTree ) + fTree->Branch(tempObjects.back()->GetName(),tempObjects.back()->ClassName(),&fOutputObjects[ipart]); + fTree->SetBranchAddress(tempObjects.back()->GetName(),&fOutputObjects[ipart]); } - tempObjects.clear(); - - if ( fAckChannelName != "" ) - { - unique_ptr msg(NewMessage()); - Send(msg, fAckChannelName); + // LOG(INFO) << "Finished branches"; + fTree->Fill(); + + for ( unsigned int ipart = 0 ; ipart < tempObjects.size() ; ipart++ ) { + if ( tempObjects[ipart] ) + delete tempObjects[ipart]; + } + tempObjects.clear(); + + if ( fAckChannelName != "" ) { + unique_ptr msg(NewMessage()); + Send(msg, fAckChannelName); } - return true; + return true; } FairMQPixelFileSink::~FairMQPixelFileSink() diff --git a/examples/MQ/pixelDetector/src/devices/FairMQPixelFileSink.h b/examples/MQ/pixelDetector/src/devices/FairMQPixelFileSink.h index 7af805c200..74d47f7e1f 100644 --- a/examples/MQ/pixelDetector/src/devices/FairMQPixelFileSink.h +++ b/examples/MQ/pixelDetector/src/devices/FairMQPixelFileSink.h @@ -19,7 +19,6 @@ #include "TFile.h" #include "TFolder.h" #include "TTree.h" -#include "FairEventHeader.h" #include "FairMQDevice.h" @@ -30,11 +29,6 @@ class FairMQPixelFileSink : public FairMQDevice virtual ~FairMQPixelFileSink(); void SetOutputFileName(std::string tempString) { fFileName = tempString; } - void AddOutputBranch (std::string classString, std::string branchString) - { - fClassNames .push_back(classString); - fBranchNames.push_back(branchString); - } std::string GetOutputFileName () { return fFileName;} void SetInputChannelName (std::string tstr) {fInputChannelName = tstr;} @@ -51,9 +45,6 @@ class FairMQPixelFileSink : public FairMQDevice std::string fFileName; std::string fTreeName; - std::vector fBranchNames; - std::vector fClassNames; - std::string fFileOption; bool fFlowMode; bool fWrite; @@ -62,8 +53,6 @@ class FairMQPixelFileSink : public FairMQDevice TTree* fTree; unsigned int fNObjects; TObject** fOutputObjects; - /* FairEventHeader* fEventHeader; */ - /* TClonesArray* fOutput; */ TFolder* fFolder; FairMQPixelFileSink(const FairMQPixelFileSink&); diff --git a/examples/MQ/pixelDetector/src/devices/FairMQPixelSampler.cxx b/examples/MQ/pixelDetector/src/devices/FairMQPixelSampler.cxx index 02bb633d33..e998d7610f 100644 --- a/examples/MQ/pixelDetector/src/devices/FairMQPixelSampler.cxx +++ b/examples/MQ/pixelDetector/src/devices/FairMQPixelSampler.cxx @@ -94,7 +94,6 @@ bool FairMQPixelSampler::ConditionalRun() if ( readEventReturn != 0 ) return false; - TMessage* message[1000]; FairMQParts parts; for ( int iobj = 0 ; iobj < fNObjects ; iobj++ ) { diff --git a/examples/MQ/pixelDetector/src/devices/FairMQRunDevice.cxx b/examples/MQ/pixelDetector/src/devices/FairMQRunDevice.cxx new file mode 100644 index 0000000000..7adea3cedd --- /dev/null +++ b/examples/MQ/pixelDetector/src/devices/FairMQRunDevice.cxx @@ -0,0 +1,102 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence version 3 (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/** + * FairMQRunDevice.cxx + * + * @since 2017.10.24 + * @author R. Karabowicz + */ + +#include "FairMQRunDevice.h" + +#include "FairMQLogger.h" +#include "FairMQMessage.h" +#include "FairMQProgOptions.h" + +#include "FairOnlineSink.h" + +#include "FairMCEventHeader.h" +#include "FairRootManager.h" +#include "FairRunSim.h" +#include "FairRuntimeDb.h" + +#include "FairEventHeader.h" +#include "FairModule.h" +#include "FairPrimaryGenerator.h" +#include "FairParRootFileIo.h" +#include "FairParSet.h" + +#include "TROOT.h" +#include "TRint.h" +#include "TVirtualMC.h" +#include "TVirtualMCApplication.h" +#include "TList.h" +#include "TObjString.h" +#include "TObjArray.h" +#include "RootSerializer.h" + +using namespace std; + +FairMQRunDevice::FairMQRunDevice() + : FairMQDevice() +{ +} + +void FairMQRunDevice::SendObject(TObject* obj, std::string chan) { + FairMQMessagePtr mess(NewMessage()); + Serialize(*mess,obj); + + std::unique_ptr rep(NewMessage()); + + printf ("sending %s",obj->GetName()); + if (Send(mess, chan) > 0) + { + if (Receive(rep, chan) > 0) + { + std::string repString = string(static_cast(rep->GetData()), rep->GetSize()); + LOG(INFO) << " -> " << repString.data(); + } + } +} + +FairMQRunDevice::~FairMQRunDevice() +{ +} + +void FairMQRunDevice::SendBranches() +{ + /// Fill the Root tree. + LOG(DEBUG) << "called FairMQRunDevice::SendBranches()!!!!"; + + TList* branchNameList = FairRootManager::Instance()->GetBranchNameList(); + TObjString* ObjStr; + + for (auto& mi : fChannels) + { + LOG(DEBUG) << "trying channel >" << mi.first.data() << "<"; + + FairMQParts parts; + + for(Int_t t=0; tGetEntries(); t++) + { + ObjStr= static_cast(branchNameList->TList::At(t)); + LOG(DEBUG) << " branch >" << ObjStr->GetString().Data() << "<"; + std::string modifiedBranchName = std::string("#") + ObjStr->GetString().Data() + "#"; + if ( mi.first.find(modifiedBranchName) != std::string::npos || mi.first.find("#all#") != std::string::npos ) + { + TObject* object = (FairRootManager::Instance()->GetObject(ObjStr->GetString()))->Clone(); + FairMQMessagePtr mess(NewMessage()); + Serialize(*mess,object); + parts.AddPart(std::move(mess)); + LOG(DEBUG) << "channel >" << mi.first.data() << "< --> >" << ObjStr->GetString().Data() << "<"; + } + } + if ( parts.Size() > 0 ) + Send(parts,mi.first.data()); + } +} diff --git a/examples/MQ/pixelDetector/src/devices/FairMQRunDevice.h b/examples/MQ/pixelDetector/src/devices/FairMQRunDevice.h new file mode 100644 index 0000000000..d4641d05c8 --- /dev/null +++ b/examples/MQ/pixelDetector/src/devices/FairMQRunDevice.h @@ -0,0 +1,45 @@ +/******************************************************************************** + * Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence version 3 (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ + +/** + * FairMQRunDevice.h + * + * @since 2018-02-01 + * @author R. Karabowicz + */ + +#ifndef FAIRMQRUNDEVICE_H_ +#define FAIRMQRUNDEVICE_H_ + +#include +#include "TString.h" + +#include "FairMQDevice.h" + +class TObject; +class TObjArray; +class FairSink; + +class FairMQRunDevice : public FairMQDevice +{ + public: + FairMQRunDevice(); + virtual ~FairMQRunDevice(); + + virtual void SendBranches(); + + protected: + void SendObject(TObject* obj, std::string chan); + + private: + + FairMQRunDevice(const FairMQRunDevice&); + FairMQRunDevice& operator=(const FairMQRunDevice&); +}; + +#endif /* FAIRMQRUNDEVICE_H_ */ diff --git a/examples/MQ/pixelDetector/src/devices/FairMQSimDevice.cxx b/examples/MQ/pixelDetector/src/devices/FairMQSimDevice.cxx index 6b56078800..29dcb2d14d 100644 --- a/examples/MQ/pixelDetector/src/devices/FairMQSimDevice.cxx +++ b/examples/MQ/pixelDetector/src/devices/FairMQSimDevice.cxx @@ -43,7 +43,7 @@ using namespace std; FairMQSimDevice::FairMQSimDevice() - : FairMQDevice() + : FairMQRunDevice() , fSimDeviceId(0) , fUpdateChannelName("updateChannel") , fRunSim(NULL) @@ -174,27 +174,19 @@ void FairMQSimDevice::UpdateParameterServer() { std::string ridString = std::string("RUNID") + std::to_string(fRunSim->GetRunId()) + std::string("RUNID") + std::string(cont->getDescription()); cont->setDescription(ridString.data()); - SendObject(cont,fUpdateChannelName); + FairMQRunDevice::SendObject(cont,fUpdateChannelName); } printf("FairMQSimDevice::UpdateParameterServer() finished\n"); } -void FairMQSimDevice::SendObject(TObject* obj, std::string chan) { - FairMQMessagePtr mess(NewMessage()); - Serialize(*mess,obj); - - std::unique_ptr rep(NewMessage()); - - printf ("sending %s",obj->GetName()); - if (Send(mess, chan) > 0) +void FairMQSimDevice::SendBranches() +{ + if ( !CheckCurrentState(RUNNING) ) { - if (Receive(rep, chan) > 0) - { - std::string repString = string(static_cast(rep->GetData()), rep->GetSize()); - LOG(INFO) << " -> " << repString.data(); - } + fRunSim->StopMCRun(); } + FairMQRunDevice::SendBranches(); } void FairMQSimDevice::PostRun() @@ -204,40 +196,3 @@ void FairMQSimDevice::PostRun() FairMQSimDevice::~FairMQSimDevice() { } - -void FairMQSimDevice::SendBranches() -{ - /// Fill the Root tree. - LOG(DEBUG) << "called FairMQSimDevice::SendBranches()!!!!"; - if ( !CheckCurrentState(RUNNING) ) - { - fRunSim->StopMCRun(); - } - - TList* branchNameList = FairRootManager::Instance()->GetBranchNameList(); - TObjString* ObjStr; - - for (auto& mi : fChannels) - { - LOG(DEBUG) << "trying channel >" << mi.first.data() << "<"; - - FairMQParts parts; - - for(Int_t t=0; tGetEntries(); t++) - { - ObjStr= static_cast(branchNameList->TList::At(t)); - LOG(DEBUG) << " branch >" << ObjStr->GetString().Data() << "<"; - std::string modifiedBranchName = std::string("#") + ObjStr->GetString().Data() + "#"; - if ( mi.first.find(modifiedBranchName) != std::string::npos || mi.first.find("#all#") != std::string::npos ) - { - TObject* object = (FairRootManager::Instance()->GetObject(ObjStr->GetString()))->Clone(); - FairMQMessagePtr mess(NewMessage()); - Serialize(*mess,object); - parts.AddPart(std::move(mess)); - LOG(DEBUG) << "channel >" << mi.first.data() << "< --> >" << ObjStr->GetString().Data() << "<"; - } - } - if ( parts.Size() > 0 ) - Send(parts,mi.first.data()); - } -} diff --git a/examples/MQ/pixelDetector/src/devices/FairMQSimDevice.h b/examples/MQ/pixelDetector/src/devices/FairMQSimDevice.h index 7a92e62b88..d342bebc91 100644 --- a/examples/MQ/pixelDetector/src/devices/FairMQSimDevice.h +++ b/examples/MQ/pixelDetector/src/devices/FairMQSimDevice.h @@ -19,7 +19,7 @@ #include #include "TString.h" -#include "FairMQDevice.h" +#include "FairMQRunDevice.h" class FairEventHeader; class FairRunSim; @@ -30,13 +30,13 @@ class TObject; class TObjArray; class FairSink; -class FairMQSimDevice : public FairMQDevice +class FairMQSimDevice : public FairMQRunDevice { public: FairMQSimDevice(); virtual ~FairMQSimDevice(); - virtual void SendBranches(); + virtual void SetParamUpdateChannelName(TString tString) { fUpdateChannelName = tString; } // ------ FairRunSim setters ------ void SetNofEvents (int64_t nofev) { fNofEvents = nofev;}; @@ -54,7 +54,7 @@ class FairMQSimDevice : public FairMQDevice void SetSink (FairSink* sink) { fSink = sink;} // ------ ---------- -------- ------ - void SetParamUpdateChannelName(TString tString) { fUpdateChannelName = tString; } + virtual void SendBranches(); protected: virtual void InitTask(); @@ -84,7 +84,6 @@ class FairMQSimDevice : public FairMQDevice // ------ ---------- -------- ------ void UpdateParameterServer(); - void SendObject(TObject* obj, std::string chan); FairMQSimDevice(const FairMQSimDevice&); FairMQSimDevice& operator=(const FairMQSimDevice&); diff --git a/examples/MQ/simulation_split/CMakeLists.txt b/examples/MQ/simulation_split/CMakeLists.txt new file mode 100644 index 0000000000..c0d1ab72ce --- /dev/null +++ b/examples/MQ/simulation_split/CMakeLists.txt @@ -0,0 +1,9 @@ + ################################################################################ + # Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH # + # # + # This software is distributed under the terms of the # + # GNU Lesser General Public Licence (LGPL) version 3, # + # copied verbatim in the file "LICENSE" # + ################################################################################ +Add_Subdirectory(src) +Add_Subdirectory(run) diff --git a/examples/MQ/simulation_split/run/CMakeLists.txt b/examples/MQ/simulation_split/run/CMakeLists.txt new file mode 100644 index 0000000000..34ad7dc5a5 --- /dev/null +++ b/examples/MQ/simulation_split/run/CMakeLists.txt @@ -0,0 +1,108 @@ + ################################################################################ + # Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH # + # # + # This software is distributed under the terms of the # + # GNU Lesser General Public Licence (LGPL) version 3, # + # copied verbatim in the file "LICENSE" # + ################################################################################ + +Set(MaxTestTime 90) + +GENERATE_TEST_SCRIPT(${CMAKE_BINARY_DIR}/bin/examples/MQ/simulation_split/test-splitMC.sh ${CMAKE_CURRENT_BINARY_DIR}) +GENERATE_TEST_SCRIPT(${CMAKE_BINARY_DIR}/bin/examples/MQ/simulation_split/test-splitMQ.sh ${CMAKE_CURRENT_BINARY_DIR}) + +Add_Test(splitMC + ${CMAKE_CURRENT_BINARY_DIR}/test-splitMC.sh) +Set_Tests_Properties(splitMC PROPERTIES TIMEOUT ${MaxTestTime}) +Set_Tests_Properties(splitMC PROPERTIES PASS_REGULAR_EXPRESSION "Shell script finished successfully") + +Add_Test(splitMQ + ${CMAKE_CURRENT_BINARY_DIR}/test-splitMQ.sh) +Set_Tests_Properties(splitMQ PROPERTIES TIMEOUT ${MaxTestTime}) +Set_Tests_Properties(splitMQ PROPERTIES PASS_REGULAR_EXPRESSION "Shell script finished successfully") + +set(INCLUDE_DIRECTORIES + ${BASE_INCLUDE_DIRECTORIES} + ${CMAKE_SOURCE_DIR}/base/MQ/policies/Sampler + ${CMAKE_SOURCE_DIR}/base/MQ/policies/Serialization + ${CMAKE_SOURCE_DIR}/base/MQ/policies/Storage + ${CMAKE_SOURCE_DIR}/base/MQ/baseMQtools + ${CMAKE_SOURCE_DIR}/generators + ${CMAKE_SOURCE_DIR}/examples/common/passive + ${CMAKE_SOURCE_DIR}/examples/MQ/pixelDetector + ${CMAKE_SOURCE_DIR}/examples/MQ/pixelDetector/src + ${CMAKE_SOURCE_DIR}/examples/MQ/pixelDetector/src/devices + ${CMAKE_SOURCE_DIR}/examples/MQ/simulation_split/src + ${CMAKE_SOURCE_DIR}/examples/MQ/simulation_split/src/devices +) + +Set(SYSTEM_INCLUDE_DIRECTORIES + ${SYSTEM_INCLUDE_DIRECTORIES} + ${ZeroMQ_INCLUDE_DIR} +) + +include_directories(${INCLUDE_DIRECTORIES}) +include_directories(SYSTEM ${SYSTEM_INCLUDE_DIRECTORIES}) + +set(EXAMPLE_LIBRARY_EXTENSION so) +If(APPLE) + set(EXAMPLE_LIBRARY_EXTENSION dylib) +EndIf(APPLE) + +set(LINK_DIRECTORIES + ${ROOT_LIBRARY_DIR} + ${Boost_LIBRARY_DIRS} +) + +link_directories(${LINK_DIRECTORIES}) + +Set(Exe_Names + runMQGen + runMQTrans + runMQChMer +) + +set(Exe_Source + runMQGen.cxx + runMQTrans.cxx + runMQChunkMerger.cxx +) + + +List(LENGTH Exe_Names _length) +Math(EXPR _length ${_length}-1) + + +set(BIN_DESTINATION share/fairbase/examples/MQ/simulation_split/bin) +set(EXECUTABLE_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/examples/MQ/simulation_split") + +ForEach(_file RANGE 0 ${_length}) + List(GET Exe_Names ${_file} _name) + List(GET Exe_Source ${_file} _src) + Set(EXE_NAME ${_name}) + Set(SRCS ${_src}) + Set(DEPENDENCIES Pixel SimMQ) + GENERATE_EXECUTABLE() +EndForEach(_file RANGE 0 ${_length}) + +set(SPLITMC_BIN_LOCATION ${CMAKE_BINARY_DIR}/bin/examples/MQ/simulation_split) +set(SPLITMC_FILE_LOCATION ${CMAKE_SOURCE_DIR}/examples/MQ/simulation_split/run/scripts/) +set(PIXEL_BIN_LOCATION ${CMAKE_BINARY_DIR}/bin/examples/MQ/pixelDetector) +set(FAIRROOT_BIN_LOCATION ${CMAKE_BINARY_DIR}/bin) + +Message(STATUS "Looking for DDS!!!") +find_package(DDS) +set(DDS_LOCATION ${DDS_INCLUDE_DIR}/../) +MESSAGE(STATUS "Set ${DDS_LOCATION} as place to look for DDS_env.sh") + +configure_file( ${CMAKE_SOURCE_DIR}/examples/MQ/simulation_split/run/scripts/splitMC-topology.xml + ${CMAKE_BINARY_DIR}/bin/examples/MQ/simulation_split/splitMC-topology.xml ) + +set(SPLITMC_FILE_LOCATION ${CMAKE_BINARY_DIR}/bin/examples/MQ/simulation_split) + +configure_file( ${CMAKE_SOURCE_DIR}/examples/MQ/simulation_split/run/scripts/splitMC-topology.xml + ${CMAKE_BINARY_DIR}/bin/examples/MQ/simulation_split/test-splitMC.xml ) +configure_file( ${CMAKE_SOURCE_DIR}/examples/MQ/simulation_split/run/scripts/test-splitMC.sh.in + ${CMAKE_BINARY_DIR}/bin/examples/MQ/simulation_split/test-splitMC.sh) +configure_file( ${CMAKE_SOURCE_DIR}/examples/MQ/simulation_split/run/scripts/test-splitMQ.sh.in + ${CMAKE_BINARY_DIR}/bin/examples/MQ/simulation_split/test-splitMQ.sh) diff --git a/examples/MQ/simulation_split/run/runMQChunkMerger.cxx b/examples/MQ/simulation_split/run/runMQChunkMerger.cxx new file mode 100644 index 0000000000..cb7b68e159 --- /dev/null +++ b/examples/MQ/simulation_split/run/runMQChunkMerger.cxx @@ -0,0 +1,30 @@ +#include "runFairMQDevice.h" + +// MQRunSim +#include "FairPrimaryGenerator.h" +#include "FairBoxGenerator.h" +#include "FairMQChunkMerger.h" + +#include "TRandom.h" +#include "TRint.h" +#include "TROOT.h" +#include "TSystem.h" +#include "TVirtualMC.h" +#include "TVirtualMCApplication.h" + +namespace bpo = boost::program_options; + +void addCustomOptions(bpo::options_description& options) +{ + options.add_options() + ("in-channel", bpo::value()->default_value("data-in") , "input channel name") + ("out-channel", bpo::value()->default_value("data-out") , "output channel name") + ; +} + +FairMQDevicePtr getDevice(const FairMQProgOptions& config) +{ + FairMQChunkMerger* mqDevice = new FairMQChunkMerger(); + + return mqDevice; +} diff --git a/examples/MQ/simulation_split/run/runMQGen.cxx b/examples/MQ/simulation_split/run/runMQGen.cxx new file mode 100644 index 0000000000..d18e5ad429 --- /dev/null +++ b/examples/MQ/simulation_split/run/runMQGen.cxx @@ -0,0 +1,64 @@ +#include "runFairMQDevice.h" + +// MQRunSim +#include "FairPrimaryGenerator.h" +#include "FairBoxGenerator.h" +#include "FairMQPrimaryGeneratorDevice.h" + +#include "TRandom.h" +#include "TRint.h" +#include "TROOT.h" +#include "TSystem.h" +#include "TVirtualMC.h" +#include "TVirtualMCApplication.h" + +namespace bpo = boost::program_options; + +void addCustomOptions(bpo::options_description& options) +{ + options.add_options() + ("random-seed", bpo::value ()->default_value(0) , "Random seed number") + ("nof-events", bpo::value ()->required() , "Number of events to simulate") + ("running-mode", bpo::value()->default_value("pp") , "pp to push, rr to reply") + ("chunk-size", bpo::value ()->default_value(0) , "Max nof primaries in chunk") + ; +} + +FairMQDevicePtr getDevice(const FairMQProgOptions& config) +{ + gRandom->SetSeed(config.GetValue ("random-seed")); + + TString dir = getenv("VMCWORKDIR"); + TString tutdir = dir + "/MQ/pixelDetector"; + + TString tut_configdir = config.GetValue("fairroot-config-dir"); + if ( tut_configdir.Length() < 1 ) + tut_configdir = dir + "/common/gconfig"; + gSystem->Setenv("CONFIG_DIR",tut_configdir.Data()); + + Int_t partPdgC[] = { 211, 11, 2212}; //{"pions","eplus","proton"} + Int_t chosenPart = 0; + + FairPrimaryGenerator* primGen = new FairPrimaryGenerator(); + FairBoxGenerator* boxGen = new FairBoxGenerator(partPdgC[chosenPart], 100); + boxGen->SetPRange(1,2); + boxGen->SetThetaRange(0,180); + boxGen->SetPhiRange(0,360); + primGen->AddGenerator(boxGen); + + FairMQPrimaryGeneratorDevice* mqDevice = new FairMQPrimaryGeneratorDevice(); + LOG(INFO) << "Going to generate " << config.GetValue ("nof-events") << " events."; + mqDevice->SetChunkSize(config.GetValue("chunk-size")); + mqDevice->RunInPushMode(true); + if ( config.GetValue ("running-mode") == "rr" ) { + LOG(INFO) << "Going to reply with data."; + mqDevice->RunInPushMode(false); + } + else + LOG(INFO) << "Going to push data."; + + mqDevice->SetNofEvents(config.GetValue ("nof-events")); + mqDevice->SetGenerator(primGen); + + return mqDevice; +} diff --git a/examples/MQ/simulation_split/run/runMQTrans.cxx b/examples/MQ/simulation_split/run/runMQTrans.cxx new file mode 100644 index 0000000000..c6a9fcb4d7 --- /dev/null +++ b/examples/MQ/simulation_split/run/runMQTrans.cxx @@ -0,0 +1,99 @@ +#include "runFairMQDevice.h" + +// MQRunSim +#include "FairMQTransportDevice.h" +#include "FairRuntimeDb.h" +#include "FairModule.h" +#include "FairCave.h" +#include "FairParRootFileIo.h" +#include "FairParAsciiFileIo.h" + +#include "Pixel.h" +#include "PixelDigitize.h" + +#include "FairOnlineSink.h" +//#include "FairRootFileSink.h" + +#include "TRandom.h" +#include "TRint.h" +#include "TROOT.h" +#include "TSystem.h" +#include "TVirtualMC.h" +#include "TVirtualMCApplication.h" + +namespace bpo = boost::program_options; + +void addCustomOptions(bpo::options_description& options) +{ + options.add_options() + ("random-seed", bpo::value ()->default_value(0) , "Random seed number") + ("transport-name", bpo::value()->default_value("TGeant3") , "Transport name") + ("fairroot-config-dir", bpo::value()->default_value("") , "FairRoot config dir") + ("param-channel-name", bpo::value()->default_value("updateChannel"), "Parameter update channel name") + ("running-mode", bpo::value()->default_value("pp") , "pp to pull, rr to request") + ("detector-library", bpo::value>() , "detector library") + ("run-digi-tasks", bpo::value ()->default_value(false) , "Run digi tasks") + ; +} + +FairMQDevicePtr getDevice(const FairMQProgOptions& config) +{ + gRandom->SetSeed(config.GetValue ("random-seed")); + + TString dir = getenv("VMCWORKDIR"); + TString tutdir = dir + "/MQ/pixelDetector"; + + TString tut_geomdir = dir + "/common/geometry"; + gSystem->Setenv("GEOMPATH",tut_geomdir.Data()); + + TString tut_configdir = config.GetValue("fairroot-config-dir"); + if ( tut_configdir.Length() < 1 ) + tut_configdir = dir + "/common/gconfig"; + gSystem->Setenv("CONFIG_DIR",tut_configdir.Data()); + + FairMQTransportDevice* run = new FairMQTransportDevice(); + run->RunInPullMode(true); + if ( config.GetValue ("running-mode") == "rr" ) { + LOG(INFO) << "Going to request data."; + run->RunInPullMode(false); + } + else + LOG(INFO) << "Going to pull data."; + + // TString outputfilename = Form("outputfile_%d.root",(int)(getpid())); + // FairRootFileSink* sink = new FairRootFileSink(outputfilename); + FairOnlineSink* sink = new FairOnlineSink(); + sink->SetMQRunDevice(run); + run->SetSink(sink); + + run->SetParamUpdateChannelName(config.GetValue("param-channel-name")); + + run->SetTransportName (config.GetValue("transport-name")); + run->SetMaterials ("media.geo"); + + TObjArray* detArray = new TObjArray(); + FairModule* cave= new FairCave("CAVE"); + cave->SetGeometryFileName("cave_vacuum.geo"); + detArray->Add(cave); + Pixel* det = new Pixel("PixelDetector", kTRUE); + det->SetGeometryFileName("pixel.geo"); + detArray->Add(det); + run->SetDetectorArray (detArray); + + run->SetStoreTraj (false); + + if ( (config.GetValue("run-digi-tasks")) == true ) { + // Attach tasks if needed + TString digParFile = tutdir + "/param/pixel_digi.par"; + FairParAsciiFileIo* parIo1 = new FairParAsciiFileIo(); + parIo1->open(digParFile.Data(),"in"); + run->SetFirstParameter(parIo1); + + TObjArray* taskArray = new TObjArray(); + PixelDigitize* digiTask = new PixelDigitize(); + taskArray->Add(digiTask); + run->SetTaskArray(taskArray); + } + + return run; +} diff --git a/examples/MQ/simulation_split/run/scripts/splitMC-topology.xml b/examples/MQ/simulation_split/run/scripts/splitMC-topology.xml new file mode 100644 index 0000000000..b30ab85249 --- /dev/null +++ b/examples/MQ/simulation_split/run/scripts/splitMC-topology.xml @@ -0,0 +1,57 @@ + + + + + + + + + @SPLITMC_BIN_LOCATION@/runMQGen --id splitMC-gen --channel-config name=primariesChannel,type=push,method=bind --running-mode pp --severity INFO --nof-events 1 --chunk-size 0 -S "<@FairMQ_LIBDIR@" -P dds --color false + + primariesChannel + + + + + @SPLITMC_BIN_LOCATION@/runMQTrans --config-key splitMC-trans --id splitMC-trans_%taskIndex% --channel-config name=updateChannel,type=req,method=connect --channel-config name=primariesChannel,type=pull,method=connect --channel-config name=data#all#,type=push,method=connect --transport-name TGeant3 --running-mode pp --severity INFO -S "<@FairMQ_LIBDIR@" -P dds --color false + @CMAKE_BINARY_DIR@/config.sh + + primariesChannel + data#all# + updateChannel + + + + + @SPLITMC_BIN_LOCATION@/runMQChMer --id splitMC-merger --in-channel data#all# --channel-config name=data#all#,type=pull,method=bind --out-channel dataOut --channel-config name=dataOut,type=push,method=bind --transport zeromq --severity INFO -S "<@FairMQ_LIBDIR@" -P dds --color false + + data#all# + dataOut + + + + + @PIXEL_BIN_LOCATION@/pixel-sink --id splitMC-sink --in-channel dataOut --severity INFO --channel-config name=dataOut,type=pull,method=connect --file-name @SPLITMC_FILE_LOCATION@/DDS.simulation_TGeant3.data.root -S "<@FairMQ_LIBDIR@" -P dds --color false + + dataOut + + + + + @FAIRROOT_BIN_LOCATION@/parmq-server zeromq --id splitMC-parmq-server --channel-config name=updateChannel,type=rep,method=bind --severity INFO --update-channel-name updateChannel --output-name @SPLITMC_FILE_LOCATION@/DDS.simulation_TGeant3.pars.root -S "<@FairMQ_LIBDIR@" -P dds --color false + + updateChannel + + + +
+ Generator + Merger + Sink + ParamServer + + Transporter + +
+ +
diff --git a/examples/MQ/simulation_split/run/scripts/test-splitMC.sh.in b/examples/MQ/simulation_split/run/scripts/test-splitMC.sh.in new file mode 100644 index 0000000000..f3b5c7fb61 --- /dev/null +++ b/examples/MQ/simulation_split/run/scripts/test-splitMC.sh.in @@ -0,0 +1,130 @@ +#!/bin/bash + +NOFNEEDEDAGENTS=5 + +echo "*************** check paths" +env + +echo "*************** run config.sh in ${CMAKE_BINARY_DIR}" +cat ${CMAKE_BINARY_DIR}/config.sh +echo "****************************************************" +source ${CMAKE_BINARY_DIR}/config.sh +echo "****************************************************" +env +echo "*************** load dds from @DDS_LOCATION@" +cat @DDS_LOCATION@/DDS_env.sh +source @DDS_LOCATION@/DDS_env.sh +echo "*************** double check paths" +env +echo "****************************************************" +echo "DYLD_LIBRARIES_PATH=$DYLD_LIBRARY_PATH" +echo "****************************************************" + +echo "***** Start dds server" +dds-session start &> dds-server.dat + +cat dds-server.dat +DDS_ID=$(cat dds-server.dat | grep "Default DDS session is set to" | awk '{print $NF}' ) + +echo "***** Create local cluster with $NOFNEEDEDAGENTS agents" +dds-submit -s $DDS_ID -r localhost -n $NOFNEEDEDAGENTS &> dds-agents.dat +cat dds-agents.dat + +#wait 5 seconds to start agents +COUNTER=0 +LOOPING=1 +until [ $LOOPING -eq 0 ]; do + sleep 1; + echo "waiting $COUNTER seconds to start $NOFNEEDEDAGENTS agents "; + ((COUNTER++)); + if [ $COUNTER -ge 5 ]; then LOOPING=0; fi + if dds-info -s $DDS_ID -n | grep -m 1 "$NOFNEEDEDAGENTS"; then LOOPING=0; fi + : ; +done + +echo "***** Print number of agents available" +NOFAGENTS=$(dds-info -s $DDS_ID -n) +echo $NOFAGENTS +if [ $NOFAGENTS -lt $NOFNEEDEDAGENTS ]; then + echo "Not enough agents. Exiting" + dds-server stop $DDS_ID + exit +fi + +echo "***** Activate topology" +dds-topology -s $DDS_ID --activate @SPLITMC_BIN_LOCATION@/test-splitMC.xml --disable-validation + +#wait 20 seconds to finish jobs +COUNTER=0 +LOOPING=1 +until [ $LOOPING -eq 0 ]; do + echo "waiting $COUNTER seconds for the output file to grow"; + ((COUNTER++)); + if [ $COUNTER -ge 50 ]; then LOOPING=0; fi + FILESIZE=0 + if [ -f @SPLITMC_FILE_LOCATION@/DDS.simulation_TGeant3.data.$DDS_ID.root ]; then + FILESIZE=$(ls -l @SPLITMC_FILE_LOCATION@/DDS.simulation_TGeant3.data.$DDS_ID.root | awk '{print $5}') + fi + fairmq-dds-command-ui -s $DDS_ID -c c &> dds_check.log + NOF_RUNNG=$(grep RUNNING dds_check.log | wc -l) + NOF_READY=$(grep READY dds_check.log | wc -l) + NOF_AGENT=$(dds-info -s $DDS_ID -n | grep -m 1 "$NOFNEEDEDAGENTS") + echo "GOT $NOF_RUNNG RUNNING, $NOF_READY READY ($NOF_AGENT AGENTS)" + if [ $NOF_RUNNG -eq $((NOFNEEDEDAGENTS - 1)) ] && [ $NOF_READY -eq 1 ] + then + LOOPING=0; + fi +# if [ $FILESIZE -ge 100 ]; then LOOPING=0; fi + sleep 1; + : ; +done +sleep 10 + +echo "print Transporter logs" +#cat dds-agents.dat | grep "Starting DDSScout" | sed -e "s#\'##g" | awk '{print $8}' +AGENTS_WORK_DIR=$(cat dds-agents.dat | grep "Starting DDSScout" | sed "s#'##g" | awk '{print $8}') +echo "want to get logs from $AGENTS_WORK_DIR" +echo "==============================================================================================================================" +find $AGENTS_WORK_DIR* -name "Trans*log" | xargs -I {} cat {} +echo "==============================================================================================================================" +find $AGENTS_WORK_DIR* -name "Merge*log" | xargs -I {} cat {} +echo "==============================================================================================================================" +find $AGENTS_WORK_DIR* -name "Gener*log" | xargs -I {} cat {} +echo "==============================================================================================================================" +find $AGENTS_WORK_DIR* -name "Param*log" | xargs -I {} cat {} +echo "==============================================================================================================================" +find $AGENTS_WORK_DIR* -name "Sink_*log" | xargs -I {} cat {} +echo "==============================================================================================================================" +echo "print Transporter logs" + +echo "check dds states again" +fairmq-dds-command-ui -s $DDS_ID -c c +echo "^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^" + +fairmq-dds-command-ui -s $DDS_ID -c s +sleep 1 +fairmq-dds-command-ui -s $DDS_ID -c t +sleep 1 +fairmq-dds-command-ui -s $DDS_ID -c d +sleep 1 +fairmq-dds-command-ui -s $DDS_ID -c q +sleep 1 + +echo "***** Stop DDS" +dds-session stop $DDS_ID -f + +echo "***** Check the output file" +ls -ltr @SPLITMC_FILE_LOCATION@/DDS.simulation_TGeant3.data.$DDS_ID.root +OUTPUT_EVENTS="$(echo "cout<GetEntries()< gen_log.dat & +GENERATOR_PID=$! +$TRANSPORTER &> tra_log.dat & +TRANSPORTER_PID=$! +$MERGER &> mer_log.dat & +MERGER_PID=$! +$FILESINK &> sin_log.dat & +FILESINK_PID=$! +$PARMQSERVER &> par_log.dat & +PARMQSERVER_PID=$! + +echo "Wait for generator to finish" +wait $GENERATOR_PID + +echo "Sleep 5 seconds" +sleep 5 + +echo "Kill other devices" +kill $TRANSPORTER_PID +kill $MERGER_PID +kill $PARMQSERVER_PID +kill $FILESINK_PID + +INPUT_EVENTS="1" +OUTPUT_EVENTS="$(echo "cout<GetEntries()<Register("MCEventHeader.", "Event", this, kTRUE); +} + +ClassImp(FairMCSplitEventHeader) diff --git a/examples/MQ/simulation_split/src/FairMCSplitEventHeader.h b/examples/MQ/simulation_split/src/FairMCSplitEventHeader.h new file mode 100644 index 0000000000..9d600d8deb --- /dev/null +++ b/examples/MQ/simulation_split/src/FairMCSplitEventHeader.h @@ -0,0 +1,46 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/** FairMCSplitEventHeader.h **/ + + +#ifndef FAIRMCSPLITEVENTHEADER_H +#define FAIRMCSPLITEVENTHEADER_H 1 + +#include "FairMCEventHeader.h" +#include "FairRootManager.h" + +class FairMCSplitEventHeader : public FairMCEventHeader +{ + public: + + FairMCSplitEventHeader(); + + FairMCSplitEventHeader(UInt_t runID, UInt_t eventID, UInt_t nofChunks, UInt_t chunkStart); + + /** Destructor **/ + virtual ~FairMCSplitEventHeader(); + + void SetRECC(UInt_t i1, UInt_t i2, UInt_t i3, UInt_t i4) { SetRunID(i1); SetEventID(i2); SetNofChunks(i3); SetChunkStart(i4); }; + void SetNofChunks (UInt_t ti) { fNofChunks = ti; }; + void SetChunkStart(UInt_t ti) { fChunkStart = ti; }; + + UInt_t GetNofChunks () { return fNofChunks; }; + UInt_t GetChunkStart() { return fChunkStart; }; + + virtual void Register(); + + protected: + + UInt_t fNofChunks; + UInt_t fChunkStart; + + ClassDef(FairMCSplitEventHeader,1); + +}; + +#endif /* FAIRMCSPLITEVENTHEADER_H_ */ diff --git a/examples/MQ/simulation_split/src/SimMQLinkDef.h b/examples/MQ/simulation_split/src/SimMQLinkDef.h new file mode 100644 index 0000000000..bf4d19dfe4 --- /dev/null +++ b/examples/MQ/simulation_split/src/SimMQLinkDef.h @@ -0,0 +1,16 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifdef __CINT__ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; + +#pragma link C++ class FairMCSplitEventHeader+; + +#endif diff --git a/examples/MQ/simulation_split/src/devices/FairMQChunkMerger.cxx b/examples/MQ/simulation_split/src/devices/FairMQChunkMerger.cxx new file mode 100644 index 0000000000..fb1a02e742 --- /dev/null +++ b/examples/MQ/simulation_split/src/devices/FairMQChunkMerger.cxx @@ -0,0 +1,191 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/** + * FairMQChunkMerger.cxx + * + * @since 2016-03-21 + * @author R. Karabowicz + */ + +#include +#include + +#include "FairMQChunkMerger.h" +#include "FairMQLogger.h" + +#include "RootSerializer.h" + +#include "FairMCTrack.h" +#include "FairMCPoint.h" +#include "FairTask.h" + +using namespace std; + +FairMQChunkMerger::FairMQChunkMerger() + : FairMQDevice() + , fInputChannelName("data-in") + , fOutputChannelName("data-out") + , fNofPartsPerEventMap() + , fObjectMap() + , fEvRIPair() + , fEvCOPair() + , fRet() + , fNofReceivedMessages(0) + , fNofSentMessages(0) + , fNofParts(3) + , fMCSplitEventHeader(NULL) +{ +} + +void FairMQChunkMerger::Init() +{ + fInputChannelName = fConfig->GetValue("in-channel"); + fOutputChannelName = fConfig->GetValue("out-channel"); + + OnData(fInputChannelName, &FairMQChunkMerger::MergeData); +} + +bool FairMQChunkMerger::MergeData(FairMQParts& parts, int /*index*/) +{ + bool printInfo = false; + int nofReceivedParts = 0; // if set to -1, the data seems to be duplicated + int nofExpectedParts = 1; + + fNofReceivedMessages++; + // dataDuplicationFlag = false; + + std::vector tcaVector; + for ( int ipart = 0 ; ipart < parts.Size() ; ++ipart ) { + TObject* tempObject = nullptr; + Deserialize(*parts.At(ipart),tempObject); + + // LOG(INFO) << "Got object " << tempObject->ClassName() << " named " << tempObject->GetName(); + if ( strcmp(tempObject->GetName(),"MCEventHeader.") == 0 ) { + fMCSplitEventHeader = dynamic_cast(tempObject); + // LOG(info) << "GOT PART [" << fMCSplitEventHeader->GetRunID() << "][" << fMCSplitEventHeader->GetEventID() << "][" << fMCSplitEventHeader->GetChunkStart() << "]"; + fEvRIPair.first = fMCSplitEventHeader->GetEventID(); + fEvRIPair.second = fMCSplitEventHeader->GetRunID(); + fEvCOPair.first = fMCSplitEventHeader->GetChunkStart(); + nofExpectedParts = fMCSplitEventHeader->GetNofChunks(); + + fRet = fObjectMap.equal_range(fEvRIPair); + for ( MultiMapDef::iterator it = fRet.first ; it != fRet.second ; ++it ) { + // LOG(info) << "comparing " << it->second.first << " and " << fEvCOPair.first; + if ( it->second.first == fMCSplitEventHeader->GetChunkStart() ) + LOG(fatal) << "got part starting at " << fEvCOPair.first << " again!!!"; + } + + std::map,int>::iterator it2; + it2 = fNofPartsPerEventMap.find(fEvRIPair); + if ( it2 == fNofPartsPerEventMap.end() ) { + fNofPartsPerEventMap[fEvRIPair] = 1; + nofReceivedParts = 1; + } + else { + it2->second+=1; + nofReceivedParts = it2->second; + } + } + else { + tcaVector.push_back(dynamic_cast(tempObject)); + } + } + + // not all parts are there yet, have to put them in buffer + if ( nofReceivedParts != nofExpectedParts ) { + // LOG(info) << "not all parts are yet here (got " << nofReceivedParts << " out of " << nofExpectedParts << ")... adding to (size = " << fObjectMap.size() << ")"; + // LOG(info) << "+" << fMCSplitEventHeader->GetName() << "[" << fEvRIPair.second << "][" << fEvRIPair.first << "][" << fEvCOPair.first << "]"; + for ( int iarray = 0 ; iarray < tcaVector.size() ; ++iarray ) { + LOG(debug) << "+ [" << fEvRIPair.second << "][" << fEvRIPair.first << "][" << fEvCOPair.first << "] " << tcaVector[iarray]->GetName(); + fEvCOPair.second = (dynamic_cast(tcaVector[iarray])); + fObjectMap.insert(std::pair,std::pair>(fEvRIPair,fEvCOPair)); + } + // LOG(info) << " now we have fObjectMap (size = " << fObjectMap.size() << ")"; + if ( printInfo) + LOG(info) << ">> [" << fMCSplitEventHeader->GetRunID() << "][" << fMCSplitEventHeader->GetEventID() << "][" << fMCSplitEventHeader->GetChunkStart() << "] Received: " << fNofReceivedMessages << " // Buffered: " << fObjectMap.size() << " // Sent: " << fNofSentMessages << " <<"; + } + else { + // got all the parts of the event, have to combine and send message, consisting of objects from fObjectMap + int currentEventPart = fMCSplitEventHeader->GetChunkStart(); + fRet = fObjectMap.equal_range(fEvRIPair); + std::vector trackShift; + LOG(debug) << "- [" << fEvRIPair.second << "][" << fEvRIPair.first << "][ALL]"; + for ( int iarray = 0 ; iarray < tcaVector.size() ; ++iarray ) { + if ( strcmp(tcaVector[iarray]->GetName(),"MCTrack") != 0 ) continue; // want only MCTrack array to renumber tracks and get track shifts... + // LOG(info) << "BEFORE ADDING, TCA \"" << tcaVector[iarray]->GetName() << "\" has " << tcaVector[iarray]->GetEntries() << " entries."; + TClonesArray* arrayToAdd; + for ( MultiMapDef::iterator it = fRet.first ; it != fRet.second ; ++it ) { + if ( it->second.first == fMCSplitEventHeader->GetChunkStart() ) continue; + if ( strcmp(tcaVector[iarray]->GetName(),it->second.second->GetName()) == 0 ) { + trackShift.push_back(tcaVector[iarray]->GetEntries()); + arrayToAdd = dynamic_cast(it->second.second); + for ( int iobj = 0 ; iobj < arrayToAdd->GetEntries() ; ++iobj ) { + FairMCTrack* temp = dynamic_cast(arrayToAdd->At(iobj)); + if ( temp->GetMotherId() >= 0 ) { + temp->SetMotherId(temp->GetMotherId()+trackShift.back()); + } + } + tcaVector[iarray]->AbsorbObjects(arrayToAdd); + // LOG(info) << "FOUND ONE!, TCA has now " << tcaVector[iarray]->GetEntries() << " entries."; + } + } + } + + for ( int iarray = 0 ; iarray < tcaVector.size() ; ++iarray ) { + if ( strcmp(tcaVector[iarray]->GetName(),"MCTrack") == 0 ) continue; // MCTrack already done, renumber all _other_ arrays... + // LOG(info) << "BEFORE ADDING, TCA \"" << tcaVector[iarray]->GetName() << "\" has " << tcaVector[iarray]->GetEntries() << " entries."; + int addedArray = 0; + TClonesArray* arrayToAdd; + + for ( MultiMapDef::iterator it = fRet.first ; it != fRet.second ; ++it ) { + if ( it->second.first == fMCSplitEventHeader->GetChunkStart() ) continue; + if ( strcmp(tcaVector[iarray]->GetName(),it->second.second->GetName()) == 0 ) { + int objShift = trackShift[addedArray++]; + // LOG(INFO) << "trying to add " << tcaVector[iarray]->GetName() << " and " << it->second.second->GetName() << "(shift = " << objShift << ")"; + arrayToAdd = dynamic_cast(it->second.second); + for ( int iobj = 0 ; iobj < arrayToAdd->GetEntries() ; ++iobj ) { + FairMCPoint* temp = dynamic_cast(arrayToAdd->At(iobj)); + temp->SetTrackID(temp->GetTrackID()+objShift); + } + } + tcaVector[iarray]->AbsorbObjects(arrayToAdd); + // LOG(info) << "FOUND ONE!, TCA has now " << tcaVector[iarray]->GetEntries() << " entries."; + } + } + fObjectMap.erase(fRet.first,fRet.second); + + FairMQParts partsOut; + + fMCSplitEventHeader->SetNofChunks(1); + fMCSplitEventHeader->SetChunkStart(0); + + FairMQMessagePtr messEH(NewMessage()); + Serialize(*messEH,fMCSplitEventHeader); + partsOut.AddPart(std::move(messEH)); + + for ( int iarray = 0 ; iarray < tcaVector.size() ; ++iarray ) { + FairMQMessagePtr mess(NewMessage()); + Serialize(*mess,tcaVector[iarray]); + partsOut.AddPart(std::move(mess)); + } + // LOG(info) << "created output message with " << partsOut.Size() << " parts."; + Send(partsOut, fOutputChannelName); + fNofSentMessages++; + if ( printInfo ) + LOG(info) << ">> [" << fMCSplitEventHeader->GetRunID() << "][" << fMCSplitEventHeader->GetEventID() << "][" << fMCSplitEventHeader->GetChunkStart() << "] Received: " << fNofReceivedMessages << " // Buffered: " << fObjectMap.size() << " // Sent: " << fNofSentMessages << " <<"; + } + + for( MultiMapDef::iterator it = fObjectMap.begin() ; it != fObjectMap.end() ; ++it ) { + LOG(debug) << "= [" << it->first.second << "][" << it->first.first << "][" << it->second.first << "] " << it->second.second->GetName(); + } + return true; +} + +FairMQChunkMerger::~FairMQChunkMerger() +{ +} diff --git a/examples/MQ/simulation_split/src/devices/FairMQChunkMerger.h b/examples/MQ/simulation_split/src/devices/FairMQChunkMerger.h new file mode 100644 index 0000000000..25928a4e85 --- /dev/null +++ b/examples/MQ/simulation_split/src/devices/FairMQChunkMerger.h @@ -0,0 +1,62 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/** + * FairMQChunkMerger.h + * + * @since 2018-09-28 + * @author R. Karabowicz + */ + +#ifndef FAIRMQCHUNKMERGER_H_ +#define FAIRMQCHUNKMERGER_H_ + +#include "TClonesArray.h" +#include "TFile.h" +#include "TFolder.h" +#include "TTree.h" +#include "FairMCSplitEventHeader.h" + +#include "FairMQDevice.h" + +typedef std::multimap,std::pair> MultiMapDef; + +class FairMQChunkMerger : public FairMQDevice +{ + public: + FairMQChunkMerger(); + virtual ~FairMQChunkMerger(); + + void SetNofParts(int iparts) { fNofParts = iparts; } + + protected: + bool MergeData(FairMQParts&, int); + virtual void Init(); + + private: + + std::string fInputChannelName; + std::string fOutputChannelName; + + std::map ,int> fNofPartsPerEventMap; // number of parts for pair + MultiMapDef fObjectMap; // TObjects for given pairpart> + + std::pair fEvRIPair; + std::pair fEvCOPair; + std::pair fRet; + + int fNofReceivedMessages; + int fNofSentMessages; + + int fNofParts; + FairMCSplitEventHeader* fMCSplitEventHeader; + + FairMQChunkMerger(const FairMQChunkMerger&); + FairMQChunkMerger& operator=(const FairMQChunkMerger&); +}; + +#endif /* FAIRMQCHUNKMERGER_H_ */ diff --git a/examples/MQ/simulation_split/src/devices/FairMQPrimaryGeneratorDevice.cxx b/examples/MQ/simulation_split/src/devices/FairMQPrimaryGeneratorDevice.cxx new file mode 100644 index 0000000000..ec2943e332 --- /dev/null +++ b/examples/MQ/simulation_split/src/devices/FairMQPrimaryGeneratorDevice.cxx @@ -0,0 +1,152 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence version 3 (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/** + * FairMQPrimaryGeneratorDevice.cxx + * + * @since 2017.10.24 + * @author R. Karabowicz + */ + +#include "FairMQPrimaryGeneratorDevice.h" + +#include "FairMQLogger.h" +#include "FairMQMessage.h" +#include "FairMQProgOptions.h" + +#include "FairMCSplitEventHeader.h" + +#include "FairRootManager.h" +#include "FairRunSim.h" +#include "FairRuntimeDb.h" + +#include "FairModule.h" +#include "FairPrimaryGenerator.h" +#include "FairParRootFileIo.h" +#include "FairParSet.h" +#include "FairStack.h" + +#include "RootSerializer.h" + +#include "TROOT.h" +#include "TRint.h" +#include "TVirtualMC.h" +#include "TVirtualMCApplication.h" +#include "TList.h" +#include "TObjString.h" +#include "TObjArray.h" + +using namespace std; + +FairMQPrimaryGeneratorDevice::FairMQPrimaryGeneratorDevice() + : FairMQDevice() + , fRunConditional(true) + , fGeneratorChannelName("primariesChannel") + , fEventCounter(0) + , fNofEvents(10) + , fPrimaryGenerator(NULL) + , fMCEventHeader(NULL) + , fStack(NULL) + , fChunkSize(0) + , fChunkPointer(0) +{ +} + +void FairMQPrimaryGeneratorDevice::InitTask() +{ + fStack = new FairStack(); + fMCEventHeader = new FairMCEventHeader(); + fPrimaryGenerator->SetEvent(fMCEventHeader); + fPrimaryGenerator->Init(); + + if ( !fRunConditional ) + OnData(fGeneratorChannelName, &FairMQPrimaryGeneratorDevice::Reply); +} + +void FairMQPrimaryGeneratorDevice::PreRun() +{ +} + +bool FairMQPrimaryGeneratorDevice::ConditionalRun() +{ + if ( !fRunConditional ) return false; + return GenerateAndSendData(); +} + +bool FairMQPrimaryGeneratorDevice::Reply(FairMQMessagePtr& mPtr, int /*index*/) +{ + return GenerateAndSendData(); +} + +bool FairMQPrimaryGeneratorDevice::GenerateAndSendData() { + if ( fChunkPointer == 0 ) { // only change fChunkPointer if fChunkSize is different from -1 + // LOG(INFO) << "Reseting fStack and generating new event!!!"; + fStack->Reset(); + fPrimaryGenerator->GenerateEvent(fStack); + ++fEventCounter; + } + if ( fEventCounter > fNofEvents ) + return false; + + if ( fChunkSize != 0 ) { // should send events in chunks with maximum size of fChunkSize + // shouldn't do much before, just sent from fChunkPointer to fChunkPointer+fChunkSize + } + + FairMQParts parts; + + // even if sending in chunks is set, send all of the primaries anyway, the transporter takes care of transporting needed primaries + // create FairMCEventHeader, misuse not-yet-set fRunID to store begin + TClonesArray* prims = fStack->GetListOfParticles(); + + FairMCSplitEventHeader* meh = new FairMCSplitEventHeader(0,fEventCounter,1,0); // RunId will be provided in the Transport from ParameterServer + meh->SetNPrim(prims->GetEntries()); + if ( fChunkSize != 0 ) { + meh->SetNPrim(fChunkPointer+fChunkSize); + meh->SetNofChunks ((UInt_t)(prims->GetEntries()/fChunkSize)); + meh->SetChunkStart(fChunkPointer); + if ( fChunkPointer+fChunkSize > prims->GetEntries() ) + meh->SetNPrim(prims->GetEntries()-fChunkPointer); + } + + FairMQMessagePtr messEH(NewMessage()); + Serialize(*messEH,meh); + parts.AddPart(std::move(messEH)); + + FairMQMessagePtr mess(NewMessage()); + Serialize(*mess,prims); + parts.AddPart(std::move(mess)); + + // LOG(INFO) << "sending event " << fEventCounter << ", chunk starts at " << fChunkPointer; + if (Send(parts, fGeneratorChannelName) > 0) + { + } + + int numberofparts = (int)prims->GetEntries(); + + if ( fChunkSize != 0 ) { // should send events in chunks with maximum size of fChunkSize + // the whole work should be done after + fChunkPointer += fChunkSize; + if ( fChunkPointer >= numberofparts ) { // it means that already sent all primaries from this event + fChunkPointer = 0; // this will cause the reset of the stack and generating new event + } + } + + + return true; +} + +void FairMQPrimaryGeneratorDevice::PostRun() +{ +} + +FairMQPrimaryGeneratorDevice::~FairMQPrimaryGeneratorDevice() +{ +} + +void FairMQPrimaryGeneratorDevice::SendPrimaries() +{ +} diff --git a/examples/MQ/simulation_split/src/devices/FairMQPrimaryGeneratorDevice.h b/examples/MQ/simulation_split/src/devices/FairMQPrimaryGeneratorDevice.h new file mode 100644 index 0000000000..245c1c372c --- /dev/null +++ b/examples/MQ/simulation_split/src/devices/FairMQPrimaryGeneratorDevice.h @@ -0,0 +1,78 @@ +/******************************************************************************** + * Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence version 3 (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ + +/** + * FairMQPrimaryGeneratorDevice.h + * + * @since 2018-08-31 + * @author R. Karabowicz + */ + +#ifndef FAIRMQPRIMARYGENERATORDEVICE_H_ +#define FAIRMQPRIMARYGENERATORDEVICE_H_ + +#include +#include "TString.h" + +#include "FairMQDevice.h" + +class FairMCEventHeader; +class FairRunSim; +class FairField; +class FairParIo; +class FairPrimaryGenerator; +class TObject; +class TObjArray; +class FairSink; +class FairStack; + +class FairMQPrimaryGeneratorDevice : public FairMQDevice +{ + public: + FairMQPrimaryGeneratorDevice(); + virtual ~FairMQPrimaryGeneratorDevice(); + + virtual void SendPrimaries(); + + void SetNofEvents (int64_t nofev) { fNofEvents = nofev;}; + void SetGenerator (FairPrimaryGenerator* primGen) { fPrimaryGenerator = primGen;}; + + void SetChunkSize(int64_t ti) { fChunkSize = ti;}; + + void RunInPushMode(bool tb=true) { fRunConditional = tb; }; + void RunInRepMode (bool tb=true) { fRunConditional = !tb; }; + + protected: + bool Reply(FairMQMessagePtr&, int); + virtual void InitTask(); + virtual void PreRun(); + virtual void PostRun(); + virtual bool ConditionalRun(); + + private: + std::string fGeneratorChannelName; + + bool fRunConditional; // if true run ConditionalRun, if false run Reply + + FairPrimaryGenerator* fPrimaryGenerator; + FairMCEventHeader* fMCEventHeader; + FairStack* fStack; + int64_t fNofEvents; + int64_t fEventCounter; + + int64_t fChunkSize; // to set the maximal number of primaries sent in one bunch + int64_t fChunkPointer; // to set the first primary to be sent + + bool GenerateAndSendData(); + void SendObject(TObject* obj, std::string chan); + + FairMQPrimaryGeneratorDevice(const FairMQPrimaryGeneratorDevice&); + FairMQPrimaryGeneratorDevice& operator=(const FairMQPrimaryGeneratorDevice&); +}; + +#endif /* FAIRMQPRIMARYGENERATORDEVICE_H_ */ diff --git a/examples/MQ/simulation_split/src/devices/FairMQTransportDevice.cxx b/examples/MQ/simulation_split/src/devices/FairMQTransportDevice.cxx new file mode 100644 index 0000000000..e66cf6d559 --- /dev/null +++ b/examples/MQ/simulation_split/src/devices/FairMQTransportDevice.cxx @@ -0,0 +1,291 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence version 3 (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/** + * FairMQTransportDevice.cxx + * + * @since 2017.10.24 + * @author R. Karabowicz + */ + +#include "FairMQTransportDevice.h" + +#include "FairMQLogger.h" +#include "FairMQMessage.h" +#include "FairMQProgOptions.h" + +#include "FairOnlineSink.h" + +#include "FairMCSplitEventHeader.h" +#include "FairRootManager.h" +#include "FairRunSim.h" +#include "FairRuntimeDb.h" + +#include "FairGenericStack.h" +#include "FairMCApplication.h" + +#include "FairEventHeader.h" +#include "FairModule.h" +#include "FairParRootFileIo.h" +#include "FairParSet.h" +#include "FairTask.h" + +#include "RootSerializer.h" + +#include "TClonesArray.h" +#include "TROOT.h" +#include "TRint.h" +#include "TVirtualMC.h" +#include "TVirtualMCApplication.h" +#include "TList.h" +#include "TObjString.h" +#include "TObjArray.h" + +#include + +using namespace std; + +FairMQTransportDevice::FairMQTransportDevice() + : FairMQRunDevice() + , fRunConditional(false) + , fRunId(0) + , fTransportDeviceId(0) + , fGeneratorChannelName("primariesChannel") + , fRunSim(NULL) + , fNofEvents(1) + , fTransportName("TGeant3") + , fMaterialsFile("") + , fMagneticField(NULL) + , fDetectorArray(NULL) + , fStoreTrajFlag(false) + , fTaskArray(NULL) + , fFirstParameter(NULL) + , fSecondParameter(NULL) + , fSink(NULL) + , fVMC(NULL) + , fStack(NULL) + , fMCApplication(NULL) + , fMCSplitEventHeader(NULL) +{ +} + +void FairMQTransportDevice::Init() +{ + if ( !fRunConditional ) + OnData(fGeneratorChannelName, &FairMQTransportDevice::TransportData); +} + +void FairMQTransportDevice::InitTask() +{ + fRunSim = new FairRunSim(); + + fMCSplitEventHeader = new FairMCSplitEventHeader(fRunId,0,0,0); + fRunSim->SetMCEventHeader(fMCSplitEventHeader); + fRunSim->SetRunId(fRunSim->GetMCEventHeader()->GetRunID()); + + fRunSim->SetSink(fSink); + + if ( fFirstParameter || fSecondParameter ) { + FairRuntimeDb *rtdb=fRunSim->GetRuntimeDb(); + if ( fFirstParameter ) + rtdb->setFirstInput(fFirstParameter); + if ( fSecondParameter ) + rtdb->setSecondInput(fSecondParameter); + } + + fRunSim->SetName(fTransportName.data()); + + if ( fUserConfig.Length() > 0 ) + fRunSim->SetUserConfig(fUserConfig); + if ( fUserCuts.Length() > 0 ) + fRunSim->SetUserCuts(fUserCuts); + // ------------------------------------------------------------------------ + + // ----- Create media ------------------------------------------------- + fRunSim->SetMaterials(fMaterialsFile.data()); + // ------------------------------------------------------------------------ + + // ----- Magnetic field ------------------------------------------- + if ( fMagneticField ) + fRunSim->SetField(fMagneticField); + // -------------------------------------------------------------------- + + // ----- Create geometry ---------------------------------------------- + for ( int idet = 0 ; idet < fDetectorArray->GetEntries() ; idet++ ) { + fRunSim->AddModule(dynamic_cast(fDetectorArray->At(idet))); + } + + std::vector detectorLibraries = fConfig->GetValue>("detector-library"); + + for ( unsigned int ilib = 0 ; ilib < detectorLibraries.size() ; ilib++ ) { + LOG(info) << " -----> library \"" << detectorLibraries.at(ilib) << "\""; + + void* handle = dlopen(detectorLibraries.at(ilib).c_str(), RTLD_LAZY); + + if (!handle) { + LOG(fatal) << "Cannot open library: " << dlerror(); + return; + } + + // load the symbol + LOG(info) << "Loading symbol ..."; + typedef void (*det_t)(); + + // reset errors + dlerror(); + det_t ExternCreateDetector = (det_t) dlsym(handle, "ExternCreateDetector"); + const char *dlsym_error = dlerror(); + if (dlsym_error) { + LOG(fatal) << "Cannot load symbol 'ExternCreateDetector': " << dlsym_error; + dlclose(handle); + return; + } + + // run the function, where detector should be added to FairRunSim + ExternCreateDetector(); + + // close the library + cout << "NOT closing library...\n"; + // dlclose(handle); + } + + // ------------------------------------------------------------------------ + + // ----- Negotiate the run number ------------------------------------- + // ----- via the fUpdateChannelName -------------------------------- + // ----- ask the fParamMQServer ------------------------------------ + // ----- receive the run number and sampler id --------------------- + std::string* askForRunNumber = new string("ReportSimDevice"); + FairMQMessagePtr req(NewMessage(const_cast(askForRunNumber->c_str()), + askForRunNumber->length(), + [](void* /*data*/, void* object) { delete static_cast(object); }, + askForRunNumber)); + std::unique_ptr rep(NewMessage()); + + if (Send(req, fUpdateChannelName) > 0) + { + if (Receive(rep, fUpdateChannelName) > 0) + { + std::string repString = string(static_cast(rep->GetData()), rep->GetSize()); + LOG(INFO) << " -> " << repString.data(); + fRunId = stoi(repString); + fMCSplitEventHeader->SetRunID(fRunId); + repString = repString.substr(repString.find_first_of('_')+1,repString.length()); + fTransportDeviceId = stoi(repString); + LOG(INFO) << "runId = " << fRunId << " /// fTransportDeviceId = " << fTransportDeviceId; + } + } + // ------------------------------------------------------------------------ + + fRunSim->SetStoreTraj(fStoreTrajFlag); + + // ----- Set tasks ---------------------------------------------------- + if ( fTaskArray ) { + for ( int itask = 0 ; itask < fTaskArray->GetEntries() ; itask++ ) { + fRunSim->AddTask(dynamic_cast(fTaskArray->At(itask))); + } + } + // ------------------------------------------------------------------------ + // ----- Initialize simulation run ------------------------------------ + // fRunSim->SetRunId(fRunId); // run n simulations with same run id - offset the event number + fRunSim->Init(); + // ------------------------------------------------------------------------ + + fVMC = TVirtualMC::GetMC(); + fMCApplication = FairMCApplication::Instance(); + fStack = fMCApplication->GetStack(); + fStack->Register(); + // fRunSim->Run(0); + UpdateParameterServer(); + LOG(INFO) << "end of FairMQTransportDevice::InitTask() run id = " << fRunSim->GetMCEventHeader()->GetRunID(); + LOG(INFO) << " name/title/classname = " << fRunSim->GetMCEventHeader()->GetName() << "/" << fRunSim->GetMCEventHeader()->GetTitle() << "/" << fRunSim->GetMCEventHeader()->ClassName(); + +} + +void FairMQTransportDevice::PreRun() +{ +} + +bool FairMQTransportDevice::ConditionalRun() +{ + if ( !fRunConditional ) return false; + + std::string* requestString = new string("RequestData"); + FairMQMessagePtr req(NewMessage(const_cast(requestString->c_str()), + requestString->length(), + [](void* /*data*/, void* object) { delete static_cast(object); }, + requestString)); + FairMQParts parts; + // FairMQMessagePtr rep(NewMessage()); + + if (Send(req, fGeneratorChannelName) > 0) + { + if (Receive(parts, fGeneratorChannelName) > 0) + { + return TransportData(parts,0); + } + } + return false; +} + +// bool FairMQTransportDevice::TransportData(FairMQMessagePtr& mPtr, int /*index*/) +// { +// TClonesArray* chunk = nullptr; +// Deserialize(*mPtr, chunk); +// fStack->SetParticleArray(chunk); +// fVMC->ProcessRun(1); + +// return true; +// } + +bool FairMQTransportDevice::TransportData(FairMQParts& mParts, int /*index*/) +{ + TClonesArray* chunk = nullptr; + FairMCSplitEventHeader* meh = nullptr; + for ( int ipart = 0 ; ipart < mParts.Size() ; ipart++ ) { + TObject* obj = nullptr; + Deserialize(*mParts.At(ipart),obj); + if (strcmp(obj->GetName(),"MCEvent") == 0) + meh = dynamic_cast(obj); + else if (strcmp(obj->GetName(),"TParticles") == 0) + chunk = dynamic_cast(obj); + } + if ( chunk != nullptr ) { + fStack->SetParticleArray(chunk,meh->GetChunkStart(),meh->GetNPrim()); + fMCSplitEventHeader->SetRECC(fRunId,meh->GetEventID(),meh->GetNofChunks(),meh->GetChunkStart()); + fVMC->ProcessRun(1); + } + + return true; +} + +void FairMQTransportDevice::UpdateParameterServer() +{ + FairRuntimeDb* rtdb = fRunSim->GetRuntimeDb(); + + LOG(info) << "FairMQTransportDevice::UpdateParameterServer() (" << rtdb->getListOfContainers()->GetEntries() << " containers)"; + + // send the parameters to be saved + TIter next(rtdb->getListOfContainers()); + FairParSet* cont; + while ((cont=static_cast(next()))) + { + std::string ridString = std::string("RUNID") + std::to_string(fRunSim->GetRunId()) + std::string("RUNID") + std::string(cont->getDescription()); + cont->setDescription(ridString.data()); + SendObject(cont,fUpdateChannelName); + } + + LOG(info) << "FairMQTransportDevice::UpdateParameterServer() finished"; +} + +void FairMQTransportDevice::PostRun() +{ +} + +FairMQTransportDevice::~FairMQTransportDevice() +{ +} diff --git a/examples/MQ/simulation_split/src/devices/FairMQTransportDevice.h b/examples/MQ/simulation_split/src/devices/FairMQTransportDevice.h new file mode 100644 index 0000000000..19d8f3b582 --- /dev/null +++ b/examples/MQ/simulation_split/src/devices/FairMQTransportDevice.h @@ -0,0 +1,106 @@ +/******************************************************************************** + * Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence version 3 (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ + +/** + * FairMQTransportDevice.h + * + * @since 2018-02-01 + * @author R. Karabowicz + */ + +#ifndef FAIRMQTRANSPORTDEVICE_H_ +#define FAIRMQTRANSPORTDEVICE_H_ + +#include +#include "TString.h" + +#include "FairMQRunDevice.h" + +class FairMCSplitEventHeader; +class FairRunSim; +class FairField; +class FairParIo; +class FairPrimaryGenerator; +class TObject; +class TObjArray; +class FairSink; +class FairMCApplication; +class FairGenericStack; +class TVirtualMC; + +class FairMQTransportDevice : public FairMQRunDevice +{ + public: + FairMQTransportDevice(); + virtual ~FairMQTransportDevice(); + + // ------ FairRunSim setters ------ + void SetNofEvents (int64_t nofev) { fNofEvents = nofev;}; + void SetTransportName (std::string str) { fTransportName = str;}; + void SetMaterials (std::string str) { fMaterialsFile = str;}; + void SetMagneticField (FairField* field) { fMagneticField = field;}; + void SetDetectorArray (TObjArray* array) { fDetectorArray = array;}; + void SetStoreTraj (bool flag=true) { fStoreTrajFlag = flag;}; + void SetTaskArray (TObjArray* array) { fTaskArray = array;}; + void SetFirstParameter (FairParIo* par) { fFirstParameter = par;}; + void SetSecondParameter (FairParIo* par) { fSecondParameter = par;}; + void SetUserConfig (const TString& Config) { fUserConfig = Config;} + void SetUserCuts (const TString& Cuts) { fUserCuts = Cuts;} + void SetSink (FairSink* sink) { fSink = sink;} + // ------ ---------- -------- ------ + + void SetParamUpdateChannelName(TString tString) { fUpdateChannelName = tString; } + + void RunInPullMode(bool tb=true) { fRunConditional = !tb; }; + void RunInReqMode (bool tb=true) { fRunConditional = tb; }; + + protected: + bool TransportData(FairMQParts&, int); + // bool TransportData(FairMQMessagePtr&, int); + virtual void Init(); + virtual void InitTask(); + virtual void PreRun(); + virtual void PostRun(); + virtual bool ConditionalRun(); + + private: + UInt_t fRunId; + UInt_t fTransportDeviceId; + std::string fGeneratorChannelName; + std::string fUpdateChannelName; + + bool fRunConditional; // if true run ConditionalRun, if false run TransportData + + TVirtualMC* fVMC; + FairGenericStack* fStack; + FairMCApplication* fMCApplication; + FairRunSim* fRunSim; + // ------ FairRunSim settings ------ + int64_t fNofEvents; + std::string fTransportName; + std::string fMaterialsFile; + FairField* fMagneticField; + TObjArray* fDetectorArray; + bool fStoreTrajFlag; + TObjArray* fTaskArray; + FairParIo* fFirstParameter; // first (prefered) input for parameters + FairParIo* fSecondParameter; // second input (used if not found in first input) + TString fUserConfig; //! /** Macro for geant configuration*/ + TString fUserCuts; //! /** Macro for geant cuts*/ + FairSink* fSink; + // ------ ---------- -------- ------ + + FairMCSplitEventHeader* fMCSplitEventHeader; + + void UpdateParameterServer(); + + FairMQTransportDevice(const FairMQTransportDevice&); + FairMQTransportDevice& operator=(const FairMQTransportDevice&); +}; + +#endif /* FAIRMQTRANSPORTDEVICE_H_ */ diff --git a/examples/common/gconfig/g3Config.C b/examples/common/gconfig/g3Config.C index a3088e4a7b..cf57460217 100644 --- a/examples/common/gconfig/g3Config.C +++ b/examples/common/gconfig/g3Config.C @@ -11,9 +11,14 @@ void Config() { + std::cout << "starting g3Config.C" << std::endl; FairRunSim *fRun = FairRunSim::Instance(); + std::cout << "got FairRunSim instance " << fRun << std::endl; TString* gModel = fRun->GetGeoModel(); + std::cout << "model is " << gModel->Data() << std::endl; TGeant3* geant3 = NULL; + std::cout << "geant3 is now " << geant3 << std::endl; + std::cout << "gMC is " << gMC << std::endl; if ( strncmp(gModel->Data(),"TGeo",4) == 0 ) { geant3 = new TGeant3TGeo("C++ Interface to Geant3"); @@ -25,6 +30,8 @@ void Config() // cout << "-I- G3Config: Geant3 native has been created." // << endl; } + std::cout << "after creating geant3 is now " << geant3 << std::endl; + std::cout << "gMC is " << gMC << std::endl; // create Fair Specific Stack FairStack *st = new FairStack(); st->SetMinPoints(0); diff --git a/examples/common/mcstack/FairStack.cxx b/examples/common/mcstack/FairStack.cxx index 4e3e2b8386..40520a5715 100644 --- a/examples/common/mcstack/FairStack.cxx +++ b/examples/common/mcstack/FairStack.cxx @@ -230,7 +230,7 @@ void FairStack::FillTrackArray() // --> Loop over fParticles array and copy selected tracks for (Int_t iPart=0; iPart // for stack #include // for pair +#include "TParticle.h" + class TClonesArray; -class TParticle; class TRefArray; class FairStack : public FairGenericStack @@ -202,6 +203,27 @@ class FairStack : public FairGenericStack TParticle* GetParticle(Int_t trackId) const; TClonesArray* GetListOfParticles() { return fParticles; } + void SetParticleArray(TClonesArray* partArray) { + for ( Int_t ipart = 0 ; ipart < partArray->GetEntries() ; ipart++ ) { + ((TParticle*)(partArray->At(ipart)))->SetUniqueID(fNPrimaries); + fStack.push((TParticle*)partArray->At(ipart)); + AddParticle((TParticle*)partArray->At(ipart)); + fNParticles++; + fNPrimaries++; + } + } + + void SetParticleArray(TClonesArray* partArray, Int_t partFrom, Int_t partTo) { + for ( Int_t ipart = partFrom ; ipart < partTo ; ipart++ ) { + ((TParticle*)(partArray->At(ipart)))->SetUniqueID(fNPrimaries); + ((TParticle*)(partArray->At(ipart)))->SetStatusCode(fNPrimaries); + fStack.push((TParticle*)partArray->At(ipart)); + AddParticle((TParticle*)partArray->At(ipart)); + fNParticles++; + fNPrimaries++; + } + } + /** Clone this object (used in MT mode only) */ virtual FairGenericStack* CloneStack() const { return new FairStack(); } diff --git a/examples/simulation/Tutorial1/src/FairTutorialDet1.cxx b/examples/simulation/Tutorial1/src/FairTutorialDet1.cxx index 6e725bc94f..c93034103a 100644 --- a/examples/simulation/Tutorial1/src/FairTutorialDet1.cxx +++ b/examples/simulation/Tutorial1/src/FairTutorialDet1.cxx @@ -14,6 +14,7 @@ #include "FairGeoVolume.h" // for FairGeoVolume #include "FairRootManager.h" // for FairRootManager #include "FairRun.h" // for FairRun +#include "FairRunSim.h" // for FairRunSim #include "FairRuntimeDb.h" // for FairRuntimeDb #include "FairStack.h" // for FairStack #include "FairTutorialDet1Geo.h" // for FairTutorialDet1Geo @@ -228,5 +229,18 @@ void FairTutorialDet1::SetSensitiveVolumes() ProcessNodes ( volList ); } +extern "C" void ExternCreateDetector() { + using std::cout; + using std::endl; + + cout << "-- ExternCreateDetector() START --" << endl; + FairRunSim* run = FairRunSim::Instance(); + + FairTutorialDet1* tutdet = new FairTutorialDet1("TUTDET", kTRUE); + tutdet->SetGeometryFileName("double_sector.geo"); + run->AddModule(tutdet); + cout << "-- ExternCreateDetector(" << tutdet->GetName() << ") DONE --" << endl; +} + ClassImp(FairTutorialDet1)