Changeset 1704 for XIOS/trunk/src/node


Ignore:
Timestamp:
09/11/19 10:22:09 (5 years ago)
Author:
yushan
Message:

Introducing the new graph functionality. Attribute build_workflow_graph=.TRUE. is used in the field definition section in the xml file to enable the workflow graph of the field and other fields referecing to it. A more detailed document will be available soon on the graph fuctionality.

Location:
XIOS/trunk/src/node
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/node/field.cpp

    r1639 r1704  
    2424#include "spatial_transform_filter.hpp" 
    2525#include "file_server_writer_filter.hpp" 
     26#include "workflow_graph.hpp" 
    2627 
    2728namespace xios{ 
     
    4546      , mustAutoTrigger(false) 
    4647      , isEOF(false), nstepMaxRead(false) 
    47    { setVirtualVariableGroup(CVariableGroup::create(getId() + "_virtual_variable_group")); } 
     48   { setVirtualVariableGroup(CVariableGroup::create(getId() + "_virtual_variable_group"));  
     49     field_graph_start = -2; 
     50     field_graph_end = -2; 
     51   } 
    4852 
    4953   CField::CField(const StdString& id) 
     
    6367      , mustAutoTrigger(false) 
    6468      , isEOF(false), nstepMaxRead(false) 
    65    { setVirtualVariableGroup(CVariableGroup::create(getId() + "_virtual_variable_group")); } 
     69   { setVirtualVariableGroup(CVariableGroup::create(getId() + "_virtual_variable_group"));  
     70     field_graph_start = -2; 
     71     field_graph_end = -2; 
     72   } 
     73 
    6674 
    6775   CField::~CField(void) 
     
    11061114    *                     read by the client or/and written to a file 
    11071115    */ 
    1108    void CField::buildFilterGraph(CGarbageCollector& gc, bool enableOutput) 
     1116   void CField::buildFilterGraph(CGarbageCollector& gc, bool enableOutput, Time start_graph, Time end_graph) 
    11091117   TRY 
    11101118   {      
    1111     if (!isReferenceSolvedAndTransformed) solveAllEnabledFieldsAndTransform(); 
    1112     if (!isGridChecked) checkGridOfEnabledFields(); 
     1119     if (!isReferenceSolvedAndTransformed) solveAllEnabledFieldsAndTransform(); 
     1120     if (!isGridChecked) checkGridOfEnabledFields(); 
    11131121 
    11141122     const bool detectMissingValues = (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value == true); 
     1123      
     1124     const bool buildWorkflowGraph = (!build_workflow_graph.isEmpty() && build_workflow_graph == true); 
     1125 
     1126      
    11151127     const double defaultValue  = detectMissingValues ? default_value : (!default_value.isEmpty() ? default_value : 0.0); 
    11161128 
    11171129     CContext* context = CContext::getCurrent(); 
     1130      
     1131     Time filter_start; 
     1132     if(!build_workflow_graph_start.isEmpty() && buildWorkflowGraph) filter_start = context->calendar->getInitDate()+build_workflow_graph_start; 
     1133     else if(build_workflow_graph_start.isEmpty() && buildWorkflowGraph) filter_start = 0; 
     1134     else filter_start = -1; 
     1135 
     1136     Time filter_end; 
     1137     if(!build_workflow_graph_end.isEmpty() && buildWorkflowGraph) filter_end = context->calendar->getInitDate()+build_workflow_graph_end; 
     1138     else if(build_workflow_graph_end.isEmpty() && buildWorkflowGraph) filter_end = 9223372036854775807; 
     1139     else filter_end = -1; 
     1140 
     1141     if(this->field_graph_start==-2) this->field_graph_start = filter_start; 
     1142     if(this->field_graph_end==-2) this->field_graph_end = filter_end;         // init 
     1143 
     1144     // if(CXios::isClient) std::cout<<"****************** buildFilterGraph : field_id = "<<this->getId()<<" BEFORE: this->field_graph_start = "<<this->field_graph_start<<" this->field_graph_end = "<<this->field_graph_end<<std::endl; 
     1145 
     1146     if(start_graph == -1) 
     1147     { 
     1148       //nothing 
     1149       // if(CXios::isClient) std::cout<<"buildFilterGraph field_id = "<<this->getId()<<" case1: this->field_graph_start = "<<this->field_graph_start<<std::endl; 
     1150     } 
     1151     else //if(start_graph != -1) 
     1152     { 
     1153       if(this->field_graph_start == -1) this->field_graph_start = start_graph; 
     1154       else this->field_graph_start = min(this->field_graph_start, start_graph); 
     1155 
     1156       // if(CXios::isClient) std::cout<<"buildFilterGraph field_id = "<<this->getId()<<" case2: this->field_graph_start = "<<this->field_graph_start<<std::endl; 
     1157     } 
     1158 
     1159 
     1160     if(end_graph == -1) 
     1161     { 
     1162       //nothing 
     1163       // if(CXios::isClient) std::cout<<"buildFilterGraph field_id = "<<this->getId()<<" case1: this->field_graph_end = "<<this->field_graph_end<<std::endl; 
     1164     } 
     1165     else 
     1166     { 
     1167       if(this->field_graph_end == -1) this->field_graph_end = end_graph; 
     1168       else this->field_graph_end = max(this->field_graph_end, end_graph); 
     1169 
     1170       // if(CXios::isClient) std::cout<<"buildFilterGraph field_id = "<<this->getId()<<" case2: this->field_graph_end = "<<this->field_graph_end<<std::endl; 
     1171     } 
     1172     
     1173 
     1174     filter_start = this->field_graph_start; 
     1175     filter_end = this->field_graph_end; 
     1176 
     1177 
     1178     // if(CXios::isClient) std::cout<<"****************** buildFilterGraph : field_id = "<<this->getId()<<" AFTER: this->field_graph_start = "<<this->field_graph_start<<" this->field_graph_end = "<<this->field_graph_end<<std::endl; 
     1179      
     1180 
     1181      
     1182      
     1183 
    11181184     bool hasWriterServer = context->hasServer && !context->hasClient; 
    11191185     bool hasIntermediateServer = context->hasServer && context->hasClient; 
     
    11591225         { 
    11601226           boost::scoped_ptr<IFilterExprNode> expr(parseExpr(getExpression() + '\0')); 
    1161            std::shared_ptr<COutputPin> filter = expr->reduce(gc, *this); 
     1227           std::shared_ptr<COutputPin> filter = expr->reduce(gc, *this, filter_start, filter_end); 
    11621228 
    11631229           // Check if a spatial transformation is needed 
     
    11681234             if (grid && grid != gridRef && grid->hasTransform()) 
    11691235             { 
    1170                  std::pair<std::shared_ptr<CFilter>, std::shared_ptr<CFilter> > filters = CSpatialTransformFilter::buildFilterGraph(gc, gridRef, grid, detectMissingValues, defaultValue);  
     1236               std::pair<std::shared_ptr<CFilter>, std::shared_ptr<CFilter> > filters = CSpatialTransformFilter::buildFilterGraph(gc, gridRef, grid, detectMissingValues, defaultValue); 
    11711237 
    11721238               filter->connectOutput(filters.first, 0); 
     
    11761242 
    11771243           instantDataFilter = filter; 
     1244           instantDataFilter->field = this; 
     1245           filter->tag = buildWorkflowGraph; 
     1246            
     1247           filter->start_graph = filter_start; 
     1248           filter->end_graph = filter_end; 
     1249 
     1250           for(int i=0; i<filter->parent_filters.size(); i++) 
     1251           { 
     1252             filter->tag = filter->tag || filter->parent_filters[i]->tag; 
     1253           } 
    11781254         } 
    11791255         // Check if we have a reference on another field 
    11801256         else if (!field_ref.isEmpty()) 
    1181            instantDataFilter = getFieldReference(gc); 
     1257         { 
     1258           instantDataFilter = getFieldReference(gc, filter_start, filter_end); 
     1259           instantDataFilter->tag = buildWorkflowGraph; 
     1260           instantDataFilter->start_graph = filter_start; 
     1261           instantDataFilter->end_graph = filter_end; 
     1262         } 
    11821263         // Check if the data is to be read from a file 
    11831264         else if (file && !file->mode.isEmpty() && file->mode == CFile::mode_attr::read) 
     
    11861267           instantDataFilter = serverSourceFilter = std::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid, true, false, freq_offset, true, 
    11871268                                                                                                       detectMissingValues, defaultValue)); 
     1269           instantDataFilter->tag = buildWorkflowGraph; 
     1270           instantDataFilter->start_graph = filter_start; 
     1271           instantDataFilter->end_graph = filter_end; 
     1272           instantDataFilter->field = this; 
     1273 
    11881274         } 
    11891275         else // The data might be passed from the model 
     
    11911277            if (check_if_active.isEmpty()) check_if_active = false;  
    11921278            instantDataFilter = clientSourceFilter = std::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid, false, true, NoneDu, false, 
    1193                                                                                                         detectMissingValues, defaultValue)); 
     1279                                                                                                      detectMissingValues, defaultValue));  
     1280            instantDataFilter->tag = buildWorkflowGraph; 
     1281            instantDataFilter->start_graph = filter_start; 
     1282            instantDataFilter->end_graph = filter_end; 
     1283            instantDataFilter->field = this; 
     1284            // if(CXios::isClient) std::cout<<"***********************buildFilterGraph init source filter : field_id = "<<this->getId()<<" sourcefilter->start_graph = "<<clientSourceFilter->start_graph<<" sourcefilter->end_graph = "<<clientSourceFilter->end_graph<<std::endl; 
    11941285         } 
    11951286       } 
     
    12031294                                                                          detectMissingValues, defaultValue)); 
    12041295           instantDataFilter->connectOutput(storeFilter, 0); 
     1296 
     1297           storeFilter->tag = (instantDataFilter->tag || buildWorkflowGraph); 
     1298           instantDataFilter->start_graph = filter_start; 
     1299           instantDataFilter->end_graph = filter_end; 
     1300 
     1301           instantDataFilter->setParentFiltersTag(); 
     1302           storeFilter->start_graph = filter_start; 
     1303           storeFilter->end_graph = filter_end; 
     1304           storeFilter->field = this; 
     1305           storeFilter->distance = instantDataFilter->distance+1; 
    12051306         } 
    12061307 
     
    12091310           fileWriterFilter = std::shared_ptr<CFileWriterFilter>(new CFileWriterFilter(gc, this)); 
    12101311           getTemporalDataFilter(gc, file->output_freq)->connectOutput(fileWriterFilter, 0); 
     1312            
     1313           fileWriterFilter->tag = (getTemporalDataFilter(gc, file->output_freq)->tag || buildWorkflowGraph); 
     1314           getTemporalDataFilter(gc, file->output_freq)->start_graph = filter_start; 
     1315           getTemporalDataFilter(gc, file->output_freq)->end_graph = filter_end; 
     1316           getTemporalDataFilter(gc, file->output_freq)->tag = buildWorkflowGraph; 
     1317           getTemporalDataFilter(gc, file->output_freq)->setParentFiltersTag(); 
     1318           fileWriterFilter->start_graph = filter_start; 
     1319           fileWriterFilter->end_graph = filter_end; 
     1320           fileWriterFilter->distance = getTemporalDataFilter(gc, file->output_freq)->distance+1; 
     1321 
     1322           // std::cout<<"CFileWriterFilter filter start = "<<filter_start<<" end = "<<filter_end<<" field = "<<this->getId()<<std::endl; 
     1323 
    12111324         } 
    12121325       } 
     
    12221335    * \return the output pin corresponding to the field reference 
    12231336    */ 
    1224    std::shared_ptr<COutputPin> CField::getFieldReference(CGarbageCollector& gc) 
     1337   std::shared_ptr<COutputPin> CField::getFieldReference(CGarbageCollector& gc, Time start_graph, Time end_graph) 
    12251338   TRY 
    12261339   { 
     
    12301343 
    12311344     CField* fieldRef = CField::get(field_ref); 
    1232      fieldRef->buildFilterGraph(gc, false); 
     1345     fieldRef->buildFilterGraph(gc, false, start_graph, end_graph); 
     1346     const bool buildWorkflowGraph = (!build_workflow_graph.isEmpty() && build_workflow_graph == true); 
     1347 
     1348     CContext* context = CContext::getCurrent(); 
     1349 
     1350     Time filter_start; 
     1351     if(!build_workflow_graph_start.isEmpty() && buildWorkflowGraph) filter_start = context->calendar->getInitDate()+build_workflow_graph_start; 
     1352     else if(build_workflow_graph_start.isEmpty() && buildWorkflowGraph) filter_start = 0; 
     1353     else filter_start = -1; 
     1354 
     1355     Time filter_end; 
     1356     if(!build_workflow_graph_end.isEmpty() && buildWorkflowGraph) filter_end = context->calendar->getInitDate()+build_workflow_graph_end; 
     1357     else if(build_workflow_graph_end.isEmpty() && buildWorkflowGraph) filter_end = 9223372036854775807; 
     1358     else filter_end = -1; 
     1359 
     1360     if(this->field_graph_start==-2) this->field_graph_start = filter_start; 
     1361     if(this->field_graph_end==-2) this->field_graph_end = filter_end;         // init 
     1362 
     1363     // if(CXios::isClient) std::cout<<"getFieldReference field_id = "<<this->getId()<<" BEFORE: this->field_graph_start = "<<this->field_graph_start<<" this->field_graph_end = "<<this->field_graph_end<<std::endl; 
     1364 
     1365     if(start_graph == -1) 
     1366     { 
     1367       //nothing 
     1368       // if(CXios::isClient) std::cout<<"getFieldReference field_id = "<<this->getId()<<" case1: this->field_graph_start = "<<this->field_graph_start<<std::endl; 
     1369     } 
     1370     else //if(start_graph != -1) 
     1371     { 
     1372       if(this->field_graph_start == -1) this->field_graph_start = start_graph; 
     1373       else this->field_graph_start = min(this->field_graph_start, start_graph); 
     1374 
     1375       // if(CXios::isClient) std::cout<<"getFieldReference field_id = "<<this->getId()<<" case2: this->field_graph_start = "<<this->field_graph_start<<std::endl; 
     1376     } 
     1377 
     1378     if(end_graph == -1) 
     1379     { 
     1380       //nothing 
     1381       // if(CXios::isClient) std::cout<<"getFieldReference field_id = "<<this->getId()<<" case1: this->field_graph_end = "<<this->field_graph_end<<std::endl; 
     1382     } 
     1383     else 
     1384     { 
     1385       if(this->field_graph_end == -1) this->field_graph_end = end_graph; 
     1386       else this->field_graph_end = max(this->field_graph_end, end_graph); 
     1387 
     1388       // if(CXios::isClient) std::cout<<"getFieldReference field_id = "<<this->getId()<<" case2: this->field_graph_end = "<<this->field_graph_end<<std::endl; 
     1389     } 
     1390 
     1391     filter_start = this->field_graph_start; 
     1392     filter_end = this->field_graph_end; 
     1393 
     1394     // if(CXios::isClient) std::cout<<"getFieldReference field_id = "<<this->getId()<<" AFTER: this->field_graph_start = "<<this->field_graph_start<<" this->field_graph_end = "<<this->field_graph_end<<std::endl; 
     1395 
    12331396 
    12341397     std::pair<std::shared_ptr<CFilter>, std::shared_ptr<CFilter> > filters; 
     
    12391402       double defaultValue  = hasMissingValue ? default_value : (!default_value.isEmpty() ? default_value : 0.0);                                 
    12401403       filters = CSpatialTransformFilter::buildFilterGraph(gc, fieldRef->grid, grid, hasMissingValue, defaultValue); 
     1404 
     1405       fieldRef->getInstantDataFilter()->connectOutput(filters.first, 0); 
     1406 
     1407      
     1408 
     1409       filters.second->parent_filters.resize(1); 
     1410       filters.second->parent_filters[0]= fieldRef->getInstantDataFilter(); 
     1411 
     1412       filters.second->tag = (buildWorkflowGraph || filters.second->parent_filters[0]->tag); 
     1413        
     1414       filters.second->start_graph = filter_start; 
     1415       filters.second->end_graph = filter_end; 
     1416       filters.second->field = this; 
     1417        
    12411418     } 
    12421419     else 
     1420     { 
    12431421       filters.first = filters.second = std::shared_ptr<CFilter>(new CPassThroughFilter(gc)); 
    12441422 
    1245      fieldRef->getInstantDataFilter()->connectOutput(filters.first, 0); 
     1423       fieldRef->getInstantDataFilter()->connectOutput(filters.first, 0); 
     1424      
     1425 
     1426       filters.second->parent_filters.resize(1); 
     1427       filters.second->parent_filters[0]= fieldRef->getInstantDataFilter(); 
     1428 
     1429       filters.second->tag = (buildWorkflowGraph || filters.second->parent_filters[0]->tag); 
     1430 
     1431       filters.second->start_graph = filter_start; 
     1432       filters.second->end_graph = filter_end; 
     1433       filters.second->field = this; 
     1434 
     1435     } 
    12461436 
    12471437     return filters.second; 
     
    12581448    * \return the output pin corresponding to a self reference 
    12591449    */ 
    1260    std::shared_ptr<COutputPin> CField::getSelfReference(CGarbageCollector& gc) 
    1261    TRY 
    1262    { 
     1450   std::shared_ptr<COutputPin> CField::getSelfReference(CGarbageCollector& gc, Time start_graph, Time end_graph) 
     1451   TRY 
     1452   { 
     1453     if(CXios::isClient) std::cout<<"getSelfReference field_id = "<<this->getId()<<" start_graph = "<<start_graph<<" end_graph = "<<end_graph<<std::endl; 
     1454 
    12631455     if (instantDataFilter || !hasExpression()) 
    12641456       ERROR("COutputPin* CField::getSelfReference(CGarbageCollector& gc)", 
    12651457             "Impossible to add a self reference to a field which has already been parsed or which does not have an expression."); 
     1458      
     1459     bool buildWorkflowGraph = (!build_workflow_graph.isEmpty() && build_workflow_graph == true); 
    12661460 
    12671461     if (!selfReferenceFilter) 
     
    13001494     } 
    13011495 
     1496     selfReferenceFilter->tag = buildWorkflowGraph; 
     1497     selfReferenceFilter->field = this; 
    13021498     return selfReferenceFilter; 
    13031499   } 
     
    13171513   { 
    13181514     std::map<CDuration, std::shared_ptr<COutputPin> >::iterator it = temporalDataFilters.find(outFreq); 
     1515     const bool buildWorkflowGraph = (!build_workflow_graph.isEmpty() && build_workflow_graph == true); 
     1516 
     1517     CContext* context = CContext::getCurrent(); 
     1518 
    13191519 
    13201520     if (it == temporalDataFilters.end()) 
     
    13321532 
    13331533       instantDataFilter->connectOutput(temporalFilter, 0); 
     1534       // temporalFilter->tag = buildWorkflowGraph; 
     1535        
     1536       temporalFilter->parent_filters.resize(1); 
     1537       temporalFilter->parent_filters[0] = instantDataFilter; 
     1538        
     1539 
     1540       if(temporalFilter->parent_filters[0]->tag) temporalFilter->tag=true; 
     1541 
     1542       // temporalFilter->start_graph = filter_start; 
     1543       // temporalFilter->end_graph = filter_end; 
     1544       temporalFilter->field = this; 
    13341545 
    13351546       it = temporalDataFilters.insert(std::make_pair(outFreq, temporalFilter)).first; 
     
    13671578 
    13681579       const bool detectMissingValues = (!detect_missing_value.isEmpty() && detect_missing_value == true); 
     1580       bool buildWorkflowGraph = (!build_workflow_graph.isEmpty() && build_workflow_graph == true); 
    13691581       std::shared_ptr<CTemporalFilter> temporalFilter(new CTemporalFilter(gc, operation, 
    1370                                                                              CContext::getCurrent()->getCalendar()->getInitDate(), 
    1371                                                                              freq_op, freq_offset, outFreq, detectMissingValues)); 
     1582                                                                           CContext::getCurrent()->getCalendar()->getInitDate(), 
     1583                                                                           freq_op, freq_offset, outFreq, detectMissingValues)); 
    13721584 
    13731585       selfReferenceFilter->connectOutput(temporalFilter, 0); 
     1586       temporalFilter->tag = buildWorkflowGraph; 
     1587       temporalFilter->field = this; 
     1588 
    13741589       return temporalFilter ; 
    13751590     } 
  • XIOS/trunk/src/node/field.hpp

    r1637 r1704  
    77#include "functor.hpp" 
    88#include "functor_type.hpp" 
     9#include "filter.hpp" 
    910#include "duration.hpp" 
    1011#include "date.hpp" 
     
    139140         void checkTimeAttributes(CDuration* freqOp=NULL); 
    140141 
    141          void buildFilterGraph(CGarbageCollector& gc, bool enableOutput); 
     142         void buildFilterGraph(CGarbageCollector& gc, bool enableOutput, Time start_graph=-1, Time end_graph=-1); 
    142143         size_t getGlobalWrittenSize(void) ; 
    143144          
    144145          
    145          std::shared_ptr<COutputPin> getFieldReference(CGarbageCollector& gc); 
    146          std::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc); 
     146         std::shared_ptr<COutputPin> getFieldReference(CGarbageCollector& gc, Time start_graph=-1, Time end_graph=-1); 
     147         std::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc, Time start_graph=-1, Time end_graph=-1); 
    147148         std::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq); 
    148149         std::shared_ptr<COutputPin> getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq); 
     
    243244         bool hasTimeCentered; 
    244245 
     246         Time field_graph_start; 
     247         Time field_graph_end; 
     248 
    245249 
    246250         DECLARE_REF_FUNC(Field,field) 
Note: See TracChangeset for help on using the changeset viewer.