Index: gen_nexus/main.cc
===================================================================
--- gen_nexus/main.cc	(revision a35d8a2a4b29f0d809a385c156c0b39d9e5194c1)
+++ gen_nexus/main.cc	(revision 435639f6f3c4ca4625af9a5d7d5347e056d1e1cc)
@@ -7,5 +7,4 @@
 #include <vector>
 #include <iostream>
-
 
 #include <tinyxml.h>
@@ -26,9 +25,7 @@
 int dim[1]={0};
 
-
 int main(int argc, char *argv[])
 //int main()
 {
-	   
     if(argc<=1)
     {
@@ -36,14 +33,11 @@
         return 0;
     }
+
     string beamline = argv[1];
+    //string beamline = "BL01"; //This is for gdb test
     string runNo=argv[2];
-    //string runno = "RUN0006346";
+    //string runNo="RUN0008764"; //This is for gdb test
     //get conf file
-    //string confFile = "/home/durong/git/Earthworm/build/gen_nexus/configure.xml";
     string confFile = "configure.xml";
-	
-    //std::string beamline="BL18";
-    //std::string runNo = "RUN0005474";
-    //string confFile = "/home/durong/git/Earthworm/gen_nexus/configure.xml";
     
     ParserNXS m_nxs(beamline, runNo, confFile);
@@ -52,10 +46,10 @@
     m_nxs.setPublic();
     m_nxs.setInstrument();
-    m_nxs.setEventData();
+    //m_nxs.setEventData();
     m_nxs.setHistData();
- 	
     
     cout<<"finish save nexus"<<endl;
-    string path = "./"+runNo+"/complete.dat";
+    //string path = "./"+runNo+"/complete.dat";
+    string path = "/home/mantid/workspace/recNexus/"+runNo+"/complete.dat";
     std::ofstream markfile;
     markfile.open(path.c_str());
Index: gen_nexus/parserNXS.cc
===================================================================
--- gen_nexus/parserNXS.cc	(revision a35d8a2a4b29f0d809a385c156c0b39d9e5194c1)
+++ gen_nexus/parserNXS.cc	(revision 435639f6f3c4ca4625af9a5d7d5347e056d1e1cc)
@@ -66,6 +66,7 @@
         string filepath = conf_xml.getPath_CONF("controlPath", bl);
         filepath = filepath + "/"+runno;
-	cout<<"we"<<filepath<<endl;
+	cout<<"summary: "<<filepath<<" || "<<run<<endl;
         sumfile = getOneFile(filepath,run,"xml");
+	
 }
 
@@ -74,5 +75,5 @@
         string filepath = conf_xml.getPath_CONF("daqPath", bl);
         filepath = filepath + "/"+runno;
-    	std::vector<std::string> moduleList=conf_xml.getModuleList_CONF("bank", bl);
+        moduleList=conf_xml.getModuleList_CONF("bank", bl);
 	for(const auto &it : moduleList)
 	{
@@ -86,4 +87,17 @@
 		moduleFilelist.insert(make_pair(mName, daqfile));
             }
+	    if (bl=="BL01")
+	    {	
+		for(int k=1; k<=10; k++)
+		{
+		    std::string str = std::to_string(k);
+		    if (str.size()<2)
+			str = "0"+str;
+		    string name = "MODULE"+str;
+		    std::string daqfile = getOneFile(filepath, name, "dat");
+		    moduleFilelist_sans.push_back(daqfile);
+		}
+
+	    }
 	}
 }
@@ -96,7 +110,9 @@
 	{
 	    std::string mName = it;
-	 
-            std::string filepath2 = filepath + "/"+mName+"/"+runno;
+	    std::string upName = mName;
+	    upName[0]=toupper(upName[0]); 
+            std::string filepath2 = filepath + "/"+upName+"/"+runno;
 	    std::string monfile = getOneFile(filepath2, runno, "bin");
+	    cout<<"find monitor file: "<<mName<<"||"<<monfile<<endl;
 	    monitorFilelist.insert(make_pair(mName, monfile));
 	}
@@ -259,9 +275,13 @@
 }
 */
-void ParserNXS::getSANSData(const vector<string> &daqFile, const int pidNum, const int pidStart,  const int tofNum, const int tofStart, const int tofEnd, std::vector<int64_t> &pid, std::vector<float> &tof, std::vector<uint64_t> &pulse, std::vector<uint32_t> &histData, float lowerValue, float upperValue, int bins)
-
-{
-   int pidEnd = pidStart+pidNum; 
-    NumpyHist2D hist2(tofNum, tofStart, tofEnd,pidNum, pidStart, pidEnd);
+void ParserNXS::setSANSData(NXstatus status, NXhandle fileID, const int pidNum, const int pidStart, float lowerValue, float upperValue)
+
+{
+   //int pidEnd = pidStart+pidNum; 
+    //NumpyHist2D hist2(timeBin_bank-1, timeStart_bank, timeEnd_bank, float(pidNum), float(pidStart), float(pidStart+pidNum));
+    NumpyHist2D hist2(10000, 0, 40000, 15000.0, 100001.0-0.5, 115000.0+0.5);
+    //std::vector<uint64_t> pidList;
+    //std::vector<float> tofList;
+    //std::vector<uint64_t> pulseList;
     uint32_t n = 0;            
     uint32_t tmp = 0;
@@ -269,15 +289,21 @@
     int y=0;
     int module=0;
-    for(auto it=daqFile.begin();it!=daqFile.end();it++)
+    for(auto it=moduleFilelist_sans.begin();it!=moduleFilelist_sans.end();it++)
     {
         string filename = *it;
+	//cout<<"start get data from: "<<filename<<endl;
         std::ifstream source(filename, std::ifstream::ate|std::ios_base::binary);
         source.seekg (0, source.end);
-        int length = source.tellg();
+        uint64_t length = source.tellg();
+	uint64_t one = 1;
+	if (length >(one<<32))
+	{
+	std::cout<<"Warning: This file is more than 4G!!!"<<std::endl;
+	}
+	//cout<<"lenth: "<<length<<endl;
         source.seekg (0, source.beg);
         const uint8_t * buffer = new uint8_t [length];
         source.read (reinterpret_cast<char*>(const_cast<uint8_t *>(buffer)),length);
         source.close();
-        
         auto *he3 = new Parser::PackageHe3PosCorr(lowerValue,upperValue);
         std::vector<Parser::HitInfo> hitinfo;
@@ -288,4 +314,5 @@
         {
             event_cnt+=hitinfo.size();
+		
             for(auto v: hitinfo)
             {   
@@ -294,12 +321,15 @@
                 y = v.posy;
                 tmp = 120-(12*(module-1)+y);
-                int pixelID = 100001+bins*(tmp-1)+uint32_t(x/(1000/bins));
-            pid.push_back(pixelID);
-            tof.push_back(v.t);
-            pulse.push_back(v.hit_t0);
+                int pixelID = 100001+125*(tmp-1)+uint32_t(x/(1000/125));
+		//cout<<pixelID<<"||"<<v.t<<endl;
+            //pidList.push_back(pixelID);
+            //tofList.push_back(v.t);
+            //pulseList.push_back(v.hit_t0);
             hist2.fill(v.t,pixelID);
             n++;
-            }   
+            }
+		
         }
+        //cout<<"345"<<endl; 
         delete [] buffer;
         delete he3;
@@ -307,6 +337,12 @@
     }
     auto tmp2 = hist2.getRaw();
-    for(unsigned i=0;i<tmp2.size();i++)
-        histData.push_back(tmp2[i]);
+    std::vector<uint32_t> histData;
+    std::copy(tmp2.cbegin(), tmp2.cend(), std::back_inserter(histData));
+        int slab_size[2]={pidNum,(timeBin_bank-1)};
+        int slab_start[2]={0,0};
+        int dim2D[2]={pidNum, timeBin_bank-1};
+        writeSlabData(status, fileID, "histogram_data",histData.data(), dim2D, slab_start, slab_size, "");
+        histData.clear();
+
 }
 
@@ -480,5 +516,5 @@
 void ParserNXS::getConfInfo()
 {
-    cout<<confName<<endl;
+    cout<<"start get conf: "<<confName<<endl;
     ParserXML conf_xml(confName);
     getSumFile(conf_xml);
@@ -632,5 +668,5 @@
     //CSNSgeometry sampleGeo_info = new_xml.getGeometry("NXsample");
     //setGeometry(status, fileID,"/csns/instrument/sample", sampleGeo_info);
-
+    cout<<"start setBank"<<endl;
     setBank(status, fileID);
     setMonitor(status,fileID);
@@ -650,7 +686,7 @@
     status=NXopen(nxsfile.c_str(), mode, &fileID);
     status=NXopengroup(fileID,"csns","NXentry");
-    for(const auto &it : moduleFilelist)
-    {
-        std::string name = it.first;
+    for(const auto &it : moduleList)
+    {
+        std::string name = it;
         NXlink eventPixelIdLink;
         NXlink eventPulseTimeLink;
@@ -687,7 +723,7 @@
     status=NXopen(nxsfile.c_str(), mode, &fileID);
     status=NXopengroup(fileID,"csns","NXentry");
-    for(const auto &it : moduleFilelist)
-    {
-        std::string name = it.first;
+    for(const auto &it : moduleList)
+    {
+        std::string name = it;
         string path ="/csns/instrument/"+name;
         NXlink HistTimeOfFlightLink;
@@ -900,8 +936,8 @@
     delay_bank = getIntFromMap(bankInfo,"delay");
     std::string localName = getStringFromMap(bankInfo, "local_name");
-
-    for(const auto &it : moduleFilelist)
-    {
-        std::string moduleName = it.first;
+    cout<<"local name: "<<localName<<endl;
+    for(const auto &it : moduleList)
+    {
+        std::string moduleName = it;
 	std::cout<<moduleName<<endl;
         writeGroup(status, fileID, moduleName.c_str(), "NXdetector");
@@ -936,9 +972,16 @@
         setTof(status,fileID,timeStart_bank,timeBin_bank,timeStep_bank, delay_bank);        
 
-	std::string daqfile = it.second;
+	std::string daqfile = moduleFilelist[moduleName];
+	//std::string daqfile = it.second;
 	if(bl=="BL18")
+	{    
 	    setGPPDData(status, fileID, daqfile, pidNum,idstart);
-        
-	NXclosegroup(fileID);//close module
+	}
+        if(bl=="BL01")
+        {
+		cout<<"start set daq data"<<endl;
+	    setSANSData(status, fileID, pidNum,idstart, 1000.0, 6000.0); 
+	}
+        NXclosegroup(fileID);//close module
     }
     bankInfo.clear();
@@ -953,11 +996,15 @@
 
     map<string, string> pcInfo = sum_xml.getPublic_SUM();
+    
     float pcValue = getFloatFromMap(pcInfo,"proton_charge");
-
+    cout<<"find pc: "<<pcValue<<endl;
 
     for(const auto &it : monitorFilelist)
     {
         std::string monitorName = it.first;
-        writeGroup(status, fileID, monitorName.c_str(), "NXdmonitor");
+	cout<<"start with: "<<monitorName<<endl;
+	status=NXmakegroup(fileID,monitorName.c_str(),"NXmonitor");
+	status=NXopengroup(fileID,monitorName.c_str(),"NXmonitor");
+        //writeGroup(status, fileID, monitorName.c_str(), "NXmonitor");
         std::map<std::string, std::string> monInfo = sum_xml.getMon_SUM(monitorName);
     	delay_monitor = getIntFromMap(monInfo,"delay");
@@ -965,30 +1012,23 @@
 	writeCharData(status, fileID, "local_name", localName);
 
-        //std::map<std::string, std::string> pidInfo = idf_xml.getPixels_IDF(monitorName);
-        //int xpid = getIntFromMap(pidInfo,"xpixels");
-        //int ypid = getIntFromMap(pidInfo,"ypixels");
-	//int pidNum = xpid*ypid;
-        //int idstart = getIntFromMap(pidInfo,"idstart");
-        //setPid(status, fileID, idstart, xpid, ypid);
-        //float xstep = getFloatFromMap(pidInfo, "xsize"); 
-        //float ystep = getFloatFromMap(pidInfo, "ysize"); 
-        //setPidSize(status, fileID, xstep, ystep, xpid, ypid);
-
-        //std::map<std::string, std::string> modulePos = idf_xml.getModulePos_IDF(moduleName);
-        //float xpos = getFloatFromMap(modulePos, "xpos"); 
-        //float ypos = getFloatFromMap(modulePos, "ypos"); 
-        //float zpos = getFloatFromMap(modulePos, "zpos"); 
-        //float rot = getFloatFromMap(modulePos, "rot"); 
-        //setCoordinate(status, fileID, xpos,ypos,zpos,xstep,ystep,rot,xpid, ypid); 
         setTof(status,fileID,timeStart_monitor,timeBin_monitor,timeStep_monitor, delay_monitor);        
-
 	std::string monfile = it.second;
-	if(bl=="BL18")
+	cout<<"monitor file: "<<monfile<<endl;
+	if(bl=="BL18"){
+		int xpid = 32;
+		int ypid = 32;
+		int idstart = 1;
+		setPid(status, fileID, idstart, xpid, ypid);
 		setMonData(status, fileID, monfile,  1024, pcValue);
+	}	
 	if(bl=="BL01")
 	{
+		int xpid = 1;
+		int ypid = 1;
+		int idstart = 1;
+		setPid(status, fileID, idstart, xpid, ypid);
 		setMonData(status, fileID, monfile,  1, pcValue);
 	}
-        NXclosegroup(fileID);//close module
+        NXclosegroup(fileID);//close monitor
     }
 }
@@ -1125,4 +1165,5 @@
 {
     FileReader reader(filename);
+    cout<<filename<<endl;
     std::vector<uint8_t> data;
     reader.readAll(data);
Index: gen_nexus/parserNXS.h
===================================================================
--- gen_nexus/parserNXS.h	(revision a35d8a2a4b29f0d809a385c156c0b39d9e5194c1)
+++ gen_nexus/parserNXS.h	(revision 435639f6f3c4ca4625af9a5d7d5347e056d1e1cc)
@@ -61,4 +61,6 @@
 	std::map<std::string, std::string> monitorFilelist;
 	std::map<std::string, std::string> moduleFilelist;
+	std::vector<std::string> moduleFilelist_sans;
+	std::vector<std::string> moduleList;
 
         std::vector<std::string> split(string str, string sep);
@@ -110,4 +112,6 @@
         void setTof(NXstatus status, NXhandle fileID,const int tStart, const int tBin, const int tStep, const uint32_t delay);
 	void setGPPDData(NXstatus status, NXhandle fileID, std::string filename,  const int pidNum,const int pidStart);
+	void setSANSData(NXstatus status, NXhandle fileID, const int pidNum, const int pidStart, float lowerValue, float upperValue);
+
         void setMonData(NXstatus status, NXhandle fileID, std::string filename,  const int pidNum, const float pc); 
 	//void getHistDataFromDrone(string prepath,string moduleName, std::vector<uint32_t> &histData);
