FairRoot/PandaRoot
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
PndLmdAlignManager Class Reference

#include <PndLmdAlignManager.h>

Public Member Functions

 PndLmdAlignManager ()
 
virtual ~PndLmdAlignManager ()
 
void init ()
 
bool addPairAndStartAligner (PndLmdHitPair &pair)
 
bool addFile (std::string filename)
 
void readFilesAndAlign ()
 
void waitForCompletion ()
 
bool writePairsToBinaryFiles ()
 
bool readPairsFromBinaryFiles ()
 
bool checkForBinaryFiles ()
 
bool checkForLmdMatrixFiles ()
 
void clearPairs ()
 
int addFilesFromDirectory (std::string directory, int maxFiles=0)
 
void validate ()
 
void alignAllSensors ()
 
void setMaxPairs (int maxPairs)
 
void setSingleAligner (bool singleAligner)
 
void setOutFilename (const std::string &filename)
 
void setMatrixOutDir (std::string matrixOutDir)
 
void setInCentimeters (bool inCentimeters)
 
void setZasTimestamp (bool timestamp)
 
void workerThread (boost::shared_ptr< boost::asio::io_service > io_service)
 
void setBinaryPairFileDirectory (const std::string &binaryPairFileDirectory)
 
void setStartAlignerWhenFull (bool value)
 
void verboseLevel (int verbose)
 

Static Public Member Functions

static void loadBar (int current, int total, int resolution, int width, std::string message="")
 
static Matrix castTGeoHMatrixToMatrix (const TGeoHMatrix &matrix)
 
static Matrix readMatrix (std::string filename)
 
static bool writeMatrix (Matrix &mat, std::string filename)
 
static std::stringstream * readFile (std::string filename)
 
static std::vector
< std::vector< double > > 
readFromCSVFile (std::string filename)
 
static int searchFiles (std::string curr_directory, std::vector< std::string > &list, std::string extension="", bool includeSubDirs=true)
 
static void clearScreen ()
 
static int searchDirectories (std::string curr_directory, std::vector< std::string > &list, bool includeSubDirs=true)
 
static bool mkdir (std::string path)
 
static bool exists (std::string file)
 
static std::vector< std::string > findRegex (std::string source, std::string regex)
 
static bool writeConfigFile (boost::property_tree::ptree configTree, std::string filename, bool replaceExisting=true)
 
static boost::property_tree::ptree readConfigFile (std::string filename)
 

Private Types

typedef std::map< int,
PndLmdSensorAligner >
::iterator 
mapIt
 

Private Member Functions

void alignST ()
 
void alignMT ()
 
void alignOne (PndLmdSensorAligner &aligner)
 
void resetMTLB (int n, int r, int w)
 
void incrementMTLB ()
 
void checkIOpaths ()
 
void verbosePrint (std::string input, int level=3)
 

Static Private Member Functions

static void readPairsFromChainMT (std::vector< std::string > files, std::map< int, PndLmdSensorAligner > &aligners, PndLmdAlignManager &manager)
 
static std::string makeBinaryPairFileName (int overlapId=0, bool incentimeters=true)
 
static std::string makeMatrixFileName (int overlapId=0, bool incentimeters=true)
 

Private Attributes

int _i
 
int _r
 
int _w
 
int _n
 
int _verboseLevel
 
std::stringstream _info
 
std::map< int,
PndLmdSensorAligner
aligners
 
std::map< int, bool > alignersFull
 
bool _allFilesAdded
 
bool allAlignersDone
 
std::vector< std::string > fileNames
 
bool _singleAligner
 
bool _inCentimeters
 
bool _enableHelperMatrix
 
bool _zIsTimestamp
 
bool startAlignerWhenFull
 
std::string outFilename
 
std::string _matrixOutDir
 
std::string _binaryPairFileDirectory
 
bool _firstInitDone
 
bool _multithreaded
 
vector< int > overlapIDs
 

Friends

class PndLmdSensorAligner
 
class PndLmdAlignQA
 

Detailed Description

Definition at line 34 of file PndLmdAlignManager.h.

Member Typedef Documentation

typedef std::map<int, PndLmdSensorAligner>::iterator PndLmdAlignManager::mapIt
private

Definition at line 36 of file PndLmdAlignManager.h.

Constructor & Destructor Documentation

PndLmdAlignManager::PndLmdAlignManager ( )

Definition at line 96 of file PndLmdAlignManager.cxx.

References init().

96  {
97  init();
98 }
PndLmdAlignManager::~PndLmdAlignManager ( )
virtual

Definition at line 141 of file PndLmdAlignManager.cxx.

141  {
142 }

Member Function Documentation

bool PndLmdAlignManager::addFile ( std::string  filename)

Definition at line 214 of file PndLmdAlignManager.cxx.

References _allFilesAdded, and fileNames.

214  {
215 
216  if (_allFilesAdded) {
217  return false;
218  }
219  else {
220  fileNames.push_back(filename);
221  return true;
222  }
223 }
std::vector< std::string > fileNames
const string filename
int PndLmdAlignManager::addFilesFromDirectory ( std::string  directory,
int  maxFiles = 0 
)

Definition at line 225 of file PndLmdAlignManager.cxx.

References _allFilesAdded, fileNames, i, and searchFiles().

Referenced by runLumiPixel2fMatrixFinder().

225  {
226 
227  if (_allFilesAdded) {
228  return fileNames.size();
229  }
230  else {
231  std::vector<string> list;
232  searchFiles(directory, list, ".root", false);
233  for (size_t i = 0; i < list.size(); i++) {
234  fileNames.push_back(list[i]);
235  if ((int) i == maxFiles - 1) { //we use == instead of >= so that maxFiles=0 always chooses all files
236  break;
237  }
238  }
239  _allFilesAdded = true;
240  cout << "looking for files in " << directory << ". choose " << fileNames.size()
241  << " files of maximum of " << maxFiles << ".\n";
242  return fileNames.size();
243  }
244 
245 }
std::vector< std::string > fileNames
Int_t i
Definition: run_full.C:25
static int searchFiles(std::string curr_directory, std::vector< std::string > &list, std::string extension="", bool includeSubDirs=true)
TString directory
bool PndLmdAlignManager::addPairAndStartAligner ( PndLmdHitPair pair)

Definition at line 166 of file PndLmdAlignManager.cxx.

References aligners, alignersFull, alignerThreadGroup, alignOne(), allAlignersDone, PndLmdHitPair::check(), PndLmdHitPair::getOverlapId(), PndLmdHitPair::isSane(), and mrfdata_8b_error::success.

Referenced by readFilesAndAlign().

166  {
167 
168  bool success = false;
169 
170  // check if the aligner for that pair is full. if yes, skip this pair.
171  // do this even before checking that pair, saves on cpu time.
172  if (alignersFull[pair.getOverlapId()]) {
173  return false;
174  }
175 
176  pair.check();
177  if (pair.isSane()) {
178  success = aligners[pair.getOverlapId()].addSimplePair(pair); //returns true if addPair succeeded
179  alignersFull[pair.getOverlapId()] = !success; //if addPair failed, the aligner is full
180  }
181  else {
182  cout << "pair is not sane. processing failed.\n";
183  }
184 
185  //if pair could not be added, aligner is full. start thread directly.
186  if (!success) {
187  alignerThreadGroup.create_thread(
188  boost::bind(&PndLmdAlignManager::alignOne, this, boost::ref(aligners[pair.getOverlapId()])));
189  }
190 
191  //check if all aligners are done
192  allAlignersDone = true;
193  for (map<int, bool>::iterator it = alignersFull.begin(); it != alignersFull.end(); it++) {
194  if (!(it->second)) {
195  allAlignersDone = false;
196  break;
197  }
198  }
199  if (allAlignersDone) {
200  cout << "all aligners are already full. no further files will be read.\n";
201  }
202 
203  return success;
204 }
boost::thread_group alignerThreadGroup
std::map< int, bool > alignersFull
std::map< int, PndLmdSensorAligner > aligners
Int_t getOverlapId() const
bool isSane() const
Definition: PndLmdHitPair.h:75
void alignOne(PndLmdSensorAligner &aligner)
void PndLmdAlignManager::alignAllSensors ( )

Definition at line 477 of file PndLmdAlignManager.cxx.

References _enableHelperMatrix, _inCentimeters, _info, _matrixOutDir, _multithreaded, alignMT(), alignST(), and checkIOpaths().

Referenced by runLumiPixel2fMatrixFinder().

477  {
478 
480  _enableHelperMatrix = false;
481  cerr << "WARNING! You can't use rotation correction in pixel ICP mode!\n";
482  }
483 
484  checkIOpaths();
485  cout << "starting aligners...\n";
486 
487  if (_multithreaded) {
488  alignMT();
489  }
490  else {
491  alignST();
492  }
493 
494  //write matrix info
495  ofstream of;
496  if (_inCentimeters) {
497  of.open((_matrixOutDir + "/info-cm.txt").c_str());
498  }
499  else {
500  of.open((_matrixOutDir + "/info-px.txt").c_str());
501  }
502 
503  of << _info.str();
504  of.close();
505  cout << "all aligners done.\n";
506 }
std::stringstream _info
void PndLmdAlignManager::alignMT ( )
private

Definition at line 405 of file PndLmdAlignManager.cxx.

References _inCentimeters, _info, _matrixOutDir, _verboseLevel, aligners, alignOne(), i, makeMatrixFileName(), resetMTLB(), WorkerThread(), and writeMatrix().

Referenced by alignAllSensors().

405  {
406 
407  //new version, multi threaded using thread pool model and boost::asio implementation
408 
409  //shared pointer, since io_services can't be copied
410  boost::shared_ptr<boost::asio::io_service> io_service(new boost::asio::io_service);
411  boost::shared_ptr<boost::asio::io_service::work> work(new boost::asio::io_service::work(*io_service));
412 
413  //thread group
414  boost::thread_group worker_threads;
415 
416  //make threads, n is number of threads:
417  int nThreads;
418  nThreads = boost::thread::hardware_concurrency();
419 
420  //sometimes hardware_concurrency returns 0 if it can't detect.
421  if (nThreads < 1) {
422  cout << "INFO:: could not detect number of cores. assuming 4.\n";
423  nThreads = 4;
424  }
425 
426  //create worker threads
427  if (_verboseLevel >= 3) cout << "creating threads... ";
428  for (int i = 0; i < nThreads; i++) {
429  worker_threads.create_thread(boost::bind(&WorkerThread, io_service));
430  if (_verboseLevel >= 3) cout << "[" << i << "] ";
431  }
432  if (_verboseLevel >= 3) cout << "done.\nposting work...\n";
433 
434  resetMTLB(aligners.size(), aligners.size(), 60);
435 
436  //post work for threads
437  for (mapIt it = aligners.begin(); it != aligners.end(); it++) {
438 
439  /*
440  * when binding member classes, boost::bind needs the namespace AND the pointer to an object
441  * of that class (here: this-pointer). Also, when using references, use boost::ref()
442  */
443  if (_verboseLevel >= 3) cout << "posting work for aligner " << it->second.getOverlapId() << "... ";
444  io_service->post(boost::bind(&PndLmdAlignManager::alignOne, this, boost::ref(it->second)));
445  if (_verboseLevel >= 3) cout << "done.\n";
446 
447  }
448 
449  //wait for all threads to complete, then and only then write matrices to disk
450  if (_verboseLevel >= 3) cout << "waiting for all threads to complete.\n";
451  work.reset();
452  worker_threads.join_all();
453  if (_verboseLevel >= 3) cout << "all threads done. getting info.\n";
454  for (mapIt it = aligners.begin(); it != aligners.end(); it++) {
455  if (it->second.successful()) {
456  if (_verboseLevel >= 3) cout << "gtting matrix from " << it->second.getOverlapId() << "\n";
457  Matrix result = it->second.getResultMatrix();
458  string matrixFilename = _matrixOutDir
459  + makeMatrixFileName(it->second.getOverlapId(), _inCentimeters);
460 
461  if (!writeMatrix(result, matrixFilename)) {
462  cout << "ERROR: could not write matrix " << matrixFilename << "\n";
463  }
464 
465  _info << "aligner " << it->second.getOverlapId() << ":\n";
466  _info << "no of pairs: " << it->second.getNoOfPairs() << "\n";
467  _info << "\n";
468 
469  if (_verboseLevel >= 3) cout << _info.str() << "\n";
470  }
471  else {
472  cout << "Error: aligner for " << it->second.getOverlapId() << " failed.\n";
473  }
474  }
475 }
Int_t i
Definition: run_full.C:25
std::map< int, PndLmdSensorAligner > aligners
void WorkerThread(boost::shared_ptr< boost::asio::io_service > io_service)
void resetMTLB(int n, int r, int w)
std::map< int, PndLmdSensorAligner >::iterator mapIt
static bool writeMatrix(Matrix &mat, std::string filename)
Definition: matrix.h:50
static std::string makeMatrixFileName(int overlapId=0, bool incentimeters=true)
std::stringstream _info
void alignOne(PndLmdSensorAligner &aligner)
void PndLmdAlignManager::alignOne ( PndLmdSensorAligner aligner)
private

Definition at line 354 of file PndLmdAlignManager.cxx.

References _binaryPairFileDirectory, PndLmdSensorAligner::calculateMatrix(), checkForBinaryFiles(), PndLmdSensorAligner::clearPairs(), incrementMTLB(), and PndLmdSensorAligner::writePairsToBinary().

Referenced by addPairAndStartAligner(), alignMT(), and waitForCompletion().

354  {
355 
356  //start aligner, this can be done concurrently
357  aligner.calculateMatrix();
358 
359  //write binary file only if not already present
360  if (!checkForBinaryFiles()) {
362  }
363  //if binary files already present, then they have been read earlier and we can display a progress bar for the aliners
364  else {
365  incrementMTLB();
366  }
367 
368  //free memory
369  aligner.clearPairs();
370 }
bool writePairsToBinary(const std::string directory)
std::string _binaryPairFileDirectory
void PndLmdAlignManager::alignST ( )
private

Definition at line 376 of file PndLmdAlignManager.cxx.

References _inCentimeters, _info, _matrixOutDir, aligners, loadBar(), makeMatrixFileName(), verbosePrint(), and writeMatrix().

Referenced by alignAllSensors().

376  {
377 
378  int cur, tot;
379  cur = 0;
380  tot = aligners.size();
381  verbosePrint("aligning single threaded.\n");
382 
383  for (mapIt it = aligners.begin(); it != aligners.end(); it++) {
384  loadBar(cur++, tot, 1000, 60);
385  verbosePrint("calculating matrix.\n");
386  it->second.calculateMatrix();
387  if (it->second.successful()) {
388  verbosePrint("success. getting matrix.\n");
389  Matrix result = it->second.getResultMatrix();
390  string matrixFilename = _matrixOutDir
391  + makeMatrixFileName(it->second.getOverlapId(), _inCentimeters);
392  writeMatrix(result, matrixFilename);
393 
394  _info << "aligner " << it->second.getOverlapId() << ":\n";
395  _info << "no of pairs: " << it->second.getNoOfPairs() << "\n";
396  _info << "\n";
397 
398  }
399  else {
400  cout << "Error: aligner for " << it->second.getOverlapId() << " failed.\n";
401  }
402  }
403 }
std::map< int, PndLmdSensorAligner > aligners
static void loadBar(int current, int total, int resolution, int width, std::string message="")
std::map< int, PndLmdSensorAligner >::iterator mapIt
static bool writeMatrix(Matrix &mat, std::string filename)
Definition: matrix.h:50
static std::string makeMatrixFileName(int overlapId=0, bool incentimeters=true)
void verbosePrint(std::string input, int level=3)
std::stringstream _info
Matrix PndLmdAlignManager::castTGeoHMatrixToMatrix ( const TGeoHMatrix &  matrix)
static

Definition at line 833 of file PndLmdAlignManager.cxx.

833  {
834 
835  //allocate memory for matrix elements
836  double* homogenousMatrix = new double[16];
837  double* finalMatrix = new double[16];
838  matrix.GetHomogenousMatrix(homogenousMatrix);
839 
840  /*
841  * this code was tested on 2016-08-29 and works. The root implementation is still not
842  * according to ROOT documentation, in that the translation parts of a matrix are not
843  * where they should be and sometimes the homogenous coordinate is not set to 1.
844  * This fixes that.
845  *
846  * DO NOT REMOVE THESE COMMENTS!
847  *
848  * When in doubt, refer to the
849  * following code example, that shows where the translations (wrongfully) is:
850  */
851  /*
852 
853  //test tgeohmatrices
854  TGeoHMatrix *h1 = new TGeoHMatrix(TGeoTranslation(1,2,3));
855  TGeoHMatrix *h2 = new TGeoHMatrix();
856  TGeoHMatrix *h3 = new TGeoHMatrix();
857  TGeoHMatrix *h4 = new TGeoHMatrix();
858 
859  h2->SetDx(1.); h2->SetDy(2.); h2->SetDz(3.);
860  double tr[3] = {1.,2.,3.};
861  h3->SetTranslation(tr);
862  const double rot[9] = {0,1,0,-1,0,0,0,0,0};
863  h4->SetRotation(rot);
864 
865  Matrix m1 = castTGeoHMatrixToMatrix(*h1);
866  Matrix m2 = castTGeoHMatrixToMatrix(*h2);
867  Matrix m3 = castTGeoHMatrixToMatrix(*h3);
868  Matrix m4 = castTGeoHMatrixToMatrix(*h4);
869 
870  cout << "m1:\n" << m1 << "\n";
871  cout << "m2:\n" << m2 << "\n";
872  cout << "m3:\n" << m3 << "\n";
873  cout << "m4:\n" << m4 << "\n";
874  */
875 
876  //copy values from the wrong to the correct positions
877  finalMatrix[0] = homogenousMatrix[0];
878  finalMatrix[1] = homogenousMatrix[1];
879  finalMatrix[2] = homogenousMatrix[2];
880  finalMatrix[3] = homogenousMatrix[12];
881  finalMatrix[4] = homogenousMatrix[4];
882  finalMatrix[5] = homogenousMatrix[5];
883  finalMatrix[6] = homogenousMatrix[6];
884  finalMatrix[7] = homogenousMatrix[13];
885  finalMatrix[8] = homogenousMatrix[8];
886  finalMatrix[9] = homogenousMatrix[9];
887  finalMatrix[10] = homogenousMatrix[10];
888  finalMatrix[11] = homogenousMatrix[14];
889  finalMatrix[12] = homogenousMatrix[3];
890  finalMatrix[13] = homogenousMatrix[7];
891  finalMatrix[14] = homogenousMatrix[11];
892  //finalMatrix[15] = homogenousMatrix[15];
893  finalMatrix[15] = 1.0;
894 
895  //create matrix and clean up
896  Matrix result(4, 4, finalMatrix);
897  delete homogenousMatrix;
898  delete finalMatrix;
899  return result;
900 
901 }
Definition: matrix.h:50
bool PndLmdAlignManager::checkForBinaryFiles ( )

Definition at line 903 of file PndLmdAlignManager.cxx.

References _binaryPairFileDirectory, _inCentimeters, files, i, makeBinaryPairFileName(), overlapIDs, and searchFiles().

Referenced by alignOne(), PndLmdAlignQA::histogramPairDistances(), and runLumiPixel2fMatrixFinder().

903  {
904 
905  vector<string> files;
906  searchFiles(_binaryPairFileDirectory, files, "bin", false);
907  int foundFiles = 0;
908 
909  //no binary files at all!
910  if (files.size() == 0) {
911  return false;
912  }
913 
914  string matrixName;
915  bool tempfilefound = false;
916 
917  //check for every ID that should be there if there is a corresponding file
918  for (size_t i = 0; i < overlapIDs.size(); i++) {
919 
920  tempfilefound = false;
922  for (size_t j = 0; j < files.size(); j++) {
923  if (files[j].find(matrixName) != string::npos) {
924  tempfilefound = true;
925  foundFiles++;
926  }
927  }
928 
929  //file not found? then at least one is missing, return false
930  if (!tempfilefound) {
931  return tempfilefound;
932  }
933  }
934  return true;
935 }
Int_t i
Definition: run_full.C:25
static int searchFiles(std::string curr_directory, std::vector< std::string > &list, std::string extension="", bool includeSubDirs=true)
std::map< int, TString > files
Definition: simubg.C:28
static std::string makeBinaryPairFileName(int overlapId=0, bool incentimeters=true)
std::string _binaryPairFileDirectory
vector< int > overlapIDs
bool PndLmdAlignManager::checkForLmdMatrixFiles ( )

Definition at line 937 of file PndLmdAlignManager.cxx.

References _binaryPairFileDirectory, files, i, makeMatrixFileName(), overlapIDs, and searchFiles().

Referenced by runLumiPixel2fMatrixFinder().

937  {
938 
939  vector<string> files;
940  searchFiles(_binaryPairFileDirectory, files, "mat", false);
941  int foundFiles = 0;
942 
943  //no binary files at all!
944  if (files.size() == 0) {
945  return false;
946  }
947 
948  string matrixName1, matrixName2;
949  bool tempfilefound = false;
950 
951  //check for every ID that should be there if there is a corresponding file
952  for (size_t i = 0; i < overlapIDs.size(); i++) {
953 
954  //reset counter
955  tempfilefound = false;
956  matrixName1 = makeMatrixFileName(overlapIDs[i], true);
957  matrixName1 = makeMatrixFileName(overlapIDs[i], false);
958 
959  for (size_t j = 0; j < files.size(); j++) {
960  if (files[j].find(matrixName1) != string::npos) {
961  //file is present
962  //cout << "file: " << files[j] << ", id: " << availableIds[i] << "\n";
963  tempfilefound = true;
964  foundFiles++;
965  }
966  }
967 
968  //file not found? then at least one is missing, return false
969  if (!tempfilefound) {
970  return tempfilefound;
971  }
972  }
973  //cout << "found " << foundFiles << "\n";
974  return true;
975 }
Int_t i
Definition: run_full.C:25
static int searchFiles(std::string curr_directory, std::vector< std::string > &list, std::string extension="", bool includeSubDirs=true)
std::map< int, TString > files
Definition: simubg.C:28
std::string _binaryPairFileDirectory
static std::string makeMatrixFileName(int overlapId=0, bool incentimeters=true)
vector< int > overlapIDs
void PndLmdAlignManager::checkIOpaths ( )
private

Definition at line 605 of file PndLmdAlignManager.cxx.

References _matrixOutDir, exit(), fileNames, and outFilename.

Referenced by alignAllSensors(), and setOutFilename().

605  {
606 
607  if (fileNames.size() == 0) {
608  //cout << "no pair files specified, are we using binary data?\n";
609  }
610  for (size_t iFile = 0; iFile < fileNames.size(); iFile++) {
611  if (!boost::filesystem::exists(fileNames[iFile])) {
612  cout << "error opening file:";
613  cout << fileNames[iFile] << "\n";
614  exit(1);
615  }
616  }
617 
618  if (!(outFilename == "")) {
619  boost::filesystem::path outPath(outFilename);
620  if (!boost::filesystem::exists(outPath.parent_path())) {
621  boost::filesystem::create_directories(outPath.parent_path());
622  }
623  }
624 
625  if (!(_matrixOutDir == "")) {
626  if (!boost::filesystem::exists(_matrixOutDir)) {
627  boost::filesystem::create_directories(_matrixOutDir);
628  }
629  }
630 }
std::vector< std::string > fileNames
exit(0)
void PndLmdAlignManager::clearPairs ( )

Definition at line 1578 of file PndLmdAlignManager.cxx.

References aligners.

1578  {
1579  for (mapIt it = aligners.begin(); it != aligners.end(); it++) {
1580  it->second.clearPairs();
1581  }
1582 }
std::map< int, PndLmdSensorAligner > aligners
std::map< int, PndLmdSensorAligner >::iterator mapIt
void PndLmdAlignManager::clearScreen ( )
static

Definition at line 1396 of file PndLmdAlignManager.cxx.

1396  {
1397  cout << "\x1B[2J\x1B[H";
1398 }
bool PndLmdAlignManager::exists ( std::string  file)
static

Definition at line 761 of file PndLmdAlignManager.cxx.

Referenced by PndLmdPairFinderTask::Init().

761  {
762  boost::filesystem::path bpath(path);
763  if (boost::filesystem::exists(bpath)) {
764  return true;
765  }
766  return false;
767 }
vector< string > PndLmdAlignManager::findRegex ( std::string  source,
std::string  regex 
)
static

Definition at line 770 of file PndLmdAlignManager.cxx.

Referenced by PndLmdAlignQA::readMatrixInfo().

770  {
771 
772  boost::regex expression(regex);
773  std::string::const_iterator start, end;
774  start = source.begin();
775  end = source.end();
776  boost::match_results<std::string::const_iterator> result;
777  boost::match_flag_type flags = boost::match_default;
778 
779  vector<string> resultStrings;
780 
781  while (regex_search(start, end, result, expression, flags)) {
782  // update search position:
783  start = result[0].second;
784 
785  for (size_t j = 0; j < result.size(); j++) {
786  resultStrings.push_back(boost::lexical_cast<string>(result[j]));
787  }
788 
789  // update flags:
790  flags |= boost::match_prev_avail;
791  flags |= boost::match_not_bob;
792  }
793 
794  return resultStrings;
795 }
void PndLmdAlignManager::incrementMTLB ( )
private

Definition at line 56 of file PndLmdAlignManager.cxx.

References _i, _n, _r, _w, c, incrementMutex, printf(), and x.

Referenced by alignOne().

56  {
57 
58  incrementMutex.lock();
59  _i++;
60 
61  // Only update r times.
62  if (_n == 0) return;
63  if (_n == 1) return;
64 
65  if (_r > _n) {
66  _r = _n;
67  }
68 
69  //calculate ev / sec every 100000 iterations
70  if (_i % (_n / _r) != 0) {
71  return;
72  }
73 
74  flush(cout);
75 
76  // Calculate the ratio of complete-to-incomplete.
77  float ratio = _i / (float) _n;
78  int c = ratio * _w;
79 
80  // Show the percentage complete.
81  printf("%3d%% [", (int) (ratio * 100));
82 
83  // Show the load bar.
84  for (int x = 0; x < c; x++)
85  printf("=");
86 
87  for (int x = c; x < _w; x++)
88  printf(" ");
89 
90  // ANSI Control codes to go back to the
91  // previous line and clear it.
92  printf("] %d of %d \n\033[F\033[J", _i, _n);
93  incrementMutex.unlock();
94 }
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
Double_t x
boost::mutex incrementMutex
void PndLmdAlignManager::init ( )

Definition at line 100 of file PndLmdAlignManager.cxx.

References _allFilesAdded, _enableHelperMatrix, _firstInitDone, _inCentimeters, _info, _multithreaded, _singleAligner, _verboseLevel, _zIsTimestamp, aligners, alignersFull, fileNames, PndLmdGeometryHelper::getAvailableOverlapIDs(), i, outFilename, overlapIDs, PndLmdSensorAligner::setInCentimeters(), PndLmdSensorAligner::setOverlapId(), and PndLmdSensorAligner::setZasTimetamp().

Referenced by PndLmdAlignQA::histogramPairDistances(), and PndLmdAlignManager().

100  {
101 
102  _info << "info for aligned areas\n";
103 
104  _zIsTimestamp = true;
105  _allFilesAdded = false;
106  _singleAligner = true;
107  _inCentimeters = false;
108  _enableHelperMatrix = false;
109  _multithreaded = true;
110 
111  _verboseLevel = 0;
112 
113  //int overlapId=-1;
114  fileNames.clear();
115  aligners.clear();
116 
117  //FIXME: remove
118  //helper = &PndLmdGeometryHelper::getInstance();
119 
121  for (size_t i = 0; i < overlapIDs.size(); i++) {
122  int overlapId = overlapIDs[i];
123 
124  PndLmdSensorAligner tempAligner;
125  tempAligner.setOverlapId(overlapId);
126  tempAligner.setZasTimetamp(_zIsTimestamp);
127  tempAligner.setInCentimeters(_inCentimeters);
128  aligners[overlapId] = tempAligner;
129  }
130 
131  // we just started, all aligners are empty
132  for (size_t i = 0; i < overlapIDs.size(); i++) {
133  alignersFull[overlapIDs[i]] = false;
134  }
135 
136  outFilename = "";
137  _firstInitDone = true;
138  std::cout << "PndLmdAlignManager::Init(): Initialization successful." << "\n";
139 }
std::vector< std::string > fileNames
void setInCentimeters(bool inCentimeters)
static std::vector< int > getAvailableOverlapIDs()
Int_t i
Definition: run_full.C:25
std::map< int, bool > alignersFull
std::map< int, PndLmdSensorAligner > aligners
void setOverlapId(Int_t overlapId)
void setZasTimetamp(bool value)
std::stringstream _info
vector< int > overlapIDs
void PndLmdAlignManager::loadBar ( int  current,
int  total,
int  resolution,
int  width,
std::string  message = "" 
)
static

Definition at line 568 of file PndLmdAlignManager.cxx.

References c, i, n, printf(), and x.

Referenced by alignST(), readFilesAndAlign(), readPairsFromBinaryFiles(), and writePairsToBinaryFiles().

568  {
569 
570  // Only update r times.
571  if (n == 0) return;
572  if (n == 1) return;
573 
574  if (r > n) {
575  r = n;
576  }
577 
578  //calculate ev / sec every 100000 iterations
579  if (i % (n / r) != 0) {
580  return;
581  }
582 
583  flush(cout);
584 
585  // Calculate the ratio of complete-to-incomplete.
586  float ratio = i / (float) n;
587  int c = ratio * w;
588 
589  // Show the percentage complete.
590  printf("%3d%% [", (int) (ratio * 100));
591 
592  // Show the load bar.
593  for (int x = 0; x < c; x++)
594  printf("=");
595 
596  for (int x = c; x < w; x++)
597  printf(" ");
598 
599  // ANSI Control codes to go back to the
600  // previous line and clear it.
601  printf("] %s %d of %d \n\033[F\033[J", message.c_str(), i, n);
602 
603 }
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
double r
Definition: RiemannTest.C:14
Int_t i
Definition: run_full.C:25
int n
Double_t x
std::string PndLmdAlignManager::makeBinaryPairFileName ( int  overlapId = 0,
bool  incentimeters = true 
)
staticprivate

Definition at line 977 of file PndLmdAlignManager.cxx.

References filename.

Referenced by checkForBinaryFiles(), PndLmdSensorAligner::readPairsFromBinary(), and PndLmdSensorAligner::writePairsToBinary().

977  {
978  std::stringstream filename;
979  filename << "/pairs-";
980  filename << overlapId;
981  if (incentimeters) {
982  filename << "-cm";
983  }
984  else {
985  filename << "-px";
986  }
987  filename << ".bin";
988  return filename.str();
989 }
const string filename
std::string PndLmdAlignManager::makeMatrixFileName ( int  overlapId = 0,
bool  incentimeters = true 
)
staticprivate

Definition at line 996 of file PndLmdAlignManager.cxx.

Referenced by alignMT(), alignST(), checkForLmdMatrixFiles(), PndLmdAlignQA::checkForMatrixFiles(), PndLmdAlignQA::plotCMvsPXmatrices(), PndLmdAlignQA::plotMatrixresiduals(), PndLmdAlignQA::plotPXvsCMmatricesResiduals(), and waitForCompletion().

996  {
997  stringstream matrixName;
998  matrixName << "/m";
999  if (incentimeters) {
1000  matrixName << overlapId << "cm.mat";
1001  }
1002  else {
1003  matrixName << overlapId << "px.mat";
1004  }
1005  return matrixName.str();
1006 }
bool PndLmdAlignManager::mkdir ( std::string  path)
static

Definition at line 753 of file PndLmdAlignManager.cxx.

Referenced by PndLmdAlignQA::createHist(), PndLmdSensorAligner::writePairsToBinary(), and writePairsToBinaryFiles().

753  {
754  boost::filesystem::path bpath(path);
755  if (boost::filesystem::exists(bpath)) {
756  return true;
757  }
758  return boost::filesystem::create_directories(bpath);
759 }
boost::property_tree::ptree PndLmdAlignManager::readConfigFile ( std::string  filename)
static

Definition at line 1540 of file PndLmdAlignManager.cxx.

References is.

Referenced by PndLmdPairFinderTask::Init().

1540  {
1541 
1542  //check if file exists
1543  if (!boost::filesystem::exists(filename)) {
1544  cerr << "PndLmdAlignManager::readConfig: ERROR! File " << filename << " not found!\n";
1545  }
1546 
1547  std::ifstream is(filename);
1548  boost::property_tree::ptree root;
1549  try {
1550  boost::property_tree::read_json(is, root);
1551  }
1552  catch (std::exception &e) {
1553  cerr << "PndLmdAlignManager::readConfig: ERROR! Can't parse json file " << filename << ".\n";
1554  }
1555  return root;
1556 }
static int is
Definition: ranlxd.cxx:374
const string filename
std::stringstream * PndLmdAlignManager::readFile ( std::string  filename)
static

Definition at line 634 of file PndLmdAlignManager.cxx.

References filename.

Referenced by readFromCSVFile(), and PndLmdAlignQA::readMatrixInfo().

634  {
635 
636  int lines = 0;
637  stringstream *valueStream = new stringstream();
638 
639  ifstream ifs;
640  ifs.open(filename.c_str());
641  if (!ifs.is_open()) {
642  cout << "could not read ";
643  cout << filename;
644  cout << "! aborting." << "\n";
645  return NULL;
646  }
647  string linebuffer; // = new string();
648  while (std::getline(ifs, linebuffer)) {
649  *valueStream << linebuffer << "\n";
650  lines++;
651  }
652  ifs.close();
653 
654  return valueStream;
655 }
const string filename
void PndLmdAlignManager::readFilesAndAlign ( )

Definition at line 299 of file PndLmdAlignManager.cxx.

References _allFilesAdded, addPairAndStartAligner(), allAlignersDone, exit(), fileNames, i, and loadBar().

Referenced by runLumiPixel2fMatrixFinder().

299  {
300 
301  _allFilesAdded = true;
302 
303  int noOfFiles = fileNames.size();
304  if (noOfFiles > 0) {
305  cout << "found " << noOfFiles << " file(s). reading...\n";
306  }
307  else {
308  cout << "no files found. exiting.\n";
309  exit(0);
310  }
311 
312  TChain* chainPairs = new TChain("pndsim");
313  for (size_t i = 0; i < fileNames.size(); i++) {
314  //cout << files[i] << endl;
315  if (fileNames[i].find("Lumi_Pairs") != std::string::npos) {
316  chainPairs->Add(fileNames[i].c_str());
317  }
318  }
319 
320  //pairs of sensors in LMD coordinates
321  TClonesArray* hitPairs = new TClonesArray("PndLmdHitPair");
322  chainPairs->SetBranchAddress("PndLmdHitPair", &hitPairs);
323  int nEntries = chainPairs->GetEntries();
324  cout << "HitPairs no of entries: " << nEntries << "\n";
325 
326  cout << "Sorting Pairs to Manager...\n";
327  int totalPairs = 0;
328  for (int i_event = 0; i_event < nEntries; i_event++) {
329 
330  loadBar(i_event, nEntries, 1000, 60);
331  chainPairs->GetEntry(i_event);
332  int nPairs = hitPairs->GetEntries();
333 
334  //loop over hitPairs per Event
335  for (int i_Pair = 0; i_Pair < nPairs; i_Pair++) {
336  PndLmdHitPair* currentPair = (PndLmdHitPair*) hitPairs->At(i_Pair);
337  addPairAndStartAligner(*currentPair);
338  totalPairs++;
339  if (allAlignersDone) {
340  return;
341  }
342  }
343  }
344 
345  cout << "================================ \n";
346  cout << "total Pairs: " << totalPairs << "\n";
347  cout << "All done. Running Align Manager. \n";
348  cout << "================================ \n";
349 
350  delete chainPairs;
351  delete hitPairs;
352 }
std::vector< std::string > fileNames
Int_t i
Definition: run_full.C:25
exit(0)
static void loadBar(int current, int total, int resolution, int width, std::string message="")
bool addPairAndStartAligner(PndLmdHitPair &pair)
vector< vector< double > > PndLmdAlignManager::readFromCSVFile ( std::string  filename)
static

Definition at line 708 of file PndLmdAlignManager.cxx.

References i, and readFile().

Referenced by readMatrix().

708  {
709  stringstream *ss;
710  stringstream iss;
711  int i = 0;
712  ss = readFile(filename);
713  string line, token;
714  std::vector<std::vector<double> > data;
715  while (getline(*ss, line)) {
716  iss << line;
717  std::vector<double> tempvec;
718  while (getline(iss, token, ',')) {
719  tempvec.push_back(boost::lexical_cast<double>(token));
720  }
721  data.push_back(tempvec);
722  ++i;
723  iss.clear();
724  }
725  ss->str("");
726  delete ss;
727  iss.str("");
728  return data;
729 }
Int_t i
Definition: run_full.C:25
static std::stringstream * readFile(std::string filename)
const string filename
Matrix PndLmdAlignManager::readMatrix ( std::string  filename)
static

Definition at line 657 of file PndLmdAlignManager.cxx.

References exit(), i, readFromCSVFile(), and Matrix::val.

Referenced by PndLmdAlignQA::plotCMvsPXmatrices(), PndLmdAlignQA::plotMatrixresiduals(), and PndLmdAlignQA::plotPXvsCMmatricesResiduals().

657  {
658 
659  vector<vector<double> > temp = readFromCSVFile(filename);
660 
661  if (temp.size() < 1) {
662  cout << "warning! can't read matrix from file " << filename << "\n";
663  exit(1);
664  }
665  if (temp[0].size() < 1) {
666  cout << "warning! can't read matrix from file " << filename << "\n";
667  exit(1);
668  }
669 
670  int rows, columns;
671  rows = temp.size();
672  columns = temp[0].size();
673  Matrix result(rows, columns);
674 
675  for (int i = 0; i < rows; i++) {
676  for (int j = 0; j < columns; j++) {
677  result.val[i][j] = temp[i][j];
678  }
679  }
680 
681  return result;
682 }
Int_t i
Definition: run_full.C:25
exit(0)
Definition: matrix.h:50
static std::vector< std::vector< double > > readFromCSVFile(std::string filename)
const string filename
bool PndLmdAlignManager::readPairsFromBinaryFiles ( )

Definition at line 1506 of file PndLmdAlignManager.cxx.

References _binaryPairFileDirectory, aligners, loadBar(), and mrfdata_8b_error::success.

Referenced by PndLmdAlignQA::histogramPairDistances(), and runLumiPixel2fMatrixFinder().

1506  {
1507 
1508  bool success = false;
1509 
1510  if (_binaryPairFileDirectory == "") {
1511  cout << "error: binary pair file directory not set.\n";
1512  cout << "use PndLmdAlignManager::setBinaryPairFileDirectory()\n";
1513  return false;
1514  }
1515 
1516  int cur, tot;
1517  cur = 0;
1518  tot = aligners.size();
1519 
1520  cout << "reading all pairs from binary files\n";
1521 
1522  for (mapIt it = aligners.begin(); it != aligners.end(); it++) {
1523  loadBar(cur++, tot, 1000, 60);
1524  if (!it->second.readPairsFromBinary(_binaryPairFileDirectory)) {
1525  success = false;
1526  }
1527  else {
1528  success = true;
1529  }
1530  }
1531  return success;
1532 }
std::map< int, PndLmdSensorAligner > aligners
static void loadBar(int current, int total, int resolution, int width, std::string message="")
std::string _binaryPairFileDirectory
std::map< int, PndLmdSensorAligner >::iterator mapIt
static void PndLmdAlignManager::readPairsFromChainMT ( std::vector< std::string >  files,
std::map< int, PndLmdSensorAligner > &  aligners,
PndLmdAlignManager manager 
)
staticprivate
void PndLmdAlignManager::resetMTLB ( int  n,
int  r,
int  w 
)
private

Definition at line 49 of file PndLmdAlignManager.cxx.

References _i, _n, _r, _w, n, and r.

Referenced by alignMT().

49  {
50  _i = 0;
51  _n = n;
52  _r = r;
53  _w = w;
54 }
double r
Definition: RiemannTest.C:14
int n
int PndLmdAlignManager::searchDirectories ( std::string  curr_directory,
std::vector< std::string > &  list,
bool  includeSubDirs = true 
)
static

Definition at line 797 of file PndLmdAlignManager.cxx.

798  {
799 
800  if (!boost::filesystem::exists(curr_directory)) {
801  return 0;
802  }
803  boost::filesystem::directory_iterator iterator(curr_directory);
804  for (; iterator != boost::filesystem::directory_iterator(); ++iterator) {
805  if (boost::filesystem::is_directory(iterator->path())) {
806  list.push_back(iterator->path().string());
807 
808  //recursively call for sub directories
809  if (includeSubDirs) {
810  searchDirectories(iterator->path().string(), list, includeSubDirs);
811  }
812  }
813  }
814  sort(list.begin(), list.end());
815  return list.size();
816 
817 }
static int searchDirectories(std::string curr_directory, std::vector< std::string > &list, bool includeSubDirs=true)
int PndLmdAlignManager::searchFiles ( std::string  curr_directory,
std::vector< std::string > &  list,
std::string  extension = "",
bool  includeSubDirs = true 
)
static

Definition at line 731 of file PndLmdAlignManager.cxx.

Referenced by addFilesFromDirectory(), checkForBinaryFiles(), checkForLmdMatrixFiles(), and PndLmdAlignQA::checkForMatrixFiles().

732  {
733 
734  if (!boost::filesystem::exists(path)) {
735  return 0;
736  }
737  boost::filesystem::directory_iterator iterator(path);
738  for (; iterator != boost::filesystem::directory_iterator(); ++iterator) {
739  if (boost::filesystem::is_directory(iterator->path()) && includeSubDirs) {
740  list.push_back(iterator->path().string());
741  searchFiles(iterator->path().string(), list, detail, includeSubDirs);
742  }
743  else if (boost::filesystem::is_regular_file(iterator->path())) {
744  if (iterator->path().string().find(detail) != std::string::npos) {
745  list.push_back(iterator->path().string());
746  }
747  }
748  }
749  sort(list.begin(), list.end());
750  return list.size();
751 }
static int searchFiles(std::string curr_directory, std::vector< std::string > &list, std::string extension="", bool includeSubDirs=true)
void PndLmdAlignManager::setBinaryPairFileDirectory ( const std::string &  binaryPairFileDirectory)
inline

Definition at line 202 of file PndLmdAlignManager.h.

References _binaryPairFileDirectory.

Referenced by PndLmdAlignQA::histogramPairDistances(), and runLumiPixel2fMatrixFinder().

202  {
203  _binaryPairFileDirectory = binaryPairFileDirectory;
204  }
std::string _binaryPairFileDirectory
void PndLmdAlignManager::setInCentimeters ( bool  inCentimeters)

Definition at line 819 of file PndLmdAlignManager.cxx.

References _inCentimeters, and aligners.

Referenced by PndLmdAlignQA::checkCombinedMatrices(), PndLmdAlignQA::checkCyclicMatrices(), PndLmdAlignQA::histogramPairDistances(), PndLmdAlignQA::plotMatrixresiduals(), and runLumiPixel2fMatrixFinder().

819  {
820  _inCentimeters = inCentimeters;
821  for (mapIt it = aligners.begin(); it != aligners.end(); it++) {
822  it->second.setInCentimeters(_inCentimeters);
823  }
824 }
std::map< int, PndLmdSensorAligner > aligners
std::map< int, PndLmdSensorAligner >::iterator mapIt
void PndLmdAlignManager::setMatrixOutDir ( std::string  matrixOutDir)
inline

Definition at line 178 of file PndLmdAlignManager.h.

References _matrixOutDir.

Referenced by PndLmdAlignQA::checkCombinedMatrices(), PndLmdAlignQA::checkCyclicMatrices(), and runLumiPixel2fMatrixFinder().

178  {
179  _matrixOutDir = matrixOutDir;
180  }
void PndLmdAlignManager::setMaxPairs ( int  maxPairs)

Definition at line 1381 of file PndLmdAlignManager.cxx.

References aligners.

Referenced by runLumiPixel2fMatrixFinder().

1381  {
1382 
1383  if (maxPairs > 0) {
1384  for (mapIt it = aligners.begin(); it != aligners.end(); it++) {
1385  it->second.setMaximumNumberOfHitPairs(maxPairs);
1386  }
1387  return;
1388  }
1389  else {
1390  cout << "warning. max pairs must be larger than 0!\n";
1391  return;
1392  }
1393 
1394 }
std::map< int, PndLmdSensorAligner > aligners
std::map< int, PndLmdSensorAligner >::iterator mapIt
void PndLmdAlignManager::setOutFilename ( const std::string &  filename)
inline

Definition at line 152 of file PndLmdAlignManager.h.

References checkIOpaths(), filename, and outFilename.

152  {
154  checkIOpaths();
155  }
const string filename
void PndLmdAlignManager::setSingleAligner ( bool  singleAligner)
inline

Definition at line 148 of file PndLmdAlignManager.h.

References _singleAligner.

148  {
149  _singleAligner = singleAligner;
150  }
void PndLmdAlignManager::setStartAlignerWhenFull ( bool  value)
inline

Definition at line 206 of file PndLmdAlignManager.h.

References startAlignerWhenFull.

206  {
207  startAlignerWhenFull = value;
208  }
void PndLmdAlignManager::setZasTimestamp ( bool  timestamp)

Definition at line 826 of file PndLmdAlignManager.cxx.

References _zIsTimestamp, and aligners.

826  {
827  _zIsTimestamp = timestamp;
828  for (mapIt it = aligners.begin(); it != aligners.end(); it++) {
829  it->second.setZasTimetamp(_zIsTimestamp);
830  }
831 }
std::map< int, PndLmdSensorAligner > aligners
std::map< int, PndLmdSensorAligner >::iterator mapIt
void PndLmdAlignManager::validate ( )

Definition at line 206 of file PndLmdAlignManager.cxx.

References aligners.

206  {
207  std::cout << "using " << aligners.size() << " aligners, which have:\n";
208  for (mapIt it = aligners.begin(); it != aligners.end(); it++) {
209  cout << "id: " << it->second.getModuleID() << " has " << it->second.getNoOfPairs() << " pairs."
210  << "\n";
211  }
212 }
std::map< int, PndLmdSensorAligner > aligners
std::map< int, PndLmdSensorAligner >::iterator mapIt
void PndLmdAlignManager::verboseLevel ( int  verbose)
inline

Definition at line 210 of file PndLmdAlignManager.h.

References _verboseLevel, a, aligners, and verbose.

Referenced by runLumiPixel2fMatrixFinder().

210  {
212  for (auto &a : aligners) {
213  a.second.verboseLevel(_verboseLevel);
214  }
215  }
#define verbose
std::map< int, PndLmdSensorAligner > aligners
Int_t a
Definition: anaLmdDigi.C:126
void PndLmdAlignManager::verbosePrint ( std::string  input,
int  level = 3 
)
private

Definition at line 1534 of file PndLmdAlignManager.cxx.

References _verboseLevel.

Referenced by alignST().

1534  {
1535  if (_verboseLevel >= level) {
1536  cout << input;
1537  }
1538 }
void PndLmdAlignManager::waitForCompletion ( )

Definition at line 1400 of file PndLmdAlignManager.cxx.

References _inCentimeters, _info, _matrixOutDir, aligners, alignersFull, alignerThreadGroup, alignOne(), makeMatrixFileName(), and writeMatrix().

Referenced by runLumiPixel2fMatrixFinder().

1400  {
1401 
1402  //start all alignsers that have not already started (i.e. don't have required no of Pairs)
1403  int notStarted = 0;
1404 
1405  cout << "starting remaining aligners.\n";
1406  for (map<int, bool>::iterator it = alignersFull.begin(); it != alignersFull.end(); it++) {
1407  if (!(it->second)) {
1408 
1409  //cout << "starting aligner " << it->first << "\n";
1410  //if pair could not be added, aligner is full. start thread directly.
1411  alignerThreadGroup.create_thread(
1412  boost::bind(&PndLmdAlignManager::alignOne, this, boost::ref(aligners[it->first])));
1413  notStarted++;
1414  }
1415  }
1416  cout << notStarted << " aligners remained.\n";
1417  cout << "jobs queue size : " << alignerThreadGroup.size() << "/360\n";
1418  cout << "waiting for all aligners to finish...";
1419 
1420  //wait for all threads to complete
1421  alignerThreadGroup.join_all();
1422  cout << "done!\n";
1423 
1424  for (mapIt it = aligners.begin(); it != aligners.end(); it++) {
1425  if (it->second.successful()) {
1426 
1427  Matrix result = it->second.getResultMatrix();
1428  string matrixFilename = _matrixOutDir
1429  + makeMatrixFileName(it->second.getOverlapId(), _inCentimeters);
1430 
1431  if (!writeMatrix(result, matrixFilename)) {
1432  cout << "ERROR: could not write matrix " << matrixFilename << "\n";
1433  }
1434 
1435  _info << "aligner " << it->second.getOverlapId() << ":\n";
1436  _info << "no of pairs: " << it->second.getNoOfPairs() << "\n";
1437  _info << "\n";
1438  }
1439  else {
1440  cout << "Error: aligner for " << it->second.getOverlapId() << " failed.\n";
1441  }
1442  }
1443 
1444  //write matrix info
1445  ofstream of;
1446  if (_inCentimeters) {
1447  of.open((_matrixOutDir + "/info-cm.txt").c_str());
1448  }
1449  else {
1450  of.open((_matrixOutDir + "/info-px.txt").c_str());
1451  }
1452 
1453  of << _info.str();
1454  of.close();
1455  cout << "all aligners done.\n";
1456 }
boost::thread_group alignerThreadGroup
std::map< int, bool > alignersFull
std::map< int, PndLmdSensorAligner > aligners
std::map< int, PndLmdSensorAligner >::iterator mapIt
static bool writeMatrix(Matrix &mat, std::string filename)
Definition: matrix.h:50
static std::string makeMatrixFileName(int overlapId=0, bool incentimeters=true)
std::stringstream _info
void alignOne(PndLmdSensorAligner &aligner)
void PndLmdAlignManager::workerThread ( boost::shared_ptr< boost::asio::io_service >  io_service)
bool PndLmdAlignManager::writeConfigFile ( boost::property_tree::ptree  configTree,
std::string  filename,
bool  replaceExisting = true 
)
static

Definition at line 1558 of file PndLmdAlignManager.cxx.

Referenced by PndLmdPairFinderTask::FinishTask().

1559  {
1560 
1561  //replace logic
1562 
1563  if (boost::filesystem::exists(filename) && !replaceExisting) {
1564  cerr << "PndLmdAlignManager::writeConfig: Config already exists, will not be replaced.\n";
1565  return false;
1566  }
1567 
1568  boost::filesystem::path outPath(filename);
1569  if (!boost::filesystem::exists(outPath.parent_path())) {
1570  boost::filesystem::create_directories(outPath.parent_path());
1571  }
1572 
1573  std::ofstream os(filename);
1574  boost::property_tree::write_json(os, configTree);
1575  return true;
1576 }
const string filename
bool PndLmdAlignManager::writeMatrix ( Matrix mat,
std::string  filename 
)
static

Definition at line 685 of file PndLmdAlignManager.cxx.

Referenced by alignMT(), alignST(), and waitForCompletion().

685  {
686 
687  if (!(filename == "")) {
688  boost::filesystem::path outPath(filename);
689  if (!boost::filesystem::exists(outPath.parent_path())) {
690  boost::filesystem::create_directories(outPath.parent_path());
691  }
692  }
693 
694  //cout << "writing matrix " << filename << "\n";
695  std::ofstream outFileStream;
696  outFileStream.open(filename.c_str());
697 
698  if (outFileStream.fail()) {
699  return false;
700  }
701 
702  outFileStream << std::setprecision(16);
703  outFileStream << mat;
704  outFileStream.close();
705  return true;
706 }
const string filename
bool PndLmdAlignManager::writePairsToBinaryFiles ( )

Definition at line 1481 of file PndLmdAlignManager.cxx.

References _binaryPairFileDirectory, aligners, loadBar(), and mkdir().

1481  {
1482 
1483  if (_binaryPairFileDirectory == "") {
1484  cout << "error: binary pair file directory not set.\n";
1485  cout << "use PndLmdAlignManager::setBinaryPairFileDirectory()\n";
1486  return false;
1487  }
1488 
1489  int cur, tot;
1490  cur = 0;
1491  tot = aligners.size();
1492 
1493  cout << "writing all pairs to binary files\n";
1495 
1496  //maybe do this multithreaded?
1497  for (auto &aligner : aligners) {
1498  loadBar(cur++, tot, 1000, 60);
1499  if (!aligner.second.writePairsToBinary(_binaryPairFileDirectory)) {
1500  return false;
1501  }
1502  }
1503  return true;
1504 }
std::map< int, PndLmdSensorAligner > aligners
static bool mkdir(std::string path)
static void loadBar(int current, int total, int resolution, int width, std::string message="")
std::string _binaryPairFileDirectory

Friends And Related Function Documentation

friend class PndLmdAlignQA
friend

Definition at line 42 of file PndLmdAlignManager.h.

friend class PndLmdSensorAligner
friend

Definition at line 41 of file PndLmdAlignManager.h.

Member Data Documentation

bool PndLmdAlignManager::_allFilesAdded
private

Definition at line 54 of file PndLmdAlignManager.h.

Referenced by addFile(), addFilesFromDirectory(), init(), and readFilesAndAlign().

std::string PndLmdAlignManager::_binaryPairFileDirectory
private
bool PndLmdAlignManager::_enableHelperMatrix
private

Definition at line 56 of file PndLmdAlignManager.h.

Referenced by alignAllSensors(), and init().

bool PndLmdAlignManager::_firstInitDone
private

Definition at line 58 of file PndLmdAlignManager.h.

Referenced by init().

int PndLmdAlignManager::_i
private

Definition at line 45 of file PndLmdAlignManager.h.

Referenced by incrementMTLB(), and resetMTLB().

bool PndLmdAlignManager::_inCentimeters
private
std::stringstream PndLmdAlignManager::_info
private

Definition at line 49 of file PndLmdAlignManager.h.

Referenced by alignAllSensors(), alignMT(), alignST(), init(), and waitForCompletion().

std::string PndLmdAlignManager::_matrixOutDir
private
bool PndLmdAlignManager::_multithreaded
private

Definition at line 59 of file PndLmdAlignManager.h.

Referenced by alignAllSensors(), and init().

int PndLmdAlignManager::_n
private

Definition at line 45 of file PndLmdAlignManager.h.

Referenced by incrementMTLB(), and resetMTLB().

int PndLmdAlignManager::_r
private

Definition at line 45 of file PndLmdAlignManager.h.

Referenced by incrementMTLB(), and resetMTLB().

bool PndLmdAlignManager::_singleAligner
private

Definition at line 56 of file PndLmdAlignManager.h.

Referenced by init(), and setSingleAligner().

int PndLmdAlignManager::_verboseLevel
private

Definition at line 47 of file PndLmdAlignManager.h.

Referenced by alignMT(), init(), verboseLevel(), and verbosePrint().

int PndLmdAlignManager::_w
private

Definition at line 45 of file PndLmdAlignManager.h.

Referenced by incrementMTLB(), and resetMTLB().

bool PndLmdAlignManager::_zIsTimestamp
private

Definition at line 56 of file PndLmdAlignManager.h.

Referenced by init(), and setZasTimestamp().

std::map<int, PndLmdSensorAligner> PndLmdAlignManager::aligners
private
std::map<int, bool> PndLmdAlignManager::alignersFull
private

Definition at line 52 of file PndLmdAlignManager.h.

Referenced by addPairAndStartAligner(), init(), and waitForCompletion().

bool PndLmdAlignManager::allAlignersDone
private

Definition at line 54 of file PndLmdAlignManager.h.

Referenced by addPairAndStartAligner(), and readFilesAndAlign().

std::vector<std::string> PndLmdAlignManager::fileNames
private
std::string PndLmdAlignManager::outFilename
private

Definition at line 57 of file PndLmdAlignManager.h.

Referenced by checkIOpaths(), init(), and setOutFilename().

vector<int> PndLmdAlignManager::overlapIDs
private

Definition at line 61 of file PndLmdAlignManager.h.

Referenced by checkForBinaryFiles(), checkForLmdMatrixFiles(), and init().

bool PndLmdAlignManager::startAlignerWhenFull
private

Definition at line 56 of file PndLmdAlignManager.h.

Referenced by setStartAlignerWhenFull().


The documentation for this class was generated from the following files: