00001 #include "TIterator.h"
00002 #include "TROOT.h"
00003 #include "TSystem.h"
00004 #include "MessageService/MsgService.h"
00005 #include "MinosObjectMap/MomNavigator.h"
00006 #include "RawData/RawRecord.h"
00007 #include "Persistency/Per.h"
00008 #include "Dispatcher/DDS.h"
00009 #include "Dispatcher/DDSClient.h"
00010 #include "Dispatcher/DDSSubscription.h"
00011
00012 TROOT root("DemoClient","MINOS Data Dispatcher System Demo Client");
00013 CVSID("$Id: DemoClient.cc,v 1.21 2007/08/24 05:39:07 schubert Exp $");
00014
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00032
00033 int main(int argc, char **argv) {
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
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
00068
00069
00070
00071
00072 ddsclient = new DDSClient(serverhostname,9090,DDS::kData,DDS::kEventDisplay,"Control Room");
00073
00074
00075 if (! ddsclient -> IsValid() ) {
00076 ms << "Error in creation of socket connected to server." << endl;
00077 delete ddsclient; ddsclient = 0;
00078 return 1;
00079 }
00080 else {
00081 ms << "Successfully connected to dispatcher server.\n"
00082 << ddsclient << endl;
00083 }
00084
00085
00086
00087
00088
00089
00090
00091 ddsclient->GetSubscription()->SetDataSource(DDS::kDaq);
00092
00093
00094 ddsclient->GetSubscription()->SetStreams("DaqSnarl");
00095
00096
00097
00098
00099
00100
00101
00102 ddsclient->GetSubscription()->SetKeepUpMode(DDS::kRecordKeepUp);
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
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
00130
00131
00132
00133
00134 msgrc = DDS::kOk;
00135 Int_t nentry = 0;
00136 while (msgrc == DDS::kOk) {
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 MomNavigator* mom = 0;
00151 UInt_t waittime = 120;
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 msgrc = ddsclient -> Next(mom,waittime);
00162 if (msgrc == DDS::kOk) {
00163 nentry++;
00164 if ( mom ) {
00165
00166
00167 TIter fiter = mom -> FragmentIter();
00168 RawRecord* rawrecord;
00169 while ( (rawrecord = dynamic_cast<RawRecord*>(fiter.Next())) ) {
00170
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;
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
00207
00208
00209
00210
00211
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 }
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243