Changeset 277 in Idarraga


Ignore:
Timestamp:
Apr 18, 2012, 7:29:01 PM (12 years ago)
Author:
idarraga
Message:
 
Location:
mpxdataconverter
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • mpxdataconverter/MediPixROOTConverter.cpp

    r176 r277  
    2525#include "MediPixWriteToEntuple.h"
    2626#include "allpix_dm.h"
     27
     28using namespace std;
    2729
    2830void checkParameters(int, char**, TString *);
     
    5658  std::cout << "[INFO] there are " << listOfDSCFiles.size() << " DSC files in directory" << std::endl;
    5759
     60
    5861  if(listOfFiles.empty()){
    5962    std::cout << "[ERROR] I could not find any frame files in the specified directory," << std::endl;
     
    6568  if(listOfDSCFiles.size() != 0)
    6669    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
    6979  if((listOfFiles.size() != listOfDSCFiles.size()) && listOfDSCFiles.size() != 0)
    7080    {
     
    8898      oneDSCFileName = listOfDSCFiles[filesItr];
    8999      //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      }
    92105
    93106    }
  • mpxdataconverter/allpix_dm.cc

    r263 r277  
    425425        if ( frameType == 0 ) { // if still 0
    426426                std::cout << "[ERROR] could not determine the frame type --> " << fullDSCFileName << std::endl;
    427                 exit(1);
     427                return false;
    428428        }
    429429
  • mpxdataconverter/listHandler.cpp

    r26 r277  
    88ListHandler::ListHandler(Char_t * dirPath){
    99
    10   m_dirPath = dirPath;
    11   std::cout << "[INFO] looking up in " << m_dirPath << std::endl;
     10        m_dirPath = dirPath;
     11        std::cout << "[INFO] looking up in " << m_dirPath << std::endl;
    1212
    1313}
     
    1616
    1717
    18   std::vector<std::string> orderedString;
     18        std::vector<std::string> orderedString;
    1919
    20   std::vector<std::string>::iterator itFrames = listFrames.begin();
    21   std::vector<std::string>::iterator itDSD = listDSC.begin();
     20        std::vector<std::string>::iterator itFrames = listFrames.begin();
     21        std::vector<std::string>::iterator itDSD = listDSC.begin();
    2222
    23   TString tempName = "";
    24   for( ; itFrames != listFrames.end() ; itFrames++ )
    25     {
    26       tempName = ((TString)(*itFrames));
     23        TString tempName = "";
     24        TString tempName2 = "";
    2725
    28       /* check if the file ends with .txt */
    29       if(((TString)(*itFrames)).Contains(".txt"))
     26        for( ; itFrames != listFrames.end() ; itFrames++ )
    3027        {
    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";
    4231
    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
    5559        }
    5660
    57     }
    58 
    59   return orderedString;
     61        return orderedString;
    6062}
    6163
    6264std::vector<std::string> ListHandler::getListToLoop(TString tempScratchDir, Int_t typeF){
    6365
    64   TString filename = "";
    65   if(tempScratchDir.Length() > 0){
    66     filename += tempScratchDir;
    67     filename += "/";
    68   }
     66        TString filename = "";
     67        if(tempScratchDir.Length() > 0){
     68                filename += tempScratchDir;
     69                filename += "/";
     70        }
    6971
    70   if(typeF==FRAME_FILES) filename += "listOfFiles.txt";
    71   if(typeF==DSC_FILES) filename += "listOfFiles.dsc.txt";
     72        if(typeF==FRAME_FILES) filename += "listOfFiles.txt";
     73        if(typeF==DSC_FILES) filename += "listOfFiles.dsc.txt";
    7274
    73   std::string command0 = "/bin/bash -c 'rm -f "; // listOfFiles.txt"   "'";
    74   command0 += filename.Data();
    75   command0 += "'";
     75        std::string command0 = "/bin/bash -c 'rm -f "; // listOfFiles.txt"   "'";
     76        command0 += filename.Data();
     77        command0 += "'";
    7678
    77   std::string command02 = "/bin/bash -c 'rm -f ";
    78   command02 += filename.Data();
    79   command02 += "'";
     79        std::string command02 = "/bin/bash -c 'rm -f ";
     80        command02 += filename.Data();
     81        command02 += "'";
    8082
    81   std::string commandn = "/bin/bash -c 'ls ";
    82   std::string commandn2 = "/bin/bash -c 'ls ";
     83        std::string commandn = "/bin/bash -c 'ls ";
     84        std::string commandn2 = "/bin/bash -c 'ls ";
    8385
    84   std::string command1 = "/bin/bash -c 'for a in ";
    85   std::string command2 = "/bin/bash -c 'for a in ";
     86        std::string command1 = "/bin/bash -c 'for a in ";
     87        std::string command2 = "/bin/bash -c 'for a in ";
    8688
    87   /* how many .dsc files do we have ? */
    88   commandn += m_dirPath + " | grep \".dsc\" | wc -l >> "; //listOfFiles.txt'";
    89   commandn += filename.Data();
    90   commandn += "'";
     89        /* how many .dsc files do we have ? */
     90        commandn += m_dirPath + " | grep \".dsc\" | wc -l >> "; //listOfFiles.txt'";
     91        commandn += filename.Data();
     92        commandn += "'";
    9193
    92   commandn2 += m_dirPath + " | grep \".dsc\" | wc -l >> "; //listOfFiles.dsc.txt'";
    93   commandn2 += filename.Data();
    94   commandn2 += "'";
     94        commandn2 += m_dirPath + " | grep \".dsc\" | wc -l >> "; //listOfFiles.dsc.txt'";
     95        commandn2 += filename.Data();
     96        commandn2 += "'";
    9597
    96   /* get the files that are not dsc, sometimes frame data comes
     98        /* get the files that are not dsc, sometimes frame data comes
    9799     withouth extention (.txt), or can be any other */
    98   command1 += m_dirPath + "/* ; do [[ $a == *.dsc ]] || echo $a >> "; // listOfFiles.txt ; done'";
    99   command1 += filename.Data();
    100   command1 += " ; done'";
     100        command1 += m_dirPath + "/* ; do [[ $a == *.dsc ]] || echo $a >> "; // listOfFiles.txt ; done'";
     101        command1 += filename.Data();
     102        command1 += " ; done'";
    101103
    102104
    103   /* get the files that are dsc */
    104   command2 += m_dirPath + "/* ; do [[ $a == *.dsc ]] && echo $a >> "; // listOfFiles.dsc.txt ; done'";
    105   command2 += filename.Data();
    106   command2 += " ; done'";
     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'";
    107109
    108   /* get old files erased */
    109   if(typeF==FRAME_FILES) system(command0.c_str());
    110   if(typeF==DSC_FILES) system(command02.c_str());
     110        /* get old files erased */
     111        if(typeF==FRAME_FILES) system(command0.c_str());
     112        if(typeF==DSC_FILES) system(command02.c_str());
    111113
    112   if(typeF==FRAME_FILES) system(commandn.c_str());
    113   if(typeF==DSC_FILES) system(commandn2.c_str());
     114        if(typeF==FRAME_FILES) system(commandn.c_str());
     115        if(typeF==DSC_FILES) system(commandn2.c_str());
    114116
    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());
    129120
    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        }
    138131
    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())
    144142        {
    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++;
    146156        }
    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);
    152162        }
    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;
    162164}
Note: See TracChangeset for help on using the changeset viewer.