ODIN
collector_code.h
1 #include "collector.h"
2 
3 
4 template<unsigned int Nin, class In, unsigned int Ncoll, class Coll, bool use_numof>
6  Log<Reco> odinlog(c_label(),"process");
7 
8  TinyVector<int,Ncoll> index;
9  Coll::create_index(rd.coord(), index);
10 
11  TinyVector<int,Ncoll> shape;
12  Coll::create_shape(rd.coord(), shape);
13 
14  // create shape of collected data
15  TinyVector<int,Ncoll+Nin> collshape;
16  for(int i=0; i<int(Ncoll); i++) collshape(i)=shape(i);
17  for(int i=0; i<int(Nin); i++) collshape(Ncoll+i)=rd.data(Rank<Nin>()).extent(i);
18  ODINLOG(odinlog,normalDebug) << "index/shape/collshape=" << index << "/" << shape << "/" << collshape << STD_endl;
19  if(!product(collshape)) {
20  ODINLOG(odinlog,errorLog) << "Zero-size shape " << collshape << STD_endl;
21  return false;
22  }
23 
24  // adjust coordinate to output dims for correct indexing of todo map
25  modify_coord(rd.coord());
26 
27  // create new view of input data
29  rd.data(Rank<Nin>()).convert_to(indata); // bring to same rank
30 
31  // create domains for copying input data to the correct position
32  TinyVector<int,Ncoll+Nin> lowin=0;
33  TinyVector<int,Ncoll+Nin> uppin=0;
34 
35  TinyVector<int,Ncoll+Nin> lowdst=0;
36  TinyVector<int,Ncoll+Nin> uppdst=0;
37 
38  for(int i=0; i<int(Ncoll); i++) lowdst(i)=uppdst(i)=index(i);
39  for(int i=0; i<int(Nin); i++) uppin(Ncoll+i)=uppdst(Ncoll+i)=rd.data(Rank<Nin>()).extent(i)-1;
40  ODINLOG(odinlog,normalDebug) << "lowin/uppin=" << lowin << "/" << uppin << STD_endl;
41  ODINLOG(odinlog,normalDebug) << "lowdst/uppdst=" << lowdst << "/" << uppdst << STD_endl;
42 
43  RectDomain<Ncoll+Nin> indomain(lowin,uppin);
44  RectDomain<Ncoll+Nin> dstdomain(lowdst,uppdst);
45 
46  // fill data
47  mutex.lock();
48  ComplexData<Ncoll+Nin>& dataref=datamap[rd.coord()];
49  if(dataref.shape()!=collshape) {
50  dataref.resize(collshape);
51  dataref=STD_complex(0.0); // Initialize to zero for partial k-space acquisition
52  }
53  dataref(dstdomain)=dataref(dstdomain)+indata(indomain);
54  mutex.unlock();
55 
56  unsigned int numof_count=0;
57  if(use_numof) numof_count=product(shape);
58 
59  if( completed(rd.coord(),numof_count) ) {
60  ODINLOG(odinlog,normalDebug) << " data " << collshape << " complete" << STD_endl;
61 
62  // fill rd with collected data
63  mutex.lock();
64  typename DataMap::iterator it=datamap.find(rd.coord()); // typename is necessary here for GCC4
65  rd.data(Rank<Nin>()).free(); // deallocate input data
66  rd.data(Rank<Ncoll+Nin>()).reference(it->second);
67  datamap.erase(it); // delete entry from map to save memory and to trigger initialization if data is needed again
68  mutex.unlock();
69 
70  if(!execute_next_step(rd,controller)) return false;
71  }
72 
73  return true;
74 }
75 
76 
77 
78 template<unsigned int Nin, class In, unsigned int Ncoll, class Coll, bool use_numof>
80  Log<Reco> odinlog(c_label(),"query");
81 
82  if(context.mode==RecoQueryContext::prep) {
83  if(!use_numof) {
84  RecoCoord outmask=context.coord;
85  modify_coord(outmask);
86  if(!calculate_count(context, context.coord, outmask)) return false;
87  }
88  }
89 
90  return RecoStep::query(context);
91 }
Data< T2, N_rank2 > & convert_to(Data< T2, N_rank2 > &dst, bool autoscale=true) const
Definition: tjlog.h:218
averagecoll, chancoll, chanrepcoll, chanrepslicecoll, cyclecoll, driftcoll, echocoll,...
Definition: collector.h:86
ComplexData< 1 > & data(Rank< 1 >) const
Definition: odinreco/data.h:91
RecoCoord & coord()
virtual bool query(RecoQueryContext &context)