00001 #include "ArchivingWorkerGroup.h"
00002 #include "archiving/ArchRawScanResult.h"
00003 #include "archiving/ArchFitScanResult.h"
00004 #include "archiving/ArchNPtGainTestResult.h"
00005 #include "archiving/ArchNoiseOccupancyTestResult.h"
00006 #include "archiving/ArchStrobeDelayTestResult.h"
00007 #include "archiving/ArchTrimRangeTestResult.h"
00008 #include "archiving/ArchTimeWalkTestResult.h"
00009 #include "archiving/ArchPipelineTestResult.h"
00010 #include "archiving/ArchFullBypassTestResult.h"
00011 #include "archiving/ArchNMaskTestResult.h"
00012 #include "archiving/ArchivingManager.h"
00013 
00014 
00015 
00016 #include "Sct/LogicErrors.h"
00017 
00018 using namespace Sct;
00019 using namespace SctData;
00020 using namespace boost;
00021 
00022 namespace SctArchivingService {
00023     
00024 void ArchivingWorkerGroup::work(shared_ptr<Serializable> ob) throw() {
00025   try {
00026     if (!ob) throw InvalidArgumentError("Failed to get object from IS", __FILE__, __LINE__);
00027     
00028     
00032       if(ob->getClassName() == "SctData::FitScanResult" || ob->getClassName() == "SctData::RawScanResult") {
00033     
00034     
00035     
00036     {
00037       boost::recursive_mutex::scoped_lock lock(m_file_access);  
00038       shared_ptr<ArchScanResult> myScanArchiving = ArchivingManager::instance().getScanFromMap(ob);
00039       shared_ptr<ScanResult> scan = dynamic_pointer_cast<ScanResult>(ob);
00040       
00041       shared_ptr<ArchScanResult> cloned_scan = myScanArchiving->clone(scan);
00042       
00043       
00044       unsigned long runno = scan->getHeader().getRunNumber();
00045       unsigned long scanno = scan->getHeader().getScanNumber();
00046       
00047     
00048       while (findTest(runno, scanno).get() == 0  ) {
00049         
00050         sleep(1);
00051         cout<<"RawScanWork: I am sleeping"<<endl;
00052       }
00053       
00054     
00055       cout<< "(Work) About to save ScanResult... " << endl;
00056       cloned_scan->SetUNIXDir();
00057       string testName = findTest( runno, scanno )->getTest().testName;
00058       cout <<"TestName = " << testName<<endl;
00059       cloned_scan->SetTestType(testName);
00060       
00061       cloned_scan->Save();
00062     }
00063  
00064     cout<< "ScanResult Correctly Saved (work) " << endl;
00065     return;
00066       }
00067       
00068     
00069 
00070 
00073       if(ob->getClassName() == "SctData::FullBypassTestResult" 
00074      || ob->getClassName() == "SctData::NMaskTestResult"
00075      || ob->getClassName() == "SctData::NoiseOccupancyTestResult" 
00076      || ob->getClassName() == "SctData::NPtGainTestResult" 
00077      || ob->getClassName() == "SctData::PipelineTestResult"
00078      || ob->getClassName() == "SctData::StrobeDelayTestResult"
00079      || ob->getClassName() == "SctData::TimeWalkTestResult"
00080      || ob->getClassName() == "SctData::TrimRangeTestResult") {
00081     
00082     {
00083       boost::recursive_mutex::scoped_lock lock(m_file_access); 
00084       
00085       shared_ptr<ArchTestResult> myTestArchiving = ArchivingManager::instance().getTestFromMap(ob);
00086       shared_ptr<TestResult> test = dynamic_pointer_cast<TestResult>(ob);
00087       
00088       shared_ptr<ArchTestResult> cloned_test = myTestArchiving->clone(test);
00089       
00090       
00091       cout<< "(Work) About to save TestResult... " << endl;
00092       cloned_test->SetUNIXDir();
00093       
00094     
00095       cloned_test->Save();
00096     }
00097     cout<< "TestResult Correctly Saved (work) " << endl;
00098     return;
00099       }
00100       
00101       
00102       
00103     
00104     
00105     
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 
00138     
00139     
00140 
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156 
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 
00165 
00166 
00167 
00168 
00169 
00170 
00171 
00172 
00173 
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181 
00182 
00183 
00184 
00185 
00186 
00187 
00188 
00189 
00190 
00191 
00192 
00193 
00194 
00195 
00196 
00197 
00198 
00199 
00200 
00201 
00202 
00203 
00204 
00205 
00206 
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00215 
00216 
00217 
00218 
00219 
00220 
00221 
00222 
00223 
00224 
00225 
00226 
00227 
00228 
00229 
00230 
00231 
00232 
00233 
00234 
00235 
00236 
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 
00245 
00246 
00247 
00248 
00249 
00250 
00251 
00252 
00253 
00254 
00255 
00256 
00257 
00258 
00259 
00260 
00261 
00262 
00263 
00264       throw InvalidArgumentError("The object on IS is an unknown Test type: " + ob->getClassName(), __FILE__, __LINE__);
00265   } catch(Throwable& e) {
00266     e.sendToMrs(MRS_ERROR);
00267   }
00268   
00269 
00270   
00271 
00272 
00273 
00274 }    
00275 
00276 
00277 
00278 
00279 shared_ptr<ArchivingWorkerGroup::TestAlgs> ArchivingWorkerGroup::findTest(const TestData& testdata) const throw() {
00280     return findTest(testdata.runNumber, testdata.startScanNumber);
00281 }
00282 
00283 
00284 shared_ptr<ArchivingWorkerGroup::TestAlgs> ArchivingWorkerGroup::findTest(const unsigned long runno, const unsigned long scanno) const throw() {
00285     
00286     shared_ptr<ArchivingWorkerGroup::TestAlgs> talgs;
00287     for (list<shared_ptr<TestAlgs> >::const_iterator it = m_tests.begin();
00288             it != m_tests.end();
00289             ++it ) {
00290         const TestData& td=(*it)->getTest();
00291         if ( runno == td.runNumber &&
00292                 scanno >= td.startScanNumber &&
00293                 scanno < td.startScanNumber + td.nScans) {
00294             talgs=*it;
00295             cout << "found test for run " << runno<< ", scan " << scanno << endl;
00296         }
00297     }
00298     return talgs;
00299 }
00300 
00301 
00302 
00303 void ArchivingWorkerGroup::addTest(shared_ptr<const TestData> testdata) {
00304   boost::recursive_mutex::scoped_lock lock(m_tests_access);
00305   m_tests.push_back(shared_ptr<TestAlgs>(new TestAlgs(testdata) ) );
00306 
00307    
00308 }
00309 
00310 
00311 
00312   
00313 
00314 
00315 
00316 
00317 
00318 
00319 
00320 
00321 
00322 
00323 
00324 
00325 
00326 
00327 
00328 
00329 
00330 
00331 
00332 
00333 
00334 
00335 
00336 
00337 
00338 
00339 
00340 
00341 
00342 
00343 
00344 
00345 
00346 
00347 
00348 
00349 
00350 
00351 
00352 
00353 
00354 
00355 
00356 
00357 
00358 
00359 
00360 
00361 
00362 
00363 
00364 
00365 
00366 
00367 
00368 
00369 
00370 
00371 
00372 
00373 
00374 
00375 
00376 
00377 
00378 
00379 
00380 
00381 
00382 
00383 
00384 
00385 
00386 ArchivingWorkerGroup::TestAlgs::~TestAlgs() {
00387   
00388 
00389     
00390     
00391     
00392    
00393 }
00394 
00395 ostream& ArchivingWorkerGroup::TestAlgs::printStatus(ostream& os) const throw() {
00396     
00397     os << "   Test name: "  << getTest().testName 
00398        << ", run number = " << getTest().runNumber
00399        << ", first scan number = " << getTest().startScanNumber
00400        << ", nscans = " << getTest().nScans 
00401        <<  endl;
00402 
00403     
00404     return os;
00405 }
00406 
00407 
00408 
00409 
00410 
00411 
00412 
00413 
00414 }