17 #include "Identifier/Identifier.h"
21 #include "GaudiKernel/MsgStream.h"
33 #define MAX_TOKEN_SIZE 256
40 IdentifierHash hash_id;
44 std::vector<std::string> neighbours[4];
45 std::vector<int> neighbours_ind[4];
80 log << MSG::ERROR <<
"Could not open file " <<
file <<
endmsg;
87 unsigned int line=0, record=0;
92 std::vector<Cell> allCells;
94 while (
fin >> token ) {
96 if ( token[0] ==
'#' || token[0] ==
'!' || ( token[0] ==
'/' && token[1] ==
'/' ) ) {
101 unsigned int toklen = strlen(token) - 1 ;
106 newCell.name = token;
107 for (
unsigned int i=0;
i<4; ++
i) newCell.neighbours[
i].clear();
110 while (
fin >> token) {
111 toklen = strlen(token) - 1;
112 bool lastelem = ( token[toklen] ==
';' );
115 if (strcmp(token,
"none") != 0)
116 newCell.neighbours[
column].emplace_back(token);
126 allCells.push_back(newCell);
135 unsigned int curSize = allCells.size();
136 for (
unsigned int i=0;
i<curSize; ++
i) {
138 std::string::size_type
pos = allCells[
i].name.find(
'-', 0 );
139 if ( std::string::npos !=
pos ) {
143 tmpName = allCells[
i].name;
144 tmpName.replace(
pos,1,
"+");
145 newCell.name = tmpName;
147 for (
unsigned int j=0; j<4; ++j) {
148 unsigned int j1 = (j<2) ? 1-j : j;
149 unsigned int nb_size=allCells[
i].neighbours[j].size();
150 for (
unsigned int k=0;
k<nb_size; ++
k) {
151 tmpName = allCells[
i].neighbours[j][
k];
152 pos = tmpName.find(
'-', 0 );
153 if ( std::string::npos !=
pos ) {
154 tmpName.replace(
pos,1,
"+");
156 pos = tmpName.find(
'+', 0 );
157 if ( std::string::npos !=
pos ) {
158 tmpName.replace(
pos,1,
"-");
161 newCell.neighbours[
j1].push_back(tmpName);
164 allCells.push_back(newCell);
168 unsigned int nids = 0;
169 unsigned int max_phi = 0,
phi=0;
170 std::set<std::pair<IdentifierHash,int> >
ids;
179 if (
phi > max_phi) max_phi =
phi;
187 log << MSG::ERROR <<
"init_hashes "
188 <<
" Error: duplicated id for cell id. nids= " << nids
203 curSize = allCells.size();
205 std::string nb_name[4] = {
"Prev_eta_",
"Next_eta_",
"Prev_smp_",
"Next_smp_"};
207 for (
unsigned int i=0;
i<curSize; ++
i) {
210 for (
unsigned int ii=0; ii<
m_length; ++ii) {
212 allCells[
i].index = ii;
217 for (
unsigned int j=0; j<4; ++j) {
218 unsigned int nb_size=allCells[
i].neighbours[j].size();
219 allCells[
i].neighbours_ind[j].resize(nb_size);
220 for (
unsigned int k=0;
k<nb_size; ++
k) {
221 for (
unsigned int ii=0; ii<curSize; ++ii) {
222 if ( allCells[ii].
name == allCells[
i].neighbours[j][
k]) {
223 allCells[
i].neighbours_ind[j][
k] = ii;
226 << tileID->
to_string(allCells[
i].
id,-2) <<
" "
227 << allCells[
i].hash_id <<
" "
228 << allCells[
i].index <<
" "
229 << nb_name[j] <<
k <<
" "
230 << allCells[
i].neighbours[j][
k] <<
" "
231 << allCells[
i].neighbours_ind[j][
k] <<
" "
248 std::vector<short int> neighbours[4];
249 for (
unsigned int i=0;
i<curSize; ++
i) {
250 unsigned int ind = allCells[
i].index;
252 for (
unsigned int j=0; j<4; ++j) {
253 unsigned int nb_size=allCells[
i].neighbours[j].size();
254 neighbours[j].resize(nb_size);
255 for (
unsigned int k=0;
k<nb_size; ++
k) {
256 neighbours[j][
k] = allCells[allCells[
i].neighbours_ind[j][
k]].index;
268 int sd = tileID->
side(allCells[
i].
id);
269 int tw = tileID->
tower(allCells[
i].
id);
270 int sm = tileID->
sample(allCells[
i].
id);
273 for (
unsigned int j=2; j<4; ++j) {
276 unsigned int nb_size=allCells[
i].neighbours[j].size();
277 for (
unsigned int k=0;
k<nb_size; ++
k) {
278 unsigned int new_i = allCells[
i].neighbours_ind[j][
k];
279 for (
unsigned int new_j=0; new_j<2; ++new_j) {
280 unsigned int new_nb_size=allCells[new_i].neighbours[new_j].size();
281 for (
unsigned int new_k=0; new_k<new_nb_size; ++new_k) {
282 unsigned int new_nb_i = allCells[new_i].neighbours_ind[new_j][new_k];
283 short new_nb_index = allCells[new_nb_i].index;
284 int n=neighbours[j].size()-1;
286 if (neighbours[j][
n] == new_nb_index)
290 int new_sd = tileID->
side(allCells[new_nb_i].
id);
291 int new_tw = tileID->
tower(allCells[new_nb_i].
id);
292 int new_sm = tileID->
sample(allCells[new_nb_i].
id);
293 int new_se = tileID->
section(allCells[new_nb_i].
id);
294 if ( ( new_sd !=
sd && new_tw == tw ) ||
296 ( new_se ==
se && abs(new_tw - tw) < 3 ) ||
298 ( new_sm == sm+1 && abs(new_tw - tw) < 3 ) ||
299 ( new_sm != sm+1 && abs(new_tw - tw) < 4 ) ))))) {
300 neighbours[j].push_back(new_nb_index);
315 std::vector<IdentifierHash> nb_list;
318 for (
unsigned int i=0;
i<hash_max; ++
i) {
321 tileID->
get_id (
i,
id, &context);
322 if ( tileID->
module(
id) != 0 )
continue;
324 IdentifierHash hash_id=
i;
325 nb_list.clear(); nb_list.push_back(hash_id);
329 print_list(nb_list, tileID, &context,
log,
"Prev phi ",
" ; ");
332 print_list(nb_list, tileID, &context,
log,
"Next phi ",
" ; ");
335 print_list(nb_list, tileID, &context,
log,
"Prev eta ",
" ; ");
338 print_list(nb_list, tileID, &context,
log,
"Next eta ",
" ; ");
341 print_list(nb_list, tileID, &context,
log,
"Prev smp ",
" ; ");
344 print_list(nb_list, tileID, &context,
log,
"Next smp ",
" ; ");
347 print_list(nb_list, tileID, &context,
log,
"Face 2D ",
" ; ");
350 print_list(nb_list, tileID, &context,
log,
"Corn 2D ",
" ; ");
359 print_list(nb_list, tileID, &context,
log,
"All 3DC ",
" ; ");
362 print_list(nb_list, tileID, &context,
log,
"Super 3D ",
" ; ");
371 unsigned int hash_max,
unsigned int max_phi, MsgStream &
log)
374 if(
ids.size() != hash_max) {
375 log << MSG::ERROR <<
"fill_phi_vec "
376 <<
" Error: set size NOT EQUAL to hash max. size " <<
ids.size()
377 <<
" hash max " << hash_max
386 int dphi = hash_max / max_phi;
388 int ind_min=0, ind_max=-1,
phi, phi_prev=-1,
index=0;
390 std::set<std::pair<IdentifierHash,int> >::const_iterator
first =
ids.begin();
391 std::set<std::pair<IdentifierHash,int> >::const_iterator last =
ids.end();
394 phi = (*first).second;
395 if (
phi != phi_prev) {
408 IdentifierHash hash_id = (*first).first;
456 std::vector<IdentifierHash> & neighbourList)
const
469 std::vector<IdentifierHash> & neighbourList)
const
482 std::vector<IdentifierHash> & neighbourList)
const
488 for (
unsigned int i=0;
i<
size; ++
i) {
496 std::vector<IdentifierHash> & neighbourList)
const
502 for (
unsigned int i=0;
i<
size; ++
i) {
510 std::vector<IdentifierHash> & neighbourList)
const
516 for (
unsigned int i=0;
i<
size; ++
i) {
524 std::vector<IdentifierHash> & neighbourList)
const
530 for (
unsigned int i=0;
i<
size; ++
i) {
538 std::vector<IdentifierHash> & neighbourList)
const
544 for (
unsigned int i=0;
i<
size; ++
i) {
552 std::vector<IdentifierHash> & neighbourList)
const
558 for (
unsigned int i=0;
i<
size; ++
i) {
567 const char *
name = strName.c_str();
573 std::string::size_type
pos = strName.find(
'-', 0 );
574 if ( std::string::npos !=
pos )
sd = -1;
else sd = 1;
576 sscanf(
name+2,
"%80d",&tw);
580 case 'a':
case 'A': sm = 0; tw -= 1;
581 if (tw<10)
se = 1;
else se = 2;
583 case 'b':
case 'B': sm = 1; tw -= 1;
584 if (tw<10)
se = 1;
else se = 2;
586 case 'c':
case 'C': sm = 1; tw -= 1;
589 case 'd':
case 'D': sm = 2; tw *= 2;
590 if (tw<10)
se = 1;
else se = 2;
593 case 'e':
case 'E': sm = 3;
595 case 1: tw = 10;
break;
596 case 2: tw = 11;
break;
597 case 3: tw = 13;
break;
598 case 4: tw = 15;
break;
602 case 's':
case 'S': sm = 0; tw -= 1;
603 if (tw<9)
se = 1;
else se = 2;
605 case 'v':
case 'V': sm = 2; tw *= 2;
606 if (tw<10)
se = 1;
else se = 2;
608 default:
se = 0; sm = -1; tw = -1;
break;
615 int &
module, std::string & strCell,
621 int tower = tileID->
tower (
id);
626 case 0: strSection =
"Online";
break;
627 case 1: strSection =
"Barrel";
break;
628 case 2: strSection =
"Ext.Barrel";
break;
629 case 3: strSection = (
sample < 3) ?
"ITC":
"Gap.Scin";
break;
630 default: strSection =
"Unknown";
634 char sd = (
side<0) ?
'-' :
'+';
638 case 0: sm=(supercell?
'S':
'A');
646 case 2: sm=(supercell?
'V':
'D');
660 else snprintf(
name,
sizeof(
name),
"%c%c%d", sm,
sd,tw);
665 << strSection <<
" " <<
module <<
" " << strCell <<
end;
678 std::string strSection;
680 std::sort(nb_list.begin(), nb_list.end());
681 unsigned int size=nb_list.size();
687 for (
unsigned int j=0; j<
size; ++j) {
690 tileID->
get_id (nb_list[j],
id, context);