aboutsummaryrefslogtreecommitdiff
path: root/src/rdf.cc
blob: f818bfb09c6ea15413496d2e8af0b4501b4ba80c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
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
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
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
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
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
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <string>
#include <sstream>

#include <signal.h>
#include <sys/wait.h>
#include <unistd.h>

#include "cctk.h"
#include "cctk_Parameters.h"
#include "cctk_Version.h"
#include "util_Network.h"
#include "util_String.h"

#include "Publish.h"

#include "rdf.hh"
#include "senddata.hh"



namespace Formaline
{
  using namespace std;

  // The jobID is shared between this source file and PublishAsRDF.cc
  // ES 2008-04-29: Check this, I think this is wrong
  string jobID;



  // NUM_RDF_ENTRIES must match the size of the
  // Formaline::rdf_hostname and Formaline::rdf_port parameter arrays
  int const NUM_RDF_ENTRIES = 5;

  // Number of space chars for indentation
  // int const NUM_INDENT_SPACES = 2;



#if 0
  static list<string>
  parse (char const * const key, string& node);
#endif


  rdf::
  rdf (char const * const id,
       enum state const st,
       cGH const * const cctkGH,
       char const * const n,
       rdf * const par)
    : storage (st), groupname (n), parent (par)
  {
    if (parent) return;
    
    // set the unique ID for this simulation
    jobID = clean (string (id));

    //
    // document contents
    //
    switch (get_state()) {
      case initial: Initial (); break;
      case update:
      case final:   Update (cctkGH); break;
      default:      assert (0); // invalid state
    }
  }

  void rdf::Initial (void)
  {
    //
    // This code was copied over from function Formaline_AnnounceInitial()
    // in announce.cc and modified here to create a valid RDF/XML (rather then
    // an unstructured plain XML document).
    //
    DECLARE_CCTK_PARAMETERS;

    if (verbose) CCTK_INFO ("Announcing initial RDF metadata information");

    //
    // general metadata with inlined attribute values
    //
    char hostbuf[512] = "";
    Util_GetHostName (hostbuf, sizeof (hostbuf));
    const string host = clean (hostbuf);
    const cGH* const cctkGH = NULL;
    const int nprocs = CCTK_nProcs (cctkGH);
#if 0
    const string user = clean (CCTK_RunUser());
#else
    const string user = clean (getenv ("USER"));
#endif
    char** argv;
    CCTK_CommandLine (&argv);
    const string executable = clean (argv[0]);
    const string version = clean (CCTK_FullVersion ());
    const string compiled_at (clean (CCTK_CompileDateTime ()));
    char* rundatebuf = Util_CurrentDateTime ();
    const string started_at (clean (rundatebuf));
    free (rundatebuf);
    char buf[512] = "";
    getcwd (buf, sizeof (buf));
    const string cwd (clean (buf));
    buf[0] = 0;
    CCTK_RunTitle (sizeof (buf) - 1, buf);
    const string title(clean(buf));
    const string configID(clean(static_cast<const char *> (UniqueConfigID(0))));
    const string buildID(clean(static_cast<const char *> (UniqueBuildID(0))));
    const string bbhID(clean(static_cast<const char *> (UniqueSimulationID(0))));
    const string runID(clean(static_cast<const char *> (UniqueRunID(0))));

    msgbuf << "<cctk:Simulation rdf:about=\"#" << jobID << "\"" << endl
           << "\tcctk:simulationID=\""  << jobID      << "\"" << endl
           << "\tcctk:host=\""          << host       << "\"" << endl
           << "\tcctk:user=\""          << user       << "\"" << endl
           << "\tcctk:executable=\""    << executable << "\"" << endl
           << "\tcctk:version=\""       << version    << "\"" << endl
           << "\tcctk:title=\""         << title      << "\"" << endl
           << "\tcctk:configID=\""      << configID   << "\"" << endl
           << "\tcctk:buildID=\""       << buildID    << "\"" << endl
           << "\tcctk:bbhID=\""         << bbhID      << "\"" << endl
           << "\tcctk:runID=\""         << runID      << "\"" << endl;
    const char* const pbsJobID = getenv ("PBS_JOBID");
    if (pbsJobID) {
      msgbuf << "\tcctk:pbsJobID=\"" << clean (pbsJobID) << "\"" << endl;
    }
    const char* const pbsJobname = getenv ("PBS_JOBNAME");
    if (pbsJobname) {
      msgbuf << "\tcctk:pbsJobname=\"" << clean (pbsJobname) << "\"" << endl;
    }
#if 0
    const char* pbsHost = getenv ("PBS_O_HOST");
    if (not pbsHost) {
      // check whether we are running on damiana where the MPI runtime system
      // doesn't pass on PBS environment settings
      if (strlen(hostbuf) == 21 &&
          strncmp(hostbuf, "node", 4) == 0 &&
          strncmp(hostbuf + 7, ".damiana.admin", 13) == 0) {
        pbsHost = "damiana.damiana.admin";
      }
    }
    if (pbsHost) {
      // fix incomplete and/or strange PBS headnode hostnames
      if (strncmp(pbsHost, "peyote", 6) == 0) {
        pbsHost = "peyote.aei.mpg.de";
      } else if (strcmp(pbsHost, "master.ic") == 0) {
        pbsHost = "belladonna.aei.mpg.de";
      } else if (strcmp(pbsHost, "damiana.damiana.admin") == 0) {
        pbsHost = "damiana.aei.mpg.de";
      }
      msgbuf << "\tcctk:pbsHost=\"" << clean (pbsHost) << "\"" << endl;
    }
#endif
    msgbuf << "\tcctk:cwd=\"" << cwd         << "\">" << endl
           << "\t<cctk:nProcs rdf:datatype=\"&xsd;integer\">"
           << nprocs << "</cctk:nProcs>" << endl
           << "\t<cctk:compiledAt rdf:datatype=\"&xsd;dateTime\">"
           << compiled_at << "</cctk:compiledAt>" << endl
           << "\t<cctk:startedAt rdf:datatype=\"&xsd;dateTime\">"
           << started_at << "</cctk:startedAt>" << endl
           << "\t<cctk:lastUpdated rdf:datatype=\"&xsd;dateTime\">"
           << started_at << "</cctk:lastUpdated>" << endl;

    //
    // metadata as references to other nodes
    //
    msgbuf << "\t<cctk:thornList rdf:resource=\"#ThornList\"/>" << endl
           << "\t<cctk:parameterFile rdf:resource=\"#ParameterFile\"/>" << endl
           << "</cctk:Simulation>" << endl << endl;

#ifdef ALSO_STORE_THORNLIST_AND_PARAMETERS
    // store thorn list
    msgbuf << "<cctk:ThornList rdf:about=\"#ThornList\">" << endl;
    const int numthorns = CCTK_NumCompiledThorns ();
    for (int thorn = 0; thorn < numthorns; ++ thorn) {
      const char* const thornname = CCTK_CompiledThorn (thorn);

      msgbuf << "\t<cctk:thorn rdf:resource=\"#Thorns/"
             << thornname << "\"/>" << endl;
    }
    msgbuf << "</cctk:ThornList>" << endl << endl;
#endif

    // store parameter file name and contents
    char parfilebuf[512] = "";
    CCTK_ParameterFilename (sizeof (parfilebuf), parfilebuf);
    const string parfile = clean (parfilebuf);
    msgbuf << "<cctk:ParameterFile rdf:about=\"#ParameterFile\"" << endl
           << "\tcctk:name=\"" << parfile     << "\">" << endl
           << "\t<rdf:value>";
    ifstream file (parfile.c_str());
    char c;
    ostringstream filebuf;
    while (filebuf and file.get (c)) filebuf.put (c);
    file.close();
    msgbuf << clean (filebuf.str());
    filebuf.clear();
    msgbuf << "</rdf:value>" << endl
           << "</cctk:ParameterFile>" << endl << endl;

#ifdef ALSO_STORE_THORNLIST_AND_PARAMETERS
    // store all parameters which have been set in the parfile
    msgbuf
<< "<!-- ============================================================ -->" << endl
<< "<!-- thorn graphs with their parameters                           -->" << endl
<< "<!-- ============================================================ -->" << endl;
    ostringstream parambuf;
    parambuf
<< "<!-- ============================================================ -->" << endl
<< "<!-- list of parameters and their values                          -->" << endl
<< "<!-- ============================================================ -->" << endl;

    const bool list_all_parameters = CCTK_Equals (out_save_parameters, "all");

    for (int thorn = 0; thorn < numthorns; ++ thorn) {
      const char* const thornname = CCTK_CompiledThorn (thorn);

      msgbuf << "<cctk:Thorn rdf:about=\"#Thorns/"
             << thornname << "\"" << endl;
      msgbuf << "\tcctk:name=\"" << thornname << "\">" << endl;

      // skip parameters that belong to inactive thorns
      const bool is_active = CCTK_IsThornActive (thornname);
      msgbuf << "\t<cctk:active rdf:datatype=\"&xsd;boolean\">"
             << (is_active ? "true" : "false") << "</cctk:active>" << endl;

      // loop over all parameters of this thorn (if it is active)
      if (is_active) {
        for (int first = 1; ; first = 0) {
          char* fullname = NULL;
          const cParamData* pdata = NULL;

          // get the first/next parameter
          const int ierr = CCTK_ParameterWalk (first, thornname,
                                               &fullname, &pdata);
          assert (ierr >= 0);
          if (ierr > 0) break;

          // brackets in array parameter names have to be escaped
          msgbuf << "\t<cctk:parameter rdf:resource=\"#Parameters/"
                 << pdata->thorn << "/" << cleanURI (pdata->name) << "\"/>"
                 << endl;

          // get its value
          const void* const pvalue
            = CCTK_ParameterGet (pdata->name, pdata->thorn, NULL);
          assert (pvalue);

          if (pdata->n_set or list_all_parameters) {
            const char* paramtype;
            const char* paramdatatype;
            ostringstream paramvaluebuf;

            switch (pdata->type) {
              case PARAMETER_BOOLEAN:
              {
                paramtype = "BooleanParameter";
                paramdatatype = "boolean";
                const CCTK_INT v = *static_cast<const CCTK_INT*> (pvalue);
                paramvaluebuf << (v ? "true" : "false");
              }
              break;

              case PARAMETER_INT:
              {
                paramtype = "IntegerParameter";
                paramdatatype = "integer";
                const CCTK_INT v = *static_cast<const CCTK_INT*> (pvalue);
                paramvaluebuf << v;
              }
              break;

              case PARAMETER_REAL:
              {
                paramtype = "RealParameter";
                paramdatatype = "double";
                CCTK_REAL const v = *static_cast<const CCTK_REAL*> (pvalue);
                paramvaluebuf << v;
              }
              break;

              case PARAMETER_KEYWORD:
              {
                paramtype = "KeywordParameter";
                paramdatatype = "string";
                const char* const v = *static_cast<const char* const*> (pvalue);
                paramvaluebuf << clean (v);
              }
              break;

              case PARAMETER_STRING:
              {
                paramtype = "StringParameter";
                paramdatatype = "string";
                const char* const v = *static_cast<const char* const*> (pvalue);
                paramvaluebuf << clean (v);
              }
              break;

              default: assert (0); // invalid parameter type

            } // switch (pdata->type)

            // brackets in array parameter names have to be escaped
            parambuf << "<cctk:" << paramtype << " rdf:about=\"#Parameters/"
                     << pdata->thorn << "/" << cleanURI (pdata->name) << "\""
                     << endl
                     << "\tcctk:name=\"" << fullname <<"\">" << endl
                     << "\t<cctk:value rdf:datatype=\"&xsd;" << paramdatatype
                     << "\">" << paramvaluebuf.str() << "</cctk:value>" << endl
                     << "</cctk:" << paramtype << ">" << endl;
          } // if (pdata->n_set or list_all_parameters)

          free (fullname);

        } // loop over all parameters of this thorn
      } // if (is_active)

      msgbuf << "</cctk:Thorn>" << endl;

    } // loop over all thorns

    msgbuf << endl << parambuf.str();
#endif
  }


  static string AppendToTransaction(const string operation,
                                    const string& subject,
                                    const string& predicate,
                                    const string& object)
  {
    ostringstream buf;
    buf << "<" << operation << ">\n"
           "  <uri>&simID;" << subject << "</uri>\n"
           "  <uri>&cctk;" << predicate << "</uri>\n"
           "  " << object  << "\n"
           "  <contexts>\n"
           "    <uri>&context;</uri>\n"
           "  </contexts>\n"
           "</" << operation << ">\n\n";
    return buf.str();
  }


  void rdf::Update (cGH const * const cctkGH)
  {
    DECLARE_CCTK_PARAMETERS;

    if (verbose) {
      if (get_state() == update) {
        CCTK_INFO ("Announcing RDF metadata information update");
      } else {
        CCTK_INFO ("Announcing final RDF metadata information");
      }
    }

    if (CCTK_IsFunctionAliased ("PublishBoolean")) {
      const int retval = PublishBoolean (cctkGH, get_state() == final ? 1 : 2,
                                         get_state() == final ? 1 : 0,
                                         "Simulation finished ?",
                                         CCTK_THORNSTRING " runtime info");
      if (retval < 0) {
        CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                    "Failed to publish runtime information (error code %d)",
                    retval);
      }
    }

    // check if there was anything published
    if (rdfPublishList.empty()) return;

    char* rundatebuf = Util_CurrentDateTime ();
    const string started_at (clean (rundatebuf));
    free (rundatebuf);

    static int publishedItems = 0;
    for (size_t i = 0; i < rdfPublishList.size(); i++) {
      ostringstream object;
      object  << "<uri>&simID;Publish/" << (publishedItems + i) << "</uri>";
      msgbuf << AppendToTransaction("add", jobID, "publish", object.str());
    }
    for (size_t i = 0; i < rdfPublishList.size(); i++, publishedItems++) {
      const rdfPublishItem& item = rdfPublishList[i];
      ostringstream subject, object;
      subject << "Publish/" << publishedItems;
      object << "<literal datatype=\"&xsd;dateTime\">" << item.datetime << "</literal>";
      msgbuf << AppendToTransaction("add", subject.str(), "datetime", object.str());
      object.str("");
      object << "<literal>" << item.key << "</literal>";
      msgbuf << AppendToTransaction("add", subject.str(), "key", object.str());
      if (not item.name.empty()) {
        object.str("");
        object << "<literal>" << item.name << "</literal>";
        msgbuf << AppendToTransaction("add", subject.str(), "name", object.str());
      }
      if (item.hasCCTKinfo) {
        object.str("");
        object << "<literal datatype=\"&xsd;double\">" << item.cctk_time << "</literal>";
        msgbuf << AppendToTransaction("add", subject.str(), "time", object.str());
        object.str("");
        object << "<literal datatype=\"&xsd;int\">" << item.cctk_iteration << "</literal>";
        msgbuf << AppendToTransaction("add", subject.str(), "iteration", object.str());
      }

      ostringstream tablebuf;
      if (item.isTable) {
        for (size_t j = 0; j < item.table.size(); j++) {
          const rdfTableEntry& entry = item.table[j];
          subject.str("");
          subject << "Publish/" << publishedItems;
          object.str("");
          object << "<uri>&simID;Publish/" << publishedItems  << "/" << j << "</uri>";
          msgbuf << AppendToTransaction("add", subject.str(), "tableEntry", object.str());
          subject.str("");
          subject << "Publish/" << publishedItems << "/" << j;
          object.str("");
          object << "<literal>" << entry.key << "</literal>";
          msgbuf << AppendToTransaction("add", subject.str(), "key", object.str());
          object.str("");
          object << "<literal";
          if (not entry.value.type.empty()) {
            object << " datatype=\"&xsd;" << entry.value.type << "\"";
          }
          object << ">" << entry.value.value << "</literal>";
          msgbuf << AppendToTransaction("add", subject.str(), "value", object.str());
        }
      } else {
        object.str("");
        object << "<literal";
        if (not item.scalar.type.empty()) {
          object << " datatype=\"&xsd;" << item.scalar.type << "\"";
        }
        object << ">" << item.scalar.value << "</literal>";
        msgbuf << AppendToTransaction("add", subject.str(), "value", object.str());
      }
    }

    rdfPublishList.clear();
  }


  rdf::
  ~ rdf ()
  {
    DECLARE_CCTK_PARAMETERS;

    if (parent)
    {
      parent->msgbuf << "<cctk:" << groupname << ">" << endl
                     << msgbuf.str()
                     << "</cctk:" << groupname << ">" << endl;
      return;
    }

    // check if anything needs to be done
    if (msgbuf.str().empty()) return;

    // this simulation's RDF context
    const string context = "CactusSimulations:" + jobID;
    const string contextURI = cleanURI("<" + context + ">");

    // RDF/XML document header with some namespace definitions
    string header =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<!DOCTYPE owl [\n"
"\t<!ENTITY rdf     'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n"
"\t<!ENTITY xsd     'http://www.w3.org/2001/XMLSchema#'>\n"
"\t<!ENTITY cctk    'http://www.gac-grid.org/project-products/Software/InformationService/InformationProducer/CactusRDFProducer/2006/08/cctk-schema#'>\n"
"\t<!ENTITY simID   '" + context + "#'>\n"
"\t<!ENTITY context '" + context + "'>\n"
"]>\n\n";
    if (get_state() == initial) {
      header += "<rdf:RDF xmlns:rdf=\"&rdf;\"\n"
                "  xmlns:xsd=\"&xsd;\"\n"
                "  xmlns:cctk=\"&cctk;\"\n"
                ">\n\n";
    } else {
      header += "<transaction>\n\n";
    }

    // RDF/XML document footer
    const string footer = get_state() == initial ?
                          "\n</rdf:RDF>\n" : "\n</transaction>\n";

    if (get_state() != initial) {
      char* dateBuffer = Util_CurrentDateTime();
      const string lastUpdated = "<literal datatype=\"&xsd;dateTime\">" +
                                 clean(dateBuffer) + "</literal>";
      free(dateBuffer);

      msgbuf << AppendToTransaction("remove", jobID, "lastUpdated", "<null/>");
      msgbuf << AppendToTransaction("add", jobID, "lastUpdated", lastUpdated);
    }

    const int len = header.length() + msgbuf.str().length() + footer.length();

    // Loop over all destinations
    for (int i = 0; i < NUM_RDF_ENTRIES; i++) {
      if (*rdf_hostname[i]) {

        // Create the data
        // use PUT to create a new context and
        // POST to add metadata to an existing one
        ostringstream databuf;
        databuf
<< (get_state() == initial ? "PUT" : "POST")
<< " /openrdf-sesame/repositories/Simulations/statements"
   "?context=" << contextURI << "&baseURI=" << contextURI;
//<< " /context/CactusSimulations/" << jobID;
        // set a metadata lifetime if requested by the user
        // (Formaline::time_to_live is hours but the RDF service wants seconds)
        // if (metadata_lifetime) databuf << "?ttl=" << (metadata_lifetime * 3600);
        databuf << " HTTP/1.0\r\n"
<< "Host: " << rdf_hostname[i] << "\r\n"
<< "Content-Type: application/"
<< (get_state() == initial ? "rdf+xml" : "x-rdftransaction") << "\r\n"
<< "Content-Length: " << len << "\r\n\r\n"
<< header << msgbuf.str() << footer << "\r\n\r\n";

        // Send the data
        SendData (rdf_hostname[i], rdf_port[i], databuf.str());

      }
    } // loop over all destinations
  }



  rdf * rdf::
  open_group (char const * const name)
  {
    return new rdf (0, get_state (), 0, name, this);
  }



  void rdf::
  store (char const * const key,
         bool const value)
  {
    const void* dummy = &dummy;
    dummy = &key; dummy = &value;
#if 0
    ostringstream valuebuf;
    valuebuf << (value ? "true" : "false");

    string node;
    list<string> const keys = parse (key, node);
    string indent_string (NUM_INDENT_SPACES, ' ');
    for (list<string>::const_iterator lsi = keys.begin();
         lsi != keys.end(); ++ lsi)
    {
      msgbuf << indent_string << "<form:" << * lsi << ">" << endl;
      indent_string.append (NUM_INDENT_SPACES, ' ');
    }

    msgbuf << indent_string
           << "<form:" << node << " rdf:datatype=\"&xsd;boolean\">"
           << clean (valuebuf.str())
           << "</form:" << node << ">" << endl;

    for (list<string>::const_reverse_iterator lsi = keys.rbegin();
         lsi != keys.rend(); ++ lsi)
    {
      indent_string.erase(0, NUM_INDENT_SPACES);
      msgbuf << indent_string << "</form:" << * lsi << ">" << endl;
    }
    msgbuf << endl;
#endif
  }



  void rdf::
  store (char const * const key,
         CCTK_INT const value)
  {
    const void* dummy = &dummy;
    dummy = &key; dummy = &value;
#if 0
    ostringstream valuebuf;
    valuebuf << value;

    string node;
    list<string> const keys = parse (key, node);
    string indent_string (NUM_INDENT_SPACES, ' ');
    for (list<string>::const_iterator lsi = keys.begin();
         lsi != keys.end(); ++ lsi)
    {
      msgbuf << indent_string << "<form:" << * lsi << ">" << endl;
      indent_string.append (NUM_INDENT_SPACES, ' ');
    }

    msgbuf << indent_string
           << "<form:" << node << " rdf:datatype=\"&xsd;integer\">"
           << clean (valuebuf.str())
           << "</form:" << node << ">" << endl;

    for (list<string>::const_reverse_iterator lsi = keys.rbegin();
         lsi != keys.rend(); ++ lsi)
    {
      indent_string.erase(0, NUM_INDENT_SPACES);
      msgbuf << indent_string << "</form:" << * lsi << ">" << endl;
    }
    msgbuf << endl;
#endif
  }



  void rdf::
  store (char const * const key,
         CCTK_REAL const value)
  {
    const void* dummy = &dummy;
    dummy = &key; dummy = &value;
#if 0
    int const prec = numeric_limits<CCTK_REAL>::digits10;
    ostringstream valuebuf;
    valuebuf << setprecision(prec) << value;

    string node;
    list<string> const keys = parse (key, node);
    string indent_string (NUM_INDENT_SPACES, ' ');
    for (list<string>::const_iterator lsi = keys.begin();
         lsi != keys.end(); ++ lsi)
    {
      msgbuf << indent_string << "<form:" << * lsi << ">" << endl;
      indent_string.append (NUM_INDENT_SPACES, ' ');
    }

    msgbuf << indent_string
           << "<form:" << node << " rdf:datatype=\"&xsd;double\">"
           << clean (valuebuf.str())
           << "</form:" << node << ">" << endl;

    for (list<string>::const_reverse_iterator lsi = keys.rbegin();
         lsi != keys.rend(); ++ lsi)
    {
      indent_string.erase(0, NUM_INDENT_SPACES);
      msgbuf << indent_string << "</form:" << * lsi << ">" << endl;
    }
    msgbuf << endl;
#endif
  }



  void rdf::
  store (char const * const key,
         char const * const value)
  {
    const void* dummy = &dummy;
    dummy = &key; dummy = &value;
#if 0
    // don't store keys with empty string values
    if (not *value) return;

    ostringstream valuebuf;
    valuebuf << value;

    string node;
    list<string> const keys = parse (key, node);
    string indent_string (NUM_INDENT_SPACES, ' ');
    for (list<string>::const_iterator lsi = keys.begin();
         lsi != keys.end(); ++ lsi)
    {
      msgbuf << indent_string << "<form:" << * lsi << ">" << endl;
      indent_string.append (NUM_INDENT_SPACES, ' ');
    }

    msgbuf << indent_string
           // FIXME: is <string> the default datatype for RDF objects ??
           << "<form:" << node << ">" // " rdf:datatype=\"&xsd;string\">"
           << clean (valuebuf.str())
           << "</form:" << node << ">" << endl;

    for (list<string>::const_reverse_iterator lsi = keys.rbegin();
         lsi != keys.rend(); ++ lsi)
    {
      indent_string.erase(0, NUM_INDENT_SPACES);
      msgbuf << indent_string << "</form:" << * lsi << ">" << endl;
    }
    msgbuf << endl;
#endif
  }


  string
  clean (string const & txt)
  {
    ostringstream buf;

    for (string::const_iterator p = txt.begin(); p != txt.end(); ++ p)
    {
      switch (* p)
      {
      case '<': buf << "&lt;"; break;
      case '&': buf << "&amp;"; break;
      default: buf << * p;
      }
    }

    return buf.str();
  }


  string
  cleanURI (string const & uri)
  {
    const string allowed_charset ("-_.!~*'()/");
    ostringstream buf;

    for (string::const_iterator p = uri.begin(); p != uri.end(); ++ p) {
      if (isalnum (*p) or allowed_charset.find (*p, 0) != string::npos) {
        buf << *p;
      } else if (*p == ' ') {
        buf << '+';
      } else {
        buf << '%' << hex << int (*p);
      }
    }

    return buf.str();
  }



#if 0
  static list<string>
  parse (char const * const key, string& node)
  {
    assert (key);
    string str(key);
    list<string> strs;
    size_t p = 0;
    for (;;) {
      size_t const s = str.find ("/", p);
      if (s == string::npos) break;
      strs.push_back (str.substr (p, s - p));
      p = s + 1;
    }
    node = str.substr (p);
    return strs;
  }
#endif


} // namespace Formaline