Skip to content

Commit fce0150

Browse files
author
contuandrea
committed
Fix main_maps
1 parent a777a78 commit fce0150

File tree

4 files changed

+43
-29
lines changed

4 files changed

+43
-29
lines changed

include/deposits/deposit.h

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,59 +35,77 @@ namespace deposit{
3535
class owndeposit{
3636
private:
3737
//static are useful not to reload deposits if not needed
38-
static std::string _static_path;
39-
static RunningStateHost_t _static_data;
40-
static size_t _static_nparticles;
41-
static double _static_length;
38+
std::string _cached_path;
39+
RunningStateHost_t _cached_data;
40+
size_t _cached_nparticles;
41+
size_t cached_group;
42+
double _cached_length;
4243

4344
std::string _path;
4445
RunningStateHost_t _data;
4546
size_t _nparticles;
47+
size_t _group;
4648
double _length=1.;
49+
bool _isloaded;
4750

4851
public:
52+
53+
owndeposit(){}
54+
4955
owndeposit(std::string path, size_t nparticles, double length, size_t group=DEFAULT_GROUP){
5056
this->init(path, nparticles, length);
5157
}
5258

53-
owndeposit(singleconf cf){
54-
this->init(std::get<std::string>(cf.get("path")), std::get<size_t>(cf.get("nparticles")),std::get<double>(cf.get("length")));
59+
owndeposit(singleconf& cf){
60+
this->init(cf);
5561
}
5662
//initialise
63+
64+
void init(singleconf& cf){
65+
this->init(std::get<std::string>(cf.get("path")), std::get<size_t>(cf.get("nparticles")),std::get<double>(cf.get("length"),,std::get<size_t>(cf.get("group")));
66+
}
67+
5768
void init(std::string path, size_t nparticles, double length, size_t group=DEFAULT_GROUP){
5869
if(_path==DEFAULT_PATH){
59-
if(nparticles!=_static_nparticles || length!=_static_length){
70+
if(nparticles!=_cached_nparticles || length!=_cached_length || group!=_cached_group){
6071
_data = this->gendummy(nparticles,length);
6172
}
6273
else{
6374
_data.resize(_nparticles);
64-
hydra::copy(_static_data,_data);
75+
hydra::copy(_cached_data,_data);
6576
}
6677
_nparticles = nparticles;
6778
_length = length;
6879
}
6980
else{
70-
if(path!=_static_path){
81+
if(path!=_cached_path){
7182
_data = loaddata::loadfile(path);
7283
_nparticles = _data.size();
73-
_static_data.resize(_nparticles);
74-
hydra::copy(_data,_static_data);
84+
_cached_data.resize(_nparticles);
85+
hydra::copy(_data,_cached_data);
86+
_cached_nparticles = _nparticles;
87+
_cached_length = length;
7588
}
7689
else{
7790
_data.resize(_nparticles);
78-
hydra::copy(_static_data,_data);
91+
hydra::copy(_cached_data,_data);
7992
_nparticles = _data.size();
8093
}
8194
}
95+
_isloaded=true;
8296
}
97+
98+
//get _isloaded
99+
bool isloaded(){return _isloaded;}
100+
83101
//get length
84102
double getlength(){return _length;}
85103

86104
//get nparticles
87105
double getnparticles(){return _nparticles;}
88106

89107
//generate dummy deposit
90-
RunningStateHost_t gendummy(size_t nparticles, double length, size_t group=DEFAULT_GROUP){
108+
void gendummy(size_t nparticles, double length, size_t group=DEFAULT_GROUP){
91109
INFO_LINE("Generating deposit")
92110
hydra::Random<> Generator( std::chrono::system_clock::now().time_since_epoch().count());
93111
size_t np=(nparticles<=0) ? MAXPARTICLES : nparticles;
@@ -111,21 +129,14 @@ namespace deposit{
111129
}
112130
hydra::copy(data_de,hydra::make_range(data_d.begin(),data_d.begin()+halfsize));
113131
hydra::copy(data_dh,hydra::make_range(data_d.begin()+halfsize,data_d.end()));
114-
115-
return data_d;
116132
}
117133

118134
//get deposit
119-
RunningStateHost_t* getdata(){return &_data;}
135+
RunningStateHost_t getdata(){return _data;}
120136

121137
//get deposit and change if different
122-
RunningStateHost_t* getdata(std::string newfile, size_t nparticles, double length=1., size_t group=DEFAULT_GROUP){
123-
if(_path!=newfile){
124-
_path=newfile;
125-
if(newfile==DEFAULT_PATH) _data = loaddata::getDummy(nparticles,length);
126-
else _data=loaddata::loadfile(newfile);
127-
}
128-
return &_data;
138+
void SendToDevice(RunningStateDev_t& todev, singleconf)
139+
129140
}
130141
};
131142
}

include/main_maps.inl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ int main(int argv, char** argc){
186186
cfg::Setting & root = Cfg.getRoot();
187187

188188
root.add("OutputDirectory", cfg::Setting::TypeString) = outputdir;
189-
190189
if(PHYSMAPfile!="none"){
190+
root.add("map",cfg::Setting::TypeGroup);
191191
cfg::Setting & root_pm = root["map"];
192192
root_pm.add("path", cfg::Setting::TypeString) = PHYSMAPfile;
193193
root_pm.add("out", cfg::Setting::TypeString) = PHYSMAPfile_out;
@@ -197,6 +197,7 @@ int main(int argv, char** argc){
197197
root_pm.add("scalespace", cfg::Setting::TypeFloat) = physmap_scalespace;
198198
}
199199
else{
200+
root.add("efield",cfg::Setting::TypeGroup);
200201
cfg::Setting & root_efield = root["efield"];
201202
root_efield.add("path", cfg::Setting::TypeString) = EFfile;
202203
root_efield.add("out", cfg::Setting::TypeString) = EFfile_out;
@@ -205,6 +206,7 @@ int main(int argv, char** argc){
205206
root_efield.add("scale", cfg::Setting::TypeFloat) = efield_scale;
206207
root_efield.add("scalespace", cfg::Setting::TypeFloat) = efield_scalespace;
207208

209+
root.add("wfield",cfg::Setting::TypeGroup);
208210
cfg::Setting & root_wfield = root["wfield"];
209211
root_wfield.add("path", cfg::Setting::TypeString) = WFfile;
210212
root_wfield.add("out", cfg::Setting::TypeString) = WFfile_out;
@@ -213,6 +215,7 @@ int main(int argv, char** argc){
213215
root_wfield.add("scale", cfg::Setting::TypeFloat) = wfield_scale;
214216
root_wfield.add("scalespace", cfg::Setting::TypeFloat) = wfield_scalespace;
215217

218+
root.add("emob",cfg::Setting::TypeGroup);
216219
cfg::Setting & root_emob = root["emob"];
217220
root_emob.add("path", cfg::Setting::TypeString) = EMOBfile;
218221
root_emob.add("out", cfg::Setting::TypeString) = EMOBfile_out;
@@ -221,6 +224,7 @@ int main(int argv, char** argc){
221224
root_emob.add("scale", cfg::Setting::TypeFloat) = emob_scale;
222225
root_emob.add("scalespace", cfg::Setting::TypeFloat) = emob_scalespace;
223226

227+
root.add("hmob",cfg::Setting::TypeGroup);
224228
cfg::Setting & root_hmob = root["hmob"];
225229
root_hmob.add("path", cfg::Setting::TypeString) = HMOBfile;
226230
root_hmob.add("out", cfg::Setting::TypeString) = HMOBfile_out;

include/maps/preparemaps.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,6 @@ namespace maps{
773773

774774
//prepare maps
775775
void preparemaps(cfg::Setting const& root){
776-
777776
//check if output directory exists, if it does not it is created
778777
std::string outputdir=root["OutputDirectory"];
779778
mkdir(outputdir.c_str(),S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IROTH);

include/simulation/simulation.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ namespace sim{
8383
//prepare simulation
8484
void prepare(){
8585
deposit::owndeposit mydep(_path,_nparticles,_length);
86-
if(_nparticles==0 || _nparticles> mydep.getnparticles()) _nparticles = mydep.getnparticles();
87-
_data.resize(_nparticles);
88-
hydra::copy(hydra::make_range(mydep.getdata()->begin(),mydep.getdata()->begin() + _nparticles),_data); // copy deposit to device
89-
_prepared = true;
86+
// if(_nparticles==0 || _nparticles> mydep.getnparticles()) _nparticles = mydep.getnparticles();
87+
// // _data.resize(_nparticles);
88+
// hydra::copy(hydra::make_range(mydep.getdata().begin(),mydep.getdata().begin() + _nparticles),_data); // copy deposit to device
89+
// _prepared = true;
9090
// hydra::for_each(_data, loaddata::Translate(xshift,yshift,zshift,_xmin,_xmax,_ymin,_ymax,_zmin,_zmax));
9191
}
9292

0 commit comments

Comments
 (0)