NetworkManager.C 222 KB
Newer Older
hrchilds's avatar
hrchilds committed
1 2
/*****************************************************************************
*
brugger's avatar
 
brugger committed
3
* Copyright (c) 2000 - 2011, Lawrence Livermore National Security, LLC
hrchilds's avatar
hrchilds committed
4
* Produced at the Lawrence Livermore National Laboratory
brugger's avatar
 
brugger committed
5
* LLNL-CODE-442911
hrchilds's avatar
hrchilds committed
6 7
* All rights reserved.
*
brugger's avatar
 
brugger committed
8
* This file is  part of VisIt. For  details, see https://visit.llnl.gov/.  The
hrchilds's avatar
hrchilds committed
9 10 11 12 13 14 15 16 17 18
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution  and  use  in  source  and  binary  forms,  with  or  without
* modification, are permitted provided that the following conditions are met:
*
*  - Redistributions of  source code must  retain the above  copyright notice,
*    this list of conditions and the disclaimer below.
*  - Redistributions in binary form must reproduce the above copyright notice,
*    this  list of  conditions  and  the  disclaimer (as noted below)  in  the
brugger's avatar
 
brugger committed
19 20 21
*    documentation and/or other materials provided with the distribution.
*  - Neither the name of  the LLNS/LLNL nor the names of  its contributors may
*    be used to endorse or promote products derived from this software without
hrchilds's avatar
hrchilds committed
22 23 24 25 26
*    specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR  IMPLIED WARRANTIES, INCLUDING,  BUT NOT  LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE
brugger's avatar
 
brugger committed
27 28 29
* ARE  DISCLAIMED. IN  NO EVENT  SHALL LAWRENCE  LIVERMORE NATIONAL  SECURITY,
* LLC, THE  U.S.  DEPARTMENT OF  ENERGY  OR  CONTRIBUTORS BE  LIABLE  FOR  ANY
* DIRECT,  INDIRECT,   INCIDENTAL,   SPECIAL,   EXEMPLARY,  OR   CONSEQUENTIAL
hrchilds's avatar
hrchilds committed
30 31 32 33 34 35 36 37 38
* DAMAGES (INCLUDING, BUT NOT  LIMITED TO, PROCUREMENT OF  SUBSTITUTE GOODS OR
* SERVICES; LOSS OF  USE, DATA, OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER
* CAUSED  AND  ON  ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT
* LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY  WAY
* OUT OF THE  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/

hrchilds's avatar
hrchilds committed
39 40 41 42
// ************************************************************************* //
//                              NetworkManager.C                             //
// ************************************************************************* //

hrchilds's avatar
hrchilds committed
43
#include <snprintf.h>
hrchilds's avatar
hrchilds committed
44
#include <AttributeSubject.h>
hrchilds's avatar
hrchilds committed
45 46
#include <NetworkManager.h>
#include <DataNetwork.h>
hrchilds's avatar
hrchilds committed
47
#include <ClonedDataNetwork.h>
48
#include <CumulativeQueryNamedSelectionExtension.h>
hrchilds's avatar
hrchilds committed
49 50 51
#include <DebugStream.h>
#include <avtDatabaseFactory.h>
#include <LoadBalancer.h>
52
#include <ConstructDataBinningAttributes.h>
hrchilds's avatar
hrchilds committed
53 54
#include <DBOptionsAttributes.h>
#include <ExportDBAttributes.h>
hrchilds's avatar
hrchilds committed
55
#include <MaterialAttributes.h>
hrchilds's avatar
hrchilds committed
56
#include <MeshManagementAttributes.h>
hrchilds's avatar
hrchilds committed
57
#include <avtExpressionEvaluatorFilter.h>
58 59
#include <avtNamedSelectionFilter.h>
#include <avtNamedSelectionManager.h>
hrchilds's avatar
hrchilds committed
60
#include <ImproperUseException.h>
hrchilds's avatar
hrchilds committed
61
#include <InvalidVariableException.h>
hrchilds's avatar
hrchilds committed
62 63 64 65 66
#include <DatabaseException.h>
#include <NoInputException.h>
#include <avtPluginFilter.h>
#include <OperatorPluginManager.h>
#include <OperatorPluginInfo.h>
67
#include <AnnotationObject.h>
hrchilds's avatar
hrchilds committed
68
#include <AnnotationObjectList.h>
fogal1's avatar
fogal1 committed
69
#include <AnnotationAttributes.h>
hrchilds's avatar
hrchilds committed
70
#include <PickAttributes.h>
71
#include <SelectionProperties.h>
hrchilds's avatar
hrchilds committed
72 73
#include <VisualCueInfo.h>
#include <VisualCueList.h>
74
#include <avtApplyDataBinningExpression.h>
hrchilds's avatar
hrchilds committed
75
#include <avtCallback.h>
hrchilds's avatar
hrchilds committed
76
#include <avtColorTables.h>
77
#include <avtDebugDumpOptions.h>
hrchilds's avatar
hrchilds committed
78
#include <avtExtents.h>
hrchilds's avatar
hrchilds committed
79
#include <avtNullData.h>
80
#include <avtDatabaseMetaData.h>
hrchilds's avatar
hrchilds committed
81
#include <avtDataObjectQuery.h>
hrchilds's avatar
hrchilds committed
82
#include <avtMultipleInputQuery.h>
hrchilds's avatar
hrchilds committed
83
#include <avtAreaBetweenCurvesQuery.h>
hrchilds's avatar
hrchilds committed
84
#include <avtFileWriter.h>
hrchilds's avatar
hrchilds committed
85
#include <avtDatabaseWriter.h>
hrchilds's avatar
hrchilds committed
86
#include <avtL2NormBetweenCurvesQuery.h>
hrchilds's avatar
hrchilds committed
87
#include <avtLocateQuery.h>
hrchilds's avatar
hrchilds committed
88
#include <avtLocateCellQuery.h>
hrchilds's avatar
hrchilds committed
89 90 91 92
#include <avtLocateNodeQuery.h>
#include <avtActualCoordsQuery.h>
#include <avtActualNodeCoordsQuery.h>
#include <avtActualZoneCoordsQuery.h>
hrchilds's avatar
hrchilds committed
93
#include <avtPickQuery.h>
94
#include <avtNamedSelection.h>
hrchilds's avatar
hrchilds committed
95
#include <avtNodePickQuery.h>
hrchilds's avatar
hrchilds committed
96
#include <avtParallel.h>
hrchilds's avatar
hrchilds committed
97 98
#include <avtPickByNodeQuery.h>
#include <avtPickByZoneQuery.h>
99
#include <avtTransparencyActor.h>
hrchilds's avatar
hrchilds committed
100
#include <avtZonePickQuery.h>
hrchilds's avatar
hrchilds committed
101
#include <avtCurvePickQuery.h>
hrchilds's avatar
hrchilds committed
102
#include <avtSoftwareShader.h>
103 104
#include <avtDataBinning.h>
#include <avtDataBinningConstructor.h>
hrchilds's avatar
hrchilds committed
105 106 107
#include <avtSourceFromAVTImage.h>
#include <avtSourceFromImage.h>
#include <avtSourceFromNullData.h>
hrchilds's avatar
hrchilds committed
108
#include <avtTiledImageCompositor.h>
hrchilds's avatar
hrchilds committed
109 110
#include <avtWholeImageCompositerWithZ.h>
#include <avtWholeImageCompositerNoZ.h>
hrchilds's avatar
hrchilds committed
111
#include <avtPlot.h>
hrchilds's avatar
hrchilds committed
112 113
#include <avtQueryOverTimeFilter.h>
#include <avtQueryFactory.h>
hrchilds's avatar
hrchilds committed
114
#include <CompactSILRestrictionAttributes.h>
hrchilds's avatar
hrchilds committed
115
#include <VisWindow.h>
hrchilds's avatar
hrchilds committed
116
#include <VisWinRendering.h> // for SetStereoEnabled
hrchilds's avatar
hrchilds committed
117
#include <ParsingExprList.h>
hrchilds's avatar
hrchilds committed
118
#include <avtExprNode.h>
hrchilds's avatar
hrchilds committed
119 120
#include <DatabasePluginManager.h>
#include <DatabasePluginInfo.h>
hrchilds's avatar
hrchilds committed
121 122
#include <PlotPluginManager.h>
#include <PlotPluginInfo.h>
fogal1's avatar
fogal1 committed
123
#include <StackTimer.h>
124 125 126

#include <vtkImageData.h>

hrchilds's avatar
hrchilds committed
127 128 129
#ifdef PARALLEL
#include <mpi.h>
#endif
hrchilds's avatar
hrchilds committed
130
#include <visit-config.h>
hrchilds's avatar
hrchilds committed
131
#include <TimingsManager.h>
132
#include <SaveWindowAttributes.h>
hrchilds's avatar
hrchilds committed
133

bonnell's avatar
bonnell committed
134
#include <algorithm>
135
#include <climits>
136 137 138
#include <map>
#include <string>
#include <vector>
hrchilds's avatar
hrchilds committed
139

hrchilds's avatar
hrchilds committed
140 141 142
//
// Static functions.
//
hrchilds's avatar
hrchilds committed
143 144
static ref_ptr<avtDatabase> GetDatabase(void *, const std::string &,
                                        int, const char *);
145
static avtDataBinning *GetDataBinningCallbackBridge(void *arg, const char *name);
bonnell's avatar
bonnell committed
146
static bool OnlyRootNodeHasData(avtImage_p &);
147
static void BroadcastImage(avtImage_p &, bool, int);
148
#ifdef PARALLEL
149
static bool IsBlankImage(avtImage_p img);
150 151
static std::vector<int> BuildBlankImageVector(avtImage_p img);
#endif
hrchilds's avatar
hrchilds committed
152

hrchilds's avatar
hrchilds committed
153 154 155 156 157 158 159 160 161 162
//
// Static data members of the NetworkManager class.
//
InitializeProgressCallback NetworkManager::initializeProgressCallback = NULL;
void                      *NetworkManager::initializeProgressCallbackArgs=NULL;
ProgressCallback           NetworkManager::progressCallback = NULL;
void                      *NetworkManager::progressCallbackArgs = NULL;



hrchilds's avatar
hrchilds committed
163 164 165 166 167 168 169 170 171
// ****************************************************************************
//  Method: NetworkManager default constructor
//
//  Programmer: Jeremy Meredith
//  Creation:   September 29, 2000
//
//  Modifications:
//
//    Kathleen Bonnell, Tue Nov 20 12:35:54 PST 2001
172
//    Initialize requireOriginalCells.
hrchilds's avatar
hrchilds committed
173
//
hrchilds's avatar
hrchilds committed
174 175 176
//    Hank Childs, Mon Jan  5 16:04:57 PST 2004
//    Initialize uniqueNetworkId.
//
hrchilds's avatar
hrchilds committed
177 178 179
//    Hank Childs, Thu Mar  4 09:11:46 PST 2004
//    Change instantiation of vis window, since it is now assumed to be nowin.
//
hrchilds's avatar
hrchilds committed
180 181 182
//    Mark C. Miller, Thu Apr 29 16:15:25 PDT 2004
//    Added missing initialization of dumpRenders
//
hrchilds's avatar
hrchilds committed
183 184 185
//    Mark C. Miller, Tue May 25 20:44:10 PDT 2004
//    Removed unnecessary scope. Set annotationAttributes data member
//
186 187
//    Kathleen Bonnell, Wed Jun  2 09:48:29 PDT 2004
//    Initialize requireOriginalNodes.
hrchilds's avatar
hrchilds committed
188
//
hrchilds's avatar
hrchilds committed
189 190 191 192
//    Mark C. Miller, Tue Jan  4 10:23:19 PST 2005
//    Made the viswin part of a map of EngineVisWinInfo objects
//    Removed some unnecessary initialization
//
hrchilds's avatar
hrchilds committed
193 194 195
//    Mark C. Miller, Wed Jan  5 10:14:21 PST 2005
//    Added call to NewVisWindow
//
hrchilds's avatar
hrchilds committed
196 197 198
//    Hank Childs, Mon Feb 28 16:56:20 PST 2005
//    Initialize inQueryMode.
//
hrchilds's avatar
hrchilds committed
199 200 201
//    Hank Childs, Fri Aug 26 15:44:48 PDT 2005
//    Register a callback to get databases.
//
hrchilds's avatar
hrchilds committed
202 203 204
//    Hank Childs, Sat Feb 18 11:31:23 PST 2006
//    Added a call back for the apply ddf expression.
//
205 206 207
//    Cyrus Harrison, Tue Feb 19 08:42:51 PST 2008
//    Removed dumpRenders (now controled by avtDebugDumpOptions)
//
208 209 210
//    Brad Whitlock, Tue Jun 24 15:40:29 PDT 2008
//    Added plugin managers.
//
fogal1's avatar
fogal1 committed
211 212 213
//    Tom Fogal, Wed Dec  9 14:10:01 MST 2009
//    Remove creation of window 0; we'll do it dynamically when needed.
//
214 215 216
//    Hank Childs, Sat Aug 21 14:35:47 PDT 2010
//    Rename DDF to DataBinning.
//
hrchilds's avatar
hrchilds committed
217 218 219 220 221 222
// ****************************************************************************
NetworkManager::NetworkManager(void) : virtualDatabases()
{
    workingNet = NULL;
    loadBalancer = NULL;
    requireOriginalCells = false;
hrchilds's avatar
hrchilds committed
223
    requireOriginalNodes = false;
hrchilds's avatar
hrchilds committed
224
    inQueryMode = false;
hrchilds's avatar
hrchilds committed
225
    uniqueNetworkId = 0;
hrchilds's avatar
hrchilds committed
226

hrchilds's avatar
hrchilds committed
227
    avtCallback::RegisterGetDatabaseCallback(GetDatabase, this);
228 229 230
    avtApplyDataBinningExpression::RegisterGetDataBinningCallback(GetDataBinningCallbackBridge, this);
    avtExpressionEvaluatorFilter::RegisterGetDataBinningCallback(
                                                  GetDataBinningCallbackBridge, this);
231 232 233 234

    databasePlugins = new DatabasePluginManager;
    operatorPlugins = new OperatorPluginManager;
    plotPlugins = new PlotPluginManager;
hrchilds's avatar
hrchilds committed
235 236 237 238 239 240 241 242 243
}

// ****************************************************************************
//  Method: NetworkManager destructor
//
//  Programmer: Jeremy Meredith
//  Creation:   September 29, 2000
//
//  Modifications:
hrchilds's avatar
hrchilds committed
244 245 246 247 248 249
//    Sean Ahern, Fri May 24 11:12:25 PDT 2002
//    Got rid of deletion of the database cache, since all DBs in there
//    will be deleted by deleting the network cache.
//
//    Hank Childs, Mon Jan  5 16:30:04 PST 2004
//    Don't assume the caches are valid.
hrchilds's avatar
hrchilds committed
250
//
hrchilds's avatar
hrchilds committed
251 252 253
//    Mark C. Miller, Tue Jan  4 10:23:19 PST 2005
//    Added code to delete VisWindow objects
//
hrchilds's avatar
hrchilds committed
254 255 256
//    Hank Childs, Mon Feb 13 23:14:23 PST 2006
//    Delete the DDFs.
//
257 258 259
//    Brad Whitlock, Tue Jun 24 15:41:08 PDT 2008
//    Added plugin managers.
//
260 261 262
//    Hank Childs, Sat Aug 21 14:35:47 PDT 2010
//    Rename DDF to DataBinning.
//
263 264 265 266
//    David Camp, Thu Jan 13 11:15:00 PST 2011
//    Added the call to DeleteInstance of the avtColorTables. 
//    Help debug memory leaks.
//
hrchilds's avatar
hrchilds committed
267
// ****************************************************************************
268

hrchilds's avatar
hrchilds committed
269 270
NetworkManager::~NetworkManager(void)
{
271
    for (size_t i = 0; i < networkCache.size(); i++)
hrchilds's avatar
hrchilds committed
272 273
        if (networkCache[i] != NULL)
            delete networkCache[i];
hrchilds's avatar
hrchilds committed
274 275 276 277

    std::map<int, EngineVisWinInfo>::iterator it;
    for (it = viswinMap.begin(); it != viswinMap.end(); it++)
        delete it->second.viswin;
hrchilds's avatar
hrchilds committed
278

279 280
    for (size_t d = 0 ; d < dataBinnings.size() ; d++)
        delete dataBinnings[d];
281 282 283 284

    delete databasePlugins;
    delete operatorPlugins;
    delete plotPlugins;
285 286

    avtColorTables::Instance()->DeleteInstance();
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
}

// ****************************************************************************
// Method: NetworkManager::GetDatabasePluginManager
//
// Purpose: 
//   Return the database plugin manager.
//
// Returns:    the database plugin manager.
//
// Programmer: Brad Whitlock
// Creation:   Tue Jun 24 15:25:41 PDT 2008
//
// Modifications:
//   
// ****************************************************************************

DatabasePluginManager *
NetworkManager::GetDatabasePluginManager() const
{
    return databasePlugins;
}

// ****************************************************************************
// Method: NetworkManager::GetOperatorPluginManager
//
// Purpose: 
//   Return the operator plugin manager.
//
// Returns:    the operator plugin manager.
//
// Programmer: Brad Whitlock
// Creation:   Tue Jun 24 15:26:07 PDT 2008
//
// Modifications:
//   
// ****************************************************************************

OperatorPluginManager *
NetworkManager::GetOperatorPluginManager() const
{
    return operatorPlugins;
}

// ****************************************************************************
// Method: NetworkManager::GetPlotPluginManager
//
// Purpose: 
//   Return the plot plugin manager.
//
// Returns:    the plot plugin manager.
//
// Programmer: Brad Whitlock
// Creation:   Tue Jun 24 15:26:28 PDT 2008
//
// Modifications:
//   
// ****************************************************************************

PlotPluginManager *
NetworkManager::GetPlotPluginManager() const
{
    return plotPlugins;
hrchilds's avatar
hrchilds committed
350 351 352 353 354 355 356 357 358 359 360 361
}

// ****************************************************************************
//  Method: NetworkManager::ClearAllNetworks
//
//  Purpose:
//      Clears out the caches.  Really only used for checking for memory leaks.
//
//  Programmer: Hank Childs
//  Creation:   January 7, 2001
//
//  Modifications:
hrchilds's avatar
hrchilds committed
362 363 364 365 366
//    Sean Ahern, Tue May 14 14:35:42 PDT 2002
//    Retrofitted for my new network management techniques.
//
//    Sean Ahern, Tue May 21 16:09:56 PDT 2002
//    Told the underlying objects to free their data.
hrchilds's avatar
hrchilds committed
367
//
hrchilds's avatar
hrchilds committed
368 369 370
//    Hank Childs, Mon Jan  5 16:30:04 PST 2004
//    Don't clear out the vectors, so this can be consistent with how the
//    ClearNetworksWithDatabase works.
hrchilds's avatar
hrchilds committed
371
//
hrchilds's avatar
hrchilds committed
372 373 374
//    Brad Whitlock, Thu Feb 26 11:58:58 PDT 2004
//    I replaced the commented out cerr with debug3.
//
hrchilds's avatar
hrchilds committed
375 376 377 378 379
//    Hank Childs, Sun Mar  7 16:05:03 PST 2004
//    Delete the networks before the databases, since the networks have
//    references to the databases (and the previous ordering yielded dangling
//    pointers).
//
hrchilds's avatar
hrchilds committed
380 381 382 383
//    Mark C. Miller, Wed Sep  8 17:06:25 PDT 2004
//    Added code to clear the vis window and the list of plots currently in
//    the window.
//
hrchilds's avatar
hrchilds committed
384 385 386 387
//    Mark C. Miller, Mon Sep 13 18:30:26 PDT 2004
//    Protected call to clear viswin and plotsCurrentlyInWindow with test
//    for emptiness
//
hrchilds's avatar
hrchilds committed
388 389 390
//    Mark C. Miller, Tue Jan  4 10:23:19 PST 2005
//    Added code to delete VisWindow objects
//
hrchilds's avatar
hrchilds committed
391 392 393
//    Hank Childs, Thu Mar  2 10:06:33 PST 2006
//    Added support for image based plots.
//
hrchilds's avatar
hrchilds committed
394 395 396 397
// ****************************************************************************
void
NetworkManager::ClearAllNetworks(void)
{
hrchilds's avatar
hrchilds committed
398
    debug3 << "NetworkManager::ClearAllNetworks(void)" << endl;
hrchilds's avatar
hrchilds committed
399

400
    for (size_t i = 0; i < networkCache.size(); i++)
hrchilds's avatar
hrchilds committed
401 402 403 404 405 406
    {
        if (networkCache[i] != NULL)
            delete networkCache[i];
        networkCache[i] = NULL;
    }

407
    for (size_t i = 0; i < databaseCache.size(); i++)
hrchilds's avatar
hrchilds committed
408 409 410 411 412 413
    {
        if (databaseCache[i] != NULL)
            delete databaseCache[i];
        databaseCache[i] = NULL;
    }

414
    for (size_t i = 0 ; i < globalCellCounts.size() ; i++)
hrchilds's avatar
hrchilds committed
415
    {
hrchilds's avatar
hrchilds committed
416
        globalCellCounts[i] = -1;
hrchilds's avatar
hrchilds committed
417
    }
hrchilds's avatar
hrchilds committed
418 419 420 421 422 423

    std::map<int, EngineVisWinInfo>::iterator it;
    for (it = viswinMap.begin(); it != viswinMap.end(); it++)
    {
        it->second.viswin->ClearPlots();
        it->second.plotsCurrentlyInWindow.clear();
hrchilds's avatar
hrchilds committed
424
        it->second.imageBasedPlots.clear();
hrchilds's avatar
hrchilds committed
425 426 427 428
        delete it->second.viswin;
    }
    viswinMap.clear();
    NewVisWindow(0);
hrchilds's avatar
hrchilds committed
429 430 431 432 433 434 435 436 437 438 439 440 441 442
}

// ****************************************************************************
//  Method: NetworkManager::ClearNetworksWithDatabase
//
//  Purpose:
//      Clears out the caches that reference a specific database.
//
//  Arguments:
//      db      The name of a database.
//
//  Programmer: Hank Childs
//  Creation:   January 5, 2004
//
hrchilds's avatar
hrchilds committed
443 444 445 446
//  Modifications:
//    Brad Whitlock, Thu Feb 26 11:58:58 PDT 2004
//    I replaced the commented out cerr with debug3.
//
hrchilds's avatar
hrchilds committed
447 448 449
//    Mark C. Miller, Wed Sep  8 17:06:25 PDT 2004
//    Added code to clear the vis window and the list of plots currently in
//    the window for the first plot id it encounters in this db
hrchilds's avatar
hrchilds committed
450 451 452 453
//
//    Mark C. Miller, Mon Sep 13 18:30:26 PDT 2004
//    Moved code to delete the networkCache entry to after the clearning
//    of the viswin.
hrchilds's avatar
hrchilds committed
454 455 456
//
//    Mark C. Miller, Tue Jan  4 10:23:19 PST 2005
//    Modified for viswinMap object
457
//
hrchilds's avatar
hrchilds committed
458 459 460 461
// ****************************************************************************
void
NetworkManager::ClearNetworksWithDatabase(const std::string &db)
{
hrchilds's avatar
hrchilds committed
462
    debug3 << "NetworkManager::ClearNetworksWithDatabase()" << endl;
hrchilds's avatar
hrchilds committed
463

464
    //
hrchilds's avatar
hrchilds committed
465 466 467
    // Clear out the networks before the databases.  This is because if we
    // delete the databases first, the networks will have dangling pointers.
    //
468
    for (size_t i = 0; i < networkCache.size(); i++)
hrchilds's avatar
hrchilds committed
469 470 471 472 473 474 475 476
    {
        if (networkCache[i] != NULL)
        {
            NetnodeDB *ndb = networkCache[i]->GetNetDB();
            if (ndb != NULL)
            {
                if (ndb->GetFilename() == db)
                {
hrchilds's avatar
hrchilds committed
477
                    DoneWithNetwork(i);
hrchilds's avatar
hrchilds committed
478 479 480 481
                }
            }
        }
    }
hrchilds's avatar
hrchilds committed
482

483
    // Remove the database from the cache and delete it.
484
    for (size_t i = 0; i < databaseCache.size(); i++)
hrchilds's avatar
hrchilds committed
485 486 487 488 489 490 491 492 493 494
    {
        if (databaseCache[i] != NULL)
        {
            if (databaseCache[i]->GetFilename() == db)
            {
                delete databaseCache[i];
                databaseCache[i] = NULL;
            }
        }
    }
hrchilds's avatar
hrchilds committed
495 496 497
}

// ****************************************************************************
hrchilds's avatar
hrchilds committed
498
//  Method: NetworkManager::GetDBFromCache
hrchilds's avatar
hrchilds committed
499 500
//
//  Purpose:
hrchilds's avatar
hrchilds committed
501 502 503 504 505 506 507 508 509 510 511 512 513
//      Get a DB from the cache.  If it's not there already, create it and
//      return it.
//
//  Programmer: Sean Ahern
//  Creation:   Mon Dec 23 12:28:30 PST 2002
//
//  Modifications:
//
//    Brad Whitlock, Wed May 14 12:56:16 PDT 2003
//    I made it get the metadata and the SIL if the time is greater than 0.
//    This ensures that we pick up the metadata and SIL for the time state
//    that we're intersted in.
//
hrchilds's avatar
hrchilds committed
514 515 516 517
//    Brad Whitlock, Mon Aug 25 16:51:35 PST 2003
//    Changed the return statement to CATCH_RETURN2 so bad things don't happen
//    when we use fake exceptions.
//
hrchilds's avatar
hrchilds committed
518 519 520
//    Mark C. Miller Thu Oct  9 10:59:27 PDT 2003
//    I modified to force GetMetaData and GetSIL if they're invariant 
//
hrchilds's avatar
hrchilds committed
521 522 523
//    Hank Childs, Tue Nov  4 14:19:05 PST 2003
//    Checked in work-around (HACK) to avoid apparent compiler bug on AIX.
//
hrchilds's avatar
hrchilds committed
524 525 526
//    Hank Childs, Mon Jan  5 16:49:28 PST 2004
//    Do not assume that all of the cached databases are non-NULL.
//
hrchilds's avatar
hrchilds committed
527 528 529
//    Hank Childs, Mon Mar  1 08:48:26 PST 2004
//    Send the time to the database factory as well.
//
hrchilds's avatar
hrchilds committed
530 531 532
//    Hank Childs, Mon Mar 22 11:10:43 PST 2004
//    Allow for the DB type to be explicitly specified.
//
hrchilds's avatar
hrchilds committed
533 534 535 536 537
//    Mark C. Miller, Tue Sep 28 19:57:42 PDT 2004
//    Added code to pass avtDatabaseMetaData to LoadBalancer->AddDatabase
//
//    Hank Childs, Sun Feb 27 12:30:17 PST 2005
//    Added avtDatabase argument to AddDatabase.
hrchilds's avatar
hrchilds committed
538
//
hrchilds's avatar
hrchilds committed
539 540 541
//    Hank Childs, Tue Sep 20 13:03:00 PDT 2005
//    Don't assume that filename lengths are bigger than 6 characters ['6616].
//
hrchilds's avatar
hrchilds committed
542 543 544 545 546 547 548
//    Hank Childs, Fri Oct  7 17:22:01 PDT 2005
//    Tell database what it's full name is.  Also, remove some antiquated code
//    that the variable name in the DB info to the empty string.  I believe
//    the code was no longer doing anything useful, besides torpedoing SR
//    and CMFE when used in combination.  The test suite passes without it
//    and there is really no explanation for why we were doing it.
//
hrchilds's avatar
hrchilds committed
549 550
//    Mark C. Miller, Wed Nov 16 10:46:36 PST 2005
//    Changed interface to lb->AddDatabase 
hrchilds's avatar
hrchilds committed
551 552 553 554
//
//    Hank Childs, Thu Jan 11 16:10:12 PST 2007
//    Added argument to DatabaseFactory calls.
//
555 556
//    Mark C. Miller, Thu Jun 14 10:26:37 PDT 2007
//    Added support to treat all databases as time varying
557 558 559
//
//    Mark C. Miller, Wed Aug 22 20:16:59 PDT 2007
//    Added treatAllDBsAsTimeVarying to GetSIL call
560 561 562 563
//
//    Hank Childs, Fri Feb  1 15:45:28 PST 2008
//    Added argument for loading database plugins.
//
564 565
//    Mark C. Miller, Tue Jun 10 22:36:25 PDT 2008
//    Added support for ignoring bad extents from dbs.
566 567 568 569
//
//    Brad Whitlock, Tue Jun 24 15:45:43 PDT 2008
//    Pass the database plugin manager to the factory.
//
hrchilds's avatar
hrchilds committed
570
// ****************************************************************************
hrchilds's avatar
hrchilds committed
571

hrchilds's avatar
hrchilds committed
572
NetnodeDB *
573
NetworkManager::GetDBFromCache(const std::string &filename, int time,
574
    const char *format, bool treatAllDBsAsTimeVarying, 
575
    bool fileMayHaveUnloadedPlugin, bool ignoreExtents)
hrchilds's avatar
hrchilds committed
576 577 578 579
{
    // If we don't have a load balancer, we're dead.
    if (loadBalancer == NULL)
    {
hrchilds's avatar
hrchilds committed
580 581
        debug1 << "Internal error: A load balancer was never registered." 
               << endl;
hrchilds's avatar
hrchilds committed
582 583 584
        EXCEPTION0(ImproperUseException);
    }

hrchilds's avatar
hrchilds committed
585 586
    // Find a matching database 
    NetnodeDB* cachedDB = NULL;
587
    for (size_t i = 0; i < databaseCache.size(); i++)
hrchilds's avatar
hrchilds committed
588
    {
hrchilds's avatar
hrchilds committed
589 590
        if (databaseCache[i] == NULL)
            continue;
hrchilds's avatar
hrchilds committed
591
        if (databaseCache[i]->GetFilename() == filename)
hrchilds's avatar
hrchilds committed
592
        {
hrchilds's avatar
hrchilds committed
593 594
            cachedDB = databaseCache[i];
            break;
hrchilds's avatar
hrchilds committed
595
        }
hrchilds's avatar
hrchilds committed
596 597
    }

598 599 600 601
    // use of these makes calls to GetMetaData a little clearer
    const bool forceReadAllCyclesAndTimes = false;
    const bool forceReadThisCycleAndTime  = false;

hrchilds's avatar
hrchilds committed
602 603 604 605 606
    // got a match
    if (cachedDB != NULL)
    {
        // even if we found the DB in the cache,
        // we need to update the metadata if its time-varying
607
        if (treatAllDBsAsTimeVarying ||
608
            !cachedDB->GetDB()->MetaDataIsInvariant() ||
hrchilds's avatar
hrchilds committed
609
            !cachedDB->GetDB()->SILIsInvariant())
hrchilds's avatar
hrchilds committed
610
        {
611
            cachedDB->GetDB()->GetMetaData(time,
612 613 614
                                           forceReadAllCyclesAndTimes,
                                           forceReadThisCycleAndTime,
                                           treatAllDBsAsTimeVarying);
615
            cachedDB->GetDB()->GetSIL(time, treatAllDBsAsTimeVarying);
hrchilds's avatar
hrchilds committed
616
        }
hrchilds's avatar
hrchilds committed
617 618

        return cachedDB;
hrchilds's avatar
hrchilds committed
619 620 621 622 623 624
    }

    // No match.  Load a new DB.
    debug3 << "Loading new database" << endl;
    TRY
    {
625
        if (fileMayHaveUnloadedPlugin)
626 627
             GetDatabasePluginManager()->LoadPluginsNow();

hrchilds's avatar
hrchilds committed
628 629 630
        avtDatabase *db = NULL;
        NetnodeDB *netDB = NULL;
        const char *filename_c = filename.c_str();
hrchilds's avatar
hrchilds committed
631
        std::vector<std::string> plugins;  // unused
hrchilds's avatar
hrchilds committed
632 633
        if (filename.length() >= 6 &&
            filename.substr(filename.length() - 6) == ".visit")
634 635 636 637 638 639 640 641
        {
            db = avtDatabaseFactory::VisitFile(
                GetDatabasePluginManager(),
                filename_c,
                time,
                plugins,
                format);
        }
hrchilds's avatar
hrchilds committed
642
        else
643 644 645 646 647 648 649 650 651 652
        {
            db = avtDatabaseFactory::FileList(
                GetDatabasePluginManager(),
                &filename_c,
                1,
                time,
                plugins, 
                format);
        }

hrchilds's avatar
hrchilds committed
653
        db->SetFullDBName(filename);
654
        db->SetIgnoreExtents(ignoreExtents);
hrchilds's avatar
hrchilds committed
655 656

        // If we want to open the file at a later timestep, get the
hrchilds's avatar
hrchilds committed
657 658
        // SIL so that it contains the right data.
        if ((time > 0) ||
659
            treatAllDBsAsTimeVarying ||
hrchilds's avatar
hrchilds committed
660 661
            (!db->MetaDataIsInvariant()) ||
            (!db->SILIsInvariant()))
hrchilds's avatar
hrchilds committed
662 663 664
        {
            debug2 << "NetworkManager::AddDB: We were instructed to open "
                   << filename.c_str() << " at timestate=" << time
hrchilds's avatar
hrchilds committed
665
                   << " so we're reading the SIL early."
hrchilds's avatar
hrchilds committed
666
                   << endl;
667
            db->GetMetaData(time,
668 669 670
                            forceReadAllCyclesAndTimes,
                            forceReadThisCycleAndTime,
                            treatAllDBsAsTimeVarying);
671
            db->GetSIL(time, treatAllDBsAsTimeVarying);
hrchilds's avatar
hrchilds committed
672 673 674 675 676 677
        }

        netDB = new NetnodeDB(db);
        databaseCache.push_back(netDB);

        netDB->SetDBInfo(filename, "", time);
hrchilds's avatar
hrchilds committed
678
        loadBalancer->AddDatabase(filename, db, time);
hrchilds's avatar
hrchilds committed
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
      
        // The code here should be:
        // CATCH_RETURN2(1, netDB);
        //
        // However: this is crashing on AIX when you do a re-open (see '3984).
        // After investigating this bug, I have determined the following:
        // (1) A valid pointer is being returned from this function.  However
        // the calling function receives NULL (leading to a seg fault).
        // (2) When compiling with fake exceptions and running under purify
        // on the Suns, there are no warnings.
        // (3) The catch return unwinds into 3 calls.  If you put a print
        // statement right before the last one (the return), everything is
        // returned correctly and there is no seg fault.
        //
        // I'm always very leery to call something a compiler bug.  However,
        // on different platforms there is no problem.  I think it is even
        // more fishy that things work if there is a print statement and don't
        // if there is not.  It certainly sounds like a compiler bug.
        //
        // Below is code that "makes this work".  It is essentially a
        // CATCH_RETURN2 with a print statement in the middle.  If CATCH_RETURN
        // were to ever change, this coding would have to change as well
        // (thus, I have introduced a maintenance problem).  As such, I put
        // a comment in VisItException.h referencing this comment.  If the
        // coding below can ever be replaced with an everyday CATCH_RETURN,
        // the comment in VisItException.h should be removed.
        //
#ifdef FAKE_EXCEPTIONS
           exception_delete(exception_caught); 
           jump_stack_top -= (1); 
           debug5 << "This debug statement (from the NetworkManager) is "
                  << "being issued to get around a compiler bug." << endl;
           return (netDB); 
#else
           return netDB;
#endif
hrchilds's avatar
hrchilds committed
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
    }
    CATCH(DatabaseException)
    {
        debug1 << "ERROR - could not create database " << filename.c_str()
            << endl;
        RETHROW;
    }
    ENDTRY
}

// ****************************************************************************
//  Method: NetworkManager::StartNetwork
//
//  Purpose:
//      Start building the pipeline.
hrchilds's avatar
hrchilds committed
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
//
//  Programmer: Jeremy Meredith
//  Creation:   September 29, 2000
//
//  Modifications:
//
//    Jeremy Meredith, Thu Nov  2 14:07:34 PST 2000
//    Changed the file initialization.  Apparently substr() may not portably 
//    be a const method of strings....
//
//    Hank Childs, Tue Jun 12 20:01:55 PDT 2001
//    Incorporate data specifications and the load balancer.
//
//    Jeremy Meredith, Thu Jul 26 12:08:42 PDT 2001
//    Fixed a bug passing the data file name to the load balancer.
//
//    Hank Childs, Thu Jul 26 20:17:56 PDT 2001
//    Re-enable caching by checking data specifications.
//
//    Brad Whitlock, Mon Oct 22 18:33:37 PST 2001
//    Changed the exception keywords to macros.
//
//    Jeremy Meredith, Fri Nov  9 10:24:23 PST 2001
//    Replaced netPool with netMRU, and simply made it release its
//    data, not delete the whole network. Made is only set the data
//    specification, not the pipeline specification yet.
//
//    Hank Childs, Fri Dec 14 17:39:36 PST 2001
//    Add support for using a more compact version of sil attributes.
//
//    Sean Ahern, Mon May 13 17:24:25 PDT 2002
//    Refactored to start support for a tree-based network scheme.
//
//    Sean Ahern, Tue May 28 09:47:21 PDT 2002
//    Added tree-based networks.
//
//    Brad Whitlock, Fri Jun 28 14:03:49 PST 2002
//    I renamed Network to DataNetwork to make the Windows compiler happy.
//
//    Hank Childs, Thu Sep 12 11:11:16 PDT 2002
//    There was an issue with multiple networks sharing NetnodeDBs, so I
//    made them all have their own reference.
//
//    Jeremy Meredith, Thu Oct 24 16:03:39 PDT 2002
//    Added material options.
//
hrchilds's avatar
hrchilds committed
776 777 778 779 780 781
//    Sean Ahern, Mon Dec 23 12:38:17 PST 2002
//    Changed this dramatically.  Broke out a good portion of the logic
//    into GetDBFromCache.
//
//    Sean Ahern, Sat Mar  8 00:59:16 America/Los_Angeles 2003
//    Cleaned up unnecessarily complicated code.
hrchilds's avatar
hrchilds committed
782
//
hrchilds's avatar
hrchilds committed
783 784 785
//    Jeremy Meredith, Wed Jul 30 10:45:45 PDT 2003
//    Added the check for requiring full connectivity.
//
hrchilds's avatar
hrchilds committed
786 787 788
//    Jeremy Meredith, Fri Sep  5 15:23:13 PDT 2003
//    Added a flag for the new MIR algorithm.
//
hrchilds's avatar
hrchilds committed
789 790 791
//    Jeremy Meredith, Thu Oct 30 16:09:32 PST 2003
//    Added code to make sure varLeaves was non-empty before accessing it.
//
hrchilds's avatar
hrchilds committed
792 793 794
//    Jeremy Meredith, Fri Oct 31 13:05:26 PST 2003
//    Made the error message for no-real-variables more informative.
//
hrchilds's avatar
hrchilds committed
795 796 797 798
//    Hank Childs, Sun Mar  7 16:05:03 PST 2004
//    Do not make the database be a node for the network.  Also add the EEF
//    as a node.
//
hrchilds's avatar
hrchilds committed
799 800 801
//    Jeremy Meredith, Tue Mar 23 14:40:20 PST 2004
//    Added the file format as an argument.  Made use of it in GetDBFromCache.
//
hrchilds's avatar
hrchilds committed
802 803 804
//    Mark C. Miller, Thu Aug 19 10:28:45 PDT 2004
//    Removed #ifdef 0 code block
//
hrchilds's avatar
hrchilds committed
805 806 807 808 809 810
//    Jeremy Meredith, Tue Dec 14 14:02:35 PST 2004
//    The code to get the real variable name was a duplicate of two
//    other spots in VisIt, but this one was out of date.  I
//    refactored the best one into ParsingExprList::GetRealVariable
//    and made this one point to it.
//
hrchilds's avatar
hrchilds committed
811 812 813 814
//    Brad Whitlock, Tue Feb 22 12:13:44 PDT 2005
//    Made format argument come first. I also made it possible for an empty
//    format string to make the code behave as through no format was specified.
//
hrchilds's avatar
hrchilds committed
815 816 817
//    Hank Childs, Wed Jul 13 10:38:02 PDT 2005
//    Added call to SetTime to prevent UMR when exporting databases.
//
hrchilds's avatar
hrchilds committed
818 819 820
//    Hank Childs, Wed Aug 17 21:55:55 PDT 2005
//    Pass along the material options to simplify the interface reconstruction.
//
hrchilds's avatar
hrchilds committed
821 822 823
//    Jeremy Meredith, Thu Aug 18 17:54:51 PDT 2005
//    Added a new isovolume algorithm, with adjustable VF cutoff.
//
hrchilds's avatar
hrchilds committed
824 825
//    Mark C. Miller, Wed Nov 16 10:46:36 PST 2005
//    Added mesh management attributes 
hrchilds's avatar
hrchilds committed
826 827 828
//
//    Mark C. Miller, Sun Dec  3 12:20:11 PST 2006
//    Added setting of flatness tolerance to data spec for CSG stuff
hrchilds's avatar
hrchilds committed
829 830 831 832 833
//
//    Hank Childs, Wed Jan 17 10:42:21 PST 2007
//    Tell the output of the expression evaluator filter that it is *not*
//    transient, since picks sometimes like to look at these.
//
834 835
//    Mark C. Miller, Thu Jun 14 10:26:37 PDT 2007
//    Added support to treat all databases as time varying
836 837 838
//
//    Mark C. Miller, Wed Aug 22 20:16:59 PDT 2007
//    Added treatAllDBsAsTimeVarying to GetSIL call.
839 840 841 842
//
//    Hank Childs, Fri Feb  1 15:48:01 PST 2008
//    Add new Boolean argument to GetDBFromCache. 
//
843 844
//    Mark C. Miller, Tue Jun 10 22:36:25 PDT 2008
//    Added support for ignoring bad extents from dbs.
845 846 847 848
//
//    Hank Childs, Fri Jan 16 15:30:15 PST 2009
//    Store the variable with the working network.
//
849 850 851
//    John C. Anderson, Thu Jan 15 10:20:20 2009
//    Added annealing time for Discrete MIR.
//
852 853 854
//    Jeremy Meredith, Fri Feb 13 11:22:39 EST 2009
//    Added MIR iteration capability.
//
hrchilds's avatar
hrchilds committed
855
// ****************************************************************************
hrchilds's avatar
hrchilds committed
856

hrchilds's avatar
hrchilds committed
857
void
858 859 860
NetworkManager::StartNetwork(const std::string &format,
                             const std::string &filename,
                             const std::string &var,
hrchilds's avatar
hrchilds committed
861 862
                             int time,
                             const CompactSILRestrictionAttributes &atts,
hrchilds's avatar
hrchilds committed
863
                             const MaterialAttributes &matopts,
864
                             const MeshManagementAttributes &meshopts,
865 866
                             bool treatAllDBsAsTimeVarying,
                             bool ignoreExtents)
hrchilds's avatar
hrchilds committed
867
{
hrchilds's avatar
hrchilds committed
868 869
    // If the variable is an expression, we need to find a "real" variable
    // name to work with.
870
    std::string leaf = ParsingExprList::GetRealVariable(var);
hrchilds's avatar
hrchilds committed
871

hrchilds's avatar
hrchilds committed
872 873 874 875 876
    // Make empty strings behave as though no format was specified.
    const char *defaultFormat = 0;
    if(format.size() > 0)
        defaultFormat = format.c_str();

hrchilds's avatar
hrchilds committed
877 878
    // Start up the DataNetwork and add the database to it.
    workingNet = new DataNetwork;
879
    bool fileMayHaveUnloadedPlugin = false;
880
    NetnodeDB *netDB = GetDBFromCache(filename, time, defaultFormat,
881
                                      treatAllDBsAsTimeVarying, 
882 883
                                      fileMayHaveUnloadedPlugin,
                                      ignoreExtents);
hrchilds's avatar
hrchilds committed
884
    workingNet->SetNetDB(netDB);
885
    workingNet->SetVariable(leaf);
hrchilds's avatar
hrchilds committed
886
    netDB->SetDBInfo(filename, leaf, time);
hrchilds's avatar
hrchilds committed
887

hrchilds's avatar
hrchilds committed
888 889 890 891 892
    // Put an ExpressionEvaluatorFilter right after the netDB to handle
    // expressions that come up the pipe.
    avtExpressionEvaluatorFilter *f = new avtExpressionEvaluatorFilter();
    NetnodeFilter *filt = new NetnodeFilter(f, "ExpressionEvaluator");
    filt->GetInputNodes().push_back(netDB);
hrchilds's avatar
hrchilds committed
893
    f->GetOutput()->SetTransientStatus(false);
hrchilds's avatar
hrchilds committed
894

hrchilds's avatar
hrchilds committed
895 896
    // Push the ExpressionEvaluator onto the working list.
    workingNetnodeList.push_back(filt);
hrchilds's avatar
hrchilds committed
897

hrchilds's avatar
hrchilds committed
898
    workingNet->AddNode(filt);
hrchilds's avatar
hrchilds committed
899
    // Push the variable name onto the name stack.
hrchilds's avatar
hrchilds committed
900
    nameStack.push_back(var);
901
    debug4 << "NetworkManager::AddDB: Adding " << var.c_str()
hrchilds's avatar
hrchilds committed
902 903 904
           << " to the name stack" << endl;

    // Set up the data spec.
hrchilds's avatar
hrchilds committed
905
    avtSILRestriction_p silr =
906
        new avtSILRestriction(workingNet->GetNetDB()->GetDB()->
907
            GetSIL(time, treatAllDBsAsTimeVarying), atts);
hrchilds's avatar
hrchilds committed
908
    avtDataRequest *dataRequest = new avtDataRequest(var.c_str(), time, silr);
hrchilds's avatar
hrchilds committed
909 910

    // Set up some options from the data specification
hrchilds's avatar
hrchilds committed
911 912 913 914 915
    dataRequest->SetNeedMixedVariableReconstruction(matopts.GetForceMIR());
    dataRequest->SetNeedSmoothMaterialInterfaces(matopts.GetSmoothing());
    dataRequest->SetNeedCleanZonesOnly(matopts.GetCleanZonesOnly());
    dataRequest->SetNeedValidFaceConnectivity(matopts.GetNeedValidConnectivity());
    dataRequest->SetMIRAlgorithm(matopts.GetAlgorithm());
916 917 918
    dataRequest->SetMIRNumIterations(matopts.GetIterationEnabled() ?
                                     matopts.GetNumIterations() : 0);
    dataRequest->SetMIRIterationDamping(matopts.GetIterationDamping());
hrchilds's avatar
hrchilds committed
919 920 921
    dataRequest->SetSimplifyHeavilyMixedZones(matopts.GetSimplifyHeavilyMixedZones());
    dataRequest->SetMaxMaterialsPerZone(matopts.GetMaxMaterialsPerZone());
    dataRequest->SetIsovolumeMIRVF(matopts.GetIsoVolumeFraction());
922
    dataRequest->SetAnnealingTime(matopts.GetAnnealingTime());
hrchilds's avatar
hrchilds committed
923 924 925 926 927 928 929
    dataRequest->SetDiscTol(meshopts.GetDiscretizationTolerance()[0]);
    dataRequest->SetFlatTol(meshopts.GetDiscretizationTolerance()[1]);
    dataRequest->SetDiscMode(meshopts.GetDiscretizationMode());
    dataRequest->SetDiscBoundaryOnly(meshopts.GetDiscretizeBoundaryOnly());
    dataRequest->SetPassNativeCSG(meshopts.GetPassNativeCSG());
    workingNet->SetDataSpec(dataRequest);
    workingNet->SetTime(dataRequest->GetTimestep());
hrchilds's avatar
hrchilds committed
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944

    // The plot starts out as NULL.
    workingNet->SetPlot(NULL);
}

// ****************************************************************************
// Method: NetworkManager::DefineDB
//
// Purpose: 
//   Defines a new database with the specified name and list of files.
//
// Arguments:
//    dbName   : The database name.
//    files    : The list of files that make up the database.
//    time     : The timestep that we want to examine.
hrchilds's avatar
hrchilds committed
945
//    format   : The file format type of the DB.
hrchilds's avatar
hrchilds committed
946 947 948 949 950 951 952 953 954 955
//   
// Programmer: Brad Whitlock
// Creation:   Tue Mar 25 13:41:08 PST 2003
//
// Modifications:
//   Brad Whitlock, Wed May 14 12:56:16 PDT 2003
//   I made it get the metadata and the SIL if the time is greater than 0.
//   This ensures that we pick up the metadata and SIL for the time state
//   that we're intersted in.
//
hrchilds's avatar
hrchilds committed
956 957 958
//   Hank Childs, Mon Jan  5 16:49:28 PST 2004
//   Account for databases in the cached lists that have been cleared.
//
hrchilds's avatar
hrchilds committed
959 960 961
//   Hank Childs, Mon Mar  1 08:48:26 PST 2004
//   Send the time to the database factory as well.
//
hrchilds's avatar
hrchilds committed
962 963
//   Hank Childs, Mon Mar 22 11:10:43 PST 2004
//   Send the file format type to the database factory.
hrchilds's avatar
hrchilds committed
964 965 966 967
//
//   Mark C. Miller, Tue Sep 28 19:57:42 PDT 2004
//   Added code to pass avtDatabaseMetaData to LoadBalancer->AddDatabase
//
hrchilds's avatar
hrchilds committed
968 969 970 971
//   Brad Whitlock, Tue Feb 22 12:17:27 PDT 2005
//   I changed the code so it an empty format string behaves as though no
//   format was specified.
//
hrchilds's avatar
hrchilds committed
972 973 974
//   Hank Childs, Sun Feb 27 12:30:17 PST 2005
//   Added avtDatabase argument to AddDatabase.
//
hrchilds's avatar
hrchilds committed
975 976 977
//   Hank Childs, Fri Oct  7 09:30:57 PDT 2005
//   Tell the database what its full name is.
//
hrchilds's avatar
hrchilds committed
978 979 980 981 982 983
//   Mark C. Miller, Wed Nov 16 10:46:36 PST 2005
//   Changed interface to lb->AddDatabase 
//
//   Hank Childs, Thu Jan 11 16:10:12 PST 2007
//   Added argument to DatabaseFactory calls.
//
984 985 986
//   Brad Whitlock, Tue Jun 24 15:48:27 PDT 2008
//   Pass the database plugin manager to the database factory.
//
hrchilds's avatar
hrchilds committed
987
// ****************************************************************************
hrchilds's avatar
hrchilds committed
988

hrchilds's avatar
hrchilds committed
989
void
990 991
NetworkManager::DefineDB(const std::string &dbName, const std::string &dbPath,
    const stringVector &files, int time, const std::string &format)
hrchilds's avatar
hrchilds committed
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
{
    //
    // We gotta have a load balancer
    //
    if (loadBalancer == NULL)
    {
        debug1 << "Internal error: A load balancer was never registered."
               << endl;
        EXCEPTION0(ImproperUseException);
    }

    // Prepend the path to the files.
    stringVector filesWithPath;
    filesWithPath.reserve(files.size());
1006
    for(size_t i = 0; i < files.size(); ++i)
hrchilds's avatar
hrchilds committed
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
        filesWithPath.push_back(dbPath + files[i]);

    //
    // If the database is in the virtualDatabases map, then check the
    // new list of files against the old list of files.
    //
    StringVectorMap::const_iterator it = virtualDatabases.find(dbName);
    if(it != virtualDatabases.end())
    {
        // If the list of files is the same, return because we don't
        // need to change the list of files. If the list of files differ
        // then replace the list of files.
        if(filesWithPath == it->second)
        {
            debug3 << "NetworkManager::DefineDB: No need to change "
                   << "virtual database definition for "
                   << dbName.c_str() << endl;

            // The definition is the same so we don't need to change it
            // but we have to make sure that it exists in the database
            // cache or else we'll have to define it. It's possible that
            // a clear cache rpc could have purged it from the database
            // cache.
            bool found = false;
1031
            for(size_t i = 0; i < databaseCache.size() && !found; ++i)
hrchilds's avatar
hrchilds committed
1032 1033 1034
            {
                if (databaseCache[i] == NULL)
                    continue;
hrchilds's avatar
hrchilds committed
1035
                found = (databaseCache[i]->GetFilename() == dbName);
hrchilds's avatar
hrchilds committed
1036
            }
hrchilds's avatar
hrchilds committed
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054

            // If the database was in the database cache, we can return.
            if(found)
                return;
        }
        else
        {
            debug3 << "NetworkManager::DefineDB: Changed "
                   << "virtual database definition for "
                   << dbName.c_str() << endl;
            virtualDatabases[dbName] = filesWithPath;
        }
    }

    //
    // Remove from the database cache databases that have the same name.
    //
    std::vector<NetnodeDB*> databaseBadMatches;
1055
    for (size_t i = 0; i < databaseCache.size(); i++)
hrchilds's avatar
hrchilds committed
1056
    {
hrchilds's avatar
hrchilds committed
1057 1058
        if (databaseCache[i] == NULL)
            continue;
hrchilds's avatar
hrchilds committed
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
        if (databaseCache[i]->GetFilename() != dbName)
            databaseBadMatches.push_back(databaseCache[i]);
    }
    databaseCache = databaseBadMatches;

    const char **names = 0;
    TRY
    {
        // Open the database
        avtDatabase *db = NULL;
        const char *dbName_c = dbName.c_str();

hrchilds's avatar
hrchilds committed
1071 1072 1073 1074 1075
        // Make empty strings behave as though no format was specified.
        const char *defaultFormat = 0;
        if(format.size() > 0)
            defaultFormat = format.c_str();

hrchilds's avatar
hrchilds committed
1076
        std::vector<std::string> plugins;  // unused
hrchilds's avatar
hrchilds committed
1077 1078 1079 1080 1081 1082 1083 1084
        if (filesWithPath.size() > 0)
        {
            // Make an array of pointers that we can pass to the database
            // factory so we can create a database based on a virtual
            // file.
            names = new const char *[filesWithPath.size()];
            for(int i = 0; i < filesWithPath.size(); ++i)
                names[i] = filesWithPath[i].c_str();
1085 1086
            db = avtDatabaseFactory::FileList(GetDatabasePluginManager(),
                  names, filesWithPath.size(), time, plugins, defaultFormat);
hrchilds's avatar
hrchilds committed
1087 1088 1089 1090 1091 1092 1093 1094 1095
            delete [] names;
            names = 0;

            // Add the virtual database to the virtual database map.
            virtualDatabases[dbName] = filesWithPath;
            debug3 << "NetworkManager::DefineDB: Added new virtual database "
                   << "definition for " << dbName.c_str() << endl;
        }
        else if (dbName.substr(dbName.length() - 6) == ".visit")
1096 1097 1098 1099
        {
            db = avtDatabaseFactory::VisitFile(GetDatabasePluginManager(),
                dbName_c, time, plugins, defaultFormat);
        }