14 #include <tr1/functional>
20 using namespace GeometryInfo;
23 using tr1::placeholders::_1;
24 using tr1::placeholders::_2;
48 pos.
x -= subtrahend.
x;
49 pos.
y -= subtrahend.
y;
55 const size_t col(static_cast<size_t>(pos.
x + 0.5));
56 const size_t row(static_cast<size_t>(pos.
y + 0.5));
57 return (row*nCols + col);
62 typedef map<string,asicInfo_t> asicInfoMap_t;
63 asicInfoMap_t geomInfos;
67 ifstream geomFile (filename.c_str());
68 if (!geomFile.is_open())
69 throw invalid_argument(
"GeometryInfo::generateLookupTable(): could not open file '" +
74 while(!geomFile.eof())
76 getline(geomFile, line);
79 if (line.find(
'/') == string::npos)
83 const string asic(line.substr(0,line.find(
'/')));
84 const string valueNameAndValue(line.substr(line.find(
'/')+1));
85 string valueName(valueNameAndValue.substr(0,valueNameAndValue.find(
'=')));
86 string valueString(valueNameAndValue.substr(valueNameAndValue.find(
'=')+1));
89 valueName.erase(
remove(valueName.begin(), valueName.end(),
' '), valueName.end());
93 if (valueName ==
"min_fs")
94 geomInfos[asic].min_fs = std::strtol(valueString.c_str(),&pEnd,10);
95 else if (valueName ==
"min_ss")
96 geomInfos[asic].min_ss = std::strtol(valueString.c_str(),&pEnd,10);
97 else if (valueName ==
"max_fs")
98 geomInfos[asic].max_fs = std::strtol(valueString.c_str(),&pEnd,10);
99 else if (valueName ==
"max_ss")
100 geomInfos[asic].max_ss = std::strtol(valueString.c_str(),&pEnd,10);
101 else if (valueName ==
"badrow_direction")
103 valueString.erase(
remove(valueString.begin(), valueString.end(),
' '), valueString.end());
104 geomInfos[asic].badrow_direction = valueString;
106 else if (valueName ==
"res")
107 geomInfos[asic].res = std::strtod(valueString.c_str(),&pEnd);
108 else if (valueName ==
"clen")
110 valueString.erase(
remove(valueString.begin(), valueString.end(),
' '), valueString.end());
111 geomInfos[asic].clen = valueString;
113 else if (valueName ==
"corner_x")
114 geomInfos[asic].corner_x = std::strtod(valueString.c_str(),&pEnd);
115 else if (valueName ==
"corner_y")
116 geomInfos[asic].corner_y = std::strtod(valueString.c_str(),&pEnd);
117 else if (valueName ==
"no_index")
118 geomInfos[asic].no_index = std::strtol(valueString.c_str(),&pEnd,10);
119 else if (valueName ==
"fs")
122 pEnd = &valueString[0];
123 for (
int i(0); i < 2 ; ++i)
125 const double number = std::strtod(pEnd,&pEnd);
127 geomInfos[asic].x_fs = number;
128 else if (pEnd[0] ==
'y')
129 geomInfos[asic].y_fs = number;
131 throw runtime_error(
string(
"GeometryInfo::generateConversionMap: Cannot assign '") +
132 pEnd[0] +
"' to x or y, in line with contents'" +
133 line +
"'. Parsed info so far: " +
134 "asic '" + asic +
"', "
135 "value Name and Value '" + valueNameAndValue +
"', "
136 "value Name '" + valueName +
"', "
137 "value as String '" + valueString +
"', "
138 "number extracted so far '" +
toString(number) +
"', "
139 "parsing iteration '" +
toString(i) +
"'");
143 else if (valueName ==
"ss")
145 pEnd = &valueString[0];
146 for (
int i(0); i < 2 ; ++i)
148 const double number = std::strtod(pEnd,&pEnd);
150 geomInfos[asic].x_ss = number;
151 else if (pEnd[0] ==
'y')
152 geomInfos[asic].y_ss = number;
154 throw runtime_error(
string(
"GeometryInfo::generateConversionMap: Cannot assign '") +
155 pEnd[0] +
"' to x or y, in line with contents'" +
156 line +
"'. Parsed info so far: " +
157 "asic '" + asic +
"', "
158 "value Name and Value '" + valueNameAndValue +
"', "
159 "value Name '" + valueName +
"', "
160 "value as String '" + valueString +
"', "
161 "number extracted so far '" +
toString(number) +
"', "
162 "parsing iteration '" +
toString(i) +
"'");
169 asicInfoMap_t::iterator it(geomInfos.begin());
170 for (; it != geomInfos.end(); ++it)
177 if (convertFromCheetahToCASS)
181 const int quad(ai.
min_fs/(2*nx));
182 const int asicRow(ai.
min_ss/(1*ny));
183 const int xbegin(ai.
min_fs/(1*nx) % 2);
184 const int ybegin(quad*2*4+asicRow);
187 ai.
max_fs = xbegin*nx + nx-1;
190 ai.
max_ss = ybegin*ny + ny-1;
197 for (
int rowInAsic = 0; rowInAsic <= rowAsicRange; ++rowInAsic)
199 for (
int colInAsic = 0; colInAsic <= colAsicRange; ++colInAsic)
208 int colInSrc = ai.
min_fs+colInAsic;
209 int rowInSrc = ai.
min_ss+rowInAsic;
212 int idxInSrc = rowInSrc * nSrcCols + colInSrc;
215 if (idxInSrc >= static_cast<int>(sizeOfSrc))
216 throw out_of_range(
"generateConversionMap(): The generated index '" +
217 toString(idxInSrc) +
"' is too big for the src with size '"+
218 toString(sizeOfSrc) +
"' in position in asic '" +
219 it->first +
"', row '" +
toString(rowInAsic) +
221 ", resulting position in lab would be x '" +
223 "'. With position in source col '" +
230 src2lab[idxInSrc].x = xInLab;
231 src2lab[idxInSrc].y = yInLab;
239 const size_t sizeOfSrc,
240 const size_t nSrcCols,
241 const bool convertFromCheetahToCASS)
244 lookupTable.
lut.resize(sizeOfSrc);
250 std::tr1::bind(less<pos_t::x_t>(),
251 std::tr1::bind<pos_t::x_t>(&
pos_t::x,_1),
252 std::tr1::bind<pos_t::x_t>(&
pos_t::x,_2)))->
x;
254 std::tr1::bind(less<pos_t::y_t>(),
255 std::tr1::bind<pos_t::y_t>(&
pos_t::y,_1),
256 std::tr1::bind<pos_t::y_t>(&
pos_t::y,_2)))->
y;
258 std::tr1::bind(less<pos_t::x_t>(),
259 std::tr1::bind<pos_t::x_t>(&
pos_t::x,_1),
260 std::tr1::bind<pos_t::x_t>(&
pos_t::x,_2)))->
x;
262 std::tr1::bind(less<pos_t::y_t>(),
263 std::tr1::bind<pos_t::y_t>(&
pos_t::y,_1),
264 std::tr1::bind<pos_t::y_t>(&
pos_t::y,_2)))->
y;
270 transform(src2lab.begin(),src2lab.end(),src2lab.begin(),
271 std::tr1::bind(
minus,_1,lookupTable.
min));
277 const double max_x =
max_element(src2lab.begin(),src2lab.end(),
278 std::tr1::bind(less<pos_t::x_t>(),
279 std::tr1::bind<pos_t::x_t>(&
pos_t::x,_1),
280 std::tr1::bind<pos_t::x_t>(&
pos_t::x,_2)))->
x;
281 const double max_y =
max_element(src2lab.begin(),src2lab.end(),
282 std::tr1::bind(less<pos_t::y_t>(),
283 std::tr1::bind<pos_t::y_t>(&
pos_t::y,_1),
284 std::tr1::bind<pos_t::y_t>(&
pos_t::y,_2)))->
y;
287 lookupTable.
nCols =
static_cast<int>(max_x + 0.5)+1;
288 lookupTable.
nRows =
static_cast<int>(max_y + 0.5)+1;
294 transform(src2lab.begin(),src2lab.end(),lookupTable.
lut.begin(),
299 throw out_of_range(
"generateLookupTable(): the maximum index in the lookup table '" +
301 "' does not fit with the destination size of '" +
pos_t minus(const pos_t &minuent, const pos_t &subtrahend)
functor to substract one position from the other
std::vector< pos_t > conversion_t
define the conversion table type
ForwardIterator min_element(ForwardIterator first, ForwardIterator last)
provide own implementation of min_element to be able to compile
conversion_t generateConversionMap(const std::string &filename, const size_t sizeOfSrc, const size_t nSrcCols, const bool convertFromCheetahToCASS)
parse the geom file and generate a lookup table
combine the position in the lab into a struct
ForwardIterator max_element(ForwardIterator first, ForwardIterator last)
provide own implementation of min_element to be able to compile
size_t linearizeComponents(const pos_t &pos, const size_t nCols)
convert index with 2 components into a linearized index
file contains global definitions for project cass
class to parse and retrieve info from geom files.
std::string toString(const Type &t)
convert any type to a string
combine info needed for the lookuptable
std::vector< size_t > lut
lookupTable_t generateLookupTable(const std::string &filename, const size_t sizeOfSrc, const size_t nSrcCols, const bool convertFromCheetahToCASS)
generate a lookup table for a new image