13 #include "Identifier/Identifier.h"
17 #include "GaudiKernel/MsgStream.h"
29 #define MAX_TOKEN_SIZE 256
36 IdentifierHash hash_id;
40 std::vector<std::string> neighbours[4];
41 std::vector<int> neighbours_ind[4];
76 log << MSG::ERROR <<
"Could not open file " <<
file <<
endmsg;
83 unsigned int line=0, record=0;
88 std::vector<Cell> allCells;
90 while (
fin >> token ) {
92 if ( token[0] ==
'#' || token[0] ==
'!' || ( token[0] ==
'/' && token[1] ==
'/' ) ) {
97 unsigned int toklen = strlen(token) - 1 ;
102 newCell.name = token;
103 for (
unsigned int i=0;
i<4; ++
i) newCell.neighbours[
i].clear();
106 while (
fin >> token) {
107 toklen = strlen(token) - 1;
108 bool lastelem = ( token[toklen] ==
';' );
111 if (strcmp(token,
"none") != 0)
112 newCell.neighbours[
column].emplace_back(token);
122 allCells.emplace_back(std::move(newCell));
131 unsigned int curSize = allCells.size();
132 for (
unsigned int i=0;
i<curSize; ++
i) {
134 std::string::size_type
pos = allCells[
i].name.find(
'-', 0 );
135 if ( std::string::npos !=
pos ) {
139 tmpName = allCells[
i].name;
140 tmpName.replace(
pos,1,
"+");
141 newCell.name = tmpName;
143 for (
unsigned int j=0; j<4; ++j) {
144 unsigned int j1 = (j<2) ? 1-j : j;
145 unsigned int nb_size=allCells[
i].neighbours[j].size();
146 for (
unsigned int k=0;
k<nb_size; ++
k) {
147 tmpName = allCells[
i].neighbours[j][
k];
148 pos = tmpName.find(
'-', 0 );
149 if ( std::string::npos !=
pos ) {
150 tmpName.replace(
pos,1,
"+");
152 pos = tmpName.find(
'+', 0 );
153 if ( std::string::npos !=
pos ) {
154 tmpName.replace(
pos,1,
"-");
157 newCell.neighbours[
j1].push_back(tmpName);
160 allCells.push_back(std::move(newCell));
164 unsigned int nids = 0;
165 unsigned int max_phi = 0,
phi=0;
166 std::set<std::pair<IdentifierHash,int> >
ids;
172 auto last = rit.
end();
176 if (
phi > max_phi) max_phi =
phi;
183 if(!(
ids.insert(std::make_pair(hashid,
phi))).second){
184 log << MSG::ERROR <<
"init_hashes "
185 <<
" Error: duplicated id for cell id. nids= " << nids
200 curSize = allCells.size();
202 std::string nb_name[4] = {
"Prev_eta_",
"Next_eta_",
"Prev_smp_",
"Next_smp_"};
204 for (
unsigned int i=0;
i<curSize; ++
i) {
207 for (
unsigned int ii=0; ii<
m_length; ++ii) {
209 allCells[
i].index = ii;
214 for (
unsigned int j=0; j<4; ++j) {
215 unsigned int nb_size=allCells[
i].neighbours[j].size();
216 allCells[
i].neighbours_ind[j].resize(nb_size);
217 for (
unsigned int k=0;
k<nb_size; ++
k) {
218 for (
unsigned int ii=0; ii<curSize; ++ii) {
219 if ( allCells[ii].
name == allCells[
i].neighbours[j][
k]) {
220 allCells[
i].neighbours_ind[j][
k] = ii;
223 << tileID->
to_string(allCells[
i].
id,-2) <<
" "
224 << allCells[
i].hash_id <<
" "
225 << allCells[
i].index <<
" "
226 << nb_name[j] <<
k <<
" "
227 << allCells[
i].neighbours[j][
k] <<
" "
228 << allCells[
i].neighbours_ind[j][
k] <<
" "
245 std::vector<short int> neighbours[4];
246 for (
unsigned int i=0;
i<curSize; ++
i) {
247 unsigned int ind = allCells[
i].index;
249 for (
unsigned int j=0; j<4; ++j) {
250 unsigned int nb_size=allCells[
i].neighbours[j].size();
251 neighbours[j].resize(nb_size);
252 for (
unsigned int k=0;
k<nb_size; ++
k) {
253 neighbours[j][
k] = allCells[allCells[
i].neighbours_ind[j][
k]].index;
265 int sd = tileID->
side(allCells[
i].
id);
266 int tw = tileID->
tower(allCells[
i].
id);
267 int sm = tileID->
sample(allCells[
i].
id);
270 for (
unsigned int j=2; j<4; ++j) {
273 unsigned int nb_size=allCells[
i].neighbours[j].size();
274 for (
unsigned int k=0;
k<nb_size; ++
k) {
275 unsigned int new_i = allCells[
i].neighbours_ind[j][
k];
276 for (
unsigned int new_j=0; new_j<2; ++new_j) {
277 unsigned int new_nb_size=allCells[new_i].neighbours[new_j].size();
278 for (
unsigned int new_k=0; new_k<new_nb_size; ++new_k) {
279 unsigned int new_nb_i = allCells[new_i].neighbours_ind[new_j][new_k];
280 short new_nb_index = allCells[new_nb_i].index;
281 int n=neighbours[j].size()-1;
283 if (neighbours[j][
n] == new_nb_index)
287 int new_sd = tileID->
side(allCells[new_nb_i].
id);
288 int new_tw = tileID->
tower(allCells[new_nb_i].
id);
289 int new_sm = tileID->
sample(allCells[new_nb_i].
id);
290 int new_se = tileID->
section(allCells[new_nb_i].
id);
291 if ( ( new_sd !=
sd && new_tw == tw ) ||
293 ( new_se ==
se && abs(new_tw - tw) < 3 ) ||
295 ( new_sm == sm+1 && abs(new_tw - tw) < 3 ) ||
296 ( new_sm != sm+1 && abs(new_tw - tw) < 4 ) ))))) {
297 neighbours[j].push_back(new_nb_index);
312 std::vector<IdentifierHash> nb_list;
315 for (
unsigned int i=0;
i<hash_max; ++
i) {
318 tileID->
get_id (
i,
id, &context);
319 if ( tileID->
module(
id) != 0 )
continue;
321 IdentifierHash hash_id=
i;
322 nb_list.clear(); nb_list.push_back(hash_id);
326 print_list(nb_list, tileID, &context,
log,
"Prev phi ",
" ; ");
329 print_list(nb_list, tileID, &context,
log,
"Next phi ",
" ; ");
332 print_list(nb_list, tileID, &context,
log,
"Prev eta ",
" ; ");
335 print_list(nb_list, tileID, &context,
log,
"Next eta ",
" ; ");
338 print_list(nb_list, tileID, &context,
log,
"Prev smp ",
" ; ");
341 print_list(nb_list, tileID, &context,
log,
"Next smp ",
" ; ");
344 print_list(nb_list, tileID, &context,
log,
"Face 2D ",
" ; ");
347 print_list(nb_list, tileID, &context,
log,
"Corn 2D ",
" ; ");
356 print_list(nb_list, tileID, &context,
log,
"All 3DC ",
" ; ");
359 print_list(nb_list, tileID, &context,
log,
"Super 3D ",
" ; ");
368 unsigned int hash_max,
unsigned int max_phi, MsgStream &
log)
371 if(
ids.size() != hash_max) {
372 log << MSG::ERROR <<
"fill_phi_vec "
373 <<
" Error: set size NOT EQUAL to hash max. size " <<
ids.size()
374 <<
" hash max " << hash_max
383 int dphi = hash_max / max_phi;
385 int ind_min=0, ind_max=-1,
phi, phi_prev=-1,
index=0;
387 std::set<std::pair<IdentifierHash,int> >::const_iterator
first =
ids.begin();
388 std::set<std::pair<IdentifierHash,int> >::const_iterator last =
ids.end();
391 phi = (*first).second;
392 if (
phi != phi_prev) {
405 IdentifierHash hash_id = (*first).first;
453 std::vector<IdentifierHash> & neighbourList)
const
466 std::vector<IdentifierHash> & neighbourList)
const
479 std::vector<IdentifierHash> & neighbourList)
const
485 for (
unsigned int i=0;
i<
size; ++
i) {
493 std::vector<IdentifierHash> & neighbourList)
const
499 for (
unsigned int i=0;
i<
size; ++
i) {
507 std::vector<IdentifierHash> & neighbourList)
const
513 for (
unsigned int i=0;
i<
size; ++
i) {
521 std::vector<IdentifierHash> & neighbourList)
const
527 for (
unsigned int i=0;
i<
size; ++
i) {
535 std::vector<IdentifierHash> & neighbourList)
const
541 for (
unsigned int i=0;
i<
size; ++
i) {
549 std::vector<IdentifierHash> & neighbourList)
const
555 for (
unsigned int i=0;
i<
size; ++
i) {
564 const char *
name = strName.c_str();
570 std::string::size_type
pos = strName.find(
'-', 0 );
571 if ( std::string::npos !=
pos )
sd = -1;
else sd = 1;
573 sscanf(
name+2,
"%80d",&tw);
577 case 'a':
case 'A': sm = 0; tw -= 1;
578 if (tw<10)
se = 1;
else se = 2;
580 case 'b':
case 'B': sm = 1; tw -= 1;
581 if (tw<10)
se = 1;
else se = 2;
583 case 'c':
case 'C': sm = 1; tw -= 1;
586 case 'd':
case 'D': sm = 2; tw *= 2;
587 if (tw<10)
se = 1;
else se = 2;
590 case 'e':
case 'E': sm = 3;
592 case 1: tw = 10;
break;
593 case 2: tw = 11;
break;
594 case 3: tw = 13;
break;
595 case 4: tw = 15;
break;
599 case 's':
case 'S': sm = 0; tw -= 1;
600 if (tw<9)
se = 1;
else se = 2;
602 case 'v':
case 'V': sm = 2; tw *= 2;
603 if (tw<10)
se = 1;
else se = 2;
605 default:
se = 0; sm = -1; tw = -1;
break;
612 int &
module, std::string & strCell,
618 int tower = tileID->
tower (
id);
623 case 0: strSection =
"Online";
break;
624 case 1: strSection =
"Barrel";
break;
625 case 2: strSection =
"Ext.Barrel";
break;
626 case 3: strSection = (
sample < 3) ?
"ITC":
"Gap.Scin";
break;
627 default: strSection =
"Unknown";
631 char sd = (
side<0) ?
'-' :
'+';
635 case 0: sm=(supercell?
'S':
'A');
643 case 2: sm=(supercell?
'V':
'D');
657 else snprintf(
name,
sizeof(
name),
"%c%c%d", sm,
sd,tw);
662 << strSection <<
" " <<
module <<
" " << strCell <<
end;
675 std::string strSection;
677 std::sort(nb_list.begin(), nb_list.end());
678 unsigned int size=nb_list.size();
684 for (
unsigned int j=0; j<
size; ++j) {
687 tileID->
get_id (nb_list[j],
id, context);