DemoClient.cc File Reference

#include "TIterator.h"
#include "TROOT.h"
#include "TSystem.h"
#include "MessageService/MsgService.h"
#include "MinosObjectMap/MomNavigator.h"
#include "RawData/RawRecord.h"
#include "Persistency/Per.h"
#include "Dispatcher/DDS.h"
#include "Dispatcher/DDSClient.h"
#include "Dispatcher/DDSSubscription.h"

Go to the source code of this file.

Functions

TROOT root ("DemoClient","MINOS Data Dispatcher System Demo Client")
 CVSID ("$Id: DemoClient.cc,v 1.21 2007/08/24 05:39:07 schubert Exp $")
int main (int argc, char **argv)

Function Documentation

CVSID ( "$Id: DemoClient.  cc,
v 1.21 2007/08/24 05:39:07 schubert Exp $"   
)
int main ( int  argc,
char **  argv 
)

Definition at line 33 of file DemoClient.cc.

References DDS::AsString(), Registry::GetCharString(), Registry::GetInt(), DDSClient::GetSubscription(), DataUtil::GetTempTags(), gSystem(), DDS::kDaq, DDS::kData, DDS::kEventDisplay, Msg::kInfo, DDS::kOk, DDS::kRecordKeepUp, DDS::kTimeoutNewFile, DDS::kTimeoutNewRecord, Munits::ms, MSGSTREAM, DDSSubscription::SetDataSource(), DDSSubscription::SetKeepUpMode(), DDSSubscription::SetStreams(), and DDSClient::Subscribe().

00033                                 {
00034 
00035   MsgStream& ms = MSGSTREAM("DDS",Msg::kInfo);
00036 
00037   ms << "This demo will attempt to set up 1 client connection\n"
00038      << "with the dispatcher server." << endl;
00039 
00040   const char* serverhostname;
00041   if (argc > 1) {
00042     serverhostname = argv[1];
00043     ms << "The user has requested that the client will attempt to connect\n"
00044        << "to a parent server running on host " << serverhostname 
00045        << ".\n" << endl;
00046   }
00047   else {
00048     // Determine the host name of the current machine
00049     serverhostname = gSystem -> HostName();
00050     ms << "Since the user has not specified the host of the parent server\n"          
00051        << "as an argument to this demo, the default is to assume that the\n"
00052        << "parent server runs on the local host " << serverhostname 
00053        << ".\n" << endl;
00054   }
00055 
00056   ms << "To successfully run this program to access data, the user\n"
00057      << "must first run the DemoDaq program in the Persistency package\n"
00058      << "to produce the file testdaq.root.\n"
00059      << "The environment variable DDS_DAQ_DATA_DIR should point to\n"
00060      << "the directory which contains this file, and the symbolic\n"
00061      << "link 'currentfile' should exist within this directory to\n"
00062      << "point to testdaq.root.\n" << endl;
00063 
00064   DDSClient* ddsclient = 0;
00065 
00066   while (1) {
00067     // This primitive while loop is used to attempt to reestablish connection
00068     // if initial connection goes down due to a socket error
00069 
00070     // Create a new DDSClient object connected to ther server running on
00071     // node "serverhostname" and port 9090.
00072     ddsclient = new DDSClient(serverhostname,9090,DDS::kData,DDS::kEventDisplay,"Control Room");
00073 
00074     // Check validity of connected socket before using it
00075     if (! ddsclient -> IsValid() ) {
00076       ms << "Error in creation of socket connected to server." << endl;
00077       delete ddsclient; ddsclient = 0;
00078       return 1;  // end of session
00079     }
00080     else {
00081       ms << "Successfully connected to dispatcher server.\n" 
00082          << ddsclient << endl;
00083     }
00084 
00085     // Subscribe to data source of interest (kDaq or kDcs, default is kDaq).
00086     // Currently (I may change this in future versions), you can only 
00087     // subscribe to one data source at a time.  If you wish to 
00088     // receive data from multiple sources, you need to set up multiple client
00089     // connections.  For a given data source however, there is no restriction
00090     // as to the number of data streams (root trees) you may subscribe to.
00091     ddsclient->GetSubscription()->SetDataSource(DDS::kDaq);
00092 
00093     // Subscribe to streams of interest
00094     ddsclient->GetSubscription()->SetStreams("DaqSnarl");
00095 
00096     // Set keepupmode if requesting mode other than default DDS::kFileKeepUp
00097     // keepupmode DDS::kAll will retrieve all files from the source directory
00098     // ending in ".root".  If the user has also set the symbolic link 
00099     // "currentfile" in this directory to a file, the file retrieval will
00100     // begin with "currentfile", otherwise it will start at the first file
00101     // in the directory.
00102     ddsclient->GetSubscription()->SetKeepUpMode(DDS::kRecordKeepUp);
00103   
00104     // Optionally add selection cut on one or more streams
00105     // ddsclient -> GetSubscription() ->SetSelection("DaqSnarl",
00106     //    "((RawDaqSnarlHeader*)fHeader)->GetSnarl() % 10 == 0 
00107     //  && ((RawDaqSnarlHeader*)fHeader)->GetTrigSrc()==4");
00108     // requests only every 10th DaqSnarl generated from trigger source 4.
00109 
00110 
00111     // Optionally specify desired synchronization delay (default = 15 sec)
00112     // Useful when reading data from multiple streams. 0 => no waiting for
00113     // streams with infrequent or no entries. syncDelay > 0 => wait until difference
00114     // between last visible timestamp on any tree and current vldtimestamp is
00115     // greater than syncDelay before giving up on stream(s) with infrequent or
00116     // no entries. Set very high for perfectly synchronized streams.
00117     // ddsclient -> GetSubscription() -> SetSyncDelay(15);
00118 
00119 
00120     // Submit the subscription to the ddschildserver and check to make sure that
00121     // it was received okay
00122     DDS::EMessageType msgrc = ddsclient->Subscribe();
00123     if (msgrc != DDS::kOk) {
00124       ms << "An error message " << DDS::AsString(msgrc) 
00125          << " was received from DDS::Subscribe." << endl;    
00126       return 1;
00127     }
00128 
00129     // The client's subscription was submitted successfully.  Note that at 
00130     // anytime the clients subscription can be changed and resubmitted.
00131   
00132     // Once the subscription is sent, the user can begin to receive records.
00133     // Create a MomNavigator pointer to hold the received records
00134     msgrc = DDS::kOk;
00135     Int_t nentry = 0;
00136     while (msgrc == DDS::kOk) {
00137       // For testing inactivity shutdown, requires ddsparentserver -t 60
00138       //if ( nentry == 100 ) {
00139       //  cout << "sleeping 100 seconds" << endl;
00140       //  gSystem->Sleep(100*1000);
00141       //}
00142       
00143       
00144       // 2nd argument to DDSClient::Next can be used to adjust waittime before
00145       // ddschildserver will return DDS::kTimeOut when no new entry (or file) 
00146       // is available. The default for this waittime is 120 seconds.  This is
00147       // adjusted to 10 seconds here to avoid a long wait at the end of the demo.
00148       // 3rd argument to DDSClient::Next is the number of record sets to
00149       // advanceby (default = 1).
00150       MomNavigator* mom = 0;
00151       UInt_t waittime = 120;
00152       //Illustration of how to advance to new file using the GoTo*File methods.
00153       //std::string gotofile;
00154       //msgrc  = ddsclient->GoToFile("F00001442_0000.mdaq.root",gotofile);
00155       //cout << "GoToFile " << DDS::AsString(msgrc) << " " << gotofile << endl;
00156       //msgrc  = ddsclient->GoToNextFile(gotofile);
00157       //cout <<"GoToNextFile "<< DDS::AsString(msgrc)<< " "<< gotofile << endl;
00158       //msgrc  = ddsclient->GoToFile("currentfile",gotofile);
00159       //cout <<"GoTo currentfile "<< DDS::AsString(msgrc)<<" "<<gotofile<<endl;
00160 
00161       msgrc = ddsclient -> Next(mom,waittime); 
00162       if (msgrc == DDS::kOk) {
00163         nentry++;
00164         if ( mom ) {
00165           // If you are subscribing to multiple streams, then you should
00166           // loop over the records stored in mom like this:
00167           TIter fiter = mom -> FragmentIter();
00168           RawRecord* rawrecord;
00169           while ( (rawrecord = dynamic_cast<RawRecord*>(fiter.Next())) ) {
00170             // To determine record source use the temptags, e.g.:
00171             ms << "Received rawrecord " << nentry << " from stream "
00172                << rawrecord -> GetTempTags().GetCharString("stream")
00173                << " tree " << rawrecord -> GetTempTags().GetCharString("tree")
00174                << " index " << rawrecord -> GetTempTags().GetInt("index")
00175                << " file " << rawrecord -> GetTempTags().GetCharString("file")
00176                << endl;
00177           }
00178           delete mom; mom = 0; // deleting mom record also deletes RawRecord
00179         } 
00180       }
00181     }
00182 
00183     ms << "\nAfter " << nentry 
00184        << " total entries retrieved, an error message:\n" 
00185        << DDS::AsString(msgrc)
00186        << " was returned from DDS::Next.\n" << endl;
00187     if (msgrc == DDS::kTimeoutNewFile) {
00188       ms << "A TimeoutNewFile will occur when the record retrieval\n"
00189          << "reaches the end of the currentfile, and no new file\n"
00190          << "becomes available within the adjustable waittime specified\n"
00191          << "by the client. (So if the client has only intended to\n"
00192          << "read a set number of files, this is a successful ending.)\n" 
00193          << endl;
00194     }
00195     else if (msgrc == DDS::kTimeoutNewRecord) {
00196       ms << "A TimeoutNewRecord will occur when the record retrieval\n"
00197          << "failed to detect a new record from the currentfile, but\n"
00198          << "the file has not yet been closed by the data generator.\n"
00199          << "This could be an indication that:\n"
00200          << "  i)the waittime specified by the client is not long enough, or\n"
00201          << " ii)the data generator has paused, or\n"
00202          << "iii)the data generator crashed before closing the file.\n"
00203          << endl;
00204     }
00205    
00206     //  if ( msgrc == DDS::kSocketError ) {
00207     //  ms << "The current DDSClient connection will be shutdown\n" 
00208     //     << " and a new connection will be attempted." << endl;
00209     //  if (ddsclient) delete ddsclient; ddsclient = 0;
00210     //}
00211     //else break;  // out of primitive while loop
00212     break;
00213   }
00214   
00215 
00216   ms << "The demo will now shutdown the connected client."
00217      << endl; 
00218 
00219   if ( ddsclient ) {
00220     ddsclient -> Shutdown();
00221     delete ddsclient; ddsclient = 0;
00222   }
00223 
00224   return 0;
00225 
00226 }

TROOT root ( "DemoClient"  ,
"MINOS Data Dispatcher System Demo Client"   
)

Generated on 18 Oct 2018 for loon by  doxygen 1.6.1