Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

RawDataSet.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Database_RawDataSet_h
00002 #define Impala_Core_Database_RawDataSet_h
00003 
00004 #include "Basis/FileName.h"
00005 #include "Util/IOBufferFile.h"
00006 #include "Util/Database.h"
00007 #include "Util/StringParser.h"
00008 #include "Basis/Timer.h"
00009 #include "Basis/QuidObj.h"
00010 #include "Basis/Quids.h"
00011 #include "Core/Feature/FeatureDefinition.h"
00012 #include "Link/DiskImage/DiskImageFuncs.h"
00013 #include "Persistency/Locator.h"
00014 
00015 namespace Impala
00016 {
00017 namespace Core
00018 {
00019 namespace Database
00020 {
00021 
00022 
00026 class RawDataSet
00027 {
00028 public:
00029 
00030     RawDataSet(String setName)
00031     {
00032         Init(setName);
00033     }
00034 
00035 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00036     RawDataSet(Util::Database* db, String setName, String setFileName)
00037     {
00038         Init(db, setName, setFileName);
00039     }
00040 
00041     RawDataSet(Util::Database* db, String setName, String setFileName,
00042                String nameExt)
00043     {
00044         Init(db, setName, setFileName);
00045         GenerateFileNames(nameExt);
00046     }
00047 #endif // REPOSITORY_USED
00048 
00049     String
00050     GetSetName()
00051     {
00052         return mSetName;
00053     }
00054 
00055     String
00056     GetSetNameBase()
00057     {
00058         return mSetNameBase;
00059     }
00060 
00061     Persistency::Locator
00062     GetLocator()
00063     {
00064         //todo : allow for other sources of the protocol definition
00065         CmdOptions& options = CmdOptions::GetInstance();
00066         return Persistency::Locator(mSetName, options);
00067     }
00068 
00069 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00070     Util::Database*
00071     GetDatabase()
00072     {
00073         return mDb;
00074     }
00075 
00076     void
00077     SetDatabase(Util::Database* db)
00078     {
00079         mDb = db;
00080     }
00081 #endif // REPOSITORY_USED
00082 
00083     virtual int
00084     GetSetId()
00085     {
00086         return -1;
00087     }
00088     
00089     int
00090     GetQuidClass()
00091     {
00092         return mQuidClass;
00093     }
00094 
00095     int
00096     NrDirs()
00097     {
00098         return mDir.size();
00099     }
00100 
00101     // section
00102 
00103     String
00104     GetSection(int elemId)
00105     {
00106         return mSection[elemId];
00107     }
00108 
00109     String
00110     GetSectionOfFile(int fileId)
00111     {
00112         return mSection[mFileKey[fileId]];
00113     }
00114 
00115     // directory
00116 
00117     String
00118     GetDir(int elemId)
00119     {
00120         return mDir[elemId];
00121     }
00122 
00123     int
00124     GetDirId(String dir)
00125     {
00126         for (int i=0 ; i<mDir.size() ; i++)
00127             if (mDir[i] == dir)
00128                 return i;
00129         return -1;
00130     }
00131 
00132     int
00133     GetDirId(String section, String dir)
00134     {
00135         for (int i=0 ; i<mDir.size() ; i++)
00136             if ((mSection[i] == section) && (mDir[i] == dir))
00137                 return i;
00138         return -1;
00139     }
00140 
00141     int
00142     GetDirIdOfFile(int fileId)
00143     {
00144         return mFileKey[fileId];
00145     }
00146 
00147     String
00148     GetDirOfFile(int fileId)
00149     {
00150         return mDir[mFileKey[fileId]];
00151     }
00152 
00153     // file
00154 
00155     int
00156     GetFirstFileId(int elemId)
00157     {
00158         if ((elemId < 0) || (elemId >= mFirstFileId.size()))
00159         {
00160             ILOG_ERROR("GetFirstFileId: id " << elemId << " is out of range");
00161             return -1;
00162         }
00163         return mFirstFileId[elemId];
00164     }
00165 
00166     int
00167     GetNrFiles(int elemId)
00168     {
00169         if (!HasFiles())
00170             return 0;
00171         return mNrFiles[elemId];
00172     }
00173 
00174     bool
00175     HasFiles()
00176     {
00177         return mHasFiles;
00178     }
00179 
00180     int
00181     NrFiles()
00182     {
00183         if (!HasFiles())
00184             return NrDirs();
00185         return mFile.size();
00186     }
00187 
00188     // This may be an empty string in case there were no files specified
00189     // in the set
00190     String
00191     GetFile(int i)
00192     {
00193         return mFile[i];
00194     }
00195 
00196     // The real file if a file was specified in the set, otherwise
00197     // dir + extension
00198     String
00199     GetFileOrDir(int i, String extension)
00200     {
00201         if (mFile[i] != String(""))
00202             return mFile[i];
00203         return GetDirOfFile(i) + extension;
00204     }
00205 
00206     // The real base if a file was specified in the set, otherwise the dir name
00207     String
00208     GetFileBase(int i)
00209     {
00210         if (mFile[i] != String(""))
00211             return FileNameBase(mFile[i]);
00212         return GetDirOfFile(i);
00213     }
00214 
00215     // This is new to allow for non-consecutive fileId's
00216     int
00217     GetFileId(int idx)
00218     {
00219         if ((idx >= 0) && (idx < mFileId.size()))
00220             return mFileId[idx];
00221         ILOG_ERROR("No fileId with index " << idx);
00222         return -1;
00223     }
00224 
00225     int
00226     GetFileId(String file)
00227     {
00228         for (int i=0 ; i<mFile.size() ; i++)
00229             if (mFile[i] == file)
00230                 return i;
00231         return -1;
00232     }
00233 
00234     int
00235     GetFileId(int dirId, String file)
00236     {
00237         for (int i=0 ; i<mFile.size() ; i++)
00238             if ((mFileKey[i] == dirId) && (mFile[i] == file))
00239                 return i;
00240         return -1;
00241     }
00242 
00243     int
00244     GetFileId(String section, String dir, String file)
00245     {
00246         if ((section == String("")) && (dir == String("")))
00247             return GetFileId(file);
00248         int dirId = GetDirId(section, dir);
00249         return GetFileId(dirId, file);
00250     }
00251 
00252     // Generate file names from dir if no files were specified in the set
00253     void
00254     GenerateFileNames(String extension)
00255     {
00256         for (int i=0 ; i<mFile.size() ; i++)
00257             if (mFile[i] == String(""))
00258                 mFile[i] = GetDirOfFile(i) + extension;
00259         mHasFiles = true;
00260     }
00261 
00262     String
00263     GetAsPath(int fileId)
00264     {
00265         const int dirId = GetDirIdOfFile(fileId);
00266         String dir = GetDir(dirId);
00267 
00268         if (Link::DiskImage::DiskImageUsed() && dir.find("//#") != String::npos)
00269         {
00270             // prepare for use of escape sequence '0x'
00271             dir = StringReplaceAll(dir, "0x", "0x300x78", false);
00272             // treat every file system start token as a subfolder
00273             dir = StringReplaceAll(dir, "//#", "/0x2f#", false);
00274             if (dir.find("/") == 0)
00275                 dir = dir.substr(1); // remove leading slash
00276         }
00277 
00278         return GetSection(dirId) + "/" + dir + "/" + GetFile(fileId);
00279     }
00280 
00281     // container
00282 
00283     String
00284     GetContainerDir(int elemId)
00285     {
00286         return GetSection(elemId) + "/" + GetDir(elemId);
00287     }
00288 
00289     String
00290     GetContainerDirOfFile(int fileId)
00291     {
00292         return GetSectionOfFile(fileId) + "/" + GetDirOfFile(fileId);
00293     }
00294 
00295     String
00296     GetContainerFile(int fileId)
00297     {
00298         return GetAsPath(fileId);
00299     }
00300 
00301 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00302     // Any data directory part
00303 
00304     String
00305     MakeDir(String dir)
00306     {
00307         return mDb->MakeDir(dir);
00308     }
00309 
00310     String
00311     MakeDir(String dir1, String dir2)
00312     {
00313         return mDb->MakeDir(dir1, dir2);
00314     }
00315 
00316     String
00317     MakeDir(String dir1, String dir2, String dir3)
00318     {
00319         return mDb->MakeDir(dir1, dir2, dir3);
00320     }
00321 
00322     String
00323     MakeDir(String dir1, String dir2, String dir3, String dir4)
00324     {
00325         return mDb->MakeDir(dir1, dir2, dir3, dir4);
00326     }
00327 
00328     String
00329     MakeDir(String dir1, String dir2, String dir3, String dir4, String dir5)
00330     {
00331         return mDb->MakeDir(dir1, dir2, dir3, dir4, dir5);
00332     }
00333 
00334     // Any data file part
00335 
00336     String
00337     GetFilePath(String dir, String file, bool toWrite, bool silent)
00338     {
00339         return mDb->GetFilePath(dir, file, toWrite, silent);
00340     }
00341 
00342     String
00343     GetFilePath(String dir1, String dir2, String file, bool toWrite, bool silent)
00344     {
00345         return mDb->GetFilePath(dir1, dir2, file, toWrite, silent);
00346     }
00347 
00348     String
00349     GetFilePath(String dir1, String dir2, String dir3, String file,
00350                 bool toWrite, bool silent)
00351     {
00352         return mDb->GetFilePath(dir1, dir2, dir3, file, toWrite, silent);
00353     }
00354 
00355     String
00356     GetFilePath(String dir1, String dir2, String dir3, String dir4, String file,
00357                 bool toWrite, bool silent)
00358     {
00359         return mDb->GetFilePath(dir1, dir2, dir3, dir4, file, toWrite, silent);
00360     }
00361 
00362     String
00363     GetFilePath(String dir1, String dir2, String dir3, String dir4, String dir5,
00364                 String file, bool toWrite, bool silent)
00365     {
00366         return mDb->GetFilePath(dir1, dir2, dir3, dir4, dir5, file, toWrite,
00367                                 silent);
00368     }
00369 
00370     // "Specialized" interface to Database paths
00371 
00372     String
00373     GetFilePathVideoData(String setName, bool toWrite, bool silent)
00374     {
00375         String dir = "VideoData";
00376         if (toWrite)
00377             MakeDir(dir);
00378         return GetFilePath(dir, setName, toWrite, silent);
00379     }
00380 
00381     String
00382     GetFilePathVideoData(int nameId, bool toWrite, bool silent)
00383     {
00384         String dir = "VideoData/" + GetSectionOfFile(nameId) + "/"
00385             + GetDirOfFile(nameId);
00386         if (toWrite)
00387             MakeDir(dir);
00388         return GetFilePath(dir, GetFile(nameId), toWrite, silent);
00389     }
00390 
00391     String
00392     GetFilePathImageData(String setName, bool toWrite, bool silent)
00393     {
00394         String dir = "ImageData";
00395         if (toWrite)
00396             MakeDir(dir);
00397         return GetFilePath(dir, setName, toWrite, silent);
00398     }
00399 
00400     String
00401     GetFilePathImageData(int nameId, bool toWrite, bool silent)
00402     {
00403         String dir = "ImageData/" + GetSectionOfFile(nameId) + "/"
00404             + GetDirOfFile(nameId);
00405         if (toWrite)
00406             MakeDir(dir);
00407         return GetFilePath(dir, GetFile(nameId), toWrite, silent);
00408     }
00409 
00410     String
00411     GetFilePathImageArchive(String archiveName, bool toWrite, bool silent)
00412     {
00413         String dir = "ImageArchive";
00414         if (toWrite)
00415             MakeDir(dir);
00416         return GetFilePath(dir, archiveName, toWrite, silent);
00417     }
00418 
00419     String
00420     GetFilePathImageArchive(int fileId, String archiveName, bool toWrite,
00421                             bool silent)
00422     {
00423         String dir = "ImageArchive/" + GetSectionOfFile(fileId) + "/"
00424             + GetDirOfFile(fileId);
00425         if (toWrite)
00426             MakeDir(dir);
00427         return GetFilePath(dir, archiveName, toWrite, silent);
00428     }
00429 
00430     String
00431     GetFilePathFrames(int fileId, String name, bool toWrite, bool silent)
00432     {
00433         String dir = "Frames/" + GetAsPath(fileId);
00434         if (toWrite)
00435             MakeDir(dir);
00436         return GetFilePath(dir, name, toWrite, silent);
00437     }
00438 
00439     String
00440     GetFilePathFrames(int fileId, int frameNr, String suffix, bool toWrite,
00441                       bool silent)
00442     {
00443         String dir = "Frames/" + GetAsPath(fileId);
00444         if (toWrite)
00445             MakeDir(dir);
00446         char frameName[200];
00447         sprintf(frameName, "frame_%06d", frameNr);
00448         return GetFilePath(dir, String(frameName)+suffix, toWrite, silent);
00449     }
00450 
00451     String
00452     GetFilePathVideoIndex(String subDir, String file, bool toWrite, bool silent)
00453     {
00454         String dir("VideoIndex");
00455         if (!subDir.empty())
00456             dir += "/" + subDir;
00457         if (toWrite)
00458             MakeDir(dir);
00459         return GetFilePath(dir, file, toWrite, silent);
00460     }
00461 
00462     /*
00463     String
00464     GetFilePathImageIndex(String subDir, String file, bool toWrite,
00465                           bool silent)
00466     {
00467         String dir = "ImageIndex/" + subDir;
00468         if (toWrite)
00469             MakeDir(dir);
00470         return GetFilePath(dir, file, toWrite, silent);
00471     }
00472     */
00473 
00478     String
00479     GetFilePathMetaData(int fileId, String metaName, bool useDbFile,
00480                         String suffix, bool toWrite, bool silent)
00481     {
00482         String dir = "MetaData/" + GetAsPath(fileId) + "/" + metaName;
00483         if (toWrite)
00484             MakeDir(dir);
00485         String fName = ((useDbFile) ? GetFileBase(fileId) : "") + suffix;
00486         return mDb->GetFilePath(dir, fName, toWrite, silent);
00487     }
00488 
00489     String
00490     GetFilePathMpeg7Shot(int fileId, bool toWrite, bool silent)
00491     {
00492         String dir = "MetaData/shots/" + GetAsPath(fileId);
00493         if (toWrite)
00494             MakeDir(dir);
00495         return GetFilePath(dir, GetFileBase(fileId) + ".xml", toWrite, silent);
00496     }
00497 
00498     String
00499     GetFilePathMpeg7Anno(int fileId, String conceptSet, String xmlName,
00500                          bool toWrite, bool silent)
00501     {
00502         String dir = "MetaData/annotations/" + conceptSet + "/"
00503             + GetAsPath(fileId);
00504         if (toWrite)
00505             MakeDir(dir);
00506         return GetFilePath(dir, xmlName, toWrite, silent);
00507     }
00508 
00509     String
00510     GetFilePathMpeg7Feature(int fileId, String xmlName, bool toWrite,
00511                             bool silent)
00512     {
00513         String dir = "MetaData/features/" + GetAsPath(fileId);
00514         if (toWrite)
00515             MakeDir(dir);
00516         return GetFilePath(dir, xmlName, toWrite, silent);
00517     }
00518 
00519     String
00520     GetFilePathMpeg7Concept(int fileId, String conceptSet, String xmlName,
00521                             bool toWrite, bool silent)
00522     {
00523         String dir = "MetaData/similarities/" + conceptSet + "/"
00524             + GetAsPath(fileId);
00525         if (toWrite)
00526             MakeDir(dir);
00527         return GetFilePath(dir, xmlName, toWrite, silent);
00528     }
00529 
00530     typedef Feature::FeatureDefinition FeatureDefinition;
00531 
00532     String
00533     GetFilePathPrototype(String protoDataFile, String featureName,
00534                          String fileName, bool toWrite, bool silent)
00535     {
00536         String dir = "Prototypes/" + protoDataFile + "/" + featureName;
00537         if (toWrite)
00538             MakeDir(dir);
00539         return GetFilePath(dir, fileName, toWrite, silent);
00540     }
00541 
00542     // for video sets
00543     String
00544     GetFilePathFeatureData(String walkType, FeatureDefinition def,
00545                            int fileOrDirId, bool partial, int startFrameOrFile,
00546                            bool toWrite, bool silent)
00547     {
00548         // for backward compatibility
00549         if (walkType == "Image")
00550             walkType = ".";
00551  
00552         String dir = PathJoin("FeatureData", walkType, def.GetName());
00553         if (mQuidClass == QUID_CLASS_IMAGE)
00554         {
00555             dir = PathJoin(dir, GetSection(fileOrDirId), GetDir(fileOrDirId));
00556         }
00557         else
00558         {
00559             dir = PathJoin(dir, GetAsPath(fileOrDirId));
00560         }
00561         if (partial)
00562             dir = PathJoin(dir, "part_" + MakeString(startFrameOrFile));
00563         if (toWrite)
00564             MakeDir(dir);
00565         return GetFilePath(dir, def.AsString() + ".tab", toWrite, silent);
00566     }
00567 
00568     // for image sets
00569     String
00570     GetFilePathFeatureData(FeatureDefinition def, int dirId, bool partial,
00571                            int startFile, bool toWrite, bool silent)
00572     {
00573         String dir = "FeatureData/" + def.GetName() + "/" + GetSection(dirId)
00574             + "/" + GetDir(dirId) + "/";
00575         if (partial)
00576             dir += "/part_" + MakeString(startFile);
00577         if (toWrite)
00578             MakeDir(dir);
00579         return GetFilePath(dir, def.AsString() + ".tab", toWrite, silent);
00580     }
00581 
00582     String
00583     GetFilePathFeatureIndex(FeatureDefinition def, String subSet, bool toWrite,
00584                             bool silent)
00585     {
00586         String dir = "FeatureIndex/" + def.GetName();
00587         if (toWrite)
00588             MakeDir(dir);
00589         return GetFilePath(dir, def.AsString() + subSet + ".tab", toWrite,
00590                            silent);
00591     }
00592 
00593     // for both?
00594     String
00595     GetFilePathPrecomputedKernels(String filename, String otherSet,
00596                                   bool toWrite, bool silent)
00597     {
00598         String dir = "PrecomputedKernels";
00599         if(otherSet != "")
00600             dir += "/" + otherSet;
00601         if (toWrite)
00602             MakeDir(dir);
00603         return GetFilePath(dir, filename, toWrite, silent);
00604     }
00605 
00606     // for both
00607     String
00608     GetFilePathRandomForest(FeatureDefinition def, bool toWrite, bool silent)
00609     {
00610         String dir = "Codebooks/Forest/";
00611         if (toWrite)
00612             MakeDir(dir);
00613         return GetFilePath(dir, def.AsString() + ".tab", toWrite, silent);
00614    }
00615     
00616     // for both
00617     String
00618     GetFilePathCodebook(FeatureDefinition def, bool toWrite, bool silent)
00619     {
00620         String dir = "Codebooks/";
00621         if (toWrite)
00622             MakeDir(dir);
00623         return GetFilePath(dir, def.AsString() + ".tab", toWrite, silent);
00624    }
00625     
00626     // when using walkType
00627     String
00628     GetFilePathSimilarityData(String walkType, String conceptSet, String model,
00629                               String featureString, int fileOrDirId,
00630                               String fileName, bool toWrite, bool silent)
00631     {
00632         // for backwards compatibility
00633         if(walkType == "Image") 
00634             walkType = ".";
00635         String dir = PathJoin("SimilarityData", walkType, conceptSet, model,
00636                               featureString);
00637         if(mQuidClass == QUID_CLASS_IMAGE)
00638         {
00639             dir = PathJoin(dir, GetSection(fileOrDirId), GetDir(fileOrDirId));
00640         }
00641         else
00642         {
00643             dir = PathJoin(dir, GetAsPath(fileOrDirId));
00644         }
00645         if (toWrite)
00646             MakeDir(dir);
00647         return GetFilePath(dir, fileName, toWrite, silent);
00648     }
00649 
00650     String
00651     GetFilePathSimilarityIndex(String conceptSet, String model,
00652                                String featureString, String fileName,
00653                                bool toWrite, bool silent)
00654     {
00655         String dir = "SimilarityIndex/" + conceptSet + "/" + model + "/"
00656             + featureString;
00657         if (toWrite)
00658             MakeDir(dir);        
00659         return GetFilePath(dir, fileName, toWrite, silent);
00660     }
00661 
00662     String
00663     GetFilePathAnnotation(String annoFile, bool toWrite, bool silent)
00664     {
00665         String dir = "Annotations";
00666         if (toWrite)
00667             MakeDir(dir);
00668         return GetFilePath(dir, annoFile, toWrite, silent);
00669     }
00670 
00671     String
00672     GetFilePathAnnotation(int quidClass, String conceptSet, String annoFile,
00673                           bool toWrite, bool silent)
00674     {
00675         String dir = "Annotations/" + QuidClassToString(quidClass) + "/"
00676             + conceptSet;
00677         if (toWrite)
00678             MakeDir(dir);
00679         return GetFilePath(dir, annoFile, toWrite, silent);
00680     }
00681 
00682     String
00683     GetFilePathGroundTruth(String truthFile, bool toWrite, bool silent)
00684     {
00685         String dir = "Annotations/groundtruth";
00686         if (toWrite)
00687             MakeDir(dir);
00688         return GetFilePath(dir, truthFile, toWrite, silent);
00689     }
00690 
00691     String
00692     GetFilePathConceptModel(String conceptSet, String modelType,
00693                             FeatureDefinition def, String modelFile,
00694                             bool toWrite, bool silent)
00695     {
00696         String dir = "ConceptModels/" + conceptSet + "/" + modelType + "/"
00697             + def.AsString();
00698         if (toWrite)
00699             MakeDir(dir);
00700         return GetFilePath(dir, modelFile, toWrite, silent);
00701     }
00702 
00703     String
00704     GetFilePathReference(int fileId, String suffix, bool toWrite, bool silent)
00705     {
00706         String dir = "Reference/" + GetAsPath(fileId);
00707         if (toWrite)
00708             MakeDir(dir);
00709         return GetFilePath(dir, GetFileBase(fileId) + suffix, toWrite, silent);
00710     }
00711 
00712     String
00713     GetFilePathKernelData(String walkType, String referenceSet,
00714                           String kernelName, int fileOrDirId,
00715                           bool toWrite, bool silent)
00716     {
00717         String dir = PathJoin("KernelData", walkType, referenceSet, kernelName);
00718         if(mQuidClass == QUID_CLASS_IMAGE)
00719         {
00720             dir = PathJoin(dir, GetSection(fileOrDirId), GetDir(fileOrDirId));
00721         }
00722         else
00723         {
00724             dir = PathJoin(dir, GetAsPath(fileOrDirId));
00725         }
00726         if (toWrite)
00727             MakeDir(dir);
00728         return GetFilePath(dir, kernelName + ".tab", toWrite, silent);
00729     }
00730 #endif // REPOSITORY_USED
00731 
00732 
00733     // "construction" and I/O part
00734 
00735     void
00736     AddFile(String file, String section, String dir, int id = -1)
00737     {
00738         int key = -1;
00739         for (int i=0 ; i<mDir.size() ; i++)
00740             if (mDir[i] == dir)
00741                 if (mSection[i] == section)
00742                     key = i;
00743 
00744         if ((key != -1) && (mLastKeyForWarning != key) &&
00745             (mLastKeyForWarning != -1))
00746         {
00747             // This will cause Walkers to break down
00748             //ILOG_ERROR("File = " << file << "; section = " << section << "; dir = " << dir);         
00749             ILOG_ERROR("Files are not sorted by directory.");
00750             ILOG_ERROR("If sorting is ok, please check whether there are duplicated video files.");
00751             return;
00752         }
00753 
00754         if (id == -1)
00755         {
00756             id = mLastId;
00757         }
00758         else
00759         {
00760             for (int i=0 ; i<mFirstFileId.size() ; i++)
00761                 if (mFirstFileId[i] == id)
00762                     ILOG_ERROR("Id already in use");
00763         }
00764         if (key == -1)
00765         {
00766             mSection.push_back(section);
00767             mDir.push_back(dir);
00768             mFirstFileId.push_back(id);
00769             mNrFiles.push_back(0);
00770             key = mDir.size() - 1;
00771         }
00772         mFileId.push_back(id);
00773         mFile.push_back(file);
00774         mLastKeyForWarning = key;
00775         mFileKey.push_back(key);
00776         mNrFiles[key] = mNrFiles[key] + 1;
00777         mLastId = id + 1;
00778         if (!file.empty())
00779             mHasFiles = true;
00780     }
00781 
00782     void
00783     AddFile(String path, int id)
00784     {
00785         String section(".");
00786         String dir(".");
00787         String file("");
00788         ExtractFileSectionDir(path, file, section, dir);
00789         AddFile(file, section, dir, id);
00790     }
00791 
00792 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00793     void
00794     Save()
00795     {
00796         Save(mSetName);
00797     }
00798 
00799     void
00800     Save(String fileName)
00801     {
00802         Util::IOBuffer* ioBuf = mDb->GetIOBuffer(fileName, false, false, "tmp");
00803         if (! ioBuf)
00804             return;
00805         for (int i=0 ; i<NrFiles() ; i++)
00806             ioBuf->IOBuffer::Puts("\"" + GetAsPath(i) + "\"");
00807         delete ioBuf;
00808     }
00809 
00810     void
00811     SaveBinary()
00812     {
00813         if (mSetFileName == String(""))
00814             return;
00815         String fName = mSetFileName + ".bin";
00816         ILOG_DEBUG("saving " << fName);
00817         //IOBUfferFile(fName, false, true);
00818     }
00819 #endif // REPOSITORY_USED
00820 
00821     void
00822     Dump(int startDir, int endDir, int startFile, int endFile)
00823     {
00824         if (endDir == -1)
00825             endDir = NrDirs();
00826         ILOG_INFO("Dumping dirs from " << startDir << " to " << endDir
00827                   << " (of " << NrDirs() << ")");
00828         for (int i=startDir ; i<endDir ; i++)
00829             ILOG_INFO(GetSection(i) << " " << GetDir(i) << ": nr files = "
00830                       << GetNrFiles(i));
00831         if (!mHasFiles)
00832         {
00833             ILOG_INFO("Does not have files");
00834             return;
00835         }
00836         if (startFile == -1)
00837         {
00838             ILOG_INFO("Skipping files");
00839             return;
00840         }
00841         if (endFile == -1)
00842             endFile = NrFiles();
00843         ILOG_INFO("Dumping files from " << startFile << " to " << endFile
00844                   << " (of " << NrFiles() << ")");
00845         for (int j=startFile ; j<endFile ; j++)
00846         {
00847             ILOG_INFO(GetFileId(j) << " " << GetSectionOfFile(j) << " " <<
00848                       GetDirOfFile(j) << " " << GetFile(j));
00849         }
00850     }
00851 
00852     virtual String
00853     QuidToString(Quid quid, bool elaborate)
00854     {
00855         QuidObj qObj(quid);
00856         return qObj.ToString();
00857     }
00858 
00859 
00861     void
00862     CopyIndex(const RawDataSet* src)
00863     {
00864         mFile = src->mFile;
00865         mFileKey = src->mFileKey;
00866         mSection = src->mSection;
00867         mDir = src->mDir;
00868         mFirstFileId = src->mFirstFileId;
00869         mNrFiles = src->mNrFiles;
00870         mHasFiles = src->mHasFiles;
00871         mLastId = src->mLastId;
00872         mLastKeyForWarning = src->mLastKeyForWarning;
00873     }
00874 
00875 protected:
00876 
00877     void
00878     Init(String setName)
00879     {
00880         mLastKeyForWarning = -1;
00881         mSetName = setName;
00882         mSetNameBase = FileNameBase(mSetName);
00883         mSetFileName = "";
00884         mHasFiles = false;
00885         mLastId = 0;
00886     }
00887 
00888 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00889     void
00890     Init(Util::Database* db, String setName, String setFileName)
00891     {
00892         mLastKeyForWarning = -1;
00893         mDb = db;
00894         mSetName = setName;
00895         mSetNameBase = FileNameBase(mSetName);
00896         mSetFileName = setFileName;
00897         mHasFiles = false;
00898         mLastId = 0;
00899         if (mSetFileName == String(""))
00900             return;
00901         mQuidClass = QUID_CLASS_UNKNOWN;
00902         ILOG_DEBUG("opening data file " << mSetFileName);
00903         Timer timer(1);
00904         Util::IOBuffer* f = mDb->GetIOBuffer(mSetFileName, true, true, "");
00905         if (f->Valid())
00906         {
00907             while (f->Available())
00908             {
00909                 String line = f->ReadLine();
00910                 if (line[0] && (line[0] != '#'))
00911                 {
00912                     int id = -1;
00913                     String section(".");
00914                     String dir(".");
00915                     String file("");
00916                     Util::StringParser p(line);
00917                     while (!p.TheEnd())
00918                     {
00919                         if (p.At("<id="))
00920                         {
00921                             p.Eat('=');
00922                             id = p.GetInt('>', true);
00923                             p.Eat('>');
00924                         }
00925                         else
00926                         {
00927                             String s = p.GetString2(false);
00928                             s = StringReplaceAll(s, "\\", "/");
00929                             ExtractFileSectionDir(s, file, section, dir);
00930                         }
00931                     }
00932                     AddFile(file, section, dir, id);
00933                 }
00934             }
00935         }
00936         delete f;
00937         ILOG_DEBUG("done read file in " << timer.SplitTime());
00938     }
00939 #endif // REPOSITORY_USED
00940 
00941     void
00942     ExtractFileSectionDir(const String& src, String& file,
00943                           String& section, String& dir)
00944     {
00945         StringList sl(src, '/', true);
00946 
00947         if (Link::DiskImage::DiskImageUsed())
00948         {
00949             const String::size_type firstTokenPos = src.find("//#");
00950             const bool parseDiskImageStyle = (firstTokenPos != String::npos);
00951             if (parseDiskImageStyle)
00952             {
00953                 StringList::iterator it = sl.begin();
00954                 section = "";
00955                 // define all until first token as 'section'
00956                 while (!it->empty())
00957                 {
00958                     if (it != sl.begin())
00959                         section += "/";
00960                     section += *it++;
00961                 }
00962                 it++; // skip slash that separates section and path
00963 
00964                 // 'dir' will now start with a token
00965                 dir = "";
00966                 while (it != sl.end())
00967                 {
00968                     String& next = *it;
00969                     it++;
00970                     if (it == sl.end())
00971                         file = next;
00972                     else
00973                         dir += "/" + next;
00974                 }
00975                 return;
00976             }
00977         }
00978 
00979         StringList::reverse_iterator it = sl.rbegin();
00980         file = *it++;
00981         if (it != sl.rend())
00982             dir = *it++;
00983         if (it != sl.rend())
00984             section = *it++;
00985         while (it != sl.rend())
00986         {
00987             String subDir = *it++;
00988             if (subDir != ".")
00989                 section = subDir + "/" + section;
00990         }
00991     }
00992 
00993 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00994     Util::Database*     mDb;
00995 #endif // REPOSITORY_USED
00996     String              mSetName;
00997     String              mSetNameBase;
00998     String              mSetFileName;
00999     bool                mHasFiles;
01000     int                 mLastId;
01001     int                 mLastKeyForWarning;
01002     std::vector<int>    mFileId;
01003     std::vector<String> mFile;
01004     std::vector<int>    mFileKey;
01005 
01006     std::vector<String> mSection;
01007     std::vector<String> mDir;
01008     std::vector<int>    mFirstFileId;
01009     std::vector<int>    mNrFiles;
01010     
01011     int                 mQuidClass;
01012 
01013     ILOG_VAR_DEC;
01014 };
01015 
01016 ILOG_VAR_INIT(RawDataSet, Impala.Core.Database);
01017 
01018 } // namespace Database
01019 } // namespace Core
01020 } // namespace Impala
01021 
01022 #endif

Generated on Fri Mar 19 09:31:05 2010 for ImpalaSrc by  doxygen 1.5.1