Updates will be applied April 15th at 12pm EDT (UTC-0400). GitLab could be a little slow between 12 - 12:45pm EDT.

NetworkManager.C 122 KB
Newer Older
hrchilds's avatar
hrchilds committed
1
#include <snprintf.h>
hrchilds's avatar
hrchilds committed
2
#include <AttributeSubject.h>
hrchilds's avatar
hrchilds committed
3 4
#include <NetworkManager.h>
#include <DataNetwork.h>
hrchilds's avatar
hrchilds committed
5
#include <ClonedDataNetwork.h>
hrchilds's avatar
hrchilds committed
6 7 8
#include <DebugStream.h>
#include <avtDatabaseFactory.h>
#include <LoadBalancer.h>
hrchilds's avatar
hrchilds committed
9 10
#include <DBOptionsAttributes.h>
#include <ExportDBAttributes.h>
hrchilds's avatar
hrchilds committed
11
#include <MaterialAttributes.h>
hrchilds's avatar
hrchilds committed
12
#include <avtExpressionEvaluatorFilter.h>
hrchilds's avatar
hrchilds committed
13
#include <ImproperUseException.h>
hrchilds's avatar
hrchilds committed
14
#include <InvalidVariableException.h>
hrchilds's avatar
hrchilds committed
15 16 17 18 19
#include <DatabaseException.h>
#include <NoInputException.h>
#include <avtPluginFilter.h>
#include <OperatorPluginManager.h>
#include <OperatorPluginInfo.h>
hrchilds's avatar
hrchilds committed
20
#include <AnnotationObjectList.h>
hrchilds's avatar
hrchilds committed
21
#include <PickAttributes.h>
hrchilds's avatar
hrchilds committed
22 23
#include <VisualCueInfo.h>
#include <VisualCueList.h>
hrchilds's avatar
hrchilds committed
24
#include <avtCallback.h>
hrchilds's avatar
hrchilds committed
25
#include <avtColorTables.h>
hrchilds's avatar
hrchilds committed
26
#include <avtExtents.h>
hrchilds's avatar
hrchilds committed
27
#include <avtNullData.h>
hrchilds's avatar
hrchilds committed
28
#include <avtDatabaseMetaData.h>
hrchilds's avatar
hrchilds committed
29
#include <avtDataObjectQuery.h>
hrchilds's avatar
hrchilds committed
30
#include <avtMultipleInputQuery.h>
hrchilds's avatar
hrchilds committed
31
#include <avtAreaBetweenCurvesQuery.h>
hrchilds's avatar
hrchilds committed
32
#include <avtFileWriter.h>
hrchilds's avatar
hrchilds committed
33
#include <avtDatabaseWriter.h>
hrchilds's avatar
hrchilds committed
34
#include <avtL2NormBetweenCurvesQuery.h>
hrchilds's avatar
hrchilds committed
35
#include <avtLocateQuery.h>
hrchilds's avatar
hrchilds committed
36
#include <avtLocateCellQuery.h>
hrchilds's avatar
hrchilds committed
37 38 39 40
#include <avtLocateNodeQuery.h>
#include <avtActualCoordsQuery.h>
#include <avtActualNodeCoordsQuery.h>
#include <avtActualZoneCoordsQuery.h>
hrchilds's avatar
hrchilds committed
41
#include <avtPickQuery.h>
hrchilds's avatar
hrchilds committed
42
#include <avtNodePickQuery.h>
hrchilds's avatar
hrchilds committed
43
#include <avtParallel.h>
hrchilds's avatar
hrchilds committed
44 45 46
#include <avtPickByNodeQuery.h>
#include <avtPickByZoneQuery.h>
#include <avtZonePickQuery.h>
hrchilds's avatar
hrchilds committed
47
#include <avtCurvePickQuery.h>
hrchilds's avatar
hrchilds committed
48
#include <avtSoftwareShader.h>
hrchilds's avatar
hrchilds committed
49 50 51
#include <avtSourceFromAVTImage.h>
#include <avtSourceFromImage.h>
#include <avtSourceFromNullData.h>
hrchilds's avatar
hrchilds committed
52
#include <avtTiledImageCompositor.h>
hrchilds's avatar
hrchilds committed
53 54
#include <avtWholeImageCompositerWithZ.h>
#include <avtWholeImageCompositerNoZ.h>
hrchilds's avatar
hrchilds committed
55
#include <avtPlot.h>
hrchilds's avatar
hrchilds committed
56 57
#include <avtQueryOverTimeFilter.h>
#include <avtQueryFactory.h>
hrchilds's avatar
hrchilds committed
58
#include <CompactSILRestrictionAttributes.h>
hrchilds's avatar
hrchilds committed
59
#include <VisWindow.h>
hrchilds's avatar
hrchilds committed
60
#include <ParsingExprList.h>
hrchilds's avatar
hrchilds committed
61
#include <avtExprNode.h>
hrchilds's avatar
hrchilds committed
62 63
#include <DatabasePluginManager.h>
#include <DatabasePluginInfo.h>
hrchilds's avatar
hrchilds committed
64 65
#include <PlotPluginManager.h>
#include <PlotPluginInfo.h>
hrchilds's avatar
hrchilds committed
66 67
#ifdef PARALLEL
#include <mpi.h>
hrchilds's avatar
hrchilds committed
68
#include <parallel.h>
hrchilds's avatar
hrchilds committed
69
#endif
hrchilds's avatar
hrchilds committed
70
#include <visit-config.h>
hrchilds's avatar
hrchilds committed
71
#include <TimingsManager.h>
hrchilds's avatar
hrchilds committed
72

hrchilds's avatar
hrchilds committed
73
#include <set>
hrchilds's avatar
hrchilds committed
74
#include <map>
hrchilds's avatar
hrchilds committed
75 76
using std::set;

hrchilds's avatar
hrchilds committed
77
static double RenderBalance(int numTrianglesIHave);
hrchilds's avatar
hrchilds committed
78 79
static void   DumpImage(avtDataObject_p, const char *fmt, bool allprocs=true);
static void   DumpImage(avtImage_p, const char *fmt, bool allprocs=true);
hrchilds's avatar
hrchilds committed
80 81 82 83 84 85 86 87 88 89 90 91

// ****************************************************************************
//  Method: NetworkManager default constructor
//
//  Programmer: Jeremy Meredith
//  Creation:   September 29, 2000
//
//  Modifications:
//
//    Kathleen Bonnell, Tue Nov 20 12:35:54 PST 2001
//    Initialize requireOriginalCells. 
//
hrchilds's avatar
hrchilds committed
92 93 94
//    Hank Childs, Mon Jan  5 16:04:57 PST 2004
//    Initialize uniqueNetworkId.
//
hrchilds's avatar
hrchilds committed
95 96 97
//    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
98 99 100
//    Mark C. Miller, Thu Apr 29 16:15:25 PDT 2004
//    Added missing initialization of dumpRenders
//
hrchilds's avatar
hrchilds committed
101 102 103
//    Mark C. Miller, Tue May 25 20:44:10 PDT 2004
//    Removed unnecessary scope. Set annotationAttributes data member
//
hrchilds's avatar
hrchilds committed
104 105 106
//    Kathleen Bonnell, Wed Jun  2 09:48:29 PDT 2004 
//    Initialize requireOriginalNodes. 
//
hrchilds's avatar
hrchilds committed
107 108 109 110
//    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
111 112 113
//    Mark C. Miller, Wed Jan  5 10:14:21 PST 2005
//    Added call to NewVisWindow
//
hrchilds's avatar
hrchilds committed
114 115 116
//    Hank Childs, Mon Feb 28 16:56:20 PST 2005
//    Initialize inQueryMode.
//
hrchilds's avatar
hrchilds committed
117 118 119 120 121 122
// ****************************************************************************
NetworkManager::NetworkManager(void) : virtualDatabases()
{
    workingNet = NULL;
    loadBalancer = NULL;
    requireOriginalCells = false;
hrchilds's avatar
hrchilds committed
123
    requireOriginalNodes = false;
hrchilds's avatar
hrchilds committed
124
    inQueryMode = false;
hrchilds's avatar
hrchilds committed
125
    uniqueNetworkId = 0;
hrchilds's avatar
hrchilds committed
126
    dumpRenders = false;
hrchilds's avatar
hrchilds committed
127

hrchilds's avatar
hrchilds committed
128
    // stuff to support scalable rendering. We always have window 0
hrchilds's avatar
hrchilds committed
129
    NewVisWindow(0);
hrchilds's avatar
hrchilds committed
130 131 132 133 134 135 136 137 138
}

// ****************************************************************************
//  Method: NetworkManager destructor
//
//  Programmer: Jeremy Meredith
//  Creation:   September 29, 2000
//
//  Modifications:
hrchilds's avatar
hrchilds committed
139 140 141 142 143 144
//    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
145
//
hrchilds's avatar
hrchilds committed
146 147 148
//    Mark C. Miller, Tue Jan  4 10:23:19 PST 2005
//    Added code to delete VisWindow objects
//
hrchilds's avatar
hrchilds committed
149 150 151 152
// ****************************************************************************
NetworkManager::~NetworkManager(void)
{
    for (int i = 0; i < networkCache.size(); i++)
hrchilds's avatar
hrchilds committed
153 154
        if (networkCache[i] != NULL)
            delete networkCache[i];
hrchilds's avatar
hrchilds committed
155 156 157 158

    std::map<int, EngineVisWinInfo>::iterator it;
    for (it = viswinMap.begin(); it != viswinMap.end(); it++)
        delete it->second.viswin;
hrchilds's avatar
hrchilds committed
159 160 161 162 163 164 165 166 167 168 169 170
}

// ****************************************************************************
//  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
171 172 173 174 175
//    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
176
//
hrchilds's avatar
hrchilds committed
177 178 179
//    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
180
//
hrchilds's avatar
hrchilds committed
181 182 183
//    Brad Whitlock, Thu Feb 26 11:58:58 PDT 2004
//    I replaced the commented out cerr with debug3.
//
hrchilds's avatar
hrchilds committed
184 185 186 187 188
//    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
189 190 191 192
//    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
193 194 195 196
//    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
197 198 199
//    Mark C. Miller, Tue Jan  4 10:23:19 PST 2005
//    Added code to delete VisWindow objects
//
hrchilds's avatar
hrchilds committed
200 201 202 203
// ****************************************************************************
void
NetworkManager::ClearAllNetworks(void)
{
hrchilds's avatar
hrchilds committed
204
    debug3 << "NetworkManager::ClearAllNetworks(void)" << endl;
hrchilds's avatar
hrchilds committed
205 206
    int i;

hrchilds's avatar
hrchilds committed
207 208 209 210 211 212 213
    for (i = 0; i < networkCache.size(); i++)
    {
        if (networkCache[i] != NULL)
            delete networkCache[i];
        networkCache[i] = NULL;
    }

hrchilds's avatar
hrchilds committed
214 215 216 217 218 219 220
    for (i = 0; i < databaseCache.size(); i++)
    {
        if (databaseCache[i] != NULL)
            delete databaseCache[i];
        databaseCache[i] = NULL;
    }

hrchilds's avatar
hrchilds committed
221 222
    for (i = 0 ; i < globalCellCounts.size() ; i++)
    {
hrchilds's avatar
hrchilds committed
223
        globalCellCounts[i] = -1;
hrchilds's avatar
hrchilds committed
224
    }
hrchilds's avatar
hrchilds committed
225 226 227 228 229 230 231 232 233 234

    std::map<int, EngineVisWinInfo>::iterator it;
    for (it = viswinMap.begin(); it != viswinMap.end(); it++)
    {
        it->second.viswin->ClearPlots();
        it->second.plotsCurrentlyInWindow.clear();
        delete it->second.viswin;
    }
    viswinMap.clear();
    NewVisWindow(0);
hrchilds's avatar
hrchilds committed
235 236 237 238 239 240 241 242 243 244 245 246 247 248
}

// ****************************************************************************
//  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
249 250 251 252
//  Modifications:
//    Brad Whitlock, Thu Feb 26 11:58:58 PDT 2004
//    I replaced the commented out cerr with debug3.
//
hrchilds's avatar
hrchilds committed
253 254 255
//    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
256 257 258 259
//
//    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
260 261 262
//
//    Mark C. Miller, Tue Jan  4 10:23:19 PST 2005
//    Modified for viswinMap object
hrchilds's avatar
hrchilds committed
263 264 265 266
// ****************************************************************************
void
NetworkManager::ClearNetworksWithDatabase(const std::string &db)
{
hrchilds's avatar
hrchilds committed
267
    debug3 << "NetworkManager::ClearNetworksWithDatabase()" << endl;
hrchilds's avatar
hrchilds committed
268
    int i;
hrchilds's avatar
hrchilds committed
269

hrchilds's avatar
hrchilds committed
270 271 272 273
    // 
    // Clear out the networks before the databases.  This is because if we
    // delete the databases first, the networks will have dangling pointers.
    //
hrchilds's avatar
hrchilds committed
274
    for (i = 0; i < networkCache.size(); i++)
hrchilds's avatar
hrchilds committed
275 276 277 278 279 280 281 282
    {
        if (networkCache[i] != NULL)
        {
            NetnodeDB *ndb = networkCache[i]->GetNetDB();
            if (ndb != NULL)
            {
                if (ndb->GetFilename() == db)
                {
hrchilds's avatar
hrchilds committed
283
                    DoneWithNetwork(i);
hrchilds's avatar
hrchilds committed
284 285 286 287
                }
            }
        }
    }
hrchilds's avatar
hrchilds committed
288

hrchilds's avatar
hrchilds committed
289 290 291 292 293 294 295 296 297 298 299
    for (i = 0; i < databaseCache.size(); i++)
    {
        if (databaseCache[i] != NULL)
        {
            if (databaseCache[i]->GetFilename() == db)
            {
                delete databaseCache[i];
                databaseCache[i] = NULL;
            }
        }
    }
hrchilds's avatar
hrchilds committed
300 301 302
}

// ****************************************************************************
hrchilds's avatar
hrchilds committed
303
//  Method: NetworkManager::GetDBFromCache
hrchilds's avatar
hrchilds committed
304 305
//
//  Purpose:
hrchilds's avatar
hrchilds committed
306 307 308 309 310 311 312 313 314 315 316 317 318
//      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
319 320 321 322
//    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
323 324 325
//    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
326 327 328
//    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
329 330 331
//    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
332 333 334
//    Hank Childs, Mon Mar  1 08:48:26 PST 2004
//    Send the time to the database factory as well.
//
hrchilds's avatar
hrchilds committed
335 336 337
//    Hank Childs, Mon Mar 22 11:10:43 PST 2004
//    Allow for the DB type to be explicitly specified.
//
hrchilds's avatar
hrchilds committed
338 339 340 341 342
//    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
343
//
hrchilds's avatar
hrchilds committed
344
// ****************************************************************************
hrchilds's avatar
hrchilds committed
345

hrchilds's avatar
hrchilds committed
346
NetnodeDB *
hrchilds's avatar
hrchilds committed
347 348
NetworkManager::GetDBFromCache(const string &filename, int time,
                               const char *format)
hrchilds's avatar
hrchilds committed
349 350 351 352
{
    // If we don't have a load balancer, we're dead.
    if (loadBalancer == NULL)
    {
hrchilds's avatar
hrchilds committed
353 354
        debug1 << "Internal error: A load balancer was never registered." 
               << endl;
hrchilds's avatar
hrchilds committed
355 356 357
        EXCEPTION0(ImproperUseException);
    }

hrchilds's avatar
hrchilds committed
358 359
    // Find a matching database 
    NetnodeDB* cachedDB = NULL;
hrchilds's avatar
hrchilds committed
360 361
    for (int i = 0; i < databaseCache.size(); i++)
    {
hrchilds's avatar
hrchilds committed
362 363
        if (databaseCache[i] == NULL)
            continue;
hrchilds's avatar
hrchilds committed
364
        if (databaseCache[i]->GetFilename() == filename)
hrchilds's avatar
hrchilds committed
365
        {
hrchilds's avatar
hrchilds committed
366 367
            cachedDB = databaseCache[i];
            break;
hrchilds's avatar
hrchilds committed
368
        }
hrchilds's avatar
hrchilds committed
369 370 371 372 373 374 375 376 377 378
    }

    // 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
        if (!cachedDB->GetDB()->MetaDataIsInvariant() ||
            !cachedDB->GetDB()->SILIsInvariant())
hrchilds's avatar
hrchilds committed
379
        {
hrchilds's avatar
hrchilds committed
380 381
            cachedDB->GetDB()->GetMetaData(time);
            cachedDB->GetDB()->GetSIL(time);
hrchilds's avatar
hrchilds committed
382
        }
hrchilds's avatar
hrchilds committed
383 384 385

        cachedDB->SetDBInfo(filename, "", time);
        return cachedDB;
hrchilds's avatar
hrchilds committed
386 387 388 389 390 391 392 393 394 395
    }

    // No match.  Load a new DB.
    debug3 << "Loading new database" << endl;
    TRY
    {
        avtDatabase *db = NULL;
        NetnodeDB *netDB = NULL;
        const char *filename_c = filename.c_str();
        if (filename.substr(filename.length() - 6) == ".visit")
hrchilds's avatar
hrchilds committed
396
            db = avtDatabaseFactory::VisitFile(filename_c, time, format);
hrchilds's avatar
hrchilds committed
397
        else
hrchilds's avatar
hrchilds committed
398
            db = avtDatabaseFactory::FileList(&filename_c, 1, time, format);
hrchilds's avatar
hrchilds committed
399 400

        // If we want to open the file at a later timestep, get the
hrchilds's avatar
hrchilds committed
401 402 403 404
        // SIL so that it contains the right data.
        if ((time > 0) ||
            (!db->MetaDataIsInvariant()) ||
            (!db->SILIsInvariant()))
hrchilds's avatar
hrchilds committed
405 406 407
        {
            debug2 << "NetworkManager::AddDB: We were instructed to open "
                   << filename.c_str() << " at timestate=" << time
hrchilds's avatar
hrchilds committed
408
                   << " so we're reading the SIL early."
hrchilds's avatar
hrchilds committed
409 410 411 412 413 414 415 416 417
                   << endl;
            db->GetMetaData(time);
            db->GetSIL(time);
        }

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

        netDB->SetDBInfo(filename, "", time);
hrchilds's avatar
hrchilds committed
418
        const   avtIOInformation & ioinfo = db->GetIOInformation(time);
hrchilds's avatar
hrchilds committed
419
        const   avtDatabaseMetaData *md = db->GetMetaData(time);
hrchilds's avatar
hrchilds committed
420
        loadBalancer->AddDatabase(filename, db, ioinfo, md);
hrchilds's avatar
hrchilds committed
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
      
        // 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
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
    }
    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
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
//
//  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
518 519 520 521 522 523
//    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
524
//
hrchilds's avatar
hrchilds committed
525 526 527
//    Jeremy Meredith, Wed Jul 30 10:45:45 PDT 2003
//    Added the check for requiring full connectivity.
//
hrchilds's avatar
hrchilds committed
528 529 530
//    Jeremy Meredith, Fri Sep  5 15:23:13 PDT 2003
//    Added a flag for the new MIR algorithm.
//
hrchilds's avatar
hrchilds committed
531 532 533
//    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
534 535 536
//    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
537 538 539 540
//    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
541 542 543
//    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
544 545 546
//    Mark C. Miller, Thu Aug 19 10:28:45 PDT 2004
//    Removed #ifdef 0 code block
//
hrchilds's avatar
hrchilds committed
547 548 549 550 551 552
//    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
553 554 555 556
//    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
557 558 559
//    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
560 561 562
//    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
563
// ****************************************************************************
hrchilds's avatar
hrchilds committed
564

hrchilds's avatar
hrchilds committed
565
void
hrchilds's avatar
hrchilds committed
566 567
NetworkManager::StartNetwork(const string &format,
                             const string &filename,
hrchilds's avatar
hrchilds committed
568
                             const string &var,
hrchilds's avatar
hrchilds committed
569 570 571
                             int time,
                             const CompactSILRestrictionAttributes &atts,
                             const MaterialAttributes &matopts)
hrchilds's avatar
hrchilds committed
572
{
hrchilds's avatar
hrchilds committed
573 574
    // If the variable is an expression, we need to find a "real" variable
    // name to work with.
hrchilds's avatar
hrchilds committed
575
    string leaf = ParsingExprList::GetRealVariable(var);
hrchilds's avatar
hrchilds committed
576

hrchilds's avatar
hrchilds committed
577 578 579 580 581
    // 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
582 583
    // Start up the DataNetwork and add the database to it.
    workingNet = new DataNetwork;
hrchilds's avatar
hrchilds committed
584
    NetnodeDB *netDB = GetDBFromCache(filename, time, defaultFormat);
hrchilds's avatar
hrchilds committed
585 586
    workingNet->SetNetDB(netDB);
    netDB->SetDBInfo(filename, leaf, time);
hrchilds's avatar
hrchilds committed
587

hrchilds's avatar
hrchilds committed
588 589 590 591 592
    // 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
593

hrchilds's avatar
hrchilds committed
594 595
    // Push the ExpressionEvaluator onto the working list.
    workingNetnodeList.push_back(filt);
hrchilds's avatar
hrchilds committed
596

hrchilds's avatar
hrchilds committed
597
    workingNet->AddNode(filt);
hrchilds's avatar
hrchilds committed
598
    // Push the variable name onto the name stack.
hrchilds's avatar
hrchilds committed
599 600 601 602 603
    nameStack.push_back(var);
    debug5 << "NetworkManager::AddDB: Adding " << var.c_str()
           << " to the name stack" << endl;

    // Set up the data spec.
hrchilds's avatar
hrchilds committed
604
    avtSILRestriction_p silr =
hrchilds's avatar
hrchilds committed
605
        new avtSILRestriction(workingNet->GetNetDB()->GetDB()->GetSIL(time), atts);
hrchilds's avatar
hrchilds committed
606 607 608 609 610 611 612
    avtDataSpecification *dspec = new avtDataSpecification(var.c_str(), time, silr);

    // Set up some options from the data specification
    dspec->SetNeedMixedVariableReconstruction(matopts.GetForceMIR());
    dspec->SetNeedSmoothMaterialInterfaces(matopts.GetSmoothing());
    dspec->SetNeedCleanZonesOnly(matopts.GetCleanZonesOnly());
    dspec->SetNeedValidFaceConnectivity(matopts.GetNeedValidConnectivity());
hrchilds's avatar
hrchilds committed
613
    dspec->SetUseNewMIRAlgorithm(matopts.GetUseNewMIRAlgorithm());
hrchilds's avatar
hrchilds committed
614 615
    dspec->SetSimplifyHeavilyMixedZones(matopts.GetSimplifyHeavilyMixedZones());
    dspec->SetMaxMaterialsPerZone(matopts.GetMaxMaterialsPerZone());
hrchilds's avatar
hrchilds committed
616
    workingNet->SetDataSpec(dspec);
hrchilds's avatar
hrchilds committed
617
    workingNet->SetTime(dspec->GetTimestep());
hrchilds's avatar
hrchilds committed
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632

    // 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
633
//    format   : The file format type of the DB.
hrchilds's avatar
hrchilds committed
634 635 636 637 638 639 640 641 642 643
//   
// 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
644 645 646
//   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
647 648 649
//   Hank Childs, Mon Mar  1 08:48:26 PST 2004
//   Send the time to the database factory as well.
//
hrchilds's avatar
hrchilds committed
650 651
//   Hank Childs, Mon Mar 22 11:10:43 PST 2004
//   Send the file format type to the database factory.
hrchilds's avatar
hrchilds committed
652 653 654 655
//
//   Mark C. Miller, Tue Sep 28 19:57:42 PDT 2004
//   Added code to pass avtDatabaseMetaData to LoadBalancer->AddDatabase
//
hrchilds's avatar
hrchilds committed
656 657 658 659
//   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
660 661 662
//   Hank Childs, Sun Feb 27 12:30:17 PST 2005
//   Added avtDatabase argument to AddDatabase.
//
hrchilds's avatar
hrchilds committed
663
// ****************************************************************************
hrchilds's avatar
hrchilds committed
664

hrchilds's avatar
hrchilds committed
665 666
void
NetworkManager::DefineDB(const string &dbName, const string &dbPath,
hrchilds's avatar
hrchilds committed
667
    const stringVector &files, int time, const string &format)
hrchilds's avatar
hrchilds committed
668 669 670 671 672 673 674 675 676 677 678 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
{
    //
    // 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());
    int i;
    for(i = 0; i < files.size(); ++i)
        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;
            for(i = 0; i < databaseCache.size() && !found; ++i)
hrchilds's avatar
hrchilds committed
709 710 711
            {
                if (databaseCache[i] == NULL)
                    continue;
hrchilds's avatar
hrchilds committed
712
                found = (databaseCache[i]->GetFilename() == dbName);
hrchilds's avatar
hrchilds committed
713
            }
hrchilds's avatar
hrchilds committed
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733

            // 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;
    for (i = 0; i < databaseCache.size(); i++)
    {
hrchilds's avatar
hrchilds committed
734 735
        if (databaseCache[i] == NULL)
            continue;
hrchilds's avatar
hrchilds committed
736 737 738 739 740 741 742 743 744 745 746 747
        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
748 749 750 751 752
        // 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
753 754 755 756 757 758 759 760
        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();
hrchilds's avatar
hrchilds committed
761
            db = avtDatabaseFactory::FileList(names, filesWithPath.size(),
hrchilds's avatar
hrchilds committed
762
                                              time, defaultFormat);
hrchilds's avatar
hrchilds committed
763 764 765 766 767 768 769 770 771
            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")
hrchilds's avatar
hrchilds committed
772
            db = avtDatabaseFactory::VisitFile(dbName_c, time, defaultFormat);
hrchilds's avatar
hrchilds committed
773
        else
hrchilds's avatar
hrchilds committed
774
            db = avtDatabaseFactory::FileList(&dbName_c, 1, time,
hrchilds's avatar
hrchilds committed
775
                                              defaultFormat);
hrchilds's avatar
hrchilds committed
776 777 778

        // If we want to open the file at a later timestep, get the
        // metadata and the SIL so that it contains the right data.
hrchilds's avatar
hrchilds committed
779 780 781
        if ((time > 0) ||
            (!db->MetaDataIsInvariant()) || 
            (!db->SILIsInvariant()))
hrchilds's avatar
hrchilds committed
782 783 784 785 786 787 788 789 790 791 792 793
        {
            debug2 << "NetworkManager::DefineDB: We were instructed to define "
                       << dbName.c_str() << " at timestate=" << time
                       << " so we're reading the MetaData and SIL early."
                       << endl;
            db->GetMetaData(time);
            db->GetSIL(time);
        }

        // Create a netnode using the opened database and stick it in
        // the database cache.
        NetnodeDB *netDB = new NetnodeDB(db);
hrchilds's avatar
hrchilds committed
794
        netDB->SetDBInfo(dbName, "", time);
hrchilds's avatar
hrchilds committed
795 796 797
        databaseCache.push_back(netDB);

        // Add the database to the load balancer.
hrchilds's avatar
hrchilds committed
798
        const   avtIOInformation & ioinfo = db->GetIOInformation(time);
hrchilds's avatar
hrchilds committed
799
        const   avtDatabaseMetaData *md = db->GetMetaData(time);
hrchilds's avatar
hrchilds committed
800
        loadBalancer->AddDatabase(dbName, db, ioinfo, md);
hrchilds's avatar
hrchilds committed
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
    }
    CATCH(DatabaseException)
    {
        delete [] names;
        debug1 << "ERROR - could not define database " << dbName.c_str()
               << endl;
        RETHROW;
    }
    ENDTRY 
}

// ****************************************************************************
//  Method: NetworkManager::AddFilter
//
//  Purpose:
//      Create a new filter and add it to the network
//
//  Programmer: Jeremy Meredith
//  Creation:   February 28, 2001
//
//  Modifications:
//    Jeremy Meredith, Sun Mar  4 16:58:13 PST 2001
//    Made it use (a new) PluginManager to create the operator.
//
//    Hank Childs, Thu Apr 12 15:34:22 PDT 2001
//    Added check to make sure that there were enough filters to compare to.
//
//    Jeremy Meredith, Thu Jul 26 03:39:21 PDT 2001
//    Added support for the new (real) operator plugin manager.
//
//    Jeremy Meredith, Fri Sep 28 13:32:56 PDT 2001
//    Made use of plugin manager keying off of ids instead of indexes.
//
//    Jeremy Meredith, Fri Nov  9 10:25:46 PST 2001
//    Added an error check, and renamed type to filtertype.
//
//    Sean Ahern, Tue May 28 08:52:48 PDT 2002
//    Added binary operators.
//
// ****************************************************************************
void
NetworkManager::AddFilter(const string &filtertype,
                          const AttributeGroup *atts,
                          const unsigned int nInputs)
{
    // Check that we have a network to work on.
    if (workingNet == NULL)
    {
        debug1 << "Adding a filter to a non-existent network." << endl;
        EXCEPTION0(ImproperUseException);
    }

    avtPluginFilter *f = OperatorPluginManager::Instance()->
        GetEnginePluginInfo(filtertype)->AllocAvtPluginFilter();
    f->SetAtts(atts);
    if (nInputs != 1)
    {
        debug1 << "Unable to handle filters with nInputs (" << nInputs << ") > 1"
            << endl;
        EXCEPTION0(ImproperUseException);
    }

    NetnodeFilter *filt = new NetnodeFilter(f, filtertype);
    std::vector<Netnode*> &filtInputs = filt->GetInputNodes();
    for (int i = 0; i < nInputs; i++)
    {
hrchilds's avatar
hrchilds committed
867
        // Pull a node off the working list and push it onto the filter
hrchilds's avatar
hrchilds committed
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904
        // inputs.
        Netnode *n = workingNetnodeList.back();
        workingNetnodeList.pop_back();
        filtInputs.push_back(n);
    }
    // Push the filter onto the working list.
    workingNetnodeList.push_back(filt);
    workingNet->AddNode(filt);
}

// ****************************************************************************
//  Method:  NetworkManager::MakePlot
//
//  Purpose:
//    Create the plot for the network.
//
//  Programmer:  Jeremy Meredith
//  Creation:    March  1, 2001
//
//  Modifications:
//    Jeremy Meredith, Sun Mar  4 16:58:13 PST 2001
//    Made it use (a new) PluginManager to create the plot.
//
//    Jeremy Meredith, Tue Mar 20 12:05:50 PST 2001
//    Made it use the new plugin manager.  For now we do a reverse lookup
//    of the name to an index.
//
//    Jeremy Meredith, Fri Sep 28 13:32:56 PDT 2001
//    Made use of plugin manager keying off of ids instead of indexes.
//
//    Jeremy Meredith, Fri Nov  9 10:26:18 PST 2001
//    Allowed it to reuse plots so we can cache whole networks again.
//
//    Jeremy Meredith, Fri Feb  8 10:37:59 PST 2002
//    Made sure the total number of filters was the same when matching
//    networks (since when a plot is applied, no more filter can be).
//
hrchilds's avatar
hrchilds committed
905 906 907
//    Eric Brugger, Fri Mar 19 15:25:20 PST 2004
//    Modified the rpc to set the data extents in the engine.
//
hrchilds's avatar
hrchilds committed
908 909
// ****************************************************************************
void
hrchilds's avatar
hrchilds committed
910 911
NetworkManager::MakePlot(const string &id, const AttributeGroup *atts,
                         const vector<double> &dataExtents)
hrchilds's avatar
hrchilds committed
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927
{
    if (workingNet == NULL)
    {
        debug1 << "Adding a plot to a non-existent network." << endl;
        EXCEPTION0(ImproperUseException);
    }

    if (*workingNet->GetPlot() != NULL)
    {
        debug1 << "Trying to stipulate plot type more than once." << endl;
        EXCEPTION0(ImproperUseException);
    }

    // Checking to see if the network has been built successfully.
    if (workingNetnodeList.size() != 1)
    {
hrchilds's avatar
hrchilds committed
928
        debug1 << "Network building still in progress.  Filter required to "
hrchilds's avatar
hrchilds committed
929
               << "absorb " << workingNetnodeList.size() << " nodes."  << endl;
hrchilds's avatar
hrchilds committed
930 931 932 933 934
        EXCEPTION0(ImproperUseException);
    }

    avtPlot *p = PlotPluginManager::Instance()->
                                GetEnginePluginInfo(id)->AllocAvtPlot();
hrchilds's avatar
hrchilds committed
935 936

    p->SetDataExtents(dataExtents);
hrchilds's avatar
hrchilds committed
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951
    workingNet->SetPlot(p);
    workingNet->GetPlot()->SetAtts(atts);
    workingNet->SetPlottype(id);
}

// ****************************************************************************
//  Method:  NetworkManager::EndNetwork
//
//  Purpose:
//    Closes off the new network, assigns a pipeline specification, and a
//    network id.
//
//  Programmer:  Jeremy Meredith
//  Creation:    November  9, 2001
//
hrchilds's avatar
hrchilds committed
952 953 954 955 956
//  Modifications:
//
//    Hank Childs, Mon Jan  5 16:04:57 PST 2004
//    Make sure that the network id is always unique for each network.
//
hrchilds's avatar
hrchilds committed
957 958 959
//    Mark C. Miller, Tue Jan  4 10:23:19 PST 2005
//    Added code to set network's window ID and manage multiple VisWindow
//    objects
hrchilds's avatar
hrchilds committed
960 961
// ****************************************************************************
int
hrchilds's avatar
hrchilds committed
962
NetworkManager::EndNetwork(int windowID)
hrchilds's avatar
hrchilds committed
963 964 965 966 967 968 969 970 971 972 973 974
{
    // Checking to see if the network has been built successfully.
    if (workingNetnodeList.size() != 1)
    {
        debug1 << "Network building still in progress.  Filter required to "
               << "absorb" << workingNetnodeList.size() << " nodes."  << endl;

        EXCEPTION0(ImproperUseException);
    }

    // set the pipeline specification
    int pipelineIndex =
hrchilds's avatar
hrchilds committed
975
        loadBalancer->AddPipeline(workingNet->GetNetDB()->GetFilename());
hrchilds's avatar
hrchilds committed
976 977 978 979 980 981 982 983
    avtPipelineSpecification_p pspec =
        new avtPipelineSpecification(workingNet->GetDataSpec(), pipelineIndex);
    workingNet->SetPipelineSpec(pspec);

    // Connect the workingNet to the workingNetnodeList.
    workingNet->SetTerminalNode(workingNetnodeList[0]);

    // Push the working net onto the network caches.
hrchilds's avatar
hrchilds committed
984 985
    workingNet->SetNetID(uniqueNetworkId++);
    workingNet->SetWinID(windowID);
hrchilds's avatar
hrchilds committed
986
    networkCache.push_back(workingNet);
hrchilds's avatar
hrchilds committed
987
    globalCellCounts.push_back(-1);
hrchilds's avatar
hrchilds committed
988

hrchilds's avatar
hrchilds committed
989 990 991 992 993
    //
    // If this plot this network is associated with is in a window we haven't
    // seen before, make a new VisWindow for it
    //
    if (viswinMap.find(windowID) == viswinMap.end())
hrchilds's avatar
hrchilds committed
994
        NewVisWindow(windowID);
hrchilds's avatar
hrchilds committed
995 996

    return workingNet->GetNetID();
hrchilds's avatar
hrchilds committed
997 998
}

hrchilds's avatar
hrchilds committed
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
// ****************************************************************************
//  Method:  NetworkManager::CancelNetwork
//
//  Purpose:
//    Terminates the current network in case of an error.
//
//  Programmer:  Jeremy Meredith
//  Creation:    November  6, 2003
//
// ****************************************************************************
void
NetworkManager::CancelNetwork(void)
{
    workingNet = NULL;
    workingNetnodeList.clear();
}

hrchilds's avatar
hrchilds committed
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
// ****************************************************************************
//  Method:  NetworkManager::UseNetwork
//
//  Purpose:
//    Allows a whole network to be reused automatically, without
//    needing to specify a database, filters, or plot.
//
//  Arguments:
//    id         the id of the network to reuse.
//
//  Programmer:  Jeremy Meredith
//  Creation:    November  9, 2001
//
//  Modifications:
//
//    Hank Childs, Wed Nov 21 11:41:59 PST 2001
//    Tell the load balancer to reset the pipeline if we re-use the network.
//
hrchilds's avatar
hrchilds committed
1034 1035 1036
//    Hank Childs, Mon Jan  5 16:39:06 PST 2004
//    Make sure that the id requested hasn't already been cleared.
//
hrchilds's avatar
hrchilds committed
1037 1038 1039
//    Mark C. Miller, Tue Jan  4 10:23:19 PST 2005
//    Changed workingNet->GetID to workingNet->GetNetID
//
hrchilds's avatar
hrchilds committed
1040 1041 1042 1043 1044 1045
// ****************************************************************************
void
NetworkManager::UseNetwork(int id)
{
    if (workingNet)
    {
hrchilds's avatar
hrchilds committed
1046 1047
        debug1 << "Internal error: UseNetwork called with an open network" 
               << endl;
hrchilds's avatar
hrchilds committed
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
        EXCEPTION0(ImproperUseException);
    }

    if (id >= networkCache.size())
    {
        debug1 << "Internal error: asked to reuse network ID (" << id
            << " >= num saved networks (" << networkCache.size() << ")"
            << endl;
        EXCEPTION0(ImproperUseException);
    }

    // re-access the given network
hrchilds's avatar
hrchilds committed
1060 1061 1062 1063 1064 1065 1066
    if (networkCache[id] == NULL)
    {
        debug1 << "Asked to use a network that was cleared out previously."
                << "  (presumably because a database was re-opened)." << endl;
        EXCEPTION0(ImproperUseException);
    }
 
hrchilds's avatar
hrchilds committed
1067 1068 1069 1070
    workingNet = networkCache[id];
    int pipelineIndex = workingNet->GetPipelineSpec()->GetPipelineIndex();
    loadBalancer->ResetPipeline(pipelineIndex);

hrchilds's avatar
hrchilds committed
1071
    if (id != workingNet->GetNetID())
hrchilds's avatar
hrchilds committed
1072 1073
    {
        debug1 << "Internal error: network at position[" << id <<
hrchilds's avatar
hrchilds committed
1074
            "] does not have same id (" << workingNet->GetNetID() << ")"
hrchilds's avatar
hrchilds committed
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
            << endl;
        EXCEPTION0(ImproperUseException);
    }
}

// ****************************************************************************
//  Method: NetworkManager::GetPlot
//
//  Purpose:
//      Gets the plot for the current working network 
//
//  Programmer: Mark C. Miller 
//  Creation:   November 19, 2002
//
// ****************************************************************************
avtPlot_p
NetworkManager::GetPlot(void)
{
    if (workingNet == NULL)
    {
        EXCEPTION0(ImproperUseException);
    }

    return workingNet->GetPlot();
}

// ****************************************************************************
//  Method: NetworkManager::GetCurrentNetworkId
//
//  Purpose:
//      Gets the network id of the current network.
//
//  Programmer: Hank Childs
//  Creation:   September 9, 2002
//
hrchilds's avatar
hrchilds committed
1110 1111 1112 1113 1114
//  Modifications:
//
//    Mark C. Miller, Tue Jan  4 10:23:19 PST 2005
//    Changed workingNet->GetID to workingNet->GetNetID
//
hrchilds's avatar
hrchilds committed
1115 1116
// ****************************************************************************
int
hrchilds's avatar
hrchilds committed
1117
NetworkManager::GetCurrentNetworkId(void) const
hrchilds's avatar
hrchilds committed
1118 1119 1120 1121 1122 1123
{
    if (workingNet == NULL)
    {
        EXCEPTION0(ImproperUseException);
    }

hrchilds's avatar
hrchilds committed
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145
    return workingNet->GetNetID();
}

// ****************************************************************************
//  Method: NetworkManager::GetCurrentWindowId
//
//  Purpose:
//      Gets the window id of the current network.
//
//  Programmer: Mark C. Miller
//  Creation:   January 4, 2005 
//
// ****************************************************************************
int
NetworkManager::GetCurrentWindowId(void) const
{
    if (workingNet == NULL)
    {
        EXCEPTION0(ImproperUseException);
    }

    return workingNet->GetWinID();
hrchilds's avatar
hrchilds committed
1146 1147
}

hrchilds's avatar
hrchilds committed
1148 1149 1150 1151 1152 1153 1154 1155 1156
// ****************************************************************************
//  Method: NetworkManager::GetTotalGlobalCellCounts
//
//  Purpose:
//      Gets the network id of the current network.
//
//  Programmer: Hank Childs
//  Creation:   September 9, 2002
//
hrchilds's avatar
hrchilds committed
1157 1158 1159 1160 1161
//  Modifications:
//
//    Hank Childs, Thu Dec  2 09:48:29 PST 2004
//    Look out for overflow.
//
hrchilds's avatar
hrchilds committed
1162 1163 1164
//    Mark C. Miller, Tue Jan  4 10:23:19 PST 2005
//    Modified to compute counts for networks in only the specified window
//
hrchilds's avatar
hrchilds committed
1165 1166
// ****************************************************************************
int
hrchilds's avatar
hrchilds committed
1167
NetworkManager::GetTotalGlobalCellCounts(int winID) const
hrchilds's avatar
hrchilds committed
1168 1169
{
   int i, sum = 0;
hrchilds's avatar
hrchilds committed
1170

hrchilds's avatar
hrchilds committed
1171
    for (i = 0; i < networkCache.size(); i++)
hrchilds's avatar
hrchilds committed
1172
    {
hrchilds's avatar
hrchilds committed
1173 1174 1175 1176
        if (networkCache[i] == NULL ||
            networkCache[i]->GetWinID() != winID)
            continue;

hrchilds's avatar
hrchilds committed
1177
        // Make sure we don't have an overflow issue.
hrchilds's avatar
hrchilds committed
1178
        if (globalCellCounts[i] == INT_MAX)
hrchilds's avatar
hrchilds committed
1179 1180
            return INT_MAX;

hrchilds's avatar
hrchilds committed
1181 1182
        if (globalCellCounts[i] >= 0)
            sum += globalCellCounts[i];
hrchilds's avatar
hrchilds committed
1183 1184
    }
    return sum;
hrchilds's avatar
hrchilds committed
1185 1186
}

hrchilds's avatar
hrchilds committed
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
// ****************************************************************************
//  Method: NetworkManager::SetGlobalCellCount
//
//  Purpose:
//      Sets the global (over all processors) cell count for the given network 
//
//  Programmer: Mark C. Miller
//  Creation:   May 24, 2004 
//
// ****************************************************************************
void
NetworkManager::SetGlobalCellCount(int netId, int cellCount)
{
   globalCellCounts[netId] = cellCount;
hrchilds's avatar
hrchilds committed
1201
   debug5 << "Setting cell count for network " << netId << " to " << cellCount << endl;
hrchilds's avatar
hrchilds committed
1202 1203
}

hrchilds's avatar
hrchilds committed
1204 1205 1206 1207 1208 1209 1210 1211
// ****************************************************************************
//  Method: NetworkManager::GetScalableThreshold
//
//  Purpose: Get the effective scalable threshold
//
//  Programmer: Mark C. Miller 
//  Creation:   May 11, 2004
//
hrchilds's avatar
hrchilds committed
1212 1213 1214 1215 1216
//  Modifications:
//
//    Mark C. Miller, Tue Jan  4 10:23:19 PST 2005
//    Modified to get information for specific window
//
hrchilds's avatar
hrchilds committed
1217 1218
// ****************************************************************************
int
hrchilds's avatar
hrchilds committed
1219
NetworkManager::GetScalableThreshold(int windowID) const
hrchilds's avatar
hrchilds committed
1220 1221 1222 1223
{
    int scalableAutoThreshold;
    RenderingAttributes::TriStateMode scalableActivationMode;

hrchilds's avatar
hrchilds committed
1224 1225 1226 1227 1228 1229 1230 1231
    // since we're in a const method, we can't use the [] operator to index
    // into the map directly becuase that operator will modify the map if the
    // key is new
    std::map<int, EngineVisWinInfo>::const_iterator it;
    it = viswinMap.find(windowID);
    const EngineVisWinInfo &viswinInfo = it->second;
    const WindowAttributes &windowAttributes = viswinInfo.windowAttributes; 

hrchilds's avatar
hrchilds committed
1232 1233 1234 1235 1236
    scalableAutoThreshold =
        windowAttributes.GetRenderAtts().GetScalableAutoThreshold();
    scalableActivationMode = 
        windowAttributes.GetRenderAtts().GetScalableActivationMode();

hrchilds's avatar
hrchilds committed
1237
    int t = RenderingAttributes::GetEffectiveScalableThreshold(
hrchilds's avatar
hrchilds committed
1238 1239
                                    scalableActivationMode,
                                    scalableAutoThreshold);
hrchilds's avatar
hrchilds committed
1240
    return t;
hrchilds's avatar
hrchilds committed
1241
}
hrchilds's avatar
hrchilds committed
1242

hrchilds's avatar
hrchilds committed
1243 1244 1245 1246 1247 1248 1249 1250 1251 1252
// ****************************************************************************
//  Method: NetworkManager::DoneWithNetwork
//
//  Purpose:
//      Indicates that we are done with a network -- we can clean up memory, 
//      etc.
//
//  Programmer: Hank Childs
//  Creation:   September 9, 2002
//
hrchilds's avatar
hrchilds committed
1253 1254 1255 1256 1257
//  Modifications:
//
//    Hank Childs, Mon Jan  5 16:39:06 PST 2004
//    Make sure that this isn't called on a previously cleared network.
//
hrchilds's avatar
hrchilds committed
1258 1259 1260 1261