295{
297
301
303
307 }
308 else {
309 std::cout <<
"CaloNeighbours::initialize ERROR Could not find input file " <<
filename << std::endl;
310 return 1;
311 }
313 std::cout <<
"CaloNeighbours::initialize ERROR Could not open file " <<
file << std::endl;
314 return 1;
315 }
316
317
318
319
320
322 std::string sLine;
323 std::string cPrevOrNext,cName,cSourceRange,cTargetRange;
324 std::string cExpId;
325 Range mySourceRange,myTargetRange;
326 std::string oArg;
327 bool isComment = true;
328 bool isNext = false;
329 bool isPrev = false;
330 const std::string cmdNext("nextSuperCalo");
331 const std::string cmdPrev("prevSuperCalo");
332 const std::string cmdPhi("calcPhi(");
333 const std::string cmdSide("calcSide(");
334
335 while( isComment ) {
336 sLine.resize( 0 );
337 do {
338 fin.getline(aLine,
sizeof(aLine)-1);
339 sLine = std::string(aLine);
340 }
while (sLine.empty() && !
fin.eof());
341 isComment = ( sLine.find('#') != std::string::npos );
342 }
343 do {
344 while ( sLine.empty() && !
fin.eof()) {
345 fin.getline(aLine,
sizeof(aLine)-1);
346 sLine = std::string(aLine);
347 }
348 std::istringstream
header( sLine.c_str() );
349 bool hasPhi=false;
350 bool hasSide=false;
351 int iPhiSource,iPhiTarget;
352 int iSideSource,iSideTarget;
353 if ( header >> cPrevOrNext >> cName >> cSourceRange >> cTargetRange) {
354 mySourceRange.
build(cSourceRange);
355 myTargetRange.
build(cTargetRange);
356 while ( header >> oArg ) {
357 if (oArg.find(cmdSide) != std::string::npos ) {
358 hasSide = true;
359 oArg.erase(0,cmdSide.size());
360 std::istringstream iside( oArg.c_str() );
361 iside >> iSideSource >>
dummy >> iSideTarget;
362 }
363 else if ( oArg.find(cmdPhi) != std::string::npos ) {
364 hasPhi = true;
365 oArg.erase(0,cmdPhi.size());
366 std::istringstream iphi( oArg.c_str() );
367 iphi >> iPhiSource >>
dummy >> iPhiTarget;
368 }
369 }
370 sLine.resize(0);
371 bool endOfBlock = false;
372 isNext = (cPrevOrNext.find(cmdNext) != std::string::npos);
373 isPrev = (cPrevOrNext.find(cmdPrev) != std::string::npos);
374 if ( isNext^isPrev ) {
375
376
377
378
379
380
381
382
383
384
385
386
387 auto myRegion = std::make_unique<CaloNeighbourRegion>(cName,
m_calo_id);
388 if ( isNext )
390 else
392 if ( hasSide )
393 myRegion->setSide(iSideSource,iSideTarget);
394 if ( hasPhi )
395 myRegion->setPhi(iPhiSource,iPhiTarget);
396 myRegion->setSourceRange(mySourceRange);
397 myRegion->setTargetRange(myTargetRange);
398
399 std::map<IdentifierHash, std::vector<IdentifierHash>, ltIdHash> neighbourMapPlus,neighbourMapMinus;
400
401 do {
402 while ( !endOfBlock && sLine.empty() && !
fin.eof()) {
403 fin.getline(aLine,
sizeof(aLine)-1);
404 sLine = std::string(aLine);
405 if ( sLine.empty() ||
fin.eof() )
406 endOfBlock = true;
407 }
408 if (!endOfBlock) {
409 std::istringstream neighbour( sLine.c_str() );
410 ExpandedIdentifier myCell,myNeighbourCell;
411 std::vector<ExpandedIdentifier> myNeighbourCells;
412 if ( neighbour >> cExpId ) {
413 myCell = ExpandedIdentifier(cExpId);
414
415 while ( neighbour >> cExpId ) {
416 myNeighbourCell = ExpandedIdentifier(cExpId);
417
418 myNeighbourCells.push_back(myNeighbourCell);
419 }
420
421 sLine.resize(0);
422 result = myRegion->setNeighbours(myCell,myNeighbourCells,neighbourMapPlus,neighbourMapMinus);
423 if ( result != 0 )
425 }
426 }
427 }
while (!
fin.eof() && !endOfBlock);
428 myRegion->initializeVectors(neighbourMapPlus,neighbourMapMinus);
429 if (isNext)
431 else
433 }
434 else {
435 std::cout << "CaloNeighbours::initialize ERROR Invalid neighbour dat file, exiting ... " << std::endl;
436 return 1;
437 }
438 }
439 }
while (!
fin.eof()) ;
441
442 return 0;
443}
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
void build(const std::string &text)
Build Range from a textual description.