NetworkManager.C 158 KB
Newer Older
hrchilds's avatar
hrchilds committed
1 2
/*****************************************************************************
*
brugger's avatar
 
brugger committed
3
* Copyright (c) 2000 - 2008, 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-400142
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>
hrchilds's avatar
hrchilds committed
48 49 50
#include <DebugStream.h>
#include <avtDatabaseFactory.h>
#include <LoadBalancer.h>
hrchilds's avatar
hrchilds committed
51
#include <ConstructDDFAttributes.h>
hrchilds's avatar
hrchilds committed
52 53
#include <DBOptionsAttributes.h>
#include <ExportDBAttributes.h>
hrchilds's avatar
hrchilds committed
54
#include <MaterialAttributes.h>
hrchilds's avatar
hrchilds committed
55
#include <MeshManagementAttributes.h>
hrchilds's avatar
hrchilds committed
56
#include <avtExpressionEvaluatorFilter.h>
hrchilds's avatar
hrchilds committed
57
#include <ImproperUseException.h>
hrchilds's avatar
hrchilds committed
58
#include <InvalidVariableException.h>
hrchilds's avatar
hrchilds committed
59 60 61 62 63
#include <DatabaseException.h>
#include <NoInputException.h>
#include <avtPluginFilter.h>
#include <OperatorPluginManager.h>
#include <OperatorPluginInfo.h>
hrchilds's avatar
hrchilds committed
64
#include <AnnotationObjectList.h>
hrchilds's avatar
hrchilds committed
65
#include <PickAttributes.h>
hrchilds's avatar
hrchilds committed
66 67
#include <VisualCueInfo.h>
#include <VisualCueList.h>
hrchilds's avatar
hrchilds committed
68
#include <avtApplyDDFExpression.h>
hrchilds's avatar
hrchilds committed
69
#include <avtCallback.h>
hrchilds's avatar
hrchilds committed
70
#include <avtColorTables.h>
hrchilds's avatar
hrchilds committed
71
#include <avtExtents.h>
hrchilds's avatar
hrchilds committed
72 73
#include <avtNullData.h>
#include <avtDataObjectQuery.h>
hrchilds's avatar
hrchilds committed
74
#include <avtMultipleInputQuery.h>
hrchilds's avatar
hrchilds committed
75
#include <avtAreaBetweenCurvesQuery.h>
hrchilds's avatar
hrchilds committed
76
#include <avtFileWriter.h>
hrchilds's avatar
hrchilds committed
77
#include <avtDatabaseWriter.h>
hrchilds's avatar
hrchilds committed
78
#include <avtL2NormBetweenCurvesQuery.h>
hrchilds's avatar
hrchilds committed
79
#include <avtLocateQuery.h>
hrchilds's avatar
hrchilds committed
80
#include <avtLocateCellQuery.h>
hrchilds's avatar
hrchilds committed
81 82 83 84
#include <avtLocateNodeQuery.h>
#include <avtActualCoordsQuery.h>
#include <avtActualNodeCoordsQuery.h>
#include <avtActualZoneCoordsQuery.h>
hrchilds's avatar
hrchilds committed
85
#include <avtPickQuery.h>
hrchilds's avatar
hrchilds committed
86
#include <avtNodePickQuery.h>
hrchilds's avatar
hrchilds committed
87
#include <avtParallel.h>
hrchilds's avatar
hrchilds committed
88 89 90
#include <avtPickByNodeQuery.h>
#include <avtPickByZoneQuery.h>
#include <avtZonePickQuery.h>
hrchilds's avatar
hrchilds committed
91
#include <avtCurvePickQuery.h>
hrchilds's avatar
hrchilds committed
92
#include <avtSoftwareShader.h>
hrchilds's avatar
hrchilds committed
93 94
#include <avtDDF.h>
#include <avtDDFConstructor.h>
hrchilds's avatar
hrchilds committed
95 96 97
#include <avtSourceFromAVTImage.h>
#include <avtSourceFromImage.h>
#include <avtSourceFromNullData.h>
hrchilds's avatar
hrchilds committed
98
#include <avtTiledImageCompositor.h>
hrchilds's avatar
hrchilds committed
99 100
#include <avtWholeImageCompositerWithZ.h>
#include <avtWholeImageCompositerNoZ.h>
hrchilds's avatar
hrchilds committed
101
#include <avtPlot.h>
hrchilds's avatar
hrchilds committed
102 103
#include <avtQueryOverTimeFilter.h>
#include <avtQueryFactory.h>
hrchilds's avatar
hrchilds committed
104
#include <CompactSILRestrictionAttributes.h>
hrchilds's avatar
hrchilds committed
105
#include <VisWindow.h>
hrchilds's avatar
hrchilds committed
106
#include <VisWinRendering.h> // for SetStereoEnabled
hrchilds's avatar
hrchilds committed
107
#include <ParsingExprList.h>
hrchilds's avatar
hrchilds committed
108
#include <avtExprNode.h>
hrchilds's avatar
hrchilds committed
109 110
#include <DatabasePluginManager.h>
#include <DatabasePluginInfo.h>
hrchilds's avatar
hrchilds committed
111 112
#include <PlotPluginManager.h>
#include <PlotPluginInfo.h>
hrchilds's avatar
hrchilds committed
113 114
#ifdef PARALLEL
#include <mpi.h>
hrchilds's avatar
hrchilds committed
115
#include <parallel.h>
hrchilds's avatar
hrchilds committed
116
#endif
hrchilds's avatar
hrchilds committed
117
#include <visit-config.h>
hrchilds's avatar
hrchilds committed
118
#include <TimingsManager.h>
119
#include <SaveWindowAttributes.h>
hrchilds's avatar
hrchilds committed
120

hrchilds's avatar
hrchilds committed
121
#include <set>
hrchilds's avatar
hrchilds committed
122
#include <map>
hrchilds's avatar
hrchilds committed
123 124
using std::set;

hrchilds's avatar
hrchilds committed
125 126 127
//
// Static functions.
//
hrchilds's avatar
hrchilds committed
128
static double RenderBalance(int numTrianglesIHave);
hrchilds's avatar
hrchilds committed
129 130
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
131 132
static ref_ptr<avtDatabase> GetDatabase(void *, const std::string &,
                                        int, const char *);
hrchilds's avatar
hrchilds committed
133
static avtDDF *GetDDFCallbackBridge(void *arg, const char *name);
hrchilds's avatar
hrchilds committed
134

hrchilds's avatar
hrchilds committed
135 136 137 138 139 140 141 142 143 144
//
// 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
145 146 147 148 149 150 151 152 153
// ****************************************************************************
//  Method: NetworkManager default constructor
//
//  Programmer: Jeremy Meredith
//  Creation:   September 29, 2000
//
//  Modifications:
//
//    Kathleen Bonnell, Tue Nov 20 12:35:54 PST 2001
154
//    Initialize requireOriginalCells.
hrchilds's avatar
hrchilds committed
155
//
hrchilds's avatar
hrchilds committed
156 157 158
//    Hank Childs, Mon Jan  5 16:04:57 PST 2004
//    Initialize uniqueNetworkId.
//
hrchilds's avatar
hrchilds committed
159 160 161
//    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
162 163 164
//    Mark C. Miller, Thu Apr 29 16:15:25 PDT 2004
//    Added missing initialization of dumpRenders
//
hrchilds's avatar
hrchilds committed
165 166 167
//    Mark C. Miller, Tue May 25 20:44:10 PDT 2004
//    Removed unnecessary scope. Set annotationAttributes data member
//
168 169
//    Kathleen Bonnell, Wed Jun  2 09:48:29 PDT 2004
//    Initialize requireOriginalNodes.
hrchilds's avatar
hrchilds committed
170
//
hrchilds's avatar
hrchilds committed
171 172 173 174
//    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
175 176 177
//    Mark C. Miller, Wed Jan  5 10:14:21 PST 2005
//    Added call to NewVisWindow
//
hrchilds's avatar
hrchilds committed
178 179 180
//    Hank Childs, Mon Feb 28 16:56:20 PST 2005
//    Initialize inQueryMode.
//
hrchilds's avatar
hrchilds committed
181 182 183
//    Hank Childs, Fri Aug 26 15:44:48 PDT 2005
//    Register a callback to get databases.
//
hrchilds's avatar
hrchilds committed
184 185 186
//    Hank Childs, Sat Feb 18 11:31:23 PST 2006
//    Added a call back for the apply ddf expression.
//
hrchilds's avatar
hrchilds committed
187 188 189 190 191 192
// ****************************************************************************
NetworkManager::NetworkManager(void) : virtualDatabases()
{
    workingNet = NULL;
    loadBalancer = NULL;
    requireOriginalCells = false;
hrchilds's avatar
hrchilds committed
193
    requireOriginalNodes = false;
hrchilds's avatar
hrchilds committed
194
    inQueryMode = false;
hrchilds's avatar
hrchilds committed
195
    uniqueNetworkId = 0;
hrchilds's avatar
hrchilds committed
196
    dumpRenders = false;
hrchilds's avatar
hrchilds committed
197

hrchilds's avatar
hrchilds committed
198
    // stuff to support scalable rendering. We always have window 0
hrchilds's avatar
hrchilds committed
199
    NewVisWindow(0);
hrchilds's avatar
hrchilds committed
200 201

    avtCallback::RegisterGetDatabaseCallback(GetDatabase, this);
hrchilds's avatar
hrchilds committed
202 203 204
    avtApplyDDFExpression::RegisterGetDDFCallback(GetDDFCallbackBridge, this);
    avtExpressionEvaluatorFilter::RegisterGetDDFCallback(
                                                  GetDDFCallbackBridge, this);
hrchilds's avatar
hrchilds committed
205 206 207 208 209 210 211 212 213
}

// ****************************************************************************
//  Method: NetworkManager destructor
//
//  Programmer: Jeremy Meredith
//  Creation:   September 29, 2000
//
//  Modifications:
hrchilds's avatar
hrchilds committed
214 215 216 217 218 219
//    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
220
//
hrchilds's avatar
hrchilds committed
221 222 223
//    Mark C. Miller, Tue Jan  4 10:23:19 PST 2005
//    Added code to delete VisWindow objects
//
hrchilds's avatar
hrchilds committed
224 225 226
//    Hank Childs, Mon Feb 13 23:14:23 PST 2006
//    Delete the DDFs.
//
hrchilds's avatar
hrchilds committed
227 228 229 230
// ****************************************************************************
NetworkManager::~NetworkManager(void)
{
    for (int i = 0; i < networkCache.size(); i++)
hrchilds's avatar
hrchilds committed
231 232
        if (networkCache[i] != NULL)
            delete networkCache[i];
hrchilds's avatar
hrchilds committed
233 234 235 236

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

    for (int d = 0 ; d < ddf.size() ; d++)
        delete ddf[d];
hrchilds's avatar
hrchilds committed
240 241 242 243 244 245 246 247 248 249 250 251
}

// ****************************************************************************
//  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
252 253 254 255 256
//    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
257
//
hrchilds's avatar
hrchilds committed
258 259 260
//    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
261
//
hrchilds's avatar
hrchilds committed
262 263 264
//    Brad Whitlock, Thu Feb 26 11:58:58 PDT 2004
//    I replaced the commented out cerr with debug3.
//
hrchilds's avatar
hrchilds committed
265 266 267 268 269
//    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
270 271 272 273
//    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
274 275 276 277
//    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
278 279 280
//    Mark C. Miller, Tue Jan  4 10:23:19 PST 2005
//    Added code to delete VisWindow objects
//
hrchilds's avatar
hrchilds committed
281 282 283
//    Hank Childs, Thu Mar  2 10:06:33 PST 2006
//    Added support for image based plots.
//
hrchilds's avatar
hrchilds committed
284 285 286 287
// ****************************************************************************
void
NetworkManager::ClearAllNetworks(void)
{
hrchilds's avatar
hrchilds committed
288
    debug3 << "NetworkManager::ClearAllNetworks(void)" << endl;
hrchilds's avatar
hrchilds committed
289 290
    int i;

hrchilds's avatar
hrchilds committed
291 292 293 294 295 296 297
    for (i = 0; i < networkCache.size(); i++)
    {
        if (networkCache[i] != NULL)
            delete networkCache[i];
        networkCache[i] = NULL;
    }

hrchilds's avatar
hrchilds committed
298 299 300 301 302 303 304
    for (i = 0; i < databaseCache.size(); i++)
    {
        if (databaseCache[i] != NULL)
            delete databaseCache[i];
        databaseCache[i] = NULL;
    }

hrchilds's avatar
hrchilds committed
305 306
    for (i = 0 ; i < globalCellCounts.size() ; i++)
    {
hrchilds's avatar
hrchilds committed
307
        globalCellCounts[i] = -1;
hrchilds's avatar
hrchilds committed
308
    }
hrchilds's avatar
hrchilds committed
309 310 311 312 313 314

    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
315
        it->second.imageBasedPlots.clear();
hrchilds's avatar
hrchilds committed
316 317 318 319
        delete it->second.viswin;
    }
    viswinMap.clear();
    NewVisWindow(0);
hrchilds's avatar
hrchilds committed
320 321 322 323 324 325 326 327 328 329 330 331 332 333
}

// ****************************************************************************
//  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
334 335 336 337
//  Modifications:
//    Brad Whitlock, Thu Feb 26 11:58:58 PDT 2004
//    I replaced the commented out cerr with debug3.
//
hrchilds's avatar
hrchilds committed
338 339 340
//    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
341 342 343 344
//
//    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
345 346 347
//
//    Mark C. Miller, Tue Jan  4 10:23:19 PST 2005
//    Modified for viswinMap object
hrchilds's avatar
hrchilds committed
348 349 350 351
// ****************************************************************************
void
NetworkManager::ClearNetworksWithDatabase(const std::string &db)
{
hrchilds's avatar
hrchilds committed
352
    debug3 << "NetworkManager::ClearNetworksWithDatabase()" << endl;
hrchilds's avatar
hrchilds committed
353
    int i;
hrchilds's avatar
hrchilds committed
354

355
    //
hrchilds's avatar
hrchilds committed
356 357 358
    // 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
359
    for (i = 0; i < networkCache.size(); i++)
hrchilds's avatar
hrchilds committed
360 361 362 363 364 365 366 367
    {
        if (networkCache[i] != NULL)
        {
            NetnodeDB *ndb = networkCache[i]->GetNetDB();
            if (ndb != NULL)
            {
                if (ndb->GetFilename() == db)
                {
hrchilds's avatar
hrchilds committed
368
                    DoneWithNetwork(i);
hrchilds's avatar
hrchilds committed
369 370 371 372
                }
            }
        }
    }
hrchilds's avatar
hrchilds committed
373

hrchilds's avatar
hrchilds committed
374 375 376 377 378 379 380 381 382 383 384
    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
385 386 387
}

// ****************************************************************************
hrchilds's avatar
hrchilds committed
388
//  Method: NetworkManager::GetDBFromCache
hrchilds's avatar
hrchilds committed
389 390
//
//  Purpose:
hrchilds's avatar
hrchilds committed
391 392 393 394 395 396 397 398 399 400 401 402 403
//      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
404 405 406 407
//    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
408 409 410
//    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
411 412 413
//    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
414 415 416
//    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
417 418 419
//    Hank Childs, Mon Mar  1 08:48:26 PST 2004
//    Send the time to the database factory as well.
//
hrchilds's avatar
hrchilds committed
420 421 422
//    Hank Childs, Mon Mar 22 11:10:43 PST 2004
//    Allow for the DB type to be explicitly specified.
//
hrchilds's avatar
hrchilds committed
423 424 425 426 427
//    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
428
//
hrchilds's avatar
hrchilds committed
429 430 431
//    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
432 433 434 435 436 437 438
//    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
439 440
//    Mark C. Miller, Wed Nov 16 10:46:36 PST 2005
//    Changed interface to lb->AddDatabase 
hrchilds's avatar
hrchilds committed
441 442 443 444
//
//    Hank Childs, Thu Jan 11 16:10:12 PST 2007
//    Added argument to DatabaseFactory calls.
//
445 446
//    Mark C. Miller, Thu Jun 14 10:26:37 PDT 2007
//    Added support to treat all databases as time varying
447 448 449
//
//    Mark C. Miller, Wed Aug 22 20:16:59 PDT 2007
//    Added treatAllDBsAsTimeVarying to GetSIL call
450 451 452 453
//
//    Hank Childs, Fri Feb  1 15:45:28 PST 2008
//    Added argument for loading database plugins.
//
hrchilds's avatar
hrchilds committed
454
// ****************************************************************************
hrchilds's avatar
hrchilds committed
455

hrchilds's avatar
hrchilds committed
456
NetnodeDB *
hrchilds's avatar
hrchilds committed
457
NetworkManager::GetDBFromCache(const string &filename, int time,
458 459
    const char *format, bool treatAllDBsAsTimeVarying, 
    bool fileMayHaveUnloadedPlugin)
hrchilds's avatar
hrchilds committed
460 461 462 463
{
    // If we don't have a load balancer, we're dead.
    if (loadBalancer == NULL)
    {
hrchilds's avatar
hrchilds committed
464 465
        debug1 << "Internal error: A load balancer was never registered." 
               << endl;
hrchilds's avatar
hrchilds committed
466 467 468
        EXCEPTION0(ImproperUseException);
    }

hrchilds's avatar
hrchilds committed
469 470
    // Find a matching database 
    NetnodeDB* cachedDB = NULL;
hrchilds's avatar
hrchilds committed
471 472
    for (int i = 0; i < databaseCache.size(); i++)
    {
hrchilds's avatar
hrchilds committed
473 474
        if (databaseCache[i] == NULL)
            continue;
hrchilds's avatar
hrchilds committed
475
        if (databaseCache[i]->GetFilename() == filename)
hrchilds's avatar
hrchilds committed
476
        {
hrchilds's avatar
hrchilds committed
477 478
            cachedDB = databaseCache[i];
            break;
hrchilds's avatar
hrchilds committed
479
        }
hrchilds's avatar
hrchilds committed
480 481
    }

482 483 484 485
    // use of these makes calls to GetMetaData a little clearer
    const bool forceReadAllCyclesAndTimes = false;
    const bool forceReadThisCycleAndTime  = false;

hrchilds's avatar
hrchilds committed
486 487 488 489 490
    // 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
491 492
        if (treatAllDBsAsTimeVarying ||
	    !cachedDB->GetDB()->MetaDataIsInvariant() ||
hrchilds's avatar
hrchilds committed
493
            !cachedDB->GetDB()->SILIsInvariant())
hrchilds's avatar
hrchilds committed
494
        {
495 496 497 498
            cachedDB->GetDB()->GetMetaData(time,
	                                   forceReadAllCyclesAndTimes,
					   forceReadThisCycleAndTime,
	                                   treatAllDBsAsTimeVarying);
499
            cachedDB->GetDB()->GetSIL(time, treatAllDBsAsTimeVarying);
hrchilds's avatar
hrchilds committed
500
        }
hrchilds's avatar
hrchilds committed
501 502

        return cachedDB;
hrchilds's avatar
hrchilds committed
503 504 505 506 507 508
    }

    // No match.  Load a new DB.
    debug3 << "Loading new database" << endl;
    TRY
    {
509 510
        if (fileMayHaveUnloadedPlugin)
             DatabasePluginManager::Instance()->LoadPluginsNow();
hrchilds's avatar
hrchilds committed
511 512 513
        avtDatabase *db = NULL;
        NetnodeDB *netDB = NULL;
        const char *filename_c = filename.c_str();
hrchilds's avatar
hrchilds committed
514
        std::vector<std::string> plugins;  // unused
hrchilds's avatar
hrchilds committed
515 516
        if (filename.length() >= 6 &&
            filename.substr(filename.length() - 6) == ".visit")
hrchilds's avatar
hrchilds committed
517
            db = avtDatabaseFactory::VisitFile(filename_c, time, plugins, format);
hrchilds's avatar
hrchilds committed
518
        else
hrchilds's avatar
hrchilds committed
519 520
            db = avtDatabaseFactory::FileList(&filename_c, 1, time, plugins, 
                                              format);
hrchilds's avatar
hrchilds committed
521
        db->SetFullDBName(filename);
hrchilds's avatar
hrchilds committed
522 523

        // If we want to open the file at a later timestep, get the
hrchilds's avatar
hrchilds committed
524 525
        // SIL so that it contains the right data.
        if ((time > 0) ||
526
	    treatAllDBsAsTimeVarying ||
hrchilds's avatar
hrchilds committed
527 528
            (!db->MetaDataIsInvariant()) ||
            (!db->SILIsInvariant()))
hrchilds's avatar
hrchilds committed
529 530 531
        {
            debug2 << "NetworkManager::AddDB: We were instructed to open "
                   << filename.c_str() << " at timestate=" << time
hrchilds's avatar
hrchilds committed
532
                   << " so we're reading the SIL early."
hrchilds's avatar
hrchilds committed
533
                   << endl;
534 535 536 537
            db->GetMetaData(time,
	                    forceReadAllCyclesAndTimes,
			    forceReadThisCycleAndTime,
			    treatAllDBsAsTimeVarying);
538
            db->GetSIL(time, treatAllDBsAsTimeVarying);
hrchilds's avatar
hrchilds committed
539 540 541 542 543 544
        }

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

        netDB->SetDBInfo(filename, "", time);
hrchilds's avatar
hrchilds committed
545
        loadBalancer->AddDatabase(filename, db, time);
hrchilds's avatar
hrchilds committed
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
      
        // 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
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
    }
    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
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
//
//  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
643 644 645 646 647 648
//    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
649
//
hrchilds's avatar
hrchilds committed
650 651 652
//    Jeremy Meredith, Wed Jul 30 10:45:45 PDT 2003
//    Added the check for requiring full connectivity.
//
hrchilds's avatar
hrchilds committed
653 654 655
//    Jeremy Meredith, Fri Sep  5 15:23:13 PDT 2003
//    Added a flag for the new MIR algorithm.
//
hrchilds's avatar
hrchilds committed
656 657 658
//    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
659 660 661
//    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
662 663 664 665
//    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
666 667 668
//    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
669 670 671
//    Mark C. Miller, Thu Aug 19 10:28:45 PDT 2004
//    Removed #ifdef 0 code block
//
hrchilds's avatar
hrchilds committed
672 673 674 675 676 677
//    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
678 679 680 681
//    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
682 683 684
//    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
685 686 687
//    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
688 689 690
//    Jeremy Meredith, Thu Aug 18 17:54:51 PDT 2005
//    Added a new isovolume algorithm, with adjustable VF cutoff.
//
hrchilds's avatar
hrchilds committed
691 692
//    Mark C. Miller, Wed Nov 16 10:46:36 PST 2005
//    Added mesh management attributes 
hrchilds's avatar
hrchilds committed
693 694 695
//
//    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
696 697 698 699 700
//
//    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.
//
701 702
//    Mark C. Miller, Thu Jun 14 10:26:37 PDT 2007
//    Added support to treat all databases as time varying
703 704 705
//
//    Mark C. Miller, Wed Aug 22 20:16:59 PDT 2007
//    Added treatAllDBsAsTimeVarying to GetSIL call.
706 707 708 709
//
//    Hank Childs, Fri Feb  1 15:48:01 PST 2008
//    Add new Boolean argument to GetDBFromCache. 
//
hrchilds's avatar
hrchilds committed
710
// ****************************************************************************
hrchilds's avatar
hrchilds committed
711

hrchilds's avatar
hrchilds committed
712
void
hrchilds's avatar
hrchilds committed
713 714
NetworkManager::StartNetwork(const string &format,
                             const string &filename,
hrchilds's avatar
hrchilds committed
715
                             const string &var,
hrchilds's avatar
hrchilds committed
716 717
                             int time,
                             const CompactSILRestrictionAttributes &atts,
hrchilds's avatar
hrchilds committed
718
                             const MaterialAttributes &matopts,
719 720
                             const MeshManagementAttributes &meshopts,
			     bool treatAllDBsAsTimeVarying)
hrchilds's avatar
hrchilds committed
721
{
hrchilds's avatar
hrchilds committed
722 723
    // If the variable is an expression, we need to find a "real" variable
    // name to work with.
hrchilds's avatar
hrchilds committed
724
    string leaf = ParsingExprList::GetRealVariable(var);
hrchilds's avatar
hrchilds committed
725

hrchilds's avatar
hrchilds committed
726 727 728 729 730
    // 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
731 732
    // Start up the DataNetwork and add the database to it.
    workingNet = new DataNetwork;
733
    bool fileMayHaveUnloadedPlugin = false;
734
    NetnodeDB *netDB = GetDBFromCache(filename, time, defaultFormat,
735 736
                                      treatAllDBsAsTimeVarying, 
                                      fileMayHaveUnloadedPlugin);
hrchilds's avatar
hrchilds committed
737 738
    workingNet->SetNetDB(netDB);
    netDB->SetDBInfo(filename, leaf, time);
hrchilds's avatar
hrchilds committed
739

hrchilds's avatar
hrchilds committed
740 741 742 743 744
    // 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
745
    f->GetOutput()->SetTransientStatus(false);
hrchilds's avatar
hrchilds committed
746

hrchilds's avatar
hrchilds committed
747 748
    // Push the ExpressionEvaluator onto the working list.
    workingNetnodeList.push_back(filt);
hrchilds's avatar
hrchilds committed
749

hrchilds's avatar
hrchilds committed
750
    workingNet->AddNode(filt);
hrchilds's avatar
hrchilds committed
751
    // Push the variable name onto the name stack.
hrchilds's avatar
hrchilds committed
752 753 754 755 756
    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
757
    avtSILRestriction_p silr =
758 759
        new avtSILRestriction(workingNet->GetNetDB()->GetDB()->
	    GetSIL(time, treatAllDBsAsTimeVarying), atts);
hrchilds's avatar
hrchilds committed
760 761 762 763 764 765 766
    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
767
    dspec->SetMIRAlgorithm(matopts.GetAlgorithm());
hrchilds's avatar
hrchilds committed
768 769
    dspec->SetSimplifyHeavilyMixedZones(matopts.GetSimplifyHeavilyMixedZones());
    dspec->SetMaxMaterialsPerZone(matopts.GetMaxMaterialsPerZone());
hrchilds's avatar
hrchilds committed
770
    dspec->SetIsovolumeMIRVF(matopts.GetIsoVolumeFraction());
hrchilds's avatar
hrchilds committed
771
    dspec->SetDiscTol(meshopts.GetDiscretizationTolerance()[0]);
hrchilds's avatar
hrchilds committed
772
    dspec->SetFlatTol(meshopts.GetDiscretizationTolerance()[1]);
hrchilds's avatar
hrchilds committed
773 774 775
    dspec->SetDiscMode(meshopts.GetDiscretizationMode());
    dspec->SetDiscBoundaryOnly(meshopts.GetDiscretizeBoundaryOnly());
    dspec->SetPassNativeCSG(meshopts.GetPassNativeCSG());
hrchilds's avatar
hrchilds committed
776
    workingNet->SetDataSpec(dspec);
hrchilds's avatar
hrchilds committed
777
    workingNet->SetTime(dspec->GetTimestep());
hrchilds's avatar
hrchilds committed
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792

    // 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
793
//    format   : The file format type of the DB.
hrchilds's avatar
hrchilds committed
794 795 796 797 798 799 800 801 802 803
//   
// 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
804 805 806
//   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
807 808 809
//   Hank Childs, Mon Mar  1 08:48:26 PST 2004
//   Send the time to the database factory as well.
//
hrchilds's avatar
hrchilds committed
810 811
//   Hank Childs, Mon Mar 22 11:10:43 PST 2004
//   Send the file format type to the database factory.
hrchilds's avatar
hrchilds committed
812 813 814 815
//
//   Mark C. Miller, Tue Sep 28 19:57:42 PDT 2004
//   Added code to pass avtDatabaseMetaData to LoadBalancer->AddDatabase
//
hrchilds's avatar
hrchilds committed
816 817 818 819
//   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
820 821 822
//   Hank Childs, Sun Feb 27 12:30:17 PST 2005
//   Added avtDatabase argument to AddDatabase.
//
hrchilds's avatar
hrchilds committed
823 824 825
//   Hank Childs, Fri Oct  7 09:30:57 PDT 2005
//   Tell the database what its full name is.
//
hrchilds's avatar
hrchilds committed
826 827 828 829 830 831
//   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.
//
hrchilds's avatar
hrchilds committed
832
// ****************************************************************************
hrchilds's avatar
hrchilds committed
833

hrchilds's avatar
hrchilds committed
834 835
void
NetworkManager::DefineDB(const string &dbName, const string &dbPath,
hrchilds's avatar
hrchilds committed
836
    const stringVector &files, int time, const string &format)
hrchilds's avatar
hrchilds committed
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 867 868 869 870 871 872 873 874 875 876 877
{
    //
    // 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
878 879 880
            {
                if (databaseCache[i] == NULL)
                    continue;
hrchilds's avatar
hrchilds committed
881
                found = (databaseCache[i]->GetFilename() == dbName);
hrchilds's avatar
hrchilds committed
882
            }
hrchilds's avatar
hrchilds committed
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902

            // 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
903 904
        if (databaseCache[i] == NULL)
            continue;
hrchilds's avatar
hrchilds committed
905 906 907 908 909 910 911 912 913 914 915 916
        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
917 918 919 920 921
        // 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
922
        std::vector<std::string> plugins;  // unused
hrchilds's avatar
hrchilds committed
923 924 925 926 927 928 929 930
        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
931
            db = avtDatabaseFactory::FileList(names, filesWithPath.size(),
hrchilds's avatar
hrchilds committed
932
                                              time, plugins, defaultFormat);
hrchilds's avatar
hrchilds committed
933 934 935 936 937 938 939 940 941
            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
942 943
            db = avtDatabaseFactory::VisitFile(dbName_c, time, plugins,
                                               defaultFormat);
hrchilds's avatar
hrchilds committed
944
        else
hrchilds's avatar
hrchilds committed
945
            db = avtDatabaseFactory::FileList(&dbName_c, 1, time, plugins,
hrchilds's avatar
hrchilds committed
946
                                              defaultFormat);
hrchilds's avatar
hrchilds committed
947
        db->SetFullDBName(dbName);
hrchilds's avatar
hrchilds committed
948 949 950

        // 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
951 952 953
        if ((time > 0) ||
            (!db->MetaDataIsInvariant()) || 
            (!db->SILIsInvariant()))
hrchilds's avatar
hrchilds committed
954 955 956 957 958 959 960 961 962 963 964 965
        {
            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
966
        netDB->SetDBInfo(dbName, "", time);
hrchilds's avatar
hrchilds committed
967 968 969
        databaseCache.push_back(netDB);

        // Add the database to the load balancer.
hrchilds's avatar
hrchilds committed
970
        loadBalancer->AddDatabase(dbName, db, time);
hrchilds's avatar
hrchilds committed
971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
    }
    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
1037
        // Pull a node off the working list and push it onto the filter
hrchilds's avatar
hrchilds committed
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
        // 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
1075 1076 1077
//    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
1078 1079 1080
//    Brad Whitlock, Wed Mar 21 23:00:00 PST 2007
//    Added plotName.
//
1081 1082 1083
//    Gunther H. Weber, Thu Apr 12 10:52:36 PDT 2007
//    Add filter to beginning of pipeline if necessary
//
hrchilds's avatar
hrchilds committed
1084 1085
// ****************************************************************************
void
hrchilds's avatar
hrchilds committed
1086 1087
NetworkManager::MakePlot(const string &plotName, const string &pluginID, 
    const AttributeGroup *atts, const vector<double> &dataExtents)
hrchilds's avatar
hrchilds committed
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
{
    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
1104
        debug1 << "Network building still in progress.  Filter required to "
hrchilds's avatar
hrchilds committed
1105
               << "absorb " << workingNetnodeList.size() << " nodes."  << endl;
hrchilds's avatar
hrchilds committed
1106 1107 1108 1109
        EXCEPTION0(ImproperUseException);
    }

    avtPlot *p = PlotPluginManager::Instance()->
hrchilds's avatar
hrchilds committed
1110
                                GetEnginePluginInfo(pluginID)->AllocAvtPlot();
hrchilds's avatar
hrchilds committed
1111

1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
    // Check, whether plot wants to place a filter at the beginning of
    // the pipeline
    if (avtFilter *f = p->GetFilterForTopOfPipeline()) {
	debug5 << "NetworkManager::MakePlot(): Inserting filter on top of pipeline." << std::endl;
	NetnodeFilter *filt = new NetnodeFilter(f, "InsertedPlotFilter");
	//f->GetOutput()->SetTransientStatus(true);

	if (workingNet->GetNodeList().size() > 1)
	    workingNet->AddFilterNodeAfterExpressionEvaluator(filt);
	else
	{
	    std::vector<Netnode*> &filtInputs = filt->GetInputNodes();
	    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);
	}
	debug5 << "NetworkManager::MakePlot(): Added filter after expression evaluator." << std::endl;
    }

hrchilds's avatar
hrchilds committed
1134
    p->SetDataExtents(dataExtents);
hrchilds's avatar
hrchilds committed
1135 1136
    workingNet->SetPlot(p);
    workingNet->GetPlot()->SetAtts(atts);
hrchilds's avatar
hrchilds committed
1137 1138
    workingNet->SetPlottype(pluginID);
    workingNet->SetPlotName(plotName);
1139 1140

    debug5 << "NetworkManager::MakePlot(): Leaving NetworkManager::MakePlot()." << std::endl;
hrchilds's avatar
hrchilds committed
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152
}

// ****************************************************************************
//  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
1153 1154 1155 1156 1157
//  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
1158 1159 1160
//    Mark C. Miller, Tue Jan  4 10:23:19 PST 2005
//    Added code to set network's window ID and manage multiple VisWindow
//    objects
1161 1162 1163
//
//    Gunther H. Weber, Thu Apr 12 11:00:57 PDT 2007
//    Added missing space to debug message
hrchilds's avatar
hrchilds committed
1164 1165
// ****************************************************************************
int
hrchilds's avatar
hrchilds committed
1166
NetworkManager::EndNetwork(int windowID)
hrchilds's avatar
hrchilds committed
1167