22 #include <TSemaphore.h>
25 #include <TServerSocket.h>
28 #include <TObjString.h>
29 #include <TObjArray.h>
39 fprintf(stderr,
"VerboseMidasServer: change verbose level from %d to %d\n",
gVerbose, verbose);
49 #define XPOINTER_T uint32_t
66 printf(
"converted %d to \'%s\'\n", p, name);
68 TObject* obj = gROOT->FindObjectAny(name);
73 return (TFolder*) obj;
85 TSocket *sock = (TSocket *) arg;
86 TMessage message(kMESS_OBJECT);
91 int rd = sock->Recv(request,
sizeof(request));
100 printf(
"Request %s\n", request);
102 if (strcmp(request,
"GetListOfFolders") == 0) {
107 if (folder == NULL) {
108 message.Reset(kMESS_OBJECT);
109 message.WriteObject(NULL);
116 TObjArray *names =
new TObjArray(100);
118 TCollection *folders = folder->GetListOfFolders();
119 TIterator *iterFolders = folders->MakeIterator();
120 while ((obj = iterFolders->Next()) != NULL)
121 names->Add(
new TObjString(obj->GetName()));
124 message.Reset(kMESS_OBJECT);
125 message.WriteObject(names);
128 for (
int i = 0; i < names->GetLast() + 1; i++)
129 delete(TObjString *) names->At(i);
133 }
else if (strncmp(request,
"FindObject", 10) == 0) {
141 if (strncmp(request + 10,
"Any", 3) == 0)
142 obj = folder->FindObjectAny(request + 14);
144 obj = folder->FindObject(request + 11);
150 message.Reset(kMESS_OBJECT);
151 message.WriteObject(obj);
157 }
else if (strncmp(request,
"FindFullPathName", 16) == 0) {
164 const char *path = folder->FindFullPathName(request + 17);
170 TObjString *obj =
new TObjString(path);
171 message.Reset(kMESS_OBJECT);
172 message.WriteObject(obj);
178 }
else if (strncmp(request,
"GetPointer", 10) == 0) {
182 TObject *obj = gROOT->FindObjectAny(request + 11);
185 message.Reset(kMESS_ANY);
189 const char* name = obj->GetName();
199 printf(
"give %d for \'%s\'\n", p, name);
205 }
else if (strncmp(request,
"Command", 7) == 0) {
206 char objName[100], method[100];
207 sock->Recv(objName,
sizeof(objName));
208 sock->Recv(method,
sizeof(method));
212 TObject *
object = gROOT->FindObjectAny(objName);
213 if (
object && object->InheritsFrom(TH1::Class())
214 && strcmp(method,
"Reset") == 0)
215 static_cast < TH1 *
>(object)->Reset();
217 }
else if (strncmp(request,
"SetCut", 6) == 0) {
221 sock->Recv(name,
sizeof(name));
229 TCutG *newc = ((TCutG *) m->ReadObject(m->GetClass()));
232 fprintf(stderr,
"root server thread: changing cut %s\n", newc->GetName());
233 newc->TAttMarker::Copy(*cut);
234 newc->TAttFill::Copy(*cut);
235 newc->TAttLine::Copy(*cut);
236 newc->TNamed::Copy(*cut);
237 cut->Set(newc->GetN());
238 for (
int i = 0; i < cut->GetN(); ++i) {
239 cut->SetPoint(i, newc->GetX()[i], newc->GetY()[i]);
242 fprintf(stderr,
"root server thread: ignoring receipt of unknown cut \'%s\'\n",
248 fprintf(stderr,
"midasServer: Received unknown request \"%s\"\n", request);
264 printf(
"MIDAS ROOT server listening on port %d...\n", port);
265 TServerSocket *lsock =
new TServerSocket(port, kTRUE);
268 TSocket *sock = lsock->Accept();
271 fprintf(stderr,
"MIDAS ROOT server accept() error\n");
280 LPDWORD lpThreadId = 0;
293 gManaHistosFolder = gROOT->GetRootFolder()->AddFolder(
"histos",
"MIDAS Analyzer Histograms");
298 static int pport = port;
304 LPDWORD lpThreadId = 0;
void StartLockRootTimer(int period_msec=100)
static std::map< XPOINTER_T, std::string > gPointers
void VerboseMidasServer(bool verbose)
static std::map< std::string, XPOINTER_T > gRevPointers
TFolder * ReadFolderPointer(TSocket *fSocket)
TFolder * gManaHistosFolder
static XPOINTER_T gLastPointer
void root_socket_server(void *arg)
void StartMidasServer(int port)
void root_server_thread(void *arg)