Changeset 277 in Idarraga
- Timestamp:
- Apr 18, 2012, 7:29:01 PM (12 years ago)
- Location:
- mpxdataconverter
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
mpxdataconverter/MediPixROOTConverter.cpp
r176 r277 25 25 #include "MediPixWriteToEntuple.h" 26 26 #include "allpix_dm.h" 27 28 using namespace std; 27 29 28 30 void checkParameters(int, char**, TString *); … … 56 58 std::cout << "[INFO] there are " << listOfDSCFiles.size() << " DSC files in directory" << std::endl; 57 59 60 58 61 if(listOfFiles.empty()){ 59 62 std::cout << "[ERROR] I could not find any frame files in the specified directory," << std::endl; … … 65 68 if(listOfDSCFiles.size() != 0) 66 69 listOfDSCFiles = handlerL.OrderFilesPairMatch(listOfFiles, listOfDSCFiles); 67 68 70 71 /* 72 vector<std::string>::iterator itrr = listOfDSCFiles.begin(); 73 for( ; itrr != listOfDSCFiles.end() ; itrr++){ 74 cout << *itrr << endl; 75 } 76 exit(1); 77 */ 78 69 79 if((listOfFiles.size() != listOfDSCFiles.size()) && listOfDSCFiles.size() != 0) 70 80 { … … 88 98 oneDSCFileName = listOfDSCFiles[filesItr]; 89 99 //frames.getAFrameMatrix((TString) oneFileName, (TString) oneDSCFileName); 90 frames.readOneFrame((TString) oneFileName, (TString) oneDSCFileName); 91 MPXnTuple.fillVars(&frames); 100 bool frameread = frames.readOneFrame((TString) oneFileName, (TString) oneDSCFileName); 101 102 if(frameread) { 103 MPXnTuple.fillVars(&frames); 104 } 92 105 93 106 } -
mpxdataconverter/allpix_dm.cc
r263 r277 425 425 if ( frameType == 0 ) { // if still 0 426 426 std::cout << "[ERROR] could not determine the frame type --> " << fullDSCFileName << std::endl; 427 exit(1);427 return false; 428 428 } 429 429 -
mpxdataconverter/listHandler.cpp
r26 r277 8 8 ListHandler::ListHandler(Char_t * dirPath){ 9 9 10 11 10 m_dirPath = dirPath; 11 std::cout << "[INFO] looking up in " << m_dirPath << std::endl; 12 12 13 13 } … … 16 16 17 17 18 18 std::vector<std::string> orderedString; 19 19 20 21 20 std::vector<std::string>::iterator itFrames = listFrames.begin(); 21 std::vector<std::string>::iterator itDSD = listDSC.begin(); 22 22 23 TString tempName = ""; 24 for( ; itFrames != listFrames.end() ; itFrames++ ) 25 { 26 tempName = ((TString)(*itFrames)); 23 TString tempName = ""; 24 TString tempName2 = ""; 27 25 28 /* check if the file ends with .txt */ 29 if(((TString)(*itFrames)).Contains(".txt")) 26 for( ; itFrames != listFrames.end() ; itFrames++ ) 30 27 { 31 tempName.Remove(TString::kTrailing, 't'); 32 tempName.Remove(TString::kTrailing, 'x'); 33 tempName.Remove(TString::kTrailing, 't'); 34 tempName.Remove(TString::kTrailing, '.'); 35 } 36 tempName+=".dsc"; 37 38 /* look for the corresponding .dsc file 39 that hopefully is not so far in the list. 40 No need to optimize this now, is fast enough. 41 */ 28 // first possible name 29 tempName = ((TString)(*itFrames)); 30 tempName+=".dsc"; 42 31 43 for(itDSD = listDSC.begin() ; itDSD != listDSC.end() ; itDSD++ ) 44 { 45 if((TString)(*itDSD) == tempName) 46 { 47 /* get the good filename in the list and erase the entry 48 in listDSC. So it gets faster next time. */ 49 orderedString.push_back((*itDSD)); 50 listDSC.erase(itDSD); 51 //std::cout << " !!! new size = " << listDSC.size() << std::endl; 52 //std::cout << " !!! found --> " << (*itDSD) << std::endl; 53 break; 54 } 32 // second possible name 33 tempName2 = ((TString)(*itFrames)); 34 if(((TString)(*itFrames)).Contains(".txt")) { 35 tempName2.Remove(TString::kTrailing, 't'); 36 tempName2.Remove(TString::kTrailing, 'x'); 37 tempName2.Remove(TString::kTrailing, 't'); 38 tempName2.Remove(TString::kTrailing, '.'); 39 } 40 tempName2+=".dsc"; 41 42 /* look for the corresponding .dsc file 43 that hopefully is not so far in the list. 44 No need to optimize this now, is fast enough. 45 */ 46 47 for(itDSD = listDSC.begin() ; itDSD != listDSC.end() ; itDSD++ ) { 48 if((TString)(*itDSD) == tempName || (TString)(*itDSD) == tempName2) { 49 /* get the good filename in the list and erase the entry 50 in listDSC. So it gets faster next time. */ 51 orderedString.push_back((*itDSD)); 52 listDSC.erase(itDSD); 53 //std::cout << " !!! new size = " << listDSC.size() << std::endl; 54 //std::cout << " !!! found --> " << (*itDSD) << std::endl; 55 break; 56 } 57 } 58 55 59 } 56 60 57 } 58 59 return orderedString; 61 return orderedString; 60 62 } 61 63 62 64 std::vector<std::string> ListHandler::getListToLoop(TString tempScratchDir, Int_t typeF){ 63 65 64 65 66 67 68 66 TString filename = ""; 67 if(tempScratchDir.Length() > 0){ 68 filename += tempScratchDir; 69 filename += "/"; 70 } 69 71 70 71 72 if(typeF==FRAME_FILES) filename += "listOfFiles.txt"; 73 if(typeF==DSC_FILES) filename += "listOfFiles.dsc.txt"; 72 74 73 74 75 75 std::string command0 = "/bin/bash -c 'rm -f "; // listOfFiles.txt" "'"; 76 command0 += filename.Data(); 77 command0 += "'"; 76 78 77 78 79 79 std::string command02 = "/bin/bash -c 'rm -f "; 80 command02 += filename.Data(); 81 command02 += "'"; 80 82 81 82 83 std::string commandn = "/bin/bash -c 'ls "; 84 std::string commandn2 = "/bin/bash -c 'ls "; 83 85 84 85 86 std::string command1 = "/bin/bash -c 'for a in "; 87 std::string command2 = "/bin/bash -c 'for a in "; 86 88 87 88 89 90 89 /* how many .dsc files do we have ? */ 90 commandn += m_dirPath + " | grep \".dsc\" | wc -l >> "; //listOfFiles.txt'"; 91 commandn += filename.Data(); 92 commandn += "'"; 91 93 92 93 94 94 commandn2 += m_dirPath + " | grep \".dsc\" | wc -l >> "; //listOfFiles.dsc.txt'"; 95 commandn2 += filename.Data(); 96 commandn2 += "'"; 95 97 96 98 /* get the files that are not dsc, sometimes frame data comes 97 99 withouth extention (.txt), or can be any other */ 98 99 100 100 command1 += m_dirPath + "/* ; do [[ $a == *.dsc ]] || echo $a >> "; // listOfFiles.txt ; done'"; 101 command1 += filename.Data(); 102 command1 += " ; done'"; 101 103 102 104 103 104 105 106 105 /* get the files that are dsc */ 106 command2 += m_dirPath + "/* ; do [[ $a == *.dsc ]] && echo $a >> "; // listOfFiles.dsc.txt ; done'"; 107 command2 += filename.Data(); 108 command2 += " ; done'"; 107 109 108 109 110 110 /* get old files erased */ 111 if(typeF==FRAME_FILES) system(command0.c_str()); 112 if(typeF==DSC_FILES) system(command02.c_str()); 111 113 112 113 114 if(typeF==FRAME_FILES) system(commandn.c_str()); 115 if(typeF==DSC_FILES) system(commandn2.c_str()); 114 116 115 int rcm = 0, rcm2 = 0; 116 if(typeF==FRAME_FILES) rcm = system(command1.c_str()); 117 if(typeF==DSC_FILES) rcm2 = system(command2.c_str()); 118 119 if(rcm != 0){ 120 std::cout << "[ERROR] unexpected error when listing files inside " << m_dirPath << std::endl; 121 std::cout << " please READ all the bash errors above. " << std::endl; 122 std::cout << " Other possible reasons: " << std::endl; 123 std::cout << " I need to make temporary files. May be you " << std::endl; 124 std::cout << " don't have 'w' permissions in this directory ? " << std::endl; 125 std::cout << " Use the third (optional) parameter to this " << std::endl; 126 std::cout << " program to change the temp dir" << std::endl; 127 exit(1); 128 } 117 int rcm = 0, rcm2 = 0; 118 if(typeF==FRAME_FILES) rcm = system(command1.c_str()); 119 if(typeF==DSC_FILES) rcm2 = system(command2.c_str()); 129 120 130 fstream filestrList; 131 filestrList.open(filename, fstream::in); 132 133 std::string lineTemp; 134 std::vector<std::string> listOfFiles; 135 Int_t cntrInFile = 0; 136 Int_t cntrInActualFiles = 0; 137 Int_t nFiles = 0; 121 if(rcm != 0){ 122 std::cout << "[ERROR] unexpected error when listing files inside " << m_dirPath << std::endl; 123 std::cout << " please READ all the bash errors above. " << std::endl; 124 std::cout << " Other possible reasons: " << std::endl; 125 std::cout << " I need to make temporary files. May be you " << std::endl; 126 std::cout << " don't have 'w' permissions in this directory ? " << std::endl; 127 std::cout << " Use the third (optional) parameter to this " << std::endl; 128 std::cout << " program to change the temp dir" << std::endl; 129 exit(1); 130 } 138 131 139 while (filestrList.good()) 140 { 141 filestrList >> lineTemp; 142 143 if(cntrInFile == 0) 132 fstream filestrList; 133 filestrList.open(filename, fstream::in); 134 135 std::string lineTemp; 136 std::vector<std::string> listOfFiles; 137 Int_t cntrInFile = 0; 138 Int_t cntrInActualFiles = 0; 139 Int_t nFiles = 0; 140 141 while (filestrList.good()) 144 142 { 145 nFiles = atoi(lineTemp.c_str()); 143 filestrList >> lineTemp; 144 145 if(cntrInFile == 0) 146 { 147 nFiles = atoi(lineTemp.c_str()); 148 } 149 if(cntrInFile > 0 && cntrInFile <= nFiles) 150 { 151 //std::cout << lineTemp << std::endl; 152 listOfFiles.push_back(lineTemp); 153 cntrInActualFiles++; 154 } 155 cntrInFile++; 146 156 } 147 if(cntrInFile > 0 && cntrInFile <= nFiles) 148 {149 //std::cout << lineTemp << std::endl;150 listOfFiles.push_back(lineTemp);151 cntrInActualFiles++;157 158 if(nFiles != cntrInActualFiles){ 159 std::cout << "[ERROR] There should be " << nFiles << " frame (and .dsc) files in this directory and I found " 160 << cntrInFile << "... giving up."; 161 exit(1); 152 162 } 153 cntrInFile++; 154 } 155 156 if(nFiles != cntrInActualFiles){ 157 std::cout << "[ERROR] There should be " << nFiles << " frame (and .dsc) files in this directory and I found " 158 << cntrInFile << "... giving up."; 159 exit(1); 160 } 161 return listOfFiles; 163 return listOfFiles; 162 164 }
Note: See TracChangeset
for help on using the changeset viewer.